Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 1 | /* Copyright (c) 2015, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
| 15 | #include <stdio.h> |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 16 | #include <stdlib.h> |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 17 | #include <string.h> |
| 18 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <vector> |
| 21 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
| 23 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 24 | #include <openssl/aes.h> |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 25 | |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 26 | #include "internal.h" |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 27 | #include "../../internal.h" |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 28 | #include "../../test/abi_test.h" |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 29 | #include "../../test/file_test.h" |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 30 | #include "../../test/test_util.h" |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 31 | #include "../../test/wycheproof_util.h" |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 32 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 33 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 34 | static void TestRaw(FileTest *t) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 35 | std::vector<uint8_t> key, plaintext, ciphertext; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 36 | ASSERT_TRUE(t->GetBytes(&key, "Key")); |
| 37 | ASSERT_TRUE(t->GetBytes(&plaintext, "Plaintext")); |
| 38 | ASSERT_TRUE(t->GetBytes(&ciphertext, "Ciphertext")); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 39 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 40 | ASSERT_EQ(static_cast<unsigned>(AES_BLOCK_SIZE), plaintext.size()); |
| 41 | ASSERT_EQ(static_cast<unsigned>(AES_BLOCK_SIZE), ciphertext.size()); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 42 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 43 | AES_KEY aes_key; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 44 | ASSERT_EQ(0, AES_set_encrypt_key(key.data(), 8 * key.size(), &aes_key)); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 45 | |
| 46 | // Test encryption. |
| 47 | uint8_t block[AES_BLOCK_SIZE]; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 48 | AES_encrypt(plaintext.data(), block, &aes_key); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 49 | EXPECT_EQ(Bytes(ciphertext), Bytes(block)); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 50 | |
| 51 | // Test in-place encryption. |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 52 | OPENSSL_memcpy(block, plaintext.data(), AES_BLOCK_SIZE); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 53 | AES_encrypt(block, block, &aes_key); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 54 | EXPECT_EQ(Bytes(ciphertext), Bytes(block)); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 55 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 56 | ASSERT_EQ(0, AES_set_decrypt_key(key.data(), 8 * key.size(), &aes_key)); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 57 | |
| 58 | // Test decryption. |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 59 | AES_decrypt(ciphertext.data(), block, &aes_key); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 60 | EXPECT_EQ(Bytes(plaintext), Bytes(block)); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 61 | |
| 62 | // Test in-place decryption. |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 63 | OPENSSL_memcpy(block, ciphertext.data(), AES_BLOCK_SIZE); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 64 | AES_decrypt(block, block, &aes_key); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 65 | EXPECT_EQ(Bytes(plaintext), Bytes(block)); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 68 | static void TestKeyWrap(FileTest *t) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 69 | // All test vectors use the default IV, so test both with implicit and |
| 70 | // explicit IV. |
| 71 | // |
| 72 | // TODO(davidben): Find test vectors that use a different IV. |
| 73 | static const uint8_t kDefaultIV[] = { |
| 74 | 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, |
| 75 | }; |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 76 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 77 | std::vector<uint8_t> key, plaintext, ciphertext; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 78 | ASSERT_TRUE(t->GetBytes(&key, "Key")); |
| 79 | ASSERT_TRUE(t->GetBytes(&plaintext, "Plaintext")); |
| 80 | ASSERT_TRUE(t->GetBytes(&ciphertext, "Ciphertext")); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 81 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 82 | ASSERT_EQ(plaintext.size() + 8, ciphertext.size()) |
| 83 | << "Invalid Plaintext and Ciphertext lengths."; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 84 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 85 | // Test encryption. |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 86 | AES_KEY aes_key; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 87 | ASSERT_EQ(0, AES_set_encrypt_key(key.data(), 8 * key.size(), &aes_key)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 88 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 89 | // Test with implicit IV. |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 90 | std::unique_ptr<uint8_t[]> buf(new uint8_t[ciphertext.size()]); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 91 | int len = AES_wrap_key(&aes_key, nullptr /* iv */, buf.get(), |
| 92 | plaintext.data(), plaintext.size()); |
| 93 | ASSERT_GE(len, 0); |
| 94 | EXPECT_EQ(Bytes(ciphertext), Bytes(buf.get(), static_cast<size_t>(len))); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 95 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 96 | // Test with explicit IV. |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 97 | OPENSSL_memset(buf.get(), 0, ciphertext.size()); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 98 | len = AES_wrap_key(&aes_key, kDefaultIV, buf.get(), plaintext.data(), |
| 99 | plaintext.size()); |
| 100 | ASSERT_GE(len, 0); |
| 101 | EXPECT_EQ(Bytes(ciphertext), Bytes(buf.get(), static_cast<size_t>(len))); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 102 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 103 | // Test decryption. |
| 104 | ASSERT_EQ(0, AES_set_decrypt_key(key.data(), 8 * key.size(), &aes_key)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 105 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 106 | // Test with implicit IV. |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 107 | buf.reset(new uint8_t[plaintext.size()]); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 108 | len = AES_unwrap_key(&aes_key, nullptr /* iv */, buf.get(), ciphertext.data(), |
| 109 | ciphertext.size()); |
| 110 | ASSERT_GE(len, 0); |
| 111 | EXPECT_EQ(Bytes(plaintext), Bytes(buf.get(), static_cast<size_t>(len))); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 112 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 113 | // Test with explicit IV. |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 114 | OPENSSL_memset(buf.get(), 0, plaintext.size()); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 115 | len = AES_unwrap_key(&aes_key, kDefaultIV, buf.get(), ciphertext.data(), |
| 116 | ciphertext.size()); |
| 117 | ASSERT_GE(len, 0); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 118 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 119 | // Test corrupted ciphertext. |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 120 | ciphertext[0] ^= 1; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 121 | EXPECT_EQ(-1, AES_unwrap_key(&aes_key, nullptr /* iv */, buf.get(), |
| 122 | ciphertext.data(), ciphertext.size())); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 125 | TEST(AESTest, TestVectors) { |
| 126 | FileTestGTest("crypto/fipsmodule/aes/aes_tests.txt", [](FileTest *t) { |
| 127 | if (t->GetParameter() == "Raw") { |
| 128 | TestRaw(t); |
| 129 | } else if (t->GetParameter() == "KeyWrap") { |
| 130 | TestKeyWrap(t); |
| 131 | } else { |
| 132 | ADD_FAILURE() << "Unknown mode " << t->GetParameter(); |
| 133 | } |
| 134 | }); |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 135 | } |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 136 | |
| 137 | TEST(AESTest, WycheproofKeyWrap) { |
| 138 | FileTestGTest("third_party/wycheproof_testvectors/kw_test.txt", |
| 139 | [](FileTest *t) { |
| 140 | std::string key_size; |
| 141 | ASSERT_TRUE(t->GetInstruction(&key_size, "keySize")); |
| 142 | std::vector<uint8_t> ct, key, msg; |
| 143 | ASSERT_TRUE(t->GetBytes(&ct, "ct")); |
| 144 | ASSERT_TRUE(t->GetBytes(&key, "key")); |
| 145 | ASSERT_TRUE(t->GetBytes(&msg, "msg")); |
| 146 | ASSERT_EQ(static_cast<unsigned>(atoi(key_size.c_str())), key.size() * 8); |
| 147 | WycheproofResult result; |
| 148 | ASSERT_TRUE(GetWycheproofResult(t, &result)); |
| 149 | |
| 150 | if (result != WycheproofResult::kInvalid) { |
| 151 | ASSERT_GE(ct.size(), 8u); |
| 152 | |
| 153 | AES_KEY aes; |
| 154 | ASSERT_EQ(0, AES_set_decrypt_key(key.data(), 8 * key.size(), &aes)); |
| 155 | std::vector<uint8_t> out(ct.size() - 8); |
| 156 | int len = AES_unwrap_key(&aes, nullptr, out.data(), ct.data(), ct.size()); |
| 157 | ASSERT_EQ(static_cast<int>(out.size()), len); |
| 158 | EXPECT_EQ(Bytes(msg), Bytes(out)); |
| 159 | |
| 160 | out.resize(msg.size() + 8); |
| 161 | ASSERT_EQ(0, AES_set_encrypt_key(key.data(), 8 * key.size(), &aes)); |
| 162 | len = AES_wrap_key(&aes, nullptr, out.data(), msg.data(), msg.size()); |
| 163 | ASSERT_EQ(static_cast<int>(out.size()), len); |
| 164 | EXPECT_EQ(Bytes(ct), Bytes(out)); |
| 165 | } else { |
| 166 | AES_KEY aes; |
| 167 | ASSERT_EQ(0, AES_set_decrypt_key(key.data(), 8 * key.size(), &aes)); |
| 168 | std::vector<uint8_t> out(ct.size() < 8 ? 0 : ct.size() - 8); |
| 169 | int len = AES_unwrap_key(&aes, nullptr, out.data(), ct.data(), ct.size()); |
| 170 | EXPECT_EQ(-1, len); |
| 171 | } |
| 172 | }); |
| 173 | } |
| 174 | |
| 175 | TEST(AESTest, WrapBadLengths) { |
| 176 | uint8_t key[128/8] = {0}; |
| 177 | AES_KEY aes; |
| 178 | ASSERT_EQ(0, AES_set_encrypt_key(key, 128, &aes)); |
| 179 | |
| 180 | // Input lengths to |AES_wrap_key| must be a multiple of 8 and at least 16. |
| 181 | static const size_t kLengths[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, |
| 182 | 9, 10, 11, 12, 13, 14, 15, 20}; |
| 183 | for (size_t len : kLengths) { |
| 184 | SCOPED_TRACE(len); |
| 185 | std::vector<uint8_t> in(len); |
| 186 | std::vector<uint8_t> out(len + 8); |
| 187 | EXPECT_EQ(-1, |
| 188 | AES_wrap_key(&aes, nullptr, out.data(), in.data(), in.size())); |
| 189 | } |
| 190 | } |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 191 | |
Robert Sloan | f63bd1f | 2019-04-16 09:26:20 -0700 | [diff] [blame] | 192 | TEST(AESTest, InvalidKeySize) { |
| 193 | static const uint8_t kZero[8] = {0}; |
| 194 | AES_KEY key; |
| 195 | EXPECT_LT(AES_set_encrypt_key(kZero, 42, &key), 0); |
| 196 | EXPECT_LT(AES_set_decrypt_key(kZero, 42, &key), 0); |
| 197 | } |
| 198 | |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 199 | #if defined(SUPPORTS_ABI_TEST) |
| 200 | TEST(AESTest, ABI) { |
| 201 | for (int bits : {128, 192, 256}) { |
| 202 | SCOPED_TRACE(bits); |
| 203 | const uint8_t kKey[256/8] = {0}; |
| 204 | AES_KEY key; |
| 205 | uint8_t block[AES_BLOCK_SIZE]; |
| 206 | uint8_t buf[AES_BLOCK_SIZE * 64] = {0}; |
| 207 | std::vector<int> block_counts; |
| 208 | if (bits == 128) { |
| 209 | block_counts = {0, 1, 2, 3, 4, 8, 16, 31}; |
| 210 | } else { |
| 211 | // Unwind tests are very slow. Assume that the various input sizes do not |
| 212 | // differ significantly by round count for ABI purposes. |
| 213 | block_counts = {0, 1, 8}; |
| 214 | } |
| 215 | |
| 216 | CHECK_ABI(aes_nohw_set_encrypt_key, kKey, bits, &key); |
| 217 | CHECK_ABI(aes_nohw_encrypt, block, block, &key); |
| 218 | #if defined(AES_NOHW_CBC) |
| 219 | for (size_t blocks : block_counts) { |
| 220 | SCOPED_TRACE(blocks); |
| 221 | CHECK_ABI(aes_nohw_cbc_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 222 | block, AES_ENCRYPT); |
| 223 | } |
| 224 | #endif |
| 225 | |
| 226 | CHECK_ABI(aes_nohw_set_decrypt_key, kKey, bits, &key); |
| 227 | CHECK_ABI(aes_nohw_decrypt, block, block, &key); |
| 228 | #if defined(AES_NOHW_CBC) |
| 229 | for (size_t blocks : block_counts) { |
| 230 | SCOPED_TRACE(blocks); |
| 231 | CHECK_ABI(aes_nohw_cbc_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 232 | block, AES_DECRYPT); |
| 233 | } |
| 234 | #endif |
| 235 | |
| 236 | if (bsaes_capable()) { |
| 237 | aes_nohw_set_encrypt_key(kKey, bits, &key); |
| 238 | for (size_t blocks : block_counts) { |
| 239 | SCOPED_TRACE(blocks); |
| 240 | if (blocks != 0) { |
| 241 | CHECK_ABI(bsaes_ctr32_encrypt_blocks, buf, buf, blocks, &key, block); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | aes_nohw_set_decrypt_key(kKey, bits, &key); |
| 246 | for (size_t blocks : block_counts) { |
| 247 | SCOPED_TRACE(blocks); |
| 248 | CHECK_ABI(bsaes_cbc_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 249 | block, AES_DECRYPT); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | if (vpaes_capable()) { |
| 254 | CHECK_ABI(vpaes_set_encrypt_key, kKey, bits, &key); |
| 255 | CHECK_ABI(vpaes_encrypt, block, block, &key); |
| 256 | for (size_t blocks : block_counts) { |
| 257 | SCOPED_TRACE(blocks); |
| 258 | CHECK_ABI(vpaes_cbc_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 259 | block, AES_ENCRYPT); |
Robert Sloan | 8967815 | 2019-03-12 14:24:00 -0700 | [diff] [blame] | 260 | #if defined(VPAES_CTR32) |
| 261 | CHECK_ABI(vpaes_ctr32_encrypt_blocks, buf, buf, blocks, &key, block); |
| 262 | #endif |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | CHECK_ABI(vpaes_set_decrypt_key, kKey, bits, &key); |
| 266 | CHECK_ABI(vpaes_decrypt, block, block, &key); |
| 267 | for (size_t blocks : block_counts) { |
| 268 | SCOPED_TRACE(blocks); |
| 269 | CHECK_ABI(vpaes_cbc_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 270 | block, AES_DECRYPT); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | if (hwaes_capable()) { |
| 275 | CHECK_ABI(aes_hw_set_encrypt_key, kKey, bits, &key); |
| 276 | CHECK_ABI(aes_hw_encrypt, block, block, &key); |
| 277 | for (size_t blocks : block_counts) { |
| 278 | SCOPED_TRACE(blocks); |
| 279 | CHECK_ABI(aes_hw_cbc_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 280 | block, AES_ENCRYPT); |
| 281 | CHECK_ABI(aes_hw_ctr32_encrypt_blocks, buf, buf, blocks, &key, block); |
| 282 | #if defined(HWAES_ECB) |
| 283 | CHECK_ABI(aes_hw_ecb_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 284 | AES_ENCRYPT); |
| 285 | #endif |
| 286 | } |
| 287 | |
| 288 | CHECK_ABI(aes_hw_set_decrypt_key, kKey, bits, &key); |
| 289 | CHECK_ABI(aes_hw_decrypt, block, block, &key); |
| 290 | for (size_t blocks : block_counts) { |
| 291 | SCOPED_TRACE(blocks); |
| 292 | CHECK_ABI(aes_hw_cbc_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 293 | block, AES_DECRYPT); |
| 294 | #if defined(HWAES_ECB) |
| 295 | CHECK_ABI(aes_hw_ecb_encrypt, buf, buf, AES_BLOCK_SIZE * blocks, &key, |
| 296 | AES_DECRYPT); |
| 297 | #endif |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | #endif // SUPPORTS_ABI_TEST |