des.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. const char *DES_options(void);
  52. void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
  53. DES_key_schedule *ks1, DES_key_schedule *ks2,
  54. DES_key_schedule *ks3, int enc);
  55. DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
  56. long length, DES_key_schedule *schedule,
  57. const_DES_cblock *ivec);
  58. /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
  59. void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
  60. long length, DES_key_schedule *schedule,
  61. DES_cblock *ivec, int enc);
  62. void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
  63. long length, DES_key_schedule *schedule,
  64. DES_cblock *ivec, int enc);
  65. void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
  66. long length, DES_key_schedule *schedule,
  67. DES_cblock *ivec, const_DES_cblock *inw,
  68. const_DES_cblock *outw, int enc);
  69. void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
  70. long length, DES_key_schedule *schedule,
  71. DES_cblock *ivec, int enc);
  72. void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
  73. DES_key_schedule *ks, int enc);
  74. /*
  75. * This is the DES encryption function that gets called by just about every
  76. * other DES routine in the library. You should not use this function except
  77. * to implement 'modes' of DES. I say this because the functions that call
  78. * this routine do the conversion from 'char *' to long, and this needs to be
  79. * done to make sure 'non-aligned' memory access do not occur. The
  80. * characters are loaded 'little endian'. Data is a pointer to 2 unsigned
  81. * long's and ks is the DES_key_schedule to use. enc, is non zero specifies
  82. * encryption, zero if decryption.
  83. */
  84. void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc);
  85. /*
  86. * This functions is the same as DES_encrypt1() except that the DES initial
  87. * permutation (IP) and final permutation (FP) have been left out. As for
  88. * DES_encrypt1(), you should not use this function. It is used by the
  89. * routines in the library that implement triple DES. IP() DES_encrypt2()
  90. * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1()
  91. * DES_encrypt1() DES_encrypt1() except faster :-).
  92. */
  93. void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
  94. void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
  95. DES_key_schedule *ks2, DES_key_schedule *ks3);
  96. void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
  97. DES_key_schedule *ks2, DES_key_schedule *ks3);
  98. void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
  99. long length,
  100. DES_key_schedule *ks1, DES_key_schedule *ks2,
  101. DES_key_schedule *ks3, DES_cblock *ivec, int enc);
  102. void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
  103. long length, DES_key_schedule *ks1,
  104. DES_key_schedule *ks2, DES_key_schedule *ks3,
  105. DES_cblock *ivec, int *num, int enc);
  106. void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
  107. int numbits, long length, DES_key_schedule *ks1,
  108. DES_key_schedule *ks2, DES_key_schedule *ks3,
  109. DES_cblock *ivec, int enc);
  110. void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  111. long length, DES_key_schedule *ks1,
  112. DES_key_schedule *ks2, DES_key_schedule *ks3,
  113. DES_cblock *ivec, int *num);
  114. char *DES_fcrypt(const char *buf, const char *salt, char *ret);
  115. char *DES_crypt(const char *buf, const char *salt);
  116. void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
  117. long length, DES_key_schedule *schedule,
  118. DES_cblock *ivec);
  119. void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
  120. long length, DES_key_schedule *schedule,
  121. DES_cblock *ivec, int enc);
  122. DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
  123. long length, int out_count, DES_cblock *seed);
  124. int DES_random_key(DES_cblock *ret);
  125. void DES_set_odd_parity(DES_cblock *key);
  126. int DES_check_key_parity(const_DES_cblock *key);
  127. int DES_is_weak_key(const_DES_cblock *key);
  128. /*
  129. * DES_set_key (= set_key = DES_key_sched = key_sched) calls
  130. * DES_set_key_unchecked
  131. */
  132. int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
  133. int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
  134. int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
  135. void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
  136. void DES_string_to_key(const char *str, DES_cblock *key);
  137. void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
  138. void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
  139. long length, DES_key_schedule *schedule,
  140. DES_cblock *ivec, int *num, int enc);
  141. void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
  142. long length, DES_key_schedule *schedule,
  143. DES_cblock *ivec, int *num);
  144. # define DES_fixup_key_parity DES_set_odd_parity
  145. # ifdef __cplusplus
  146. }
  147. # endif
  148. # endif
  149. #endif