summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pkcs12/p12_key.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pkcs12/p12_key.c')
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
index b042dcf05c..a4fd5b98ec 100644
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ b/src/lib/libcrypto/pkcs12/p12_key.c
@@ -84,7 +84,7 @@ int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
84 if(!pass) { 84 if(!pass) {
85 unipass = NULL; 85 unipass = NULL;
86 uniplen = 0; 86 uniplen = 0;
87 } else if (!asc2uni(pass, &unipass, &uniplen)) { 87 } else if (!asc2uni(pass, passlen, &unipass, &uniplen)) {
88 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE); 88 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE);
89 return 0; 89 return 0;
90 } 90 }
@@ -102,7 +102,7 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
102 const EVP_MD *md_type) 102 const EVP_MD *md_type)
103{ 103{
104 unsigned char *B, *D, *I, *p, *Ai; 104 unsigned char *B, *D, *I, *p, *Ai;
105 int Slen, Plen, Ilen; 105 int Slen, Plen, Ilen, Ijlen;
106 int i, j, u, v; 106 int i, j, u, v;
107 BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */ 107 BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */
108 EVP_MD_CTX ctx; 108 EVP_MD_CTX ctx;
@@ -180,10 +180,17 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
180 BN_bin2bn (I + j, v, Ij); 180 BN_bin2bn (I + j, v, Ij);
181 BN_add (Ij, Ij, Bpl1); 181 BN_add (Ij, Ij, Bpl1);
182 BN_bn2bin (Ij, B); 182 BN_bn2bin (Ij, B);
183 Ijlen = BN_num_bytes (Ij);
183 /* If more than 2^(v*8) - 1 cut off MSB */ 184 /* If more than 2^(v*8) - 1 cut off MSB */
184 if (BN_num_bytes (Ij) > v) { 185 if (Ijlen > v) {
185 BN_bn2bin (Ij, B); 186 BN_bn2bin (Ij, B);
186 memcpy (I + j, B + 1, v); 187 memcpy (I + j, B + 1, v);
188#ifndef PKCS12_BROKEN_KEYGEN
189 /* If less than v bytes pad with zeroes */
190 } else if (Ijlen < v) {
191 memset(I + j, 0, v - Ijlen);
192 BN_bn2bin(Ij, I + j + v - Ijlen);
193#endif
187 } else BN_bn2bin (Ij, I + j); 194 } else BN_bn2bin (Ij, I + j);
188 } 195 }
189 } 196 }