summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_xcbc_d.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_xcbc_d.c')
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c96
1 files changed, 46 insertions, 50 deletions
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
index 250e88c8c5..7313e4d225 100644
--- a/src/lib/libcrypto/evp/e_xcbc_d.c
+++ b/src/lib/libcrypto/evp/e_xcbc_d.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -67,24 +67,22 @@
67#include <openssl/des.h> 67#include <openssl/des.h>
68 68
69static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 69static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
70 const unsigned char *iv,int enc); 70 const unsigned char *iv, int enc);
71static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 71static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
72 const unsigned char *in, size_t inl); 72 const unsigned char *in, size_t inl);
73 73
74 74
75typedef struct 75typedef struct {
76 { 76 DES_key_schedule ks;/* key schedule */
77 DES_key_schedule ks;/* key schedule */ 77 DES_cblock inw;
78 DES_cblock inw; 78 DES_cblock outw;
79 DES_cblock outw; 79} DESX_CBC_KEY;
80 } DESX_CBC_KEY;
81 80
82#define data(ctx) ((DESX_CBC_KEY *)(ctx)->cipher_data) 81#define data(ctx) ((DESX_CBC_KEY *)(ctx)->cipher_data)
83 82
84static const EVP_CIPHER d_xcbc_cipher= 83static const EVP_CIPHER d_xcbc_cipher = {
85 {
86 NID_desx_cbc, 84 NID_desx_cbc,
87 8,24,8, 85 8, 24, 8,
88 EVP_CIPH_CBC_MODE, 86 EVP_CIPH_CBC_MODE,
89 desx_cbc_init_key, 87 desx_cbc_init_key,
90 desx_cbc_cipher, 88 desx_cbc_cipher,
@@ -94,45 +92,43 @@ static const EVP_CIPHER d_xcbc_cipher=
94 EVP_CIPHER_get_asn1_iv, 92 EVP_CIPHER_get_asn1_iv,
95 NULL, 93 NULL,
96 NULL 94 NULL
97 }; 95};
98 96
99const EVP_CIPHER *EVP_desx_cbc(void) 97const EVP_CIPHER *
100 { 98EVP_desx_cbc(void)
101 return(&d_xcbc_cipher); 99{
102 } 100 return (&d_xcbc_cipher);
103 101}
104static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 102
105 const unsigned char *iv, int enc) 103static int
106 { 104desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
105 const unsigned char *iv, int enc)
106{
107 DES_cblock *deskey = (DES_cblock *)key; 107 DES_cblock *deskey = (DES_cblock *)key;
108 108
109 DES_set_key_unchecked(deskey,&data(ctx)->ks); 109 DES_set_key_unchecked(deskey, &data(ctx)->ks);
110 memcpy(&data(ctx)->inw[0],&key[8],8); 110 memcpy(&data(ctx)->inw[0], &key[8], 8);
111 memcpy(&data(ctx)->outw[0],&key[16],8); 111 memcpy(&data(ctx)->outw[0], &key[16], 8);
112 112
113 return 1; 113 return 1;
114 } 114}
115 115
116static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 116static int
117 const unsigned char *in, size_t inl) 117desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
118 { 118 const unsigned char *in, size_t inl)
119 while (inl>=EVP_MAXCHUNK) 119{
120 { 120 while (inl >= EVP_MAXCHUNK) {
121 DES_xcbc_encrypt(in,out,(long)EVP_MAXCHUNK,&data(ctx)->ks, 121 DES_xcbc_encrypt(in, out, (long)EVP_MAXCHUNK, &data(ctx)->ks,
122 (DES_cblock *)&(ctx->iv[0]), 122 (DES_cblock *)&(ctx->iv[0]), &data(ctx)->inw,
123 &data(ctx)->inw, 123 &data(ctx)->outw, ctx->encrypt);
124 &data(ctx)->outw, 124 inl -= EVP_MAXCHUNK;
125 ctx->encrypt); 125 in += EVP_MAXCHUNK;
126 inl-=EVP_MAXCHUNK; 126 out += EVP_MAXCHUNK;
127 in +=EVP_MAXCHUNK; 127 }
128 out+=EVP_MAXCHUNK;
129 }
130 if (inl) 128 if (inl)
131 DES_xcbc_encrypt(in,out,(long)inl,&data(ctx)->ks, 129 DES_xcbc_encrypt(in, out, (long)inl, &data(ctx)->ks,
132 (DES_cblock *)&(ctx->iv[0]), 130 (DES_cblock *)&(ctx->iv[0]), &data(ctx)->inw,
133 &data(ctx)->inw, 131 &data(ctx)->outw, ctx->encrypt);
134 &data(ctx)->outw,
135 ctx->encrypt);
136 return 1; 132 return 1;
137 } 133}
138#endif 134#endif