10Sstevel@tonic-gate /* crypto/des/des.h */ 20Sstevel@tonic-gate /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 30Sstevel@tonic-gate * All rights reserved. 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * This package is an SSL implementation written 60Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com). 70Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as 100Sstevel@tonic-gate * the following conditions are aheared to. The following conditions 110Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA, 120Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code. The SSL documentation 130Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms 140Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com). 150Sstevel@tonic-gate * 160Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in 170Sstevel@tonic-gate * the code are not to be removed. 180Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution 190Sstevel@tonic-gate * as the author of the parts of the library used. 200Sstevel@tonic-gate * This can be in the form of a textual message at program startup or 210Sstevel@tonic-gate * in documentation (online or textual) provided with the package. 220Sstevel@tonic-gate * 230Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 240Sstevel@tonic-gate * modification, are permitted provided that the following conditions 250Sstevel@tonic-gate * are met: 260Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright 270Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 280Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 290Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 300Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 310Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 320Sstevel@tonic-gate * must display the following acknowledgement: 330Sstevel@tonic-gate * "This product includes cryptographic software written by 340Sstevel@tonic-gate * Eric Young (eay@cryptsoft.com)" 350Sstevel@tonic-gate * The word 'cryptographic' can be left out if the rouines from the library 360Sstevel@tonic-gate * being used are not cryptographic related :-). 370Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from 380Sstevel@tonic-gate * the apps directory (application code) you must include an acknowledgement: 390Sstevel@tonic-gate * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 400Sstevel@tonic-gate * 410Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 420Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 430Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 440Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 450Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 460Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 470Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 480Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 490Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 500Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 510Sstevel@tonic-gate * SUCH DAMAGE. 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * The licence and distribution terms for any publically available version or 540Sstevel@tonic-gate * derivative of this code cannot be changed. i.e. this code cannot simply be 550Sstevel@tonic-gate * copied and put under another distribution licence 560Sstevel@tonic-gate * [including the GNU Public Licence.] 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate 590Sstevel@tonic-gate #ifndef HEADER_NEW_DES_H 600Sstevel@tonic-gate #define HEADER_NEW_DES_H 610Sstevel@tonic-gate 62*2139Sjp161948 #include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES, 63*2139Sjp161948 DES_LONG (via openssl/opensslconf.h */ 64*2139Sjp161948 650Sstevel@tonic-gate #ifdef OPENSSL_NO_DES 660Sstevel@tonic-gate #error DES is disabled. 670Sstevel@tonic-gate #endif 680Sstevel@tonic-gate 690Sstevel@tonic-gate #ifdef OPENSSL_BUILD_SHLIBCRYPTO 700Sstevel@tonic-gate # undef OPENSSL_EXTERN 710Sstevel@tonic-gate # define OPENSSL_EXTERN OPENSSL_EXPORT 720Sstevel@tonic-gate #endif 730Sstevel@tonic-gate 740Sstevel@tonic-gate #ifdef __cplusplus 750Sstevel@tonic-gate extern "C" { 760Sstevel@tonic-gate #endif 770Sstevel@tonic-gate 780Sstevel@tonic-gate typedef unsigned char DES_cblock[8]; 790Sstevel@tonic-gate typedef /* const */ unsigned char const_DES_cblock[8]; 800Sstevel@tonic-gate /* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * 810Sstevel@tonic-gate * and const_DES_cblock * are incompatible pointer types. */ 820Sstevel@tonic-gate 830Sstevel@tonic-gate typedef struct DES_ks 840Sstevel@tonic-gate { 850Sstevel@tonic-gate union 860Sstevel@tonic-gate { 870Sstevel@tonic-gate DES_cblock cblock; 880Sstevel@tonic-gate /* make sure things are correct size on machines with 890Sstevel@tonic-gate * 8 byte longs */ 900Sstevel@tonic-gate DES_LONG deslong[2]; 910Sstevel@tonic-gate } ks[16]; 920Sstevel@tonic-gate } DES_key_schedule; 930Sstevel@tonic-gate 940Sstevel@tonic-gate #ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT 950Sstevel@tonic-gate # ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT 960Sstevel@tonic-gate # define OPENSSL_ENABLE_OLD_DES_SUPPORT 970Sstevel@tonic-gate # endif 980Sstevel@tonic-gate #endif 990Sstevel@tonic-gate 1000Sstevel@tonic-gate #ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT 1010Sstevel@tonic-gate # include <openssl/des_old.h> 1020Sstevel@tonic-gate #endif 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #define DES_KEY_SZ (sizeof(DES_cblock)) 1050Sstevel@tonic-gate #define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate #define DES_ENCRYPT 1 1080Sstevel@tonic-gate #define DES_DECRYPT 0 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate #define DES_CBC_MODE 0 1110Sstevel@tonic-gate #define DES_PCBC_MODE 1 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate #define DES_ecb2_encrypt(i,o,k1,k2,e) \ 1140Sstevel@tonic-gate DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate #define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 1170Sstevel@tonic-gate DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 1200Sstevel@tonic-gate DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate #define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 1230Sstevel@tonic-gate DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */ 1260Sstevel@tonic-gate #define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) 1270Sstevel@tonic-gate OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */ 1280Sstevel@tonic-gate #define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode) 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate const char *DES_options(void); 1310Sstevel@tonic-gate void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 1320Sstevel@tonic-gate DES_key_schedule *ks1,DES_key_schedule *ks2, 1330Sstevel@tonic-gate DES_key_schedule *ks3, int enc); 1340Sstevel@tonic-gate DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output, 1350Sstevel@tonic-gate long length,DES_key_schedule *schedule, 1360Sstevel@tonic-gate const_DES_cblock *ivec); 1370Sstevel@tonic-gate /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ 1380Sstevel@tonic-gate void DES_cbc_encrypt(const unsigned char *input,unsigned char *output, 1390Sstevel@tonic-gate long length,DES_key_schedule *schedule,DES_cblock *ivec, 1400Sstevel@tonic-gate int enc); 1410Sstevel@tonic-gate void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output, 1420Sstevel@tonic-gate long length,DES_key_schedule *schedule,DES_cblock *ivec, 1430Sstevel@tonic-gate int enc); 1440Sstevel@tonic-gate void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output, 1450Sstevel@tonic-gate long length,DES_key_schedule *schedule,DES_cblock *ivec, 1460Sstevel@tonic-gate const_DES_cblock *inw,const_DES_cblock *outw,int enc); 1470Sstevel@tonic-gate void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 1480Sstevel@tonic-gate long length,DES_key_schedule *schedule,DES_cblock *ivec, 1490Sstevel@tonic-gate int enc); 1500Sstevel@tonic-gate void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output, 1510Sstevel@tonic-gate DES_key_schedule *ks,int enc); 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* This is the DES encryption function that gets called by just about 1540Sstevel@tonic-gate every other DES routine in the library. You should not use this 1550Sstevel@tonic-gate function except to implement 'modes' of DES. I say this because the 1560Sstevel@tonic-gate functions that call this routine do the conversion from 'char *' to 1570Sstevel@tonic-gate long, and this needs to be done to make sure 'non-aligned' memory 1580Sstevel@tonic-gate access do not occur. The characters are loaded 'little endian'. 1590Sstevel@tonic-gate Data is a pointer to 2 unsigned long's and ks is the 1600Sstevel@tonic-gate DES_key_schedule to use. enc, is non zero specifies encryption, 1610Sstevel@tonic-gate zero if decryption. */ 1620Sstevel@tonic-gate void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* This functions is the same as DES_encrypt1() except that the DES 1650Sstevel@tonic-gate initial permutation (IP) and final permutation (FP) have been left 1660Sstevel@tonic-gate out. As for DES_encrypt1(), you should not use this function. 1670Sstevel@tonic-gate It is used by the routines in the library that implement triple DES. 1680Sstevel@tonic-gate IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same 1690Sstevel@tonic-gate as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */ 1700Sstevel@tonic-gate void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 1730Sstevel@tonic-gate DES_key_schedule *ks2, DES_key_schedule *ks3); 1740Sstevel@tonic-gate void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, 1750Sstevel@tonic-gate DES_key_schedule *ks2, DES_key_schedule *ks3); 1760Sstevel@tonic-gate void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, 1770Sstevel@tonic-gate long length, 1780Sstevel@tonic-gate DES_key_schedule *ks1,DES_key_schedule *ks2, 1790Sstevel@tonic-gate DES_key_schedule *ks3,DES_cblock *ivec,int enc); 1800Sstevel@tonic-gate void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out, 1810Sstevel@tonic-gate long length, 1820Sstevel@tonic-gate DES_key_schedule *ks1,DES_key_schedule *ks2, 1830Sstevel@tonic-gate DES_key_schedule *ks3, 1840Sstevel@tonic-gate DES_cblock *ivec1,DES_cblock *ivec2, 1850Sstevel@tonic-gate int enc); 1860Sstevel@tonic-gate void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, 1870Sstevel@tonic-gate long length,DES_key_schedule *ks1, 1880Sstevel@tonic-gate DES_key_schedule *ks2,DES_key_schedule *ks3, 1890Sstevel@tonic-gate DES_cblock *ivec,int *num,int enc); 190*2139Sjp161948 void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, 191*2139Sjp161948 int numbits,long length,DES_key_schedule *ks1, 192*2139Sjp161948 DES_key_schedule *ks2,DES_key_schedule *ks3, 193*2139Sjp161948 DES_cblock *ivec,int enc); 1940Sstevel@tonic-gate void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out, 1950Sstevel@tonic-gate long length,DES_key_schedule *ks1, 1960Sstevel@tonic-gate DES_key_schedule *ks2,DES_key_schedule *ks3, 1970Sstevel@tonic-gate DES_cblock *ivec,int *num); 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white, 2000Sstevel@tonic-gate DES_cblock *out_white); 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched, 2030Sstevel@tonic-gate DES_cblock *iv); 2040Sstevel@tonic-gate int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched, 2050Sstevel@tonic-gate DES_cblock *iv); 2060Sstevel@tonic-gate char *DES_fcrypt(const char *buf,const char *salt, char *ret); 2070Sstevel@tonic-gate char *DES_crypt(const char *buf,const char *salt); 2080Sstevel@tonic-gate void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 2090Sstevel@tonic-gate long length,DES_key_schedule *schedule,DES_cblock *ivec); 2100Sstevel@tonic-gate void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output, 2110Sstevel@tonic-gate long length,DES_key_schedule *schedule,DES_cblock *ivec, 2120Sstevel@tonic-gate int enc); 2130Sstevel@tonic-gate DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[], 2140Sstevel@tonic-gate long length,int out_count,DES_cblock *seed); 2150Sstevel@tonic-gate int DES_random_key(DES_cblock *ret); 2160Sstevel@tonic-gate void DES_set_odd_parity(DES_cblock *key); 2170Sstevel@tonic-gate int DES_check_key_parity(const_DES_cblock *key); 2180Sstevel@tonic-gate int DES_is_weak_key(const_DES_cblock *key); 2190Sstevel@tonic-gate /* DES_set_key (= set_key = DES_key_sched = key_sched) calls 2200Sstevel@tonic-gate * DES_set_key_checked if global variable DES_check_key is set, 2210Sstevel@tonic-gate * DES_set_key_unchecked otherwise. */ 2220Sstevel@tonic-gate int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule); 2230Sstevel@tonic-gate int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule); 2240Sstevel@tonic-gate int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule); 2250Sstevel@tonic-gate void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule); 2260Sstevel@tonic-gate void DES_string_to_key(const char *str,DES_cblock *key); 2270Sstevel@tonic-gate void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2); 2280Sstevel@tonic-gate void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, 2290Sstevel@tonic-gate DES_key_schedule *schedule,DES_cblock *ivec,int *num, 2300Sstevel@tonic-gate int enc); 2310Sstevel@tonic-gate void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, 2320Sstevel@tonic-gate DES_key_schedule *schedule,DES_cblock *ivec,int *num); 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate int DES_read_password(DES_cblock *key, const char *prompt, int verify); 2350Sstevel@tonic-gate int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt, 2360Sstevel@tonic-gate int verify); 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate #define DES_fixup_key_parity DES_set_odd_parity 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate #ifdef __cplusplus 2410Sstevel@tonic-gate } 2420Sstevel@tonic-gate #endif 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate #endif 245