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. 8296465Sdelphij * 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). 15296465Sdelphij * 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. 22296465Sdelphij * 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 :-). 37296465Sdelphij * 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)" 40296465Sdelphij * 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. 52296465Sdelphij * 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 60296465Sdelphij# define HEADER_NEW_DES_H 6155714Skris 62296465Sdelphij# include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG 63296465Sdelphij * (via openssl/opensslconf.h */ 64160817Ssimon 65296465Sdelphij# ifdef OPENSSL_NO_DES 66296465Sdelphij# error DES is disabled. 67296465Sdelphij# endif 6855714Skris 69296465Sdelphij# ifdef OPENSSL_BUILD_SHLIBCRYPTO 70296465Sdelphij# undef OPENSSL_EXTERN 71296465Sdelphij# define OPENSSL_EXTERN OPENSSL_EXPORT 72296465Sdelphij# endif 73110007Smarkm 7468654Skris#ifdef __cplusplus 7568654Skrisextern "C" { 7668654Skris#endif 7768654Skris 78110007Smarkmtypedef unsigned char DES_cblock[8]; 79110007Smarkmtypedef /* const */ unsigned char const_DES_cblock[8]; 80296465Sdelphij/* 81296465Sdelphij * With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and 82296465Sdelphij * const_DES_cblock * are incompatible pointer types. 83296465Sdelphij */ 8455714Skris 85296465Sdelphijtypedef struct DES_ks { 86296465Sdelphij union { 87296465Sdelphij DES_cblock cblock; 88296465Sdelphij /* 89296465Sdelphij * make sure things are correct size on machines with 8 byte longs 90296465Sdelphij */ 91296465Sdelphij DES_LONG deslong[2]; 92296465Sdelphij } ks[16]; 93296465Sdelphij} DES_key_schedule; 9455714Skris 95296465Sdelphij# ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT 96296465Sdelphij# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT 97296465Sdelphij# define OPENSSL_ENABLE_OLD_DES_SUPPORT 98296465Sdelphij# endif 99110007Smarkm# endif 10055714Skris 101296465Sdelphij# ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT 102296465Sdelphij# include <openssl/des_old.h> 103296465Sdelphij# endif 104110007Smarkm 105296465Sdelphij# define DES_KEY_SZ (sizeof(DES_cblock)) 106296465Sdelphij# define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) 107110007Smarkm 108296465Sdelphij# define DES_ENCRYPT 1 109296465Sdelphij# define DES_DECRYPT 0 11055714Skris 111296465Sdelphij# define DES_CBC_MODE 0 112296465Sdelphij# define DES_PCBC_MODE 1 11355714Skris 114296465Sdelphij# define DES_ecb2_encrypt(i,o,k1,k2,e) \ 115296465Sdelphij DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 11655714Skris 117296465Sdelphij# define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 118296465Sdelphij DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 11955714Skris 120296465Sdelphij# define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 121296465Sdelphij DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 12255714Skris 123296465Sdelphij# define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 124296465Sdelphij DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 12555714Skris 126296465SdelphijOPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */ 127296465Sdelphij# define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) 128296465SdelphijOPENSSL_DECLARE_GLOBAL(int, DES_rw_mode); /* defaults to DES_PCBC_MODE */ 129296465Sdelphij# 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, 133296465Sdelphij DES_key_schedule *ks1, DES_key_schedule *ks2, 134296465Sdelphij DES_key_schedule *ks3, int enc); 135296465SdelphijDES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output, 136296465Sdelphij long length, DES_key_schedule *schedule, 137296465Sdelphij const_DES_cblock *ivec); 138110007Smarkm/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ 139296465Sdelphijvoid DES_cbc_encrypt(const unsigned char *input, unsigned char *output, 140296465Sdelphij long length, DES_key_schedule *schedule, 141296465Sdelphij DES_cblock *ivec, int enc); 142296465Sdelphijvoid DES_ncbc_encrypt(const unsigned char *input, unsigned char *output, 143296465Sdelphij long length, DES_key_schedule *schedule, 144296465Sdelphij DES_cblock *ivec, int enc); 145296465Sdelphijvoid DES_xcbc_encrypt(const unsigned char *input, unsigned char *output, 146296465Sdelphij long length, DES_key_schedule *schedule, 147296465Sdelphij DES_cblock *ivec, const_DES_cblock *inw, 148296465Sdelphij const_DES_cblock *outw, int enc); 149296465Sdelphijvoid DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 150296465Sdelphij long length, DES_key_schedule *schedule, 151296465Sdelphij DES_cblock *ivec, int enc); 152296465Sdelphijvoid DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, 153296465Sdelphij DES_key_schedule *ks, int enc); 15459194Skris 155296465Sdelphij/* 156296465Sdelphij * This is the DES encryption function that gets called by just about every 157296465Sdelphij * other DES routine in the library. You should not use this function except 158296465Sdelphij * to implement 'modes' of DES. I say this because the functions that call 159296465Sdelphij * this routine do the conversion from 'char *' to long, and this needs to be 160296465Sdelphij * done to make sure 'non-aligned' memory access do not occur. The 161296465Sdelphij * characters are loaded 'little endian'. Data is a pointer to 2 unsigned 162296465Sdelphij * long's and ks is the DES_key_schedule to use. enc, is non zero specifies 163296465Sdelphij * encryption, zero if decryption. 164296465Sdelphij */ 165296465Sdelphijvoid DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc); 16659194Skris 167296465Sdelphij/* 168296465Sdelphij * This functions is the same as DES_encrypt1() except that the DES initial 169296465Sdelphij * permutation (IP) and final permutation (FP) have been left out. As for 170296465Sdelphij * DES_encrypt1(), you should not use this function. It is used by the 171296465Sdelphij * routines in the library that implement triple DES. IP() DES_encrypt2() 172296465Sdelphij * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1() 173296465Sdelphij * DES_encrypt1() DES_encrypt1() except faster :-). 174296465Sdelphij */ 175296465Sdelphijvoid DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc); 17659194Skris 177110007Smarkmvoid DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 178296465Sdelphij DES_key_schedule *ks2, DES_key_schedule *ks3); 179110007Smarkmvoid DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, 180296465Sdelphij DES_key_schedule *ks2, DES_key_schedule *ks3); 181296465Sdelphijvoid DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, 182296465Sdelphij long length, 183296465Sdelphij DES_key_schedule *ks1, DES_key_schedule *ks2, 184296465Sdelphij DES_key_schedule *ks3, DES_cblock *ivec, int enc); 185296465Sdelphijvoid DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out, 186296465Sdelphij long length, 187296465Sdelphij DES_key_schedule *ks1, DES_key_schedule *ks2, 188296465Sdelphij DES_key_schedule *ks3, 189296465Sdelphij DES_cblock *ivec1, DES_cblock *ivec2, int enc); 190296465Sdelphijvoid DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, 191296465Sdelphij long length, DES_key_schedule *ks1, 192296465Sdelphij DES_key_schedule *ks2, DES_key_schedule *ks3, 193296465Sdelphij DES_cblock *ivec, int *num, int enc); 194296465Sdelphijvoid DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out, 195296465Sdelphij int numbits, long length, DES_key_schedule *ks1, 196296465Sdelphij DES_key_schedule *ks2, DES_key_schedule *ks3, 197296465Sdelphij DES_cblock *ivec, int enc); 198296465Sdelphijvoid DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out, 199296465Sdelphij long length, DES_key_schedule *ks1, 200296465Sdelphij DES_key_schedule *ks2, DES_key_schedule *ks3, 201296465Sdelphij DES_cblock *ivec, int *num); 202296465Sdelphij# if 0 203296465Sdelphijvoid DES_xwhite_in2out(const_DES_cblock *DES_key, const_DES_cblock *in_white, 204296465Sdelphij DES_cblock *out_white); 205296465Sdelphij# endif 20655714Skris 207296465Sdelphijint DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, 208296465Sdelphij DES_cblock *iv); 209296465Sdelphijint DES_enc_write(int fd, const void *buf, int len, DES_key_schedule *sched, 210296465Sdelphij DES_cblock *iv); 211296465Sdelphijchar *DES_fcrypt(const char *buf, const char *salt, char *ret); 212296465Sdelphijchar *DES_crypt(const char *buf, const char *salt); 213296465Sdelphijvoid DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 214296465Sdelphij long length, DES_key_schedule *schedule, 215296465Sdelphij DES_cblock *ivec); 216296465Sdelphijvoid DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, 217296465Sdelphij long length, DES_key_schedule *schedule, 218296465Sdelphij DES_cblock *ivec, int enc); 219296465SdelphijDES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], 220296465Sdelphij 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); 225296465Sdelphij/* 226296465Sdelphij * DES_set_key (= set_key = DES_key_sched = key_sched) calls 227110007Smarkm * DES_set_key_checked if global variable DES_check_key is set, 228296465Sdelphij * DES_set_key_unchecked otherwise. 229296465Sdelphij */ 230296465Sdelphijint DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule); 231296465Sdelphijint DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule); 232296465Sdelphijint DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule); 233296465Sdelphijvoid DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule); 234296465Sdelphijvoid DES_string_to_key(const char *str, DES_cblock *key); 235296465Sdelphijvoid DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2); 236296465Sdelphijvoid DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, 237296465Sdelphij long length, DES_key_schedule *schedule, 238296465Sdelphij DES_cblock *ivec, int *num, int enc); 239296465Sdelphijvoid DES_ofb64_encrypt(const unsigned char *in, unsigned char *out, 240296465Sdelphij long length, DES_key_schedule *schedule, 241296465Sdelphij DES_cblock *ivec, int *num); 24255714Skris 243110007Smarkmint DES_read_password(DES_cblock *key, const char *prompt, int verify); 244296465Sdelphijint DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, 245296465Sdelphij const char *prompt, int verify); 24655714Skris 247296465Sdelphij# define DES_fixup_key_parity DES_set_odd_parity 24855714Skris 24955714Skris#ifdef __cplusplus 25055714Skris} 25155714Skris#endif 25255714Skris 25355714Skris#endif 254