des.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef HEADER_DES_H
  10. # define HEADER_DES_H
  11. # include <openssl/opensslconf.h>
  12. # ifndef OPENSSL_NO_DES
  13. # ifdef __cplusplus
  14. extern "C" {
  15. # endif
  16. # include <openssl/e_os2.h>
  17. typedef unsigned int DES_LONG;
  18. # ifdef OPENSSL_BUILD_SHLIBCRYPTO
  19. # undef OPENSSL_EXTERN
  20. # define OPENSSL_EXTERN OPENSSL_EXPORT
  21. # endif
  22. typedef unsigned char DES_cblock[8];
  23. typedef /* const */ unsigned char const_DES_cblock[8];
  24. /*
  25. * With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and
  26. * const_DES_cblock * are incompatible pointer types.
  27. */
  28. typedef struct DES_ks {
  29. union {
  30. DES_cblock cblock;
  31. /*
  32. * make sure things are correct size on machines with 8 byte longs
  33. */
  34. DES_LONG deslong[2];
  35. } ks[16];
  36. } DES_key_schedule;
  37. # define DES_KEY_SZ (sizeof(DES_cblock))
  38. # define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
  39. # define DES_ENCRYPT 1
  40. # define DES_DECRYPT 0
  41. # define DES_CBC_MODE 0
  42. # define DES_PCBC_MODE 1
  43. # define DES_ecb2_encrypt(i,o,k1,k2,e) \
  44. DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
  45. # define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
  46. DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
  47. # define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
  48. DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
  49. # define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
  50. DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
  51. OPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */
  52. # define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
  53. const char *DES_options(void);
  54. void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
  55. DES_key_schedule *ks1, DES_key_schedule *ks2,
  56. DES_key_schedule *ks3, int enc);
  57. DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
  58. long length, DES_key_schedule *schedule,
  59. const_DES_cblock *ivec);
  60. /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
  61. void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
  62. long length, DES_key_schedule *schedule,
  63. DES_cblock *ivec, int enc);
  64. void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
  65. long length, DES_key_schedule *schedule,
  66. DES_cblock *ivec, int enc);
  67. void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
  68. long length, DES_key_schedule *schedule,
  69. DES_cblock *ivec, const_DES_cblock *inw,
  70. const_DES_cblock *outw, int enc);
  71. void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
  72. long length, DES_key_schedule *schedule,
  73. DES_cblock *ivec, int enc);
  74. void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
  75. DES_key_schedule *ks, int enc);
  76. /*
  77. * This is the DES encryption function that gets called by just about every
  78. * other DES routine in the library. You should not use this function except
  79. * to implement 'modes' of DES. I say this because the functions that call
  80. * this routine do the conversion from 'char *' to long, and this needs to be
  81. * done to make sure 'non-aligned' memory access do not occur. The
  82. * characters are loaded 'little endian'. Data is a pointer to 2 unsigned
  83. * long's and ks is the DES_key_schedule to use. enc, is non zero specifies
  84. * encryption, zero if decryption.
  85. */
  86. void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc);
  87. /*
  88. * This functions is the same as DES_encrypt1() except that the DES initial
  89. * permutation (IP) and final permutation (FP) have been left out. As for
  90. * DES_encrypt1(), you should not use this function. It is used by the
  91. * routines in the library that implement triple DES. IP() DES_encrypt2()
  92. * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1()
  93. * DES_encrypt1() DES_encrypt1() except faster :-).
  94. */
  95. void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
  96. void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
  97. DES_key_schedule *ks2, DES_key_schedule *ks3);
  98. void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
  99. DES_key_schedule *ks2, DES_key_schedule *ks3);
  100. void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
  101. long length,
  102. DES_key_schedule *ks1, DES_key_schedule *ks2,
  103. DES_key_schedule *ks3, DES_cblock *ivec, int enc);
  104. void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
  105. long length, DES_key_schedule *ks1,
  106. DES_key_schedule *ks2, DES_key_schedule *ks3,
  107. DES_cblock *ivec, int *num, int enc);
  108. void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
  109. int numbits, long length, DES_key_schedule *ks1,
  110. DES_key_schedule *ks2, DES_key_schedule *ks3,
  111. DES_cblock *ivec, int enc);
  112. void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  113. long length, DES_key_schedule *ks1,
  114. DES_key_schedule *ks2, DES_key_schedule *ks3,
  115. DES_cblock *ivec, int *num);
  116. char *DES_fcrypt(const char *buf, const char *salt, char *ret);
  117. char *DES_crypt(const char *buf, const char *salt);
  118. void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
  119. long length, DES_key_schedule *schedule,
  120. DES_cblock *ivec);
  121. void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
  122. long length, DES_key_schedule *schedule,
  123. DES_cblock *ivec, int enc);
  124. DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
  125. long length, int out_count, DES_cblock *seed);
  126. int DES_random_key(DES_cblock *ret);
  127. void DES_set_odd_parity(DES_cblock *key);
  128. int DES_check_key_parity(const_DES_cblock *key);
  129. int DES_is_weak_key(const_DES_cblock *key);
  130. /*
  131. * DES_set_key (= set_key = DES_key_sched = key_sched) calls
  132. * DES_set_key_checked if global variable DES_check_key is set,
  133. * DES_set_key_unchecked otherwise.
  134. */
  135. int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
  136. int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
  137. int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
  138. void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
  139. void DES_string_to_key(const char *str, DES_cblock *key);
  140. void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
  141. void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
  142. long length, DES_key_schedule *schedule,
  143. DES_cblock *ivec, int *num, int enc);
  144. void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  145. long length, DES_key_schedule *schedule,
  146. DES_cblock *ivec, int *num);
  147. # define DES_fixup_key_parity DES_set_odd_parity
  148. # ifdef __cplusplus
  149. }
  150. # endif
  151. # endif
  152. #endif