1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/des/des.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,250 @@
1.4 +/* crypto/des/des.h */
1.5 +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
1.6 + * All rights reserved.
1.7 + *
1.8 + * This package is an SSL implementation written
1.9 + * by Eric Young (eay@cryptsoft.com).
1.10 + * The implementation was written so as to conform with Netscapes SSL.
1.11 + *
1.12 + * This library is free for commercial and non-commercial use as long as
1.13 + * the following conditions are aheared to. The following conditions
1.14 + * apply to all code found in this distribution, be it the RC4, RSA,
1.15 + * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1.16 + * included with this distribution is covered by the same copyright terms
1.17 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1.18 + *
1.19 + * Copyright remains Eric Young's, and as such any Copyright notices in
1.20 + * the code are not to be removed.
1.21 + * If this package is used in a product, Eric Young should be given attribution
1.22 + * as the author of the parts of the library used.
1.23 + * This can be in the form of a textual message at program startup or
1.24 + * in documentation (online or textual) provided with the package.
1.25 + *
1.26 + * Redistribution and use in source and binary forms, with or without
1.27 + * modification, are permitted provided that the following conditions
1.28 + * are met:
1.29 + * 1. Redistributions of source code must retain the copyright
1.30 + * notice, this list of conditions and the following disclaimer.
1.31 + * 2. Redistributions in binary form must reproduce the above copyright
1.32 + * notice, this list of conditions and the following disclaimer in the
1.33 + * documentation and/or other materials provided with the distribution.
1.34 + * 3. All advertising materials mentioning features or use of this software
1.35 + * must display the following acknowledgement:
1.36 + * "This product includes cryptographic software written by
1.37 + * Eric Young (eay@cryptsoft.com)"
1.38 + * The word 'cryptographic' can be left out if the rouines from the library
1.39 + * being used are not cryptographic related :-).
1.40 + * 4. If you include any Windows specific code (or a derivative thereof) from
1.41 + * the apps directory (application code) you must include an acknowledgement:
1.42 + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
1.43 + *
1.44 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
1.45 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.46 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.47 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.48 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.49 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.50 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.51 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.52 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.53 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.54 + * SUCH DAMAGE.
1.55 + *
1.56 + * The licence and distribution terms for any publically available version or
1.57 + * derivative of this code cannot be changed. i.e. this code cannot simply be
1.58 + * copied and put under another distribution licence
1.59 + * [including the GNU Public Licence.]
1.60 + */
1.61 +/*
1.62 + © Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.63 + */
1.64 +
1.65 +#ifndef HEADER_NEW_DES_H
1.66 +#define HEADER_NEW_DES_H
1.67 +#ifdef SYMBIAN
1.68 +#include <e32def.h>
1.69 +#endif
1.70 +#include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES,
1.71 + DES_LONG (via openssl/opensslconf.h */
1.72 +
1.73 +
1.74 +#ifdef OPENSSL_NO_DES
1.75 +#error DES is disabled.
1.76 +#endif
1.77 +
1.78 +#ifdef OPENSSL_BUILD_SHLIBCRYPTO
1.79 +# undef OPENSSL_EXTERN
1.80 +# define OPENSSL_EXTERN OPENSSL_EXPORT
1.81 +#endif
1.82 +
1.83 +#ifdef __cplusplus
1.84 +extern "C" {
1.85 +#endif
1.86 +
1.87 +typedef unsigned char DES_cblock[8];
1.88 +typedef /* const */ unsigned char const_DES_cblock[8];
1.89 +/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
1.90 + * and const_DES_cblock * are incompatible pointer types. */
1.91 +
1.92 +typedef struct DES_ks
1.93 + {
1.94 + union
1.95 + {
1.96 + DES_cblock cblock;
1.97 + /* make sure things are correct size on machines with
1.98 + * 8 byte longs */
1.99 + DES_LONG deslong[2];
1.100 + } ks[16];
1.101 + } DES_key_schedule;
1.102 +
1.103 +#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
1.104 +# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT
1.105 +# define OPENSSL_ENABLE_OLD_DES_SUPPORT
1.106 +# endif
1.107 +#endif
1.108 +
1.109 +#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT
1.110 +# include <openssl/des_old.h>
1.111 +#endif
1.112 +#define DES_KEY_SZ (sizeof(DES_cblock))
1.113 +#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
1.114 +
1.115 +#define DES_ENCRYPT 1
1.116 +#define DES_DECRYPT 0
1.117 +
1.118 +#define DES_CBC_MODE 0
1.119 +#define DES_PCBC_MODE 1
1.120 +
1.121 +#define DES_ecb2_encrypt(i,o,k1,k2,e) \
1.122 + DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
1.123 +
1.124 +#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
1.125 + DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
1.126 +
1.127 +#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
1.128 + DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
1.129 +
1.130 +#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
1.131 + DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
1.132 +#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
1.133 +#else
1.134 +OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */
1.135 +#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
1.136 +OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
1.137 +#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
1.138 +#endif
1.139 +IMPORT_C const char *DES_options(void);
1.140 +IMPORT_C void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
1.141 + DES_key_schedule *ks1,DES_key_schedule *ks2,
1.142 + DES_key_schedule *ks3, int enc);
1.143 +IMPORT_C DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
1.144 + long length,DES_key_schedule *schedule,
1.145 + const_DES_cblock *ivec);
1.146 +/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
1.147 +IMPORT_C void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
1.148 + long length,DES_key_schedule *schedule,DES_cblock *ivec,
1.149 + int enc);
1.150 +IMPORT_C void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
1.151 + long length,DES_key_schedule *schedule,DES_cblock *ivec,
1.152 + int enc);
1.153 +IMPORT_C void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
1.154 + long length,DES_key_schedule *schedule,DES_cblock *ivec,
1.155 + const_DES_cblock *inw,const_DES_cblock *outw,int enc);
1.156 +IMPORT_C void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
1.157 + long length,DES_key_schedule *schedule,DES_cblock *ivec,
1.158 + int enc);
1.159 +IMPORT_C void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
1.160 + DES_key_schedule *ks,int enc);
1.161 +
1.162 +/* This is the DES encryption function that gets called by just about
1.163 + every other DES routine in the library. You should not use this
1.164 + function except to implement 'modes' of DES. I say this because the
1.165 + functions that call this routine do the conversion from 'char *' to
1.166 + long, and this needs to be done to make sure 'non-aligned' memory
1.167 + access do not occur. The characters are loaded 'little endian'.
1.168 + Data is a pointer to 2 unsigned long's and ks is the
1.169 + DES_key_schedule to use. enc, is non zero specifies encryption,
1.170 + zero if decryption. */
1.171 +IMPORT_C void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
1.172 +
1.173 +/* This functions is the same as DES_encrypt1() except that the DES
1.174 + initial permutation (IP) and final permutation (FP) have been left
1.175 + out. As for DES_encrypt1(), you should not use this function.
1.176 + It is used by the routines in the library that implement triple DES.
1.177 + IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
1.178 + as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
1.179 +IMPORT_C void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
1.180 +
1.181 +IMPORT_C void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
1.182 + DES_key_schedule *ks2, DES_key_schedule *ks3);
1.183 +IMPORT_C void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
1.184 + DES_key_schedule *ks2, DES_key_schedule *ks3);
1.185 +IMPORT_C void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
1.186 + long length,
1.187 + DES_key_schedule *ks1,DES_key_schedule *ks2,
1.188 + DES_key_schedule *ks3,DES_cblock *ivec,int enc);
1.189 +IMPORT_C void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
1.190 + long length,
1.191 + DES_key_schedule *ks1,DES_key_schedule *ks2,
1.192 + DES_key_schedule *ks3,
1.193 + DES_cblock *ivec1,DES_cblock *ivec2,
1.194 + int enc);
1.195 +IMPORT_C void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
1.196 + long length,DES_key_schedule *ks1,
1.197 + DES_key_schedule *ks2,DES_key_schedule *ks3,
1.198 + DES_cblock *ivec,int *num,int enc);
1.199 +IMPORT_C void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
1.200 + int numbits,long length,DES_key_schedule *ks1,
1.201 + DES_key_schedule *ks2,DES_key_schedule *ks3,
1.202 + DES_cblock *ivec,int enc);
1.203 +IMPORT_C void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
1.204 + long length,DES_key_schedule *ks1,
1.205 + DES_key_schedule *ks2,DES_key_schedule *ks3,
1.206 + DES_cblock *ivec,int *num);
1.207 +
1.208 +IMPORT_C void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
1.209 + DES_cblock *out_white);
1.210 +
1.211 +IMPORT_C int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
1.212 + DES_cblock *iv);
1.213 +IMPORT_C int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
1.214 + DES_cblock *iv);
1.215 +IMPORT_C char *DES_fcrypt(const char *buf,const char *salt, char *ret);
1.216 +IMPORT_C char *DES_crypt(const char *buf,const char *salt);
1.217 +IMPORT_C void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
1.218 + long length,DES_key_schedule *schedule,DES_cblock *ivec);
1.219 +IMPORT_C void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
1.220 + long length,DES_key_schedule *schedule,DES_cblock *ivec,
1.221 + int enc);
1.222 +IMPORT_C DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
1.223 + long length,int out_count,DES_cblock *seed);
1.224 +IMPORT_C int DES_random_key(DES_cblock *ret);
1.225 +IMPORT_C void DES_set_odd_parity(DES_cblock *key);
1.226 +IMPORT_C int DES_check_key_parity(const_DES_cblock *key);
1.227 +IMPORT_C int DES_is_weak_key(const_DES_cblock *key);
1.228 +/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
1.229 + * DES_set_key_checked if global variable DES_check_key is set,
1.230 + * DES_set_key_unchecked otherwise. */
1.231 +IMPORT_C int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
1.232 +IMPORT_C int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
1.233 +IMPORT_C int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
1.234 +IMPORT_C void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
1.235 +IMPORT_C void DES_string_to_key(const char *str,DES_cblock *key);
1.236 +IMPORT_C void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
1.237 +IMPORT_C void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
1.238 + DES_key_schedule *schedule,DES_cblock *ivec,int *num,
1.239 + int enc);
1.240 +IMPORT_C void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
1.241 + DES_key_schedule *schedule,DES_cblock *ivec,int *num);
1.242 +
1.243 +IMPORT_C int DES_read_password(DES_cblock *key, const char *prompt, int verify);
1.244 +IMPORT_C int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
1.245 + int verify);
1.246 +
1.247 +#define DES_fixup_key_parity DES_set_odd_parity
1.248 +
1.249 +#ifdef __cplusplus
1.250 +}
1.251 +#endif
1.252 +
1.253 +#endif