| 1 |
// Copyright (c) 2018, Google Inc. |
| 2 |
// SPDX-License-Identifier: ISC |
| 3 |
|
| 4 |
#include <openssl/base.h> |
| 5 |
|
| 6 |
#if defined(BORINGSSL_DISPATCH_TEST) && !defined(BORINGSSL_SHARED_LIBRARY) |
| 7 |
|
| 8 |
#include <functional> |
| 9 |
#include <utility> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include <openssl/aead.h> |
| 13 |
#include <openssl/aes.h> |
| 14 |
#include <openssl/sha.h> |
| 15 |
#include <openssl/mem.h> |
| 16 |
|
| 17 |
#include <gtest/gtest.h> |
| 18 |
|
| 19 |
#include "internal.h" |
| 20 |
#include "fipsmodule/cpucap/internal.h" |
| 21 |
#include "fipsmodule/modes/internal.h" |
| 22 |
#include "fipsmodule/bn/rsaz_exp.h" |
| 23 |
#include "fipsmodule/sha/internal.h" |
| 24 |
|
| 25 |
#include "test/file_test.h" |
| 26 |
|
| 27 |
class ImplDispatchTest : public ::testing::Test { |
| 28 |
public: |
| 29 |
void SetUp() override { |
| 30 |
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) |
| 31 |
aes_hw_ = CRYPTO_is_AESNI_capable(); |
| 32 |
avx_movbe_ = CRYPTO_is_AVX_capable() && CRYPTO_is_MOVBE_capable(); |
| 33 |
aes_vpaes_ = CRYPTO_is_SSSE3_capable(); |
| 34 |
is_avx2_ = CRYPTO_is_AVX2_capable(); |
| 35 |
ifma_avx512 = CRYPTO_is_AVX512IFMA_capable(); |
| 36 |
sha_ext_ = |
| 37 |
// sha_ext_ isn't enabled on 32-bit x86 architectures. |
| 38 |
#if defined(OPENSSL_X86) |
| 39 |
false; |
| 40 |
#else |
| 41 |
CRYPTO_is_SHAEXT_capable(); |
| 42 |
#endif |
| 43 |
|
| 44 |
vaes_vpclmulqdq_ = |
| 45 |
#if !defined(OPENSSL_WINDOWS) |
| 46 |
// crypto_gcm_avx512_enabled excludes Windows |
| 47 |
CRYPTO_is_AVX512_capable() && |
| 48 |
CRYPTO_is_VAES_capable() && |
| 49 |
CRYPTO_is_VPCLMULQDQ_capable(); |
| 50 |
#else |
| 51 |
false; |
| 52 |
#endif |
| 53 |
|
| 54 |
is_x86_64_ = |
| 55 |
#if defined(OPENSSL_X86_64) |
| 56 |
true; |
| 57 |
#else |
| 58 |
false; |
| 59 |
#endif |
| 60 |
is_assembler_too_old = |
| 61 |
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX) |
| 62 |
true; |
| 63 |
#else |
| 64 |
false; |
| 65 |
#endif // MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX |
| 66 |
is_assembler_too_old_avx512 = |
| 67 |
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX) |
| 68 |
true; |
| 69 |
#else |
| 70 |
false; |
| 71 |
#endif // MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX |
| 72 |
#elif defined(OPENSSL_AARCH64) |
| 73 |
aes_hw_ = CRYPTO_is_ARMv8_AES_capable(); |
| 74 |
aes_vpaes_ = CRYPTO_is_NEON_capable(); |
| 75 |
aes_gcm_pmull_ = CRYPTO_is_ARMv8_PMULL_capable(); |
| 76 |
aes_gcm_8x_ = CRYPTO_is_ARMv8_GCM_8x_capable(); |
| 77 |
sha_ext_ = OPENSSL_armcap_P & ARMV8_SHA256; |
| 78 |
sha_512_ext_ = OPENSSL_armcap_P & ARMV8_SHA512; |
| 79 |
sha3_ext_ = CRYPTO_is_ARMv8_SHA3_capable(); |
| 80 |
neoverse_n1_ = CRYPTO_is_Neoverse_N1(); |
| 81 |
neoverse_v1_ = CRYPTO_is_Neoverse_V1(); |
| 82 |
neoverse_v2_ = CRYPTO_is_Neoverse_V2(); |
| 83 |
|
| 84 |
assembler_has_neon_sha3_extension_ = |
| 85 |
#if defined(MY_ASSEMBLER_SUPPORTS_NEON_SHA3_EXTENSION) |
| 86 |
true; |
| 87 |
#else |
| 88 |
false; |
| 89 |
#endif |
| 90 |
#endif |
| 91 |
have_s2n_bignum_asm_ = |
| 92 |
#if defined(KECCAK1600_S2N_BIGNUM_ASM) |
| 93 |
true; |
| 94 |
#else |
| 95 |
false; |
| 96 |
#endif |
| 97 |
} |
| 98 |
|
| 99 |
protected: |
| 100 |
// AssertFunctionsHit takes a list of pairs (flag index, boolean), and a |
| 101 |
// function to test. It runs the given function and asserts, for each flag |
| 102 |
// index, that the boolean reflects whether that flag index was written or |
| 103 |
// not, and that no other flagged functions were triggered. |
| 104 |
void AssertFunctionsHit(std::vector<std::pair<size_t, bool>> flags, |
| 105 |
std::function<void()> f) { |
| 106 |
OPENSSL_memset(BORINGSSL_function_hit, 0, sizeof(BORINGSSL_function_hit)); |
| 107 |
|
| 108 |
f(); |
| 109 |
|
| 110 |
for (const auto& flag : flags) { |
| 111 |
SCOPED_TRACE(flag.first); |
| 112 |
ASSERT_LT(flag.first, sizeof(BORINGSSL_function_hit)); |
| 113 |
EXPECT_EQ(flag.second, BORINGSSL_function_hit[flag.first] == 1); |
| 114 |
BORINGSSL_function_hit[flag.first] = 0; |
| 115 |
} |
| 116 |
|
| 117 |
for (size_t i = 0; i < sizeof(BORINGSSL_function_hit); i++) { |
| 118 |
EXPECT_EQ(0u, BORINGSSL_function_hit[i]) |
| 119 |
<< "Flag " << i << " unexpectedly hit"; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
bool aes_hw_ = false; |
| 124 |
bool aes_vpaes_ = false; |
| 125 |
bool sha_ext_ = false; |
| 126 |
bool have_s2n_bignum_asm_ = false; |
| 127 |
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) |
| 128 |
bool vaes_vpclmulqdq_ = false; |
| 129 |
bool avx_movbe_ = false; |
| 130 |
bool is_x86_64_ = false; |
| 131 |
bool is_avx2_ = false; |
| 132 |
bool is_assembler_too_old = false; |
| 133 |
bool is_assembler_too_old_avx512 = false; |
| 134 |
bool ifma_avx512 = false; |
| 135 |
#else // AARCH64 |
| 136 |
bool aes_gcm_pmull_ = false; |
| 137 |
bool aes_gcm_8x_ = false; |
| 138 |
bool sha_512_ext_ = false; |
| 139 |
bool sha3_ext_ = false; |
| 140 |
bool neoverse_n1_ = false; |
| 141 |
bool neoverse_v1_ = false; |
| 142 |
bool neoverse_v2_ = false; |
| 143 |
bool assembler_has_neon_sha3_extension_ = false; |
| 144 |
#endif |
| 145 |
|
| 146 |
}; |
| 147 |
|
| 148 |
#if !defined(OPENSSL_NO_ASM) && (defined(OPENSSL_X86) || \ |
| 149 |
defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)) |
| 150 |
|
| 151 |
constexpr size_t kFlag_aes_hw_ctr32_encrypt_blocks = 0; |
| 152 |
constexpr size_t kFlag_aes_hw_encrypt = 1; |
| 153 |
constexpr size_t kFlag_aes_hw_set_encrypt_key = 3; |
| 154 |
constexpr size_t kFlag_vpaes_encrypt = 4; |
| 155 |
constexpr size_t kFlag_vpaes_set_encrypt_key = 5; |
| 156 |
constexpr size_t kFlag_sha256_hw = 6; |
| 157 |
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) |
| 158 |
constexpr size_t kFlag_aesni_gcm_encrypt = 2; |
| 159 |
constexpr size_t kFlag_aes_gcm_encrypt_avx512 = 7; |
| 160 |
constexpr size_t kFlag_RSAZ_mod_exp_avx512_x2 = 8; |
| 161 |
constexpr size_t kFlag_sha3_keccak_f1600 = 9; |
| 162 |
constexpr size_t kFlag_sha3_keccak4_f1600_alt = 10; |
| 163 |
#else // AARCH64 |
| 164 |
constexpr size_t kFlag_aes_gcm_enc_kernel = 2; |
| 165 |
constexpr size_t kFlag_aesv8_gcm_8x_enc_128 = 7; |
| 166 |
constexpr size_t kFlag_sha512_hw = 8; |
| 167 |
constexpr size_t kFlag_KeccakF1600_hw = 9; |
| 168 |
constexpr size_t kFlag_sha3_keccak_f1600 = 10; |
| 169 |
constexpr size_t kFlag_sha3_keccak_f1600_alt = 11; |
| 170 |
constexpr size_t kFlag_sha3_keccak2_f1600 = 12; |
| 171 |
constexpr size_t kFlag_sha3_keccak4_f1600_alt = 13; |
| 172 |
constexpr size_t kFlag_sha3_keccak4_f1600_alt2 = 14; |
| 173 |
#endif |
| 174 |
|
| 175 |
TEST_F(ImplDispatchTest, AEAD_AES_GCM) { |
| 176 |
AssertFunctionsHit( |
| 177 |
{ |
| 178 |
{kFlag_aes_hw_encrypt, aes_hw_}, |
| 179 |
{kFlag_aes_hw_set_encrypt_key, aes_hw_}, |
| 180 |
{kFlag_vpaes_encrypt, aes_vpaes_ && !aes_hw_}, |
| 181 |
{kFlag_vpaes_set_encrypt_key, aes_vpaes_ && !aes_hw_}, |
| 182 |
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) |
| 183 |
{kFlag_aes_hw_ctr32_encrypt_blocks, aes_hw_ && |
| 184 |
(!is_x86_64_ || is_assembler_too_old || |
| 185 |
!(vaes_vpclmulqdq_ && !is_assembler_too_old_avx512))}, |
| 186 |
{kFlag_aesni_gcm_encrypt, |
| 187 |
is_x86_64_ && aes_hw_ && avx_movbe_ && |
| 188 |
!is_assembler_too_old && |
| 189 |
!(vaes_vpclmulqdq_ && !is_assembler_too_old_avx512)}, |
| 190 |
{kFlag_aes_gcm_encrypt_avx512, |
| 191 |
is_x86_64_ && aes_hw_ && |
| 192 |
!is_assembler_too_old_avx512 && |
| 193 |
vaes_vpclmulqdq_}, |
| 194 |
#else // AARCH64 |
| 195 |
{kFlag_aes_hw_ctr32_encrypt_blocks, aes_hw_ && |
| 196 |
!aes_gcm_pmull_ && !aes_gcm_8x_}, |
| 197 |
{kFlag_aes_gcm_enc_kernel, aes_hw_ && |
| 198 |
aes_gcm_pmull_ && !aes_gcm_8x_}, |
| 199 |
{kFlag_aesv8_gcm_8x_enc_128, aes_hw_ && |
| 200 |
aes_gcm_pmull_ && aes_gcm_8x_} |
| 201 |
#endif |
| 202 |
}, |
| 203 |
[] { |
| 204 |
const uint8_t kZeros[16] = {0}; |
| 205 |
const uint8_t kPlaintext[256] = {1, 2, 3, 4, 0}; |
| 206 |
uint8_t ciphertext[sizeof(kPlaintext) + 16]; |
| 207 |
size_t ciphertext_len; |
| 208 |
bssl::ScopedEVP_AEAD_CTX ctx; |
| 209 |
ASSERT_TRUE(EVP_AEAD_CTX_init(ctx.get(), EVP_aead_aes_128_gcm(), kZeros, |
| 210 |
sizeof(kZeros), |
| 211 |
EVP_AEAD_DEFAULT_TAG_LENGTH, nullptr)); |
| 212 |
ASSERT_TRUE(EVP_AEAD_CTX_seal( |
| 213 |
ctx.get(), ciphertext, &ciphertext_len, sizeof(ciphertext), kZeros, |
| 214 |
EVP_AEAD_nonce_length(EVP_aead_aes_128_gcm()), kPlaintext, |
| 215 |
sizeof(kPlaintext), nullptr, 0)); |
| 216 |
}); |
| 217 |
} |
| 218 |
|
| 219 |
TEST_F(ImplDispatchTest, AES_set_encrypt_key) { |
| 220 |
AssertFunctionsHit( |
| 221 |
{ |
| 222 |
{kFlag_aes_hw_set_encrypt_key, aes_hw_}, |
| 223 |
{kFlag_vpaes_set_encrypt_key, aes_vpaes_ && !aes_hw_}, |
| 224 |
}, |
| 225 |
[] { |
| 226 |
AES_KEY key; |
| 227 |
static const uint8_t kZeros[16] = {0}; |
| 228 |
AES_set_encrypt_key(kZeros, sizeof(kZeros) * 8, &key); |
| 229 |
}); |
| 230 |
} |
| 231 |
|
| 232 |
TEST_F(ImplDispatchTest, AES_single_block) { |
| 233 |
AES_KEY key; |
| 234 |
static const uint8_t kZeros[16] = {0}; |
| 235 |
AES_set_encrypt_key(kZeros, sizeof(kZeros) * 8, &key); |
| 236 |
|
| 237 |
AssertFunctionsHit( |
| 238 |
{ |
| 239 |
{kFlag_aes_hw_encrypt, aes_hw_}, |
| 240 |
{kFlag_vpaes_encrypt, aes_vpaes_ && !aes_hw_}, |
| 241 |
}, |
| 242 |
[&key] { |
| 243 |
uint8_t in[AES_BLOCK_SIZE] = {0}; |
| 244 |
uint8_t out[AES_BLOCK_SIZE]; |
| 245 |
AES_encrypt(in, out, &key); |
| 246 |
}); |
| 247 |
} |
| 248 |
|
| 249 |
TEST_F(ImplDispatchTest, SHA256) { |
| 250 |
AssertFunctionsHit( |
| 251 |
{ |
| 252 |
{kFlag_sha256_hw, sha_ext_}, |
| 253 |
}, |
| 254 |
[] { |
| 255 |
const uint8_t in[32] = {0}; |
| 256 |
uint8_t out[SHA256_DIGEST_LENGTH]; |
| 257 |
SHA256(in, 32, out); |
| 258 |
}); |
| 259 |
} |
| 260 |
|
| 261 |
#ifdef OPENSSL_AARCH64 |
| 262 |
TEST_F(ImplDispatchTest, SHA512) { |
| 263 |
AssertFunctionsHit( |
| 264 |
{ |
| 265 |
{kFlag_sha512_hw, sha_512_ext_}, |
| 266 |
}, |
| 267 |
[] { |
| 268 |
const uint8_t in[32] = {0}; |
| 269 |
uint8_t out[SHA512_DIGEST_LENGTH]; |
| 270 |
SHA512(in, 32, out); |
| 271 |
}); |
| 272 |
} |
| 273 |
|
| 274 |
TEST_F(ImplDispatchTest, SHA3_512) { |
| 275 |
// Assembly dispatch logic for Keccak-x1 on AArch64: |
| 276 |
// - For Neoverse N1, V1, V2, we use scalar Keccak assembly from s2n-bignum |
| 277 |
// (`sha3_keccak_f1600()`) |
| 278 |
// leveraging lazy rotations from https://eprint.iacr.org/2022/1243. |
| 279 |
// - Otherwise, if the Neon SHA3 extension is supported, we use the Neon |
| 280 |
// Keccak assembly from s2n-bignum (`sha3_keccak_f1600_alt()`), |
| 281 |
// leveraging that extension. |
| 282 |
// - Otherwise, fall back to scalar Keccak implementation from OpenSSL, |
| 283 |
// (`Keccak1600_hw()`), not using lazy rotations. |
| 284 |
AssertFunctionsHit( |
| 285 |
{ |
| 286 |
{kFlag_sha3_keccak_f1600, |
| 287 |
have_s2n_bignum_asm_ && |
| 288 |
(neoverse_n1_ || neoverse_v1_ || neoverse_v2_) }, |
| 289 |
{kFlag_sha3_keccak_f1600_alt, |
| 290 |
have_s2n_bignum_asm_ && |
| 291 |
!(neoverse_n1_ || neoverse_v1_ || neoverse_v2_) && |
| 292 |
(assembler_has_neon_sha3_extension_ && sha3_ext_) }, |
| 293 |
{kFlag_KeccakF1600_hw, |
| 294 |
!have_s2n_bignum_asm_ || |
| 295 |
( |
| 296 |
!(neoverse_n1_ || neoverse_v1_ || neoverse_v2_) && |
| 297 |
!(assembler_has_neon_sha3_extension_ && sha3_ext_) |
| 298 |
) }, |
| 299 |
}, |
| 300 |
[] { |
| 301 |
const uint8_t in[32] = {0}; |
| 302 |
uint8_t out[SHA3_512_DIGEST_LENGTH]; |
| 303 |
SHA3_512(in, 32, out); |
| 304 |
}); |
| 305 |
} |
| 306 |
#endif // OPENSSL_AARCH64 |
| 307 |
|
| 308 |
TEST_F(ImplDispatchTest, SHAKE256_Batched) { |
| 309 |
#if defined(OPENSSL_X86_64) || defined(OPENSSL_X86) |
| 310 |
// Assembly dispatch logic for Keccak-x4 on x86: |
| 311 |
// - For platforms with AVX2 support, we use batched Keccak assembly from s2n-bignum |
| 312 |
// (`sha3_keccak4_f1600_alt()`). |
| 313 |
// - Otherwise, fall back to scalar Keccak implementation from s2n-bignum, |
| 314 |
// (`sha3_keccak_f1600()`). |
| 315 |
AssertFunctionsHit( |
| 316 |
{ |
| 317 |
{kFlag_sha3_keccak4_f1600_alt, |
| 318 |
have_s2n_bignum_asm_ && |
| 319 |
is_avx2_ }, |
| 320 |
{kFlag_sha3_keccak_f1600, |
| 321 |
have_s2n_bignum_asm_ && is_x86_64_ && !is_avx2_ }, |
| 322 |
}, |
| 323 |
#else // AARCH64 |
| 324 |
// Assembly dispatch logic for Keccak-x4 on AArch64: |
| 325 |
// - For Neoverse N1, we use scalar batched hybrid Keccak assembly from s2n-bignum |
| 326 |
// (`sha3_keccak4_f1600_alt()`) leveraging Neon and scalar assembly with |
| 327 |
// lazy rotations. |
| 328 |
// - For Neoverse V1, V2, we use SIMD batched hybrid Keccak assembly from s2n-bignum |
| 329 |
// (`sha3_keccak4_f1600_alt2()`) leveraging Neon, Neon SHA3 extension, |
| 330 |
// and scalar assembly with lazy rotations. |
| 331 |
// - Otherwise, if the Neon SHA3 extension is supported, we use the 2-fold |
| 332 |
// Keccak assembly from s2n-bignum (`sha3_keccak2_f1600()`) twice, |
| 333 |
// which is a straightforward implementation using the SHA3 extension. |
| 334 |
// - Otherwise, fall back to four times the 1-fold Keccak implementation |
| 335 |
// with its own dispatch logic. |
| 336 |
AssertFunctionsHit( |
| 337 |
{ |
| 338 |
{kFlag_sha3_keccak4_f1600_alt, |
| 339 |
have_s2n_bignum_asm_ && neoverse_n1_}, |
| 340 |
{kFlag_sha3_keccak4_f1600_alt2, |
| 341 |
have_s2n_bignum_asm_ && |
| 342 |
(neoverse_v1_ || neoverse_v2_) && |
| 343 |
assembler_has_neon_sha3_extension_}, |
| 344 |
{kFlag_sha3_keccak2_f1600, |
| 345 |
have_s2n_bignum_asm_ && |
| 346 |
!(neoverse_n1_ || neoverse_v1_ || neoverse_v2_) && |
| 347 |
(assembler_has_neon_sha3_extension_ && sha3_ext_)}, |
| 348 |
// If we don't have assembly batched Keccak available, |
| 349 |
// we fall back to the dispatch logic in KeccakF1600(). |
| 350 |
// Under the assumption that no batched Keccak assembly |
| 351 |
// was chosen, this simplifies as follows: |
| 352 |
// 1. If we run on Neoverse-V1 and Neoverse-V2 and there is |
| 353 |
// no compiler support for SHA3 (otherwise, we would have |
| 354 |
// have chosen the batched hybrid with SHA3 extension), |
| 355 |
// we use the scalar assembly with lazy rotation. |
| 356 |
// 2. Otherwise, we fall back to the OpenSSL assembly. |
| 357 |
{kFlag_sha3_keccak_f1600, |
| 358 |
have_s2n_bignum_asm_ && (neoverse_v1_ || neoverse_v2_) && |
| 359 |
!(assembler_has_neon_sha3_extension_ && sha3_ext_) }, |
| 360 |
{kFlag_KeccakF1600_hw, |
| 361 |
!have_s2n_bignum_asm_ || |
| 362 |
( |
| 363 |
!neoverse_n1_ && !neoverse_v1_ && !neoverse_v2_ && |
| 364 |
!(assembler_has_neon_sha3_extension_ && sha3_ext_) |
| 365 |
) }, |
| 366 |
}, |
| 367 |
#endif |
| 368 |
[] { |
| 369 |
const uint8_t in[32] = {0}; |
| 370 |
uint8_t out0[32], out1[32], out2[32], out3[32]; |
| 371 |
SHAKE256_x4(in, in, in, in, 32, out0, out1, out2, out3, 32); |
| 372 |
}); |
| 373 |
} |
| 374 |
|
| 375 |
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) |
| 376 |
static bssl::UniquePtr<BIGNUM> GetBIGNUM(FileTest *t, const char *attr); |
| 377 |
|
| 378 |
static bssl::UniquePtr<BIGNUM> GetBIGNUM(FileTest *t, const char *attr) { |
| 379 |
std::string hex; |
| 380 |
if (!t->GetAttribute(&hex, attr)) { |
| 381 |
return nullptr; |
| 382 |
} |
| 383 |
|
| 384 |
BIGNUM *raw = NULL; |
| 385 |
int size = BN_hex2bn(&raw, hex.c_str()); |
| 386 |
if (size != static_cast<int>(hex.size())) { |
| 387 |
t->PrintLine("Could not decode '%s'.", hex.c_str()); |
| 388 |
return nullptr; |
| 389 |
} |
| 390 |
|
| 391 |
bssl::UniquePtr<BIGNUM> ret; |
| 392 |
(&ret)->reset(raw); |
| 393 |
return ret; |
| 394 |
} |
| 395 |
|
| 396 |
TEST_F(ImplDispatchTest, BN_mod_exp_mont_consttime_x2) { |
| 397 |
FileTestGTest( |
| 398 |
"crypto/fipsmodule/bn/test/mod_exp_x2_tests.txt", |
| 399 |
[&](FileTest *t) { |
| 400 |
AssertFunctionsHit( |
| 401 |
{ |
| 402 |
{kFlag_RSAZ_mod_exp_avx512_x2, |
| 403 |
is_x86_64_ && |
| 404 |
!is_assembler_too_old_avx512 && |
| 405 |
ifma_avx512}, |
| 406 |
}, |
| 407 |
[&]() { |
| 408 |
BN_CTX *ctx = BN_CTX_new(); |
| 409 |
BN_CTX_start(ctx); |
| 410 |
bssl::UniquePtr<BIGNUM> a1 = GetBIGNUM(t, "A1"); |
| 411 |
bssl::UniquePtr<BIGNUM> e1 = GetBIGNUM(t, "E1"); |
| 412 |
bssl::UniquePtr<BIGNUM> m1 = GetBIGNUM(t, "M1"); |
| 413 |
bssl::UniquePtr<BIGNUM> mod_exp1 = GetBIGNUM(t, "ModExp1"); |
| 414 |
ASSERT_TRUE(a1); |
| 415 |
ASSERT_TRUE(e1); |
| 416 |
ASSERT_TRUE(m1); |
| 417 |
ASSERT_TRUE(mod_exp1); |
| 418 |
|
| 419 |
bssl::UniquePtr<BIGNUM> a2 = GetBIGNUM(t, "A2"); |
| 420 |
bssl::UniquePtr<BIGNUM> e2 = GetBIGNUM(t, "E2"); |
| 421 |
bssl::UniquePtr<BIGNUM> m2 = GetBIGNUM(t, "M2"); |
| 422 |
bssl::UniquePtr<BIGNUM> mod_exp2 = GetBIGNUM(t, "ModExp2"); |
| 423 |
ASSERT_TRUE(a2); |
| 424 |
ASSERT_TRUE(e2); |
| 425 |
ASSERT_TRUE(m2); |
| 426 |
ASSERT_TRUE(mod_exp2); |
| 427 |
|
| 428 |
bssl::UniquePtr<BIGNUM> ret1(BN_new()); |
| 429 |
ASSERT_TRUE(ret1); |
| 430 |
|
| 431 |
bssl::UniquePtr<BIGNUM> ret2(BN_new()); |
| 432 |
ASSERT_TRUE(ret2); |
| 433 |
|
| 434 |
ASSERT_TRUE(BN_nnmod(a1.get(), a1.get(), m1.get(), ctx)); |
| 435 |
ASSERT_TRUE(BN_nnmod(a2.get(), a2.get(), m2.get(), ctx)); |
| 436 |
|
| 437 |
BN_MONT_CTX *mont1 = NULL; |
| 438 |
BN_MONT_CTX *mont2 = NULL; |
| 439 |
|
| 440 |
ASSERT_TRUE(mont1 = BN_MONT_CTX_new()); |
| 441 |
ASSERT_TRUE(BN_MONT_CTX_set(mont1, m1.get(), ctx)); |
| 442 |
ASSERT_TRUE(mont2 = BN_MONT_CTX_new()); |
| 443 |
ASSERT_TRUE(BN_MONT_CTX_set(mont2, m2.get(), ctx)); |
| 444 |
|
| 445 |
BN_mod_exp_mont_consttime_x2(ret1.get(), a1.get(), e1.get(), m1.get(), mont1, |
| 446 |
ret2.get(), a2.get(), e2.get(), m2.get(), mont2, |
| 447 |
ctx); |
| 448 |
|
| 449 |
BN_MONT_CTX_free(mont1); |
| 450 |
BN_MONT_CTX_free(mont2); |
| 451 |
BN_CTX_end(ctx); |
| 452 |
BN_CTX_free(ctx); |
| 453 |
}); |
| 454 |
}); |
| 455 |
} |
| 456 |
|
| 457 |
#endif // x86[_64] |
| 458 |
|
| 459 |
#endif // !OPENSSL_NO_ASM && (OPENSSL_X86 || OPENSSL_X86_64 || OPENSSL_AARCH64) |
| 460 |
|
| 461 |
#endif // DISPATCH_TEST && !SHARED_LIBRARY |