home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / crypto / des.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  10.1 KB  |  279 lines

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