aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-05-06 20:28:17 -0400
committerJack Lloyd <[email protected]>2020-05-08 06:19:59 -0400
commit4a895ebf662403cccb2451f9905dd105ca46fe13 (patch)
tree30a167ec5dd3811ab163870853fe625d909b44b3
parentc06cb332d7039256a9d3c0c3aa4024e1e37b7626 (diff)
Avoid extra resize during AES key schedule
-rw-r--r--src/lib/block/aes/aes.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp
index 21f580641..b1792561f 100644
--- a/src/lib/block/aes/aes.cpp
+++ b/src/lib/block/aes/aes.cpp
@@ -660,8 +660,8 @@ void aes_key_schedule(const uint8_t key[], size_t length,
CT::poison(key, length);
- EK.resize(length + 32);
- DK.resize(length + 32);
+ EK.resize(length + 28);
+ DK.resize(length + 28);
for(size_t i = 0; i != X; ++i)
EK[i] = load_be<uint32_t>(key, i);
@@ -670,7 +670,7 @@ void aes_key_schedule(const uint8_t key[], size_t length,
{
EK[i] = EK[i-X] ^ RC[(i-X)/X] ^ rotl<8>(SE_word(EK[i-1]));
- for(size_t j = 1; j != X; ++j)
+ for(size_t j = 1; j != X && (i+j) < EK.size(); ++j)
{
EK[i+j] = EK[i+j-X];
@@ -689,7 +689,7 @@ void aes_key_schedule(const uint8_t key[], size_t length,
DK[i+3] = EK[4*rounds-i+3];
}
- for(size_t i = 4; i != length + 24; ++i)
+ for(size_t i = 4; i != DK.size() - 4; ++i)
{
const uint8_t s0 = get_byte(0, DK[i]);
const uint8_t s1 = get_byte(1, DK[i]);
@@ -702,9 +702,6 @@ void aes_key_schedule(const uint8_t key[], size_t length,
rotr<24>(InvMixColumn(s3));
}
- EK.resize(length + 24 + 4);
- DK.resize(length + 24 + 4);
-
if(bswap_keys)
{
// HW AES on little endian needs the subkeys to be byte reversed