155714Skris/* crypto/des/des.h */ 255714Skris/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 8280297Sjkim * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15280297Sjkim * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 22280297Sjkim * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 37280297Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40280297Sjkim * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 52280297Sjkim * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 5855714Skris 59110007Smarkm#ifndef HEADER_NEW_DES_H 60280297Sjkim# define HEADER_NEW_DES_H 6155714Skris 62280297Sjkim# include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG 63280297Sjkim * (via openssl/opensslconf.h */ 64160817Ssimon 65280297Sjkim# ifdef OPENSSL_NO_DES 66280297Sjkim# error DES is disabled. 67280297Sjkim# endif 6855714Skris 69280297Sjkim# ifdef OPENSSL_BUILD_SHLIBCRYPTO 70280297Sjkim# undef OPENSSL_EXTERN 71280297Sjkim# define OPENSSL_EXTERN OPENSSL_EXPORT 72280297Sjkim# endif 73110007Smarkm 7468654Skris#ifdef __cplusplus 7568654Skrisextern "C" { 7668654Skris#endif 7768654Skris 78110007Smarkmtypedef unsigned char DES_cblock[8]; 79110007Smarkmtypedef /* const */ unsigned char const_DES_cblock[8]; 80280297Sjkim/* 81280297Sjkim * With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and 82280297Sjkim * const_DES_cblock * are incompatible pointer types. 83280297Sjkim */ 8455714Skris 85280297Sjkimtypedef struct DES_ks { 86280297Sjkim union { 87280297Sjkim DES_cblock cblock; 88280297Sjkim /* 89280297Sjkim * make sure things are correct size on machines with 8 byte longs 90280297Sjkim */ 91280297Sjkim DES_LONG deslong[2]; 92280297Sjkim } ks[16]; 93280297Sjkim} DES_key_schedule; 9455714Skris 95280297Sjkim# ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT 96280297Sjkim# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT 97280297Sjkim# define OPENSSL_ENABLE_OLD_DES_SUPPORT 98280297Sjkim# endif 99110007Smarkm# endif 10055714Skris 101280297Sjkim# ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT 102280297Sjkim# include <openssl/des_old.h> 103280297Sjkim# endif 104110007Smarkm 105280297Sjkim# define DES_KEY_SZ (sizeof(DES_cblock)) 106280297Sjkim# define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) 107110007Smarkm 108280297Sjkim# define DES_ENCRYPT 1 109280297Sjkim# define DES_DECRYPT 0 11055714Skris 111280297Sjkim# define DES_CBC_MODE 0 112280297Sjkim# define DES_PCBC_MODE 1 11355714Skris 114280297Sjkim# define DES_ecb2_encrypt(i,o,k1,k2,e) \ 115280297Sjkim DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 11655714Skris 117280297Sjkim# define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 118280297Sjkim DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 11955714Skris 120280297Sjkim# define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 121280297Sjkim DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 12255714Skris 123280297Sjkim# define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 124280297Sjkim DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 12555714Skris 126280297SjkimOPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */ 127280297Sjkim# define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) 128280297SjkimOPENSSL_DECLARE_GLOBAL(int, DES_rw_mode); /* defaults to DES_PCBC_MODE */ 129280297Sjkim# define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode) 13055714Skris 131110007Smarkmconst char *DES_options(void); 132160817Ssimonvoid DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 133280297Sjkim DES_key_schedule *ks1, DES_key_schedule *ks2, 134280297Sjkim DES_key_schedule *ks3, int enc); 135280297SjkimDES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output, 136280297Sjkim long length, DES_key_schedule *schedule, 137280297Sjkim const_DES_cblock *ivec); 138110007Smarkm/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ 139280297Sjkimvoid DES_cbc_encrypt(const unsigned char *input, unsigned char *output, 140280297Sjkim long length, DES_key_schedule *schedule, 141280297Sjkim DES_cblock *ivec, int enc); 142280297Sjkimvoid DES_ncbc_encrypt(const unsigned char *input, unsigned char *output, 143280297Sjkim long length, DES_key_schedule *schedule, 144280297Sjkim DES_cblock *ivec, int enc); 145280297Sjkimvoid DES_xcbc_encrypt(const unsigned char *input, unsigned char *output, 146280297Sjkim long length, DES_key_schedule *schedule, 147280297Sjkim DES_cblock *ivec, const_DES_cblock *inw, 148280297Sjkim const_DES_cblock *outw, int enc); 149280297Sjkimvoid DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 150280297Sjkim long length, DES_key_schedule *schedule, 151280297Sjkim DES_cblock *ivec, int enc); 152280297Sjkimvoid DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, 153280297Sjkim DES_key_schedule *ks, int enc); 15459194Skris 155280297Sjkim/* 156280297Sjkim * This is the DES encryption function that gets called by just about every 157280297Sjkim * other DES routine in the library. You should not use this function except 158280297Sjkim * to implement 'modes' of DES. I say this because the functions that call 159280297Sjkim * this routine do the conversion from 'char *' to long, and this needs to be 160280297Sjkim * done to make sure 'non-aligned' memory access do not occur. The 161280297Sjkim * characters are loaded 'little endian'. Data is a pointer to 2 unsigned 162280297Sjkim * long's and ks is the DES_key_schedule to use. enc, is non zero specifies 163280297Sjkim * encryption, zero if decryption. 164280297Sjkim */ 165280297Sjkimvoid DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc); 16659194Skris 167280297Sjkim/* 168280297Sjkim * This functions is the same as DES_encrypt1() except that the DES initial 169280297Sjkim * permutation (IP) and final permutation (FP) have been left out. As for 170280297Sjkim * DES_encrypt1(), you should not use this function. It is used by the 171280297Sjkim * routines in the library that implement triple DES. IP() DES_encrypt2() 172280297Sjkim * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1() 173280297Sjkim * DES_encrypt1() DES_encrypt1() except faster :-). 174280297Sjkim */ 175280297Sjkimvoid DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc); 17659194Skris 177110007Smarkmvoid DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 178280297Sjkim DES_key_schedule *ks2, DES_key_schedule *ks3); 179110007Smarkmvoid DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, 180280297Sjkim DES_key_schedule *ks2, DES_key_schedule *ks3); 181280297Sjkimvoid DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, 182280297Sjkim long length, 183280297Sjkim DES_key_schedule *ks1, DES_key_schedule *ks2, 184280297Sjkim DES_key_schedule *ks3, DES_cblock *ivec, int enc); 185280297Sjkimvoid DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out, 186280297Sjkim long length, 187280297Sjkim DES_key_schedule *ks1, DES_key_schedule *ks2, 188280297Sjkim DES_key_schedule *ks3, 189280297Sjkim DES_cblock *ivec1, DES_cblock *ivec2, int enc); 190280297Sjkimvoid DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, 191280297Sjkim long length, DES_key_schedule *ks1, 192280297Sjkim DES_key_schedule *ks2, DES_key_schedule *ks3, 193280297Sjkim DES_cblock *ivec, int *num, int enc); 194280297Sjkimvoid DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out, 195280297Sjkim int numbits, long length, DES_key_schedule *ks1, 196280297Sjkim DES_key_schedule *ks2, DES_key_schedule *ks3, 197280297Sjkim DES_cblock *ivec, int enc); 198280297Sjkimvoid DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out, 199280297Sjkim long length, DES_key_schedule *ks1, 200280297Sjkim DES_key_schedule *ks2, DES_key_schedule *ks3, 201280297Sjkim DES_cblock *ivec, int *num); 202280297Sjkim# if 0 203280297Sjkimvoid DES_xwhite_in2out(const_DES_cblock *DES_key, const_DES_cblock *in_white, 204280297Sjkim DES_cblock *out_white); 205280297Sjkim# endif 20655714Skris 207280297Sjkimint DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, 208280297Sjkim DES_cblock *iv); 209280297Sjkimint DES_enc_write(int fd, const void *buf, int len, DES_key_schedule *sched, 210280297Sjkim DES_cblock *iv); 211280297Sjkimchar *DES_fcrypt(const char *buf, const char *salt, char *ret); 212280297Sjkimchar *DES_crypt(const char *buf, const char *salt); 213280297Sjkimvoid DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 214280297Sjkim long length, DES_key_schedule *schedule, 215280297Sjkim DES_cblock *ivec); 216280297Sjkimvoid DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, 217280297Sjkim long length, DES_key_schedule *schedule, 218280297Sjkim DES_cblock *ivec, int enc); 219280297SjkimDES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], 220280297Sjkim long length, int out_count, DES_cblock *seed); 221110007Smarkmint DES_random_key(DES_cblock *ret); 222110007Smarkmvoid DES_set_odd_parity(DES_cblock *key); 223110007Smarkmint DES_check_key_parity(const_DES_cblock *key); 224110007Smarkmint DES_is_weak_key(const_DES_cblock *key); 225280297Sjkim/* 226280297Sjkim * DES_set_key (= set_key = DES_key_sched = key_sched) calls 227110007Smarkm * DES_set_key_checked if global variable DES_check_key is set, 228280297Sjkim * DES_set_key_unchecked otherwise. 229280297Sjkim */ 230280297Sjkimint DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule); 231280297Sjkimint DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule); 232280297Sjkimint DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule); 233280297Sjkimvoid DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule); 234280297Sjkim# ifdef OPENSSL_FIPS 235280297Sjkimvoid private_DES_set_key_unchecked(const_DES_cblock *key, 236280297Sjkim DES_key_schedule *schedule); 237280297Sjkim# endif 238280297Sjkimvoid DES_string_to_key(const char *str, DES_cblock *key); 239280297Sjkimvoid DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2); 240280297Sjkimvoid DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, 241280297Sjkim long length, DES_key_schedule *schedule, 242280297Sjkim DES_cblock *ivec, int *num, int enc); 243280297Sjkimvoid DES_ofb64_encrypt(const unsigned char *in, unsigned char *out, 244280297Sjkim long length, DES_key_schedule *schedule, 245280297Sjkim DES_cblock *ivec, int *num); 24655714Skris 247110007Smarkmint DES_read_password(DES_cblock *key, const char *prompt, int verify); 248280297Sjkimint DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, 249280297Sjkim const char *prompt, int verify); 25055714Skris 251280297Sjkim# define DES_fixup_key_parity DES_set_odd_parity 25255714Skris 25355714Skris#ifdef __cplusplus 25455714Skris} 25555714Skris#endif 25655714Skris 25755714Skris#endif 258