1*4724848cSchristos /* 2*4724848cSchristos * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. 3*4724848cSchristos * 4*4724848cSchristos * Licensed under the OpenSSL license (the "License"). You may not use 5*4724848cSchristos * this file except in compliance with the License. You can obtain a copy 6*4724848cSchristos * in the file LICENSE in the source distribution or at 7*4724848cSchristos * https://www.openssl.org/source/license.html 8*4724848cSchristos */ 9*4724848cSchristos 10*4724848cSchristos #ifndef HEADER_DES_H 11*4724848cSchristos # define HEADER_DES_H 12*4724848cSchristos 13*4724848cSchristos # include <openssl/opensslconf.h> 14*4724848cSchristos 15*4724848cSchristos # ifndef OPENSSL_NO_DES 16*4724848cSchristos # ifdef __cplusplus 17*4724848cSchristos extern "C" { 18*4724848cSchristos # endif 19*4724848cSchristos # include <openssl/e_os2.h> 20*4724848cSchristos 21*4724848cSchristos typedef unsigned int DES_LONG; 22*4724848cSchristos 23*4724848cSchristos # ifdef OPENSSL_BUILD_SHLIBCRYPTO 24*4724848cSchristos # undef OPENSSL_EXTERN 25*4724848cSchristos # define OPENSSL_EXTERN OPENSSL_EXPORT 26*4724848cSchristos # endif 27*4724848cSchristos 28*4724848cSchristos typedef unsigned char DES_cblock[8]; 29*4724848cSchristos typedef /* const */ unsigned char const_DES_cblock[8]; 30*4724848cSchristos /* 31*4724848cSchristos * With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and 32*4724848cSchristos * const_DES_cblock * are incompatible pointer types. 33*4724848cSchristos */ 34*4724848cSchristos 35*4724848cSchristos typedef struct DES_ks { 36*4724848cSchristos union { 37*4724848cSchristos DES_cblock cblock; 38*4724848cSchristos /* 39*4724848cSchristos * make sure things are correct size on machines with 8 byte longs 40*4724848cSchristos */ 41*4724848cSchristos DES_LONG deslong[2]; 42*4724848cSchristos } ks[16]; 43*4724848cSchristos } DES_key_schedule; 44*4724848cSchristos 45*4724848cSchristos # define DES_KEY_SZ (sizeof(DES_cblock)) 46*4724848cSchristos # define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) 47*4724848cSchristos 48*4724848cSchristos # define DES_ENCRYPT 1 49*4724848cSchristos # define DES_DECRYPT 0 50*4724848cSchristos 51*4724848cSchristos # define DES_CBC_MODE 0 52*4724848cSchristos # define DES_PCBC_MODE 1 53*4724848cSchristos 54*4724848cSchristos # define DES_ecb2_encrypt(i,o,k1,k2,e) \ 55*4724848cSchristos DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 56*4724848cSchristos 57*4724848cSchristos # define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 58*4724848cSchristos DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 59*4724848cSchristos 60*4724848cSchristos # define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 61*4724848cSchristos DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 62*4724848cSchristos 63*4724848cSchristos # define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 64*4724848cSchristos DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 65*4724848cSchristos 66*4724848cSchristos OPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */ 67*4724848cSchristos # define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) 68*4724848cSchristos 69*4724848cSchristos const char *DES_options(void); 70*4724848cSchristos void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 71*4724848cSchristos DES_key_schedule *ks1, DES_key_schedule *ks2, 72*4724848cSchristos DES_key_schedule *ks3, int enc); 73*4724848cSchristos DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output, 74*4724848cSchristos long length, DES_key_schedule *schedule, 75*4724848cSchristos const_DES_cblock *ivec); 76*4724848cSchristos /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ 77*4724848cSchristos void DES_cbc_encrypt(const unsigned char *input, unsigned char *output, 78*4724848cSchristos long length, DES_key_schedule *schedule, 79*4724848cSchristos DES_cblock *ivec, int enc); 80*4724848cSchristos void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output, 81*4724848cSchristos long length, DES_key_schedule *schedule, 82*4724848cSchristos DES_cblock *ivec, int enc); 83*4724848cSchristos void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output, 84*4724848cSchristos long length, DES_key_schedule *schedule, 85*4724848cSchristos DES_cblock *ivec, const_DES_cblock *inw, 86*4724848cSchristos const_DES_cblock *outw, int enc); 87*4724848cSchristos void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 88*4724848cSchristos long length, DES_key_schedule *schedule, 89*4724848cSchristos DES_cblock *ivec, int enc); 90*4724848cSchristos void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, 91*4724848cSchristos DES_key_schedule *ks, int enc); 92*4724848cSchristos 93*4724848cSchristos /* 94*4724848cSchristos * This is the DES encryption function that gets called by just about every 95*4724848cSchristos * other DES routine in the library. You should not use this function except 96*4724848cSchristos * to implement 'modes' of DES. I say this because the functions that call 97*4724848cSchristos * this routine do the conversion from 'char *' to long, and this needs to be 98*4724848cSchristos * done to make sure 'non-aligned' memory access do not occur. The 99*4724848cSchristos * characters are loaded 'little endian'. Data is a pointer to 2 unsigned 100*4724848cSchristos * long's and ks is the DES_key_schedule to use. enc, is non zero specifies 101*4724848cSchristos * encryption, zero if decryption. 102*4724848cSchristos */ 103*4724848cSchristos void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc); 104*4724848cSchristos 105*4724848cSchristos /* 106*4724848cSchristos * This functions is the same as DES_encrypt1() except that the DES initial 107*4724848cSchristos * permutation (IP) and final permutation (FP) have been left out. As for 108*4724848cSchristos * DES_encrypt1(), you should not use this function. It is used by the 109*4724848cSchristos * routines in the library that implement triple DES. IP() DES_encrypt2() 110*4724848cSchristos * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1() 111*4724848cSchristos * DES_encrypt1() DES_encrypt1() except faster :-). 112*4724848cSchristos */ 113*4724848cSchristos void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc); 114*4724848cSchristos 115*4724848cSchristos void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 116*4724848cSchristos DES_key_schedule *ks2, DES_key_schedule *ks3); 117*4724848cSchristos void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, 118*4724848cSchristos DES_key_schedule *ks2, DES_key_schedule *ks3); 119*4724848cSchristos void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, 120*4724848cSchristos long length, 121*4724848cSchristos DES_key_schedule *ks1, DES_key_schedule *ks2, 122*4724848cSchristos DES_key_schedule *ks3, DES_cblock *ivec, int enc); 123*4724848cSchristos void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, 124*4724848cSchristos long length, DES_key_schedule *ks1, 125*4724848cSchristos DES_key_schedule *ks2, DES_key_schedule *ks3, 126*4724848cSchristos DES_cblock *ivec, int *num, int enc); 127*4724848cSchristos void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out, 128*4724848cSchristos int numbits, long length, DES_key_schedule *ks1, 129*4724848cSchristos DES_key_schedule *ks2, DES_key_schedule *ks3, 130*4724848cSchristos DES_cblock *ivec, int enc); 131*4724848cSchristos void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out, 132*4724848cSchristos long length, DES_key_schedule *ks1, 133*4724848cSchristos DES_key_schedule *ks2, DES_key_schedule *ks3, 134*4724848cSchristos DES_cblock *ivec, int *num); 135*4724848cSchristos char *DES_fcrypt(const char *buf, const char *salt, char *ret); 136*4724848cSchristos char *DES_crypt(const char *buf, const char *salt); 137*4724848cSchristos void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, 138*4724848cSchristos long length, DES_key_schedule *schedule, 139*4724848cSchristos DES_cblock *ivec); 140*4724848cSchristos void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, 141*4724848cSchristos long length, DES_key_schedule *schedule, 142*4724848cSchristos DES_cblock *ivec, int enc); 143*4724848cSchristos DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], 144*4724848cSchristos long length, int out_count, DES_cblock *seed); 145*4724848cSchristos int DES_random_key(DES_cblock *ret); 146*4724848cSchristos void DES_set_odd_parity(DES_cblock *key); 147*4724848cSchristos int DES_check_key_parity(const_DES_cblock *key); 148*4724848cSchristos int DES_is_weak_key(const_DES_cblock *key); 149*4724848cSchristos /* 150*4724848cSchristos * DES_set_key (= set_key = DES_key_sched = key_sched) calls 151*4724848cSchristos * DES_set_key_checked if global variable DES_check_key is set, 152*4724848cSchristos * DES_set_key_unchecked otherwise. 153*4724848cSchristos */ 154*4724848cSchristos int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule); 155*4724848cSchristos int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule); 156*4724848cSchristos int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule); 157*4724848cSchristos void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule); 158*4724848cSchristos void DES_string_to_key(const char *str, DES_cblock *key); 159*4724848cSchristos void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2); 160*4724848cSchristos void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, 161*4724848cSchristos long length, DES_key_schedule *schedule, 162*4724848cSchristos DES_cblock *ivec, int *num, int enc); 163*4724848cSchristos void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out, 164*4724848cSchristos long length, DES_key_schedule *schedule, 165*4724848cSchristos DES_cblock *ivec, int *num); 166*4724848cSchristos 167*4724848cSchristos # define DES_fixup_key_parity DES_set_odd_parity 168*4724848cSchristos 169*4724848cSchristos # ifdef __cplusplus 170*4724848cSchristos } 171*4724848cSchristos # endif 172*4724848cSchristos # endif 173*4724848cSchristos 174*4724848cSchristos #endif 175