diff options
Diffstat (limited to 'src/lib/libcrypto/evp/e_rc2.c')
| -rw-r--r-- | src/lib/libcrypto/evp/e_rc2.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c index 3955c3ef84..4685198e2e 100644 --- a/src/lib/libcrypto/evp/e_rc2.c +++ b/src/lib/libcrypto/evp/e_rc2.c | |||
| @@ -56,13 +56,14 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #ifndef NO_RC2 | 59 | #ifndef OPENSSL_NO_RC2 |
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
| 63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
| 64 | #include <openssl/objects.h> | 64 | #include <openssl/objects.h> |
| 65 | #include "evp_locl.h" | 65 | #include "evp_locl.h" |
| 66 | #include <openssl/rc2.h> | ||
| 66 | 67 | ||
| 67 | static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 68 | static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
| 68 | const unsigned char *iv,int enc); | 69 | const unsigned char *iv,int enc); |
| @@ -72,9 +73,17 @@ static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | |||
| 72 | static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | 73 | static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); |
| 73 | static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); | 74 | static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); |
| 74 | 75 | ||
| 75 | IMPLEMENT_BLOCK_CIPHER(rc2, rc2.ks, RC2, rc2, NID_rc2, | 76 | typedef struct |
| 77 | { | ||
| 78 | int key_bits; /* effective key bits */ | ||
| 79 | RC2_KEY ks; /* key schedule */ | ||
| 80 | } EVP_RC2_KEY; | ||
| 81 | |||
| 82 | #define data(ctx) ((EVP_RC2_KEY *)(ctx)->cipher_data) | ||
| 83 | |||
| 84 | IMPLEMENT_BLOCK_CIPHER(rc2, ks, RC2, EVP_RC2_KEY, NID_rc2, | ||
| 76 | 8, | 85 | 8, |
| 77 | EVP_RC2_KEY_SIZE, 8, | 86 | RC2_KEY_LENGTH, 8, 64, |
| 78 | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT, | 87 | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT, |
| 79 | rc2_init_key, NULL, | 88 | rc2_init_key, NULL, |
| 80 | rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv, | 89 | rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv, |
| @@ -84,7 +93,7 @@ IMPLEMENT_BLOCK_CIPHER(rc2, rc2.ks, RC2, rc2, NID_rc2, | |||
| 84 | #define RC2_64_MAGIC 0x78 | 93 | #define RC2_64_MAGIC 0x78 |
| 85 | #define RC2_128_MAGIC 0x3a | 94 | #define RC2_128_MAGIC 0x3a |
| 86 | 95 | ||
| 87 | static EVP_CIPHER r2_64_cbc_cipher= | 96 | static const EVP_CIPHER r2_64_cbc_cipher= |
| 88 | { | 97 | { |
| 89 | NID_rc2_64_cbc, | 98 | NID_rc2_64_cbc, |
| 90 | 8,8 /* 64 bit */,8, | 99 | 8,8 /* 64 bit */,8, |
| @@ -92,15 +101,14 @@ static EVP_CIPHER r2_64_cbc_cipher= | |||
| 92 | rc2_init_key, | 101 | rc2_init_key, |
| 93 | rc2_cbc_cipher, | 102 | rc2_cbc_cipher, |
| 94 | NULL, | 103 | NULL, |
| 95 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | 104 | sizeof(EVP_RC2_KEY), |
| 96 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2)), | ||
| 97 | rc2_set_asn1_type_and_iv, | 105 | rc2_set_asn1_type_and_iv, |
| 98 | rc2_get_asn1_type_and_iv, | 106 | rc2_get_asn1_type_and_iv, |
| 99 | rc2_ctrl, | 107 | rc2_ctrl, |
| 100 | NULL | 108 | NULL |
| 101 | }; | 109 | }; |
| 102 | 110 | ||
| 103 | static EVP_CIPHER r2_40_cbc_cipher= | 111 | static const EVP_CIPHER r2_40_cbc_cipher= |
| 104 | { | 112 | { |
| 105 | NID_rc2_40_cbc, | 113 | NID_rc2_40_cbc, |
| 106 | 8,5 /* 40 bit */,8, | 114 | 8,5 /* 40 bit */,8, |
| @@ -108,20 +116,19 @@ static EVP_CIPHER r2_40_cbc_cipher= | |||
| 108 | rc2_init_key, | 116 | rc2_init_key, |
| 109 | rc2_cbc_cipher, | 117 | rc2_cbc_cipher, |
| 110 | NULL, | 118 | NULL, |
| 111 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | 119 | sizeof(EVP_RC2_KEY), |
| 112 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2)), | ||
| 113 | rc2_set_asn1_type_and_iv, | 120 | rc2_set_asn1_type_and_iv, |
| 114 | rc2_get_asn1_type_and_iv, | 121 | rc2_get_asn1_type_and_iv, |
| 115 | rc2_ctrl, | 122 | rc2_ctrl, |
| 116 | NULL | 123 | NULL |
| 117 | }; | 124 | }; |
| 118 | 125 | ||
| 119 | EVP_CIPHER *EVP_rc2_64_cbc(void) | 126 | const EVP_CIPHER *EVP_rc2_64_cbc(void) |
| 120 | { | 127 | { |
| 121 | return(&r2_64_cbc_cipher); | 128 | return(&r2_64_cbc_cipher); |
| 122 | } | 129 | } |
| 123 | 130 | ||
| 124 | EVP_CIPHER *EVP_rc2_40_cbc(void) | 131 | const EVP_CIPHER *EVP_rc2_40_cbc(void) |
| 125 | { | 132 | { |
| 126 | return(&r2_40_cbc_cipher); | 133 | return(&r2_40_cbc_cipher); |
| 127 | } | 134 | } |
| @@ -129,8 +136,8 @@ EVP_CIPHER *EVP_rc2_40_cbc(void) | |||
| 129 | static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 136 | static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
| 130 | const unsigned char *iv, int enc) | 137 | const unsigned char *iv, int enc) |
| 131 | { | 138 | { |
| 132 | RC2_set_key(&(ctx->c.rc2.ks),EVP_CIPHER_CTX_key_length(ctx), | 139 | RC2_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), |
| 133 | key,ctx->c.rc2.key_bits); | 140 | key,data(ctx)->key_bits); |
| 134 | return 1; | 141 | return 1; |
| 135 | } | 142 | } |
| 136 | 143 | ||
| @@ -173,7 +180,7 @@ static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
| 173 | key_bits =rc2_magic_to_meth((int)num); | 180 | key_bits =rc2_magic_to_meth((int)num); |
| 174 | if (!key_bits) | 181 | if (!key_bits) |
| 175 | return(-1); | 182 | return(-1); |
| 176 | if(i > 0) EVP_CipherInit(c, NULL, NULL, iv, -1); | 183 | if(i > 0) EVP_CipherInit_ex(c, NULL, NULL, NULL, iv, -1); |
| 177 | EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL); | 184 | EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL); |
| 178 | EVP_CIPHER_CTX_set_key_length(c, key_bits / 8); | 185 | EVP_CIPHER_CTX_set_key_length(c, key_bits / 8); |
| 179 | } | 186 | } |
| @@ -196,26 +203,26 @@ static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
| 196 | 203 | ||
| 197 | static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | 204 | static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) |
| 198 | { | 205 | { |
| 199 | switch(type) { | 206 | switch(type) |
| 200 | 207 | { | |
| 201 | case EVP_CTRL_INIT: | 208 | case EVP_CTRL_INIT: |
| 202 | c->c.rc2.key_bits = EVP_CIPHER_CTX_key_length(c) * 8; | 209 | data(c)->key_bits = EVP_CIPHER_CTX_key_length(c) * 8; |
| 203 | return 1; | 210 | return 1; |
| 204 | 211 | ||
| 205 | case EVP_CTRL_GET_RC2_KEY_BITS: | 212 | case EVP_CTRL_GET_RC2_KEY_BITS: |
| 206 | *(int *)ptr = c->c.rc2.key_bits; | 213 | *(int *)ptr = data(c)->key_bits; |
| 207 | return 1; | 214 | return 1; |
| 208 | 215 | ||
| 209 | 216 | case EVP_CTRL_SET_RC2_KEY_BITS: | |
| 210 | case EVP_CTRL_SET_RC2_KEY_BITS: | 217 | if(arg > 0) |
| 211 | if(arg > 0) { | 218 | { |
| 212 | c->c.rc2.key_bits = arg; | 219 | data(c)->key_bits = arg; |
| 213 | return 1; | 220 | return 1; |
| 214 | } | 221 | } |
| 215 | return 0; | 222 | return 0; |
| 216 | 223 | ||
| 217 | default: | 224 | default: |
| 218 | return -1; | 225 | return -1; |
| 219 | } | 226 | } |
| 220 | } | 227 | } |
| 221 | 228 | ||
