des3.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file des3.h
  3. * @brief Triple DES (Triple Data Encryption Algorithm)
  4. *
  5. * @section License
  6. *
  7. * SPDX-License-Identifier: GPL-2.0-or-later
  8. *
  9. * Copyright (C) 2010-2023 Oryx Embedded SARL. All rights reserved.
  10. *
  11. * This file is part of CycloneCRYPTO Open.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version 2
  16. * of the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software Foundation,
  25. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  26. *
  27. * @author Oryx Embedded SARL (www.oryx-embedded.com)
  28. * @version 2.2.4
  29. **/
  30. #ifndef _DES3_H
  31. #define _DES3_H
  32. //Dependencies
  33. #include "core/crypto.h"
  34. #include "cipher/des.h"
  35. //Application specific context
  36. #ifndef DES3_PRIVATE_CONTEXT
  37. #define DES3_PRIVATE_CONTEXT
  38. #endif
  39. //Triple DES block size
  40. #define DES3_BLOCK_SIZE 8
  41. //Common interface for encryption algorithms
  42. #define DES3_CIPHER_ALGO (&des3CipherAlgo)
  43. //C++ guard
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /**
  48. * @brief Triple DES algorithm context
  49. **/
  50. typedef struct
  51. {
  52. DesContext k1;
  53. DesContext k2;
  54. DesContext k3;
  55. DES3_PRIVATE_CONTEXT
  56. } Des3Context;
  57. //Triple DES related constants
  58. extern const CipherAlgo des3CipherAlgo;
  59. //Triple DES related functions
  60. error_t des3Init(Des3Context *context, const uint8_t *key, size_t keyLen);
  61. void des3EncryptBlock(Des3Context *context, const uint8_t *input,
  62. uint8_t *output);
  63. void des3DecryptBlock(Des3Context *context, const uint8_t *input,
  64. uint8_t *output);
  65. void des3Deinit(Des3Context *context);
  66. //C++ guard
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif