diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2004-03-28 17:38:00 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2004-03-28 17:38:00 +0000 |
commit | 216659eb87485402a8e861a6de77233d1f5d7425 (patch) | |
tree | fb761bda98537dffb5029f9b7ad71b63a4e0530a /crypto/evp/e_des.c | |
parent | 5d6383c83f34a9c8612a6eedd484d41e4be4974c (diff) |
Enhance EVP code to generate random symmetric keys of the
appropriate form, for example correct DES parity.
Update S/MIME code and EVP_SealInit to use new functions.
PR: 700
Diffstat (limited to 'crypto/evp/e_des.c')
-rw-r--r-- | crypto/evp/e_des.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/crypto/evp/e_des.c b/crypto/evp/e_des.c index f2554ecc6a..856323648c 100644 --- a/crypto/evp/e_des.c +++ b/crypto/evp/e_des.c @@ -63,9 +63,11 @@ #include <openssl/objects.h> #include "evp_locl.h" #include <openssl/des.h> +#include <openssl/rand.h> static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc); +static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); /* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */ @@ -127,26 +129,48 @@ static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64, - 0, des_init_key, NULL, + EVP_CIPH_RAND_KEY, des_init_key, NULL, EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, - NULL) + des_ctrl) -BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,0,des_init_key,NULL, +BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1, + EVP_CIPH_RAND_KEY, des_init_key,NULL, EVP_CIPHER_set_asn1_iv, - EVP_CIPHER_get_asn1_iv,NULL) + EVP_CIPHER_get_asn1_iv,des_ctrl) -BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,0,des_init_key,NULL, +BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8, + EVP_CIPH_RAND_KEY,des_init_key,NULL, EVP_CIPHER_set_asn1_iv, - EVP_CIPHER_get_asn1_iv,NULL) + EVP_CIPHER_get_asn1_iv,des_ctrl) static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { DES_cblock *deskey = (DES_cblock *)key; - +#ifdef EVP_CHECK_DES_KEY + if(DES_set_key_checked(deskey,ctx->cipher_data) != 0) + return 0; +#else DES_set_key_unchecked(deskey,ctx->cipher_data); +#endif return 1; } +static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) + { + + switch(type) + { + case EVP_CTRL_RAND_KEY: + if (RAND_bytes(ptr, 8) <= 0) + return 0; + DES_set_odd_parity((DES_cblock *)ptr); + return 1; + + default: + return -1; + } + } + #endif |