LibCrypto: Add static_assert to check that A = -3 mod p

This is required for some optimization made in the file. While this
should always be the case for the SECP256r1 curve, it is good to check
it anyway.
This commit is contained in:
Michiel Visser 2023-11-10 15:50:39 +01:00 committed by Andrew Kaster
parent 4f4034d1a4
commit c6b2a07326
Notes: sideshowbarker 2024-07-17 02:56:25 +09:00

View File

@ -52,6 +52,9 @@ static constexpr u256 A { { 0xfffffffffffffffcull, 0x00000000ffffffffull, 0x0000
static constexpr u256 B { { 0x3bce3c3e27d2604bull, 0x651d06b0cc53b0f6ull, 0xb3ebbd55769886bcull, 0x5ac635d8aa3a93e7ull } };
static constexpr u256 ORDER { { 0xf3b9cac2fc632551ull, 0xbce6faada7179e84ull, 0xffffffffffffffffull, 0xffffffff00000000ull } };
// Verify that A = -3 mod p, which is required for some optimizations
static_assert(A == PRIME - 3);
// Precomputed helper values for reduction and Montgomery multiplication
static constexpr u256 REDUCE_PRIME = u256 { 0 } - PRIME;
static constexpr u256 REDUCE_ORDER = u256 { 0 } - ORDER;