Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
11 KiB

  1. /* $OpenBSD: des.h,v 1.4 2002/03/04 22:00:13 deraadt Exp $ */
  2. /* crypto/des/des.h */
  3. /* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
  4. * All rights reserved.
  5. *
  6. * This package is an SSL implementation written
  7. * by Eric Young (eay@mincom.oz.au).
  8. * The implementation was written so as to conform with Netscapes SSL.
  9. *
  10. * This library is free for commercial and non-commercial use as long as
  11. * the following conditions are aheared to. The following conditions
  12. * apply to all code found in this distribution, be it the RC4, RSA,
  13. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  14. * included with this distribution is covered by the same copyright terms
  15. * except that the holder is Tim Hudson (tjh@mincom.oz.au).
  16. *
  17. * Copyright remains Eric Young's, and as such any Copyright notices in
  18. * the code are not to be removed.
  19. * If this package is used in a product, Eric Young should be given attribution
  20. * as the author of the parts of the library used.
  21. * This can be in the form of a textual message at program startup or
  22. * in documentation (online or textual) provided with the package.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. * 1. Redistributions of source code must retain the copyright
  28. * notice, this list of conditions and the following disclaimer.
  29. * 2. Redistributions in binary form must reproduce the above copyright
  30. * notice, this list of conditions and the following disclaimer in the
  31. * documentation and/or other materials provided with the distribution.
  32. * 3. All advertising materials mentioning features or use of this software
  33. * must display the following acknowledgement:
  34. * "This product includes cryptographic software written by
  35. * Eric Young (eay@mincom.oz.au)"
  36. * The word 'cryptographic' can be left out if the rouines from the library
  37. * being used are not cryptographic related :-).
  38. * 4. If you include any Windows specific code (or a derivative thereof) from
  39. * the apps directory (application code) you must include an acknowledgement:
  40. * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)"
  41. *
  42. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  43. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  45. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  46. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  47. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  48. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  49. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  52. * SUCH DAMAGE.
  53. *
  54. * The licence and distribution terms for any publically available version or
  55. * derivative of this code cannot be changed. i.e. this code cannot simply be
  56. * copied and put under another distribution licence
  57. * [including the GNU Public Licence.]
  58. */
  59. #ifndef HEADER_DES_H
  60. #define HEADER_DES_H
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. #include <stdio.h>
  65. #define DES_LONG unsigned int
  66. typedef unsigned char des_cblock[8];
  67. typedef struct des_ks_struct
  68. {
  69. union {
  70. des_cblock _;
  71. /* make sure things are correct size on machines with
  72. * 8 byte longs */
  73. DES_LONG pad[2];
  74. } ks;
  75. #undef _
  76. #define _ ks._
  77. } des_key_schedule[16];
  78. #define DES_KEY_SZ (sizeof(des_cblock))
  79. #define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
  80. #define DES_ENCRYPT 1
  81. #define DES_DECRYPT 0
  82. #define DES_CBC_MODE 0
  83. #define DES_PCBC_MODE 1
  84. #define des_ecb2_encrypt(i,o,k1,k2,e) \
  85. des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
  86. #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
  87. des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
  88. #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
  89. des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
  90. #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
  91. des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
  92. #define C_Block des_cblock
  93. #define Key_schedule des_key_schedule
  94. #define des_set_key_schedule des_set_key
  95. #ifdef KERBEROS
  96. #define ENCRYPT DES_ENCRYPT
  97. #define DECRYPT DES_DECRYPT
  98. #endif
  99. #define KEY_SZ DES_KEY_SZ
  100. #define string_to_key des_string_to_key
  101. #define read_pw_string des_read_pw_string
  102. #define random_key des_random_key
  103. #define pcbc_encrypt des_pcbc_encrypt
  104. #define set_key des_set_key
  105. #define key_sched des_key_sched
  106. #define ecb_encrypt des_ecb_encrypt
  107. #define cbc_encrypt des_cbc_encrypt
  108. #define ncbc_encrypt des_ncbc_encrypt
  109. #define xcbc_encrypt des_xcbc_encrypt
  110. #define cbc_cksum des_cbc_cksum
  111. #define quad_cksum des_quad_cksum
  112. /* For compatibility with the MIT lib - eay 20/05/92 */
  113. typedef des_key_schedule bit_64;
  114. #define des_fixup_key_parity des_set_odd_parity
  115. #define des_check_key_parity check_parity
  116. extern int des_check_key; /* defaults to false */
  117. extern int des_rw_mode; /* defaults to DES_PCBC_MODE */
  118. /* The next line is used to disable full ANSI prototypes, if your
  119. * compiler has problems with the prototypes, make sure this line always
  120. * evaluates to true :-) */
  121. #if defined(MSDOS) || defined(__STDC__)
  122. #undef _DES_NOPROTO
  123. #endif
  124. #ifndef _DES_NOPROTO
  125. char *des_options(void);
  126. void des_ecb3_encrypt(des_cblock *input,des_cblock *output,
  127. des_key_schedule ks1,des_key_schedule ks2,
  128. des_key_schedule ks3, int enc);
  129. DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output,
  130. long length,des_key_schedule schedule,des_cblock *ivec);
  131. void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
  132. des_key_schedule schedule,des_cblock *ivec,int enc);
  133. void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length,
  134. des_key_schedule schedule,des_cblock *ivec,int enc);
  135. void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length,
  136. des_key_schedule schedule,des_cblock *ivec,
  137. des_cblock *inw,des_cblock *outw,int enc);
  138. void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,
  139. des_key_schedule sk1,des_key_schedule sk2,
  140. des_cblock *ivec1,des_cblock *ivec2,int enc);
  141. void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
  142. long length,des_key_schedule schedule,des_cblock *ivec,int enc);
  143. void des_ecb_encrypt(des_cblock *input,des_cblock *output,
  144. des_key_schedule ks,int enc);
  145. void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
  146. void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
  147. void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
  148. des_key_schedule ks2, des_key_schedule ks3);
  149. void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
  150. des_key_schedule ks2, des_key_schedule ks3);
  151. void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output,
  152. long length, des_key_schedule ks1, des_key_schedule ks2,
  153. des_key_schedule ks3, des_cblock *ivec, int enc);
  154. void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
  155. long length, des_key_schedule ks1, des_key_schedule ks2,
  156. des_key_schedule ks3, des_cblock *ivec, int *num, int encrypt);
  157. void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
  158. long length, des_key_schedule ks1, des_key_schedule ks2,
  159. des_key_schedule ks3, des_cblock *ivec, int *num);
  160. int des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
  161. des_cblock *iv);
  162. int des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
  163. des_cblock *iv);
  164. char *des_fcrypt(const char *buf,const char *salt, char *ret);
  165. char *des_crypt(const char *buf,const char *salt);
  166. /* some stupid compilers complain because I have declared char instead
  167. * of const char */
  168. #ifdef HEADER_DES_LOCL_H
  169. char *crypt(const char *buf,const char *salt);
  170. #else
  171. char *crypt();
  172. #endif
  173. void des_ofb_encrypt(unsigned char *in,unsigned char *out,
  174. int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
  175. void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
  176. des_key_schedule schedule,des_cblock *ivec,int enc);
  177. DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output,
  178. long length,int out_count,des_cblock *seed);
  179. void des_random_seed(des_cblock key);
  180. void des_random_key(des_cblock ret);
  181. int des_read_password(des_cblock *key,char *prompt,int verify);
  182. int des_read_2passwords(des_cblock *key1,des_cblock *key2,
  183. char *prompt,int verify);
  184. int des_read_pw_string(char *buf,int length,char *prompt,int verify);
  185. void des_set_odd_parity(des_cblock *key);
  186. int des_is_weak_key(des_cblock *key);
  187. int des_set_key(des_cblock *key,des_key_schedule schedule);
  188. int des_key_sched(des_cblock *key,des_key_schedule schedule);
  189. void des_string_to_key(char *str,des_cblock *key);
  190. void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
  191. void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
  192. des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
  193. void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
  194. des_key_schedule schedule, des_cblock *ivec, int *num);
  195. /* Extra functions from Mark Murray <mark@grondar.za> */
  196. void des_cblock_print_file(des_cblock *cb, FILE *fp);
  197. /* The following functions are not in the normal unix build or the
  198. * SSLeay build. When using the SSLeay build, use RAND_seed()
  199. * and RAND_bytes() instead. */
  200. int des_new_random_key(des_cblock *key);
  201. void des_init_random_number_generator(des_cblock *key);
  202. void des_set_random_generator_seed(des_cblock *key);
  203. void des_set_sequence_number(des_cblock new_sequence_number);
  204. void des_generate_random_block(des_cblock *block);
  205. #else
  206. char *des_options();
  207. void des_ecb3_encrypt();
  208. DES_LONG des_cbc_cksum();
  209. void des_cbc_encrypt();
  210. void des_ncbc_encrypt();
  211. void des_xcbc_encrypt();
  212. void des_3cbc_encrypt();
  213. void des_cfb_encrypt();
  214. void des_ede3_cfb64_encrypt();
  215. void des_ede3_ofb64_encrypt();
  216. void des_ecb_encrypt();
  217. void des_encrypt();
  218. void des_encrypt2();
  219. void des_encrypt3();
  220. void des_decrypt3();
  221. void des_ede3_cbc_encrypt();
  222. int des_enc_read();
  223. int des_enc_write();
  224. char *des_fcrypt();
  225. char *des_crypt();
  226. char *crypt();
  227. void des_ofb_encrypt();
  228. void des_pcbc_encrypt();
  229. DES_LONG des_quad_cksum();
  230. void des_random_seed();
  231. void des_random_key();
  232. int des_read_password();
  233. int des_read_2passwords();
  234. int des_read_pw_string();
  235. void des_set_odd_parity();
  236. int des_is_weak_key();
  237. int des_set_key();
  238. int des_key_sched();
  239. void des_string_to_key();
  240. void des_string_to_2keys();
  241. void des_cfb64_encrypt();
  242. void des_ofb64_encrypt();
  243. /* Extra functions from Mark Murray <mark@grondar.za> */
  244. void des_cblock_print_file();
  245. /* The following functions are not in the normal unix build or the
  246. * SSLeay build. When using the SSLeay build, use RAND_seed()
  247. * and RAND_bytes() instead. */
  248. #ifdef FreeBSD
  249. int des_new_random_key();
  250. void des_init_random_number_generator();
  251. void des_set_random_generator_seed();
  252. void des_set_sequence_number();
  253. void des_generate_random_block();
  254. #endif
  255. #endif
  256. #ifdef __cplusplus
  257. }
  258. #endif
  259. #endif