diff options
| author | jsing <> | 2025-09-08 12:50:02 +0000 |
|---|---|---|
| committer | jsing <> | 2025-09-08 12:50:02 +0000 |
| commit | 0b23e36dfa750e5a98824fc469f69a27c5f25d3b (patch) | |
| tree | c007251634624329cae7430ff41f81d6e2ac396c /src/lib/libc | |
| parent | 27935bc83495bf29902f88b49a448b5fba6cb8ac (diff) | |
| download | openbsd-0b23e36dfa750e5a98824fc469f69a27c5f25d3b.tar.gz openbsd-0b23e36dfa750e5a98824fc469f69a27c5f25d3b.tar.bz2 openbsd-0b23e36dfa750e5a98824fc469f69a27c5f25d3b.zip | |
Zero the round keys on AES_set_{en,de}crypt_key() function entry.
This avoids leaving previous round keys around on failure, or leaving parts
of previous round keys behind if reused with a smaller key size.
ok tb@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/aes/aes.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/lib/libcrypto/aes/aes.c b/src/lib/libcrypto/aes/aes.c index f9b2cfd9dd..6ac1983968 100644 --- a/src/lib/libcrypto/aes/aes.c +++ b/src/lib/libcrypto/aes/aes.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: aes.c,v 1.15 2025/09/08 12:46:38 jsing Exp $ */ | 1 | /* $OpenBSD: aes.c,v 1.16 2025/09/08 12:50:02 jsing Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -88,6 +88,8 @@ aes_rounds_for_key_length(int bits) | |||
| 88 | int | 88 | int |
| 89 | AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) | 89 | AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) |
| 90 | { | 90 | { |
| 91 | explicit_bzero(key->rd_key, sizeof(key->rd_key)); | ||
| 92 | |||
| 91 | if (userKey == NULL || key == NULL) | 93 | if (userKey == NULL || key == NULL) |
| 92 | return -1; | 94 | return -1; |
| 93 | if ((key->rounds = aes_rounds_for_key_length(bits)) <= 0) | 95 | if ((key->rounds = aes_rounds_for_key_length(bits)) <= 0) |
| @@ -100,6 +102,8 @@ LCRYPTO_ALIAS(AES_set_encrypt_key); | |||
| 100 | int | 102 | int |
| 101 | AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) | 103 | AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) |
| 102 | { | 104 | { |
| 105 | explicit_bzero(key->rd_key, sizeof(key->rd_key)); | ||
| 106 | |||
| 103 | if (userKey == NULL || key == NULL) | 107 | if (userKey == NULL || key == NULL) |
| 104 | return -1; | 108 | return -1; |
| 105 | if ((key->rounds = aes_rounds_for_key_length(bits)) <= 0) | 109 | if ((key->rounds = aes_rounds_for_key_length(bits)) <= 0) |
