diff options
author | Pauli <pauli@openssl.org> | 2023-02-07 09:29:57 +1100 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-02-08 21:54:52 +1100 |
commit | b0e596cd254371ffc2223a755ca66bb1c12a0340 (patch) | |
tree | 37447216e8c81d6d2548ff8d1fd8420f60bf1f7a /providers | |
parent | c99faac4f1bce293cf587ff9400c0cda1987b2de (diff) |
des: prevent error when using two key triple DES with a random key
Two key 3DES only sets two keys and the random generation errors out if fewer
than three keys are required. It shouldn't.
Fixes #20212
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20224)
(cherry picked from commit 587e0407803af330c0b04238fcbce78521ce35d7)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/implementations/ciphers/cipher_tdes_common.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/providers/implementations/ciphers/cipher_tdes_common.c b/providers/implementations/ciphers/cipher_tdes_common.c index 346aec05a1..c31002b11b 100644 --- a/providers/implementations/ciphers/cipher_tdes_common.c +++ b/providers/implementations/ciphers/cipher_tdes_common.c @@ -123,13 +123,12 @@ static int tdes_generatekey(PROV_CIPHER_CTX *ctx, void *ptr) if (kl == 0 || RAND_priv_bytes_ex(ctx->libctx, ptr, kl, 0) <= 0) return 0; DES_set_odd_parity(deskey); - if (kl >= 16) + if (kl >= 16) { DES_set_odd_parity(deskey + 1); - if (kl >= 24) { - DES_set_odd_parity(deskey + 2); - return 1; + if (kl >= 24) + DES_set_odd_parity(deskey + 2); } - return 0; + return 1; } int ossl_tdes_get_ctx_params(void *vctx, OSSL_PARAM params[]) |