summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_ecb_3d.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_ecb_3d.c')
-rw-r--r--src/lib/libcrypto/evp/e_ecb_3d.c67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/lib/libcrypto/evp/e_ecb_3d.c b/src/lib/libcrypto/evp/e_ecb_3d.c
index 908fc0760a..354a8b79a7 100644
--- a/src/lib/libcrypto/evp/e_ecb_3d.c
+++ b/src/lib/libcrypto/evp/e_ecb_3d.c
@@ -56,24 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 67static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 68 unsigned char *iv,int enc);
69static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 69static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 70 unsigned char *in, unsigned int inl);
71#else
72static void des_ede_init_key();
73static void des_ede3_init_key();
74static void des_ede_cipher();
75#endif
76
77static EVP_CIPHER d_ede_cipher2= 71static EVP_CIPHER d_ede_cipher2=
78 { 72 {
79 NID_des_ede, 73 NID_des_ede,
@@ -99,63 +93,66 @@ static EVP_CIPHER d_ede3_cipher3=
99 NULL, 93 NULL,
100 }; 94 };
101 95
102EVP_CIPHER *EVP_des_ede() 96EVP_CIPHER *EVP_des_ede(void)
103 { 97 {
104 return(&d_ede_cipher2); 98 return(&d_ede_cipher2);
105 } 99 }
106 100
107EVP_CIPHER *EVP_des_ede3() 101EVP_CIPHER *EVP_des_ede3(void)
108 { 102 {
109 return(&d_ede3_cipher3); 103 return(&d_ede3_cipher3);
110 } 104 }
111 105
112static void des_ede_init_key(ctx,key,iv,enc) 106static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
113EVP_CIPHER_CTX *ctx; 107 unsigned char *iv, int enc)
114unsigned char *key;
115unsigned char *iv;
116int enc;
117 { 108 {
118 if (key != NULL) 109 des_cblock *deskey = (des_cblock *)key;
110
111 if (deskey != NULL)
119 { 112 {
120 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 113 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
121 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 114 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
122 memcpy( (char *)ctx->c.des_ede.ks3, 115 memcpy( (char *)ctx->c.des_ede.ks3,
123 (char *)ctx->c.des_ede.ks1, 116 (char *)ctx->c.des_ede.ks1,
124 sizeof(ctx->c.des_ede.ks1)); 117 sizeof(ctx->c.des_ede.ks1));
125 } 118 }
126 } 119 }
127 120
128static void des_ede3_init_key(ctx,key,iv,enc) 121static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
129EVP_CIPHER_CTX *ctx; 122 unsigned char *iv, int enc)
130unsigned char *key;
131unsigned char *iv;
132int enc;
133 { 123 {
134 if (key != NULL) 124 des_cblock *deskey = (des_cblock *)key;
125
126 if (deskey != NULL)
135 { 127 {
136 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 128 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
137 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 129 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
138 des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); 130 des_set_key(&deskey[2],ctx->c.des_ede.ks3);
139 } 131 }
140 } 132 }
141 133
142static void des_ede_cipher(ctx,out,in,inl) 134static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
143EVP_CIPHER_CTX *ctx; 135 unsigned char *in, unsigned int inl)
144unsigned char *out;
145unsigned char *in;
146unsigned int inl;
147 { 136 {
148 unsigned int i; 137 unsigned int i;
138 des_cblock *output /* = (des_cblock *)out */;
139 des_cblock *input /* = (des_cblock *)in */;
149 140
150 if (inl < 8) return; 141 if (inl < 8) return;
151 inl-=8; 142 inl-=8;
152 for (i=0; i<=inl; i+=8) 143 for (i=0; i<=inl; i+=8)
153 { 144 {
154 des_ecb3_encrypt( 145 output = (des_cblock *)(out + i);
155 (des_cblock *)&(in[i]),(des_cblock *)&(out[i]), 146 input = (des_cblock *)(in + i);
147
148 des_ecb3_encrypt(input,output,
156 ctx->c.des_ede.ks1, 149 ctx->c.des_ede.ks1,
157 ctx->c.des_ede.ks2, 150 ctx->c.des_ede.ks2,
158 ctx->c.des_ede.ks3, 151 ctx->c.des_ede.ks3,
159 ctx->encrypt); 152 ctx->encrypt);
153
154 /* output++; */
155 /* input++; */
160 } 156 }
161 } 157 }
158#endif