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