diff options
author | Ben Laurie <ben@openssl.org> | 2001-07-30 23:57:25 +0000 |
---|---|---|
committer | Ben Laurie <ben@openssl.org> | 2001-07-30 23:57:25 +0000 |
commit | dbad169019598981174ff46c7a9bf58373b0e53a (patch) | |
tree | ce8ca1188d5614648f24b03967785543f1edc8f5 /crypto/evp/e_des3.c | |
parent | 3ba5d1cf2eb6ef28ac5f6d9f3d28020d00c5be50 (diff) |
Really add the EVP and all of the DES changes.
Diffstat (limited to 'crypto/evp/e_des3.c')
-rw-r--r-- | crypto/evp/e_des3.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/crypto/evp/e_des3.c b/crypto/evp/e_des3.c index b1b36ce130..7a18cb618b 100644 --- a/crypto/evp/e_des3.c +++ b/crypto/evp/e_des3.c @@ -62,6 +62,7 @@ #include <openssl/evp.h> #include <openssl/objects.h> #include "evp_locl.h" +#include <openssl/des.h> static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv,int enc); @@ -69,6 +70,15 @@ static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv,int enc); +typedef struct + { + des_key_schedule ks1;/* key schedule */ + des_key_schedule ks2;/* key schedule (for ede) */ + des_key_schedule ks3;/* key schedule (for ede3) */ + } DES_EDE_KEY; + +#define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data) + /* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, @@ -76,8 +86,9 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, { BLOCK_CIPHER_ecb_loop() des_ecb3_encrypt((des_cblock *)(in + i), (des_cblock *)(out + i), - ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, - ctx->encrypt); + &data(ctx)->ks1, &data(ctx)->ks2, + &data(ctx)->ks3, + ctx->encrypt); return 1; } @@ -85,8 +96,8 @@ static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) { des_ede3_ofb64_encrypt(in, out, (long)inl, - ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, - (des_cblock *)ctx->iv, &ctx->num); + &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, + (des_cblock *)ctx->iv, &ctx->num); return 1; } @@ -105,8 +116,8 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } #endif /* KSSL_DEBUG */ des_ede3_cbc_encrypt(in, out, (long)inl, - ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, - (des_cblock *)ctx->iv, ctx->encrypt); + &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, + (des_cblock *)ctx->iv, ctx->encrypt); return 1; } @@ -114,12 +125,12 @@ static int des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) { des_ede3_cfb64_encrypt(in, out, (long)inl, - ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, - (des_cblock *)ctx->iv, &ctx->num, ctx->encrypt); + &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, + (des_cblock *)ctx->iv, &ctx->num, ctx->encrypt); return 1; } -BLOCK_CIPHER_defs(des_ede, des_ede, NID_des_ede, 8, 16, 8, +BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 0, des_ede_init_key, NULL, EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, @@ -130,7 +141,7 @@ BLOCK_CIPHER_defs(des_ede, des_ede, NID_des_ede, 8, 16, 8, #define des_ede3_cbc_cipher des_ede_cbc_cipher #define des_ede3_ecb_cipher des_ede_ecb_cipher -BLOCK_CIPHER_defs(des_ede3, des_ede, NID_des_ede3, 8, 24, 8, +BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 0, des_ede3_init_key, NULL, EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, @@ -141,11 +152,10 @@ static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, { des_cblock *deskey = (des_cblock *)key; - des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1); - des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); - memcpy( (char *)ctx->c.des_ede.ks3, - (char *)ctx->c.des_ede.ks1, - sizeof(ctx->c.des_ede.ks1)); + des_set_key_unchecked(&deskey[0],&data(ctx)->ks1); + des_set_key_unchecked(&deskey[1],&data(ctx)->ks2); + memcpy(&data(ctx)->ks3,&data(ctx)->ks1, + sizeof(data(ctx)->ks1)); return 1; } @@ -164,9 +174,9 @@ static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, } #endif /* KSSL_DEBUG */ - des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1); - des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2); - des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3); + des_set_key_unchecked(&deskey[0],&data(ctx)->ks1); + des_set_key_unchecked(&deskey[1],&data(ctx)->ks2); + des_set_key_unchecked(&deskey[2],&data(ctx)->ks3); return 1; } |