summaryrefslogtreecommitdiffstats
path: root/crypto/pkcs12
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2001-03-18 02:11:42 +0000
committerDr. Stephen Henson <steve@openssl.org>2001-03-18 02:11:42 +0000
commit02ee8626fbf52c6b1cd7ce2508369f59eda701e9 (patch)
treecc2a7d328d87453b5b17c7b48fe532fbae1558b0 /crypto/pkcs12
parent6276e5b41b571706cd6a47437250ae429fb91d69 (diff)
Fix PKCS#12 key generation bug.
Diffstat (limited to 'crypto/pkcs12')
-rw-r--r--crypto/pkcs12/p12_key.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/crypto/pkcs12/p12_key.c b/crypto/pkcs12/p12_key.c
index a9b4b8c972..a4fd5b98ec 100644
--- a/crypto/pkcs12/p12_key.c
+++ b/crypto/pkcs12/p12_key.c
@@ -102,7 +102,7 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
const EVP_MD *md_type)
{
unsigned char *B, *D, *I, *p, *Ai;
- int Slen, Plen, Ilen;
+ int Slen, Plen, Ilen, Ijlen;
int i, j, u, v;
BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */
EVP_MD_CTX ctx;
@@ -180,10 +180,17 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
BN_bin2bn (I + j, v, Ij);
BN_add (Ij, Ij, Bpl1);
BN_bn2bin (Ij, B);
+ Ijlen = BN_num_bytes (Ij);
/* If more than 2^(v*8) - 1 cut off MSB */
- if (BN_num_bytes (Ij) > v) {
+ if (Ijlen > v) {
BN_bn2bin (Ij, B);
memcpy (I + j, B + 1, v);
+#ifndef PKCS12_BROKEN_KEYGEN
+ /* If less than v bytes pad with zeroes */
+ } else if (Ijlen < v) {
+ memset(I + j, 0, v - Ijlen);
+ BN_bn2bin(Ij, I + j + v - Ijlen);
+#endif
} else BN_bn2bin (Ij, I + j);
}
}