7#include <botan/internal/pcurves_instance.h>
9#include <botan/internal/pcurves_solinas.h>
10#include <botan/internal/pcurves_wrap.h>
16template <
typename Params>
17class Secp384r1Rep
final {
19 static constexpr auto P = Params::P;
20 static constexpr size_t N = Params::N;
21 typedef typename Params::W W;
23 constexpr static std::array<W, N> redc(
const std::array<W, 2 * N>& z) {
50 const int64_t S0 = 0xFFFFFFFF + X00 + X12 + X20 + X21 - X23;
51 const int64_t S1 = 0x00000000 + X01 + X13 + X22 + X23 - X12 - X20;
52 const int64_t S2 = 0x00000000 + X02 + X14 + X23 - X13 - X21;
53 const int64_t S3 = 0xFFFFFFFF + X03 + X12 + X15 + X20 + X21 - X14 - X22 - X23;
54 const int64_t S4 = 0xFFFFFFFE + X04 + X12 + X13 + X16 + X20 + X21 * 2 + X22 - X15 - X23 * 2;
55 const int64_t S5 = 0xFFFFFFFF + X05 + X13 + X14 + X17 + X21 + X22 * 2 + X23 - X16;
56 const int64_t S6 = 0xFFFFFFFF + X06 + X14 + X15 + X18 + X22 + X23 * 2 - X17;
57 const int64_t S7 = 0xFFFFFFFF + X07 + X15 + X16 + X19 + X23 - X18;
58 const int64_t S8 = 0xFFFFFFFF + X08 + X16 + X17 + X20 - X19;
59 const int64_t S9 = 0xFFFFFFFF + X09 + X17 + X18 + X21 - X20;
60 const int64_t SA = 0xFFFFFFFF + X10 + X18 + X19 + X22 - X21;
61 const int64_t SB = 0xFFFFFFFF + X11 + X19 + X20 + X23 - X22;
63 std::array<W, N> r = {};
79 const auto S = sum.final_carry(0);
83 const auto correction = p384_mul_mod_384(S);
84 W borrow =
bigint_sub2(r.data(), N, correction.data(), N);
91 constexpr static std::array<W, N> one() {
return std::array<W, N>{1}; }
93 constexpr static std::array<W, N> to_rep(
const std::array<W, N>& x) {
return x; }
95 constexpr static std::array<W, N> wide_to_rep(
const std::array<W, 2 * N>& x) {
return redc(x); }
97 constexpr static std::array<W, N> from_rep(
const std::array<W, N>& z) {
return z; }
103 constexpr static std::array<W, N> p384_mul_mod_384(W i) {
104 static_assert(WordInfo<W>::bits == 32 || WordInfo<W>::bits == 64);
110 if constexpr(WordInfo<W>::bits == 32) {
116 const uint64_t i32 =
static_cast<uint64_t
>(i) << 32;
129class Params
final :
public EllipticCurveParameters<
130 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF",
131 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC",
132 "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF",
133 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973",
134 "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7",
135 "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F",
141class Curve
final :
public EllipticCurve<Params, Secp384r1Rep> {
144 static FieldElement fe_invert2(
const FieldElement& x) {
147 FieldElement r = x.square();
185 static Scalar scalar_invert(
const Scalar& x) {
188 auto t3 = x.square();
196 auto t6 = t3.square();
200 auto t9 = t8.square();
201 auto t7 = t9.square();
#define BOTAN_DEBUG_ASSERT(expr)
static std::shared_ptr< const PrimeOrderCurve > secp384r1()
static std::shared_ptr< const PrimeOrderCurve > instance()
int(* final)(unsigned char *, CTX *)
constexpr uint32_t get_uint32(const W xw[], size_t i)
constexpr W bigint_cnd_add(W cnd, W x[], size_t x_size, const W y[], size_t y_size)
constexpr auto bigint_sub2(W x[], size_t x_size, const W y[], size_t y_size) -> W