diff options
author | tb <> | 2024-03-26 07:03:10 +0000 |
---|---|---|
committer | tb <> | 2024-03-26 07:03:10 +0000 |
commit | 600e5a9c434cb614e3586918df30a3b881269d93 (patch) | |
tree | 8fbf7d8e9ec59ecab0ac2d76c3ffaef24c42ee2b | |
parent | 29662cf4ceb1e62c6b39fead7ab65b4826e9a0bd (diff) | |
download | openbsd-600e5a9c434cb614e3586918df30a3b881269d93.tar.gz openbsd-600e5a9c434cb614e3586918df30a3b881269d93.tar.bz2 openbsd-600e5a9c434cb614e3586918df30a3b881269d93.zip |
Remove PKCS5_pbe2_set_iv()
This used to be a generalization of PKCS5_pbe2_set(). Its only caller was
the latter, which always passes aiv == NULL and pbe_prf == -1. Thus, the
iv would always be random and regarding the pbe_prf, it would always end
up being NID_hmacWithSHA1 since the only ctrl grokking EVP_CTRL_PBE_PRF_NID
was RC2's control, but only if PBE_PRF_TEST was defined, which it wasn't.
ok jsing
-rw-r--r-- | src/lib/libcrypto/asn1/p5_pbev2.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c index 4a6ac06212..76872a8dec 100644 --- a/src/lib/libcrypto/asn1/p5_pbev2.c +++ b/src/lib/libcrypto/asn1/p5_pbev2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: p5_pbev2.c,v 1.34 2024/03/26 05:43:22 tb Exp $ */ | 1 | /* $OpenBSD: p5_pbev2.c,v 1.35 2024/03/26 07:03:10 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999-2004. | 3 | * project 1999-2004. |
4 | */ | 4 | */ |
@@ -177,17 +177,17 @@ PBKDF2PARAM_free(PBKDF2PARAM *a) | |||
177 | ASN1_item_free((ASN1_VALUE *)a, &PBKDF2PARAM_it); | 177 | ASN1_item_free((ASN1_VALUE *)a, &PBKDF2PARAM_it); |
178 | } | 178 | } |
179 | 179 | ||
180 | /* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: | 180 | /* |
181 | * Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: | ||
181 | * yes I know this is horrible! | 182 | * yes I know this is horrible! |
182 | * | ||
183 | * Extended version to allow application supplied PRF NID and IV. | ||
184 | */ | 183 | */ |
185 | 184 | ||
186 | static X509_ALGOR * | 185 | X509_ALGOR * |
187 | PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt, | 186 | PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, unsigned char *salt, |
188 | int saltlen, unsigned char *aiv, int prf_nid) | 187 | int saltlen) |
189 | { | 188 | { |
190 | X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL; | 189 | X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL; |
190 | int prf_nid = NID_hmacWithSHA1; | ||
191 | int alg_nid, keylen; | 191 | int alg_nid, keylen; |
192 | EVP_CIPHER_CTX ctx; | 192 | EVP_CIPHER_CTX ctx; |
193 | unsigned char iv[EVP_MAX_IV_LENGTH]; | 193 | unsigned char iv[EVP_MAX_IV_LENGTH]; |
@@ -212,12 +212,8 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt, | |||
212 | goto merr; | 212 | goto merr; |
213 | 213 | ||
214 | /* Create random IV */ | 214 | /* Create random IV */ |
215 | if (EVP_CIPHER_iv_length(cipher)) { | 215 | if (EVP_CIPHER_iv_length(cipher) > 0) |
216 | if (aiv) | 216 | arc4random_buf(iv, EVP_CIPHER_iv_length(cipher)); |
217 | memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher)); | ||
218 | else | ||
219 | arc4random_buf(iv, EVP_CIPHER_iv_length(cipher)); | ||
220 | } | ||
221 | 217 | ||
222 | EVP_CIPHER_CTX_legacy_clear(&ctx); | 218 | EVP_CIPHER_CTX_legacy_clear(&ctx); |
223 | 219 | ||
@@ -229,14 +225,6 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt, | |||
229 | EVP_CIPHER_CTX_cleanup(&ctx); | 225 | EVP_CIPHER_CTX_cleanup(&ctx); |
230 | goto err; | 226 | goto err; |
231 | } | 227 | } |
232 | /* If prf NID unspecified see if cipher has a preference. | ||
233 | * An error is OK here: just means use default PRF. | ||
234 | */ | ||
235 | if ((prf_nid == -1) && | ||
236 | EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) { | ||
237 | ERR_clear_error(); | ||
238 | prf_nid = NID_hmacWithSHA1; | ||
239 | } | ||
240 | EVP_CIPHER_CTX_cleanup(&ctx); | 228 | EVP_CIPHER_CTX_cleanup(&ctx); |
241 | 229 | ||
242 | /* If its RC2 then we'd better setup the key length */ | 230 | /* If its RC2 then we'd better setup the key length */ |
@@ -288,13 +276,6 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt, | |||
288 | } | 276 | } |
289 | 277 | ||
290 | X509_ALGOR * | 278 | X509_ALGOR * |
291 | PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, unsigned char *salt, | ||
292 | int saltlen) | ||
293 | { | ||
294 | return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1); | ||
295 | } | ||
296 | |||
297 | X509_ALGOR * | ||
298 | PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid, | 279 | PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid, |
299 | int keylen) | 280 | int keylen) |
300 | { | 281 | { |