diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs12/p12_key.c')
-rw-r--r-- | src/lib/libcrypto/pkcs12/p12_key.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c index 424203f648..a29794bbbc 100644 --- a/src/lib/libcrypto/pkcs12/p12_key.c +++ b/src/lib/libcrypto/pkcs12/p12_key.c | |||
@@ -107,7 +107,6 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, | |||
107 | unsigned char *B, *D, *I, *p, *Ai; | 107 | unsigned char *B, *D, *I, *p, *Ai; |
108 | int Slen, Plen, Ilen, Ijlen; | 108 | int Slen, Plen, Ilen, Ijlen; |
109 | int i, j, u, v; | 109 | int i, j, u, v; |
110 | int ret = 0; | ||
111 | BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */ | 110 | BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */ |
112 | EVP_MD_CTX ctx; | 111 | EVP_MD_CTX ctx; |
113 | #ifdef DEBUG_KEYGEN | 112 | #ifdef DEBUG_KEYGEN |
@@ -145,8 +144,10 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, | |||
145 | I = OPENSSL_malloc (Ilen); | 144 | I = OPENSSL_malloc (Ilen); |
146 | Ij = BN_new(); | 145 | Ij = BN_new(); |
147 | Bpl1 = BN_new(); | 146 | Bpl1 = BN_new(); |
148 | if (!D || !Ai || !B || !I || !Ij || !Bpl1) | 147 | if (!D || !Ai || !B || !I || !Ij || !Bpl1) { |
149 | goto err; | 148 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE); |
149 | return 0; | ||
150 | } | ||
150 | for (i = 0; i < v; i++) D[i] = id; | 151 | for (i = 0; i < v; i++) D[i] = id; |
151 | p = I; | 152 | p = I; |
152 | for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen]; | 153 | for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen]; |
@@ -163,22 +164,28 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, | |||
163 | } | 164 | } |
164 | memcpy (out, Ai, min (n, u)); | 165 | memcpy (out, Ai, min (n, u)); |
165 | if (u >= n) { | 166 | if (u >= n) { |
167 | OPENSSL_free (Ai); | ||
168 | OPENSSL_free (B); | ||
169 | OPENSSL_free (D); | ||
170 | OPENSSL_free (I); | ||
171 | BN_free (Ij); | ||
172 | BN_free (Bpl1); | ||
173 | EVP_MD_CTX_cleanup(&ctx); | ||
166 | #ifdef DEBUG_KEYGEN | 174 | #ifdef DEBUG_KEYGEN |
167 | fprintf(stderr, "Output KEY (length %d)\n", tmpn); | 175 | fprintf(stderr, "Output KEY (length %d)\n", tmpn); |
168 | h__dump(tmpout, tmpn); | 176 | h__dump(tmpout, tmpn); |
169 | #endif | 177 | #endif |
170 | ret = 1; | 178 | return 1; |
171 | goto end; | ||
172 | } | 179 | } |
173 | n -= u; | 180 | n -= u; |
174 | out += u; | 181 | out += u; |
175 | for (j = 0; j < v; j++) B[j] = Ai[j % u]; | 182 | for (j = 0; j < v; j++) B[j] = Ai[j % u]; |
176 | /* Work out B + 1 first then can use B as tmp space */ | 183 | /* Work out B + 1 first then can use B as tmp space */ |
177 | if (!BN_bin2bn (B, v, Bpl1)) goto err; | 184 | BN_bin2bn (B, v, Bpl1); |
178 | if (!BN_add_word (Bpl1, 1)) goto err; | 185 | BN_add_word (Bpl1, 1); |
179 | for (j = 0; j < Ilen ; j+=v) { | 186 | for (j = 0; j < Ilen ; j+=v) { |
180 | if (!BN_bin2bn (I + j, v, Ij)) goto err; | 187 | BN_bin2bn (I + j, v, Ij); |
181 | if (!BN_add (Ij, Ij, Bpl1)) goto err; | 188 | BN_add (Ij, Ij, Bpl1); |
182 | BN_bn2bin (Ij, B); | 189 | BN_bn2bin (Ij, B); |
183 | Ijlen = BN_num_bytes (Ij); | 190 | Ijlen = BN_num_bytes (Ij); |
184 | /* If more than 2^(v*8) - 1 cut off MSB */ | 191 | /* If more than 2^(v*8) - 1 cut off MSB */ |
@@ -194,19 +201,6 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, | |||
194 | } else BN_bn2bin (Ij, I + j); | 201 | } else BN_bn2bin (Ij, I + j); |
195 | } | 202 | } |
196 | } | 203 | } |
197 | |||
198 | err: | ||
199 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE); | ||
200 | |||
201 | end: | ||
202 | OPENSSL_free (Ai); | ||
203 | OPENSSL_free (B); | ||
204 | OPENSSL_free (D); | ||
205 | OPENSSL_free (I); | ||
206 | BN_free (Ij); | ||
207 | BN_free (Bpl1); | ||
208 | EVP_MD_CTX_cleanup(&ctx); | ||
209 | return ret; | ||
210 | } | 204 | } |
211 | #ifdef DEBUG_KEYGEN | 205 | #ifdef DEBUG_KEYGEN |
212 | void h__dump (unsigned char *p, int len) | 206 | void h__dump (unsigned char *p, int len) |