Skip to content

Commit

Permalink
Remove OPENSSL_ia32cap_P references from AES-NI assembly
Browse files Browse the repository at this point in the history
The AES-NI key schedule functions have two versions, dating to OpenSSL's
23f6eec71dbd472044db7dc854599f1de14a1f48. This cites RT#3576.
Unfortunately, OpenSSL purged their old RT bugs, without any archives,
so this context is now lost. Some archives of openssl-dev discussion
(also predating OpenSSL's archives) give most of the context:
https://groups.google.com/g/mailing.openssl.dev/c/OuFXwW4NfO8/m/7d2ZXVjkxVkJ

Broadly, although AES-NI has an aeskeygenassist instruction for the key
schedule, apparently it's overall faster to ignore it and use aesenclast
instead. But it's slower on older processors, so the assembly would
check for AVX && !XOP as a proxy. (Note we always set XOP to false, even
though this likely wasn't a capability check but a proxy for pre-Xen AMD
chips.)

It is unclear if the aeskeygenassist version is still worthwhile.
However, the aesenclast version requires SSSE3. SSSE3 long predates
AES-NI, but it's not clear if AES-NI implies SSSE3. In OpenSSL, the CCM
AES-NI assembly seems to assume it does. For now, I've preserved the
pair of them.

There are now only two assembly files with OPENSSL_ia32cap_P references!

Bug: 673
Change-Id: I990b1393d780db4caf074c184ce8bbd182da6e29
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68690
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
  • Loading branch information
davidben authored and Boringssl LUCI CQ committed Jun 11, 2024
1 parent a220a60 commit 962432c
Show file tree
Hide file tree
Showing 15 changed files with 1,623 additions and 1,310 deletions.
8 changes: 8 additions & 0 deletions crypto/fipsmodule/aes/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,12 @@ int aes_hw_set_decrypt_key(const uint8_t *user_key, int bits, AES_KEY *key) {
}
return ret;
}

int aes_hw_set_encrypt_key(const uint8_t *user_key, int bits, AES_KEY *key) {
if (aes_hw_set_encrypt_key_alt_preferred()) {
return aes_hw_set_encrypt_key_alt(user_key, bits, key);
} else {
return aes_hw_set_encrypt_key_base(user_key, bits, key);
}
}
#endif
11 changes: 10 additions & 1 deletion crypto/fipsmodule/aes/aes_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,16 @@ TEST(AESTest, ABI) {
}

#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
ASSERT_EQ(CHECK_ABI_SEH(aes_hw_set_encrypt_key, kKey, bits, &key), 0);
ASSERT_EQ(CHECK_ABI_SEH(aes_hw_set_encrypt_key_base, kKey, bits, &key), 0);
if (aes_hw_set_encrypt_key_alt_capable()) {
AES_KEY alt;
ASSERT_EQ(CHECK_ABI_SEH(aes_hw_set_encrypt_key_alt, kKey, bits, &alt),
0);
EXPECT_EQ(alt.rounds, key.rounds);
for (unsigned i = 0; i <= alt.rounds; i++) {
EXPECT_EQ(alt.rd_key[i], key.rd_key[i]);
}
}
CHECK_ABI_SEH(aes_hw_encrypt_key_to_decrypt_key, &key);
#else
ASSERT_EQ(CHECK_ABI_SEH(aes_hw_set_decrypt_key, kKey, bits, &key), 0);
Expand Down
Loading

0 comments on commit 962432c

Please sign in to comment.