des.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* des.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* des.h defines mini des openssl compatibility layer
  22. *
  23. */
  24. #ifndef WOLFSSL_DES_H_
  25. #define WOLFSSL_DES_H_
  26. #include <wolfssl/wolfcrypt/settings.h>
  27. #ifndef NO_DES3
  28. #ifdef WOLFSSL_PREFIX
  29. #include "prefix_des.h"
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. typedef unsigned char WOLFSSL_DES_cblock[8];
  35. typedef /* const */ WOLFSSL_DES_cblock WOLFSSL_const_DES_cblock;
  36. typedef WOLFSSL_DES_cblock WOLFSSL_DES_key_schedule;
  37. typedef unsigned int WOLFSSL_DES_LONG;
  38. enum {
  39. DES_ENCRYPT = 1,
  40. DES_DECRYPT = 0
  41. };
  42. WOLFSSL_API int wolfSSL_DES_is_weak_key(WOLFSSL_const_DES_cblock* key);
  43. WOLFSSL_API WOLFSSL_DES_LONG wolfSSL_DES_cbc_cksum(const unsigned char* in,
  44. WOLFSSL_DES_cblock* out, long length, WOLFSSL_DES_key_schedule* sc,
  45. WOLFSSL_const_DES_cblock* iv);
  46. WOLFSSL_API int wolfSSL_DES_set_key(WOLFSSL_const_DES_cblock* myDes,
  47. WOLFSSL_DES_key_schedule* key);
  48. WOLFSSL_API int wolfSSL_DES_set_key_checked(WOLFSSL_const_DES_cblock* myDes,
  49. WOLFSSL_DES_key_schedule* key);
  50. WOLFSSL_API void wolfSSL_DES_set_key_unchecked(WOLFSSL_const_DES_cblock* myDes,
  51. WOLFSSL_DES_key_schedule* key);
  52. WOLFSSL_API int wolfSSL_DES_key_sched(WOLFSSL_const_DES_cblock* key,
  53. WOLFSSL_DES_key_schedule* schedule);
  54. WOLFSSL_API void wolfSSL_DES_cbc_encrypt(const unsigned char* input,
  55. unsigned char* output, long length,
  56. WOLFSSL_DES_key_schedule* schedule, WOLFSSL_DES_cblock* ivec,
  57. int enc);
  58. WOLFSSL_API void wolfSSL_DES_ede3_cbc_encrypt(const unsigned char* input,
  59. unsigned char* output, long sz,
  60. WOLFSSL_DES_key_schedule* ks1,
  61. WOLFSSL_DES_key_schedule* ks2,
  62. WOLFSSL_DES_key_schedule* ks3,
  63. WOLFSSL_DES_cblock* ivec, int enc);
  64. WOLFSSL_API void wolfSSL_DES_ncbc_encrypt(const unsigned char* input,
  65. unsigned char* output, long length,
  66. WOLFSSL_DES_key_schedule* schedule,
  67. WOLFSSL_DES_cblock* ivec, int enc);
  68. WOLFSSL_API void wolfSSL_DES_set_odd_parity(WOLFSSL_DES_cblock* myDes);
  69. WOLFSSL_API void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* desa,
  70. WOLFSSL_DES_cblock* desb, WOLFSSL_DES_key_schedule* key, int enc);
  71. WOLFSSL_API int wolfSSL_DES_check_key_parity(WOLFSSL_DES_cblock *myDes);
  72. typedef WOLFSSL_DES_cblock DES_cblock;
  73. typedef WOLFSSL_const_DES_cblock const_DES_cblock;
  74. typedef WOLFSSL_DES_key_schedule DES_key_schedule;
  75. typedef WOLFSSL_DES_LONG DES_LONG;
  76. #define DES_check_key(x) /* Define WOLFSSL_CHECK_DESKEY to check key */
  77. #define DES_is_weak_key wolfSSL_DES_is_weak_key
  78. #define DES_set_key wolfSSL_DES_set_key
  79. #define DES_set_key_checked wolfSSL_DES_set_key_checked
  80. #define DES_set_key_unchecked wolfSSL_DES_set_key_unchecked
  81. #define DES_key_sched wolfSSL_DES_key_sched
  82. #define DES_cbc_encrypt wolfSSL_DES_cbc_encrypt
  83. #define DES_ncbc_encrypt wolfSSL_DES_ncbc_encrypt
  84. #define DES_set_odd_parity wolfSSL_DES_set_odd_parity
  85. #define DES_ecb_encrypt wolfSSL_DES_ecb_encrypt
  86. #define DES_ede3_cbc_encrypt wolfSSL_DES_ede3_cbc_encrypt
  87. #define DES_cbc_cksum wolfSSL_DES_cbc_cksum
  88. #define DES_check_key_parity wolfSSL_DES_check_key_parity
  89. #ifdef __cplusplus
  90. } /* extern "C" */
  91. #endif
  92. #endif /* NO_DES3 */
  93. #endif /* WOLFSSL_DES_H_ */