7#ifndef BOTAN_PCURVES_IMPL_H_
8#define BOTAN_PCURVES_IMPL_H_
11#include <botan/internal/buffer_stuffer.h>
12#include <botan/internal/ct_utils.h>
13#include <botan/internal/loadstor.h>
14#include <botan/internal/mem_utils.h>
15#include <botan/internal/pcurves_algos.h>
16#include <botan/internal/pcurves_mul.h>
17#include <botan/internal/pcurves_util.h>
18#include <botan/internal/target_info.h>
36 for(
size_t i = 0; i != N; ++i) {
81template <
typename Params>
86 static constexpr auto P = Params::P;
87 static constexpr size_t N = Params::N;
88 typedef typename Params::W
W;
90 static_assert(
N > 0 && (Params::P[0] & 1) == 1,
"Invalid Montgomery modulus");
101 constexpr static std::array<W, N>
one() {
return R1; }
106 constexpr static std::array<W, N>
redc(
const std::array<W, 2 * N>& z) {
107 if constexpr(
P_dash == 1) {
117 constexpr static std::array<W, N>
to_rep(
const std::array<W, N>& x) {
118 std::array<W, 2 * N> z;
129 constexpr static std::array<W, N>
wide_to_rep(
const std::array<W, 2 * N>& x) {
131 std::array<W, 2 * N> z;
139 constexpr static std::array<W, N>
from_rep(
const std::array<W, N>& z) {
140 std::array<W, 2 * N> ze = {};
141 copy_mem(std::span{ze}.template first<N>(), z);
164template <
typename Rep>
167 static constexpr auto P = Rep::P;
168 static constexpr size_t N = Rep::N;
169 typedef typename Rep::W W;
171 static constexpr auto P_MINUS_2 =
p_minus<2>(P);
214 if constexpr(L == N) {
215 return Self(Rep::to_rep(w));
217 static_assert(L < N);
218 std::array<W, N> ew = {};
219 copy_mem(std::span{ew}.template first<L>(), w);
220 return Self(Rep::to_rep(ew));
243 auto v = Rep::from_rep(m_val);
251 const auto flip = (even != this->
is_even());
271 for(
size_t i = 0; i != N; ++i) {
272 t[i] =
word_add(a.m_val[i], b.m_val[i], &carry);
286 for(
size_t i = 0; i != N; ++i) {
287 r[i] =
word_sub(a.m_val[i], b.m_val[i], &carry);
294 for(
size_t i = 0; i != N; ++i) {
295 r[i] =
word_add(r[i], P[i] & mask, &carry);
311 std::array<W, N> t = value();
319 for(
size_t i = 0; i != N; ++i) {
320 t[i] =
word_add(t[i], INV_2[i] & mask, &carry);
328 std::array<W, N> t = value();
349 std::array<W, 2 * N> z;
351 return Self(Rep::redc(z));
358 std::array<W, 2 * N> z;
360 m_val = Rep::redc(z);
372 for(
size_t i = 0; i != N; ++i) {
385 for(
size_t i = 0; i != N; ++i) {
400 for(
size_t i = 0; i != N; ++i) {
415 for(
size_t i = 0; i != N; ++i) {
429 std::array<W, 2 * N> z;
431 return Self(Rep::redc(z));
442 std::array<W, 2 * N> z;
443 for(
size_t i = 0; i != n; ++i) {
445 m_val = Rep::redc(z);
455 const W x_is_zero =
~CT::all_zeros(this->data(), N).value();
459 for(
size_t i = 0; i != N; ++i) {
460 r[i] =
word_sub(P[i] & x_is_zero, m_val[i], &carry);
480 constexpr size_t WindowBits = (
Self::BITS <= 256) ? 4 : 5;
481 constexpr size_t WindowElements = (1 << WindowBits) - 1;
483 constexpr size_t Windows = (
Self::BITS + WindowBits - 1) / WindowBits;
491 std::array<Self, WindowElements> tbl;
495 for(
size_t i = 1; i != WindowElements; ++i) {
498 tbl[i] = tbl[i / 2].square();
500 tbl[i] = tbl[i - 1] * tbl[0];
513 for(
size_t i = 1; i != Windows; ++i) {
514 r.square_n(WindowBits);
553 while((a.m_val[0] & 1) != 1) {
602 if(this->
is_zero().as_bool()) {
606 auto x =
Self(std::array<W, N>{1});
621 if(a.m_val == b.m_val) {
626 r.m_val = Rep::to_rep(r.m_val);
630 const auto nx = x + y;
673 const CT::Choice correct = (z.square() == *
this);
693 const Self& x = (*this);
702 for(
size_t i = C1_C2.first; i >= 2; i--) {
705 z.conditional_assign(!e, z * c);
707 t.conditional_assign(!e, t * c);
712 const CT::Choice correct = (z.square() == *
this);
725 return CT::is_equal(this->data(), other.data(), N).as_choice();
736 constexpr std::array<W, Self::N>
to_words()
const {
return Rep::from_rep(m_val); }
741 constexpr void serialize_to(std::span<uint8_t, Self::BYTES> bytes)
const {
742 auto v = Rep::from_rep(m_val);
743 std::reverse(v.begin(), v.end());
749 const auto padded_bytes =
store_be(v);
751 copy_mem(bytes, std::span{padded_bytes}.template subspan<extra, Self::BYTES>());
762 static_assert(L >= N);
763 std::array<W, L> stash = {};
764 for(
size_t i = 0; i != N; ++i) {
777 static_assert(L >= N);
778 std::array<W, N> val = {};
779 for(
size_t i = 0; i != N; ++i) {
794 static std::optional<Self>
deserialize(std::span<const uint8_t> bytes) {
820 std::array<uint8_t, 2 * BYTES> padded_bytes = {};
821 copy_mem(std::span{padded_bytes}.template last<L>(), bytes);
837 std::array<uint8_t, 2 * Self::BYTES> padded_bytes = {};
838 copy_mem(std::span{padded_bytes}.last(bytes.size()), bytes);
854 constexpr size_t MAX_ATTEMPTS = 1000;
856 std::array<uint8_t, Self::BYTES> buf{};
858 for(
size_t i = 0; i != MAX_ATTEMPTS; ++i) {
864 constexpr uint8_t mask = 0xFF >> (8 - (
Self::BITS % 8));
870 if(s.value().is_nonzero().as_bool()) {
876 throw Internal_Error(
"Failed to generate random Scalar within bounded number of attempts");
885 std::array<W, 1> v{};
886 v[0] = (x >= 0) ? x : -x;
888 return (x >= 0) ? s : s.negate();
896 constexpr const std::array<W, N>& value()
const {
return m_val; }
898 constexpr const W* data()
const {
return m_val.data(); }
900#if defined(BOTAN_BUILD_COMPILER_IS_GCC)
903 explicit constexpr IntMod(
const std::array<W, N>& v) :
IntMod(v, std::make_index_sequence<N>{}) {}
905 template <
size_t... I>
906 constexpr IntMod(
const std::array<W, N>& v, std::index_sequence<I...> ) : m_val{v[I]...} {}
908 explicit constexpr IntMod(std::array<W, N> v) : m_val(v) {}
911 std::array<W, N> m_val;
919template <
typename FieldElement>
922 static constexpr size_t BYTES = 1 + 2 * FieldElement::BYTES;
932 static constexpr Self identity() {
return Self(FieldElement::zero(), FieldElement::zero()); }
936 return Self(FieldElement::zero(), FieldElement::zero());
952 constexpr void serialize_to(std::span<uint8_t, Self::BYTES> bytes)
const {
956 x().serialize_to(pack.next<FieldElement::BYTES>());
957 y().serialize_to(pack.next<FieldElement::BYTES>());
966 static constexpr auto ct_select(std::span<const Self> pts,
size_t idx) {
970 const size_t idx1 = idx - 1;
971 for(
size_t i = 0; i != pts.size(); ++i) {
973 result.conditional_assign(found, pts[i]);
982 constexpr const FieldElement&
x()
const {
return m_x; }
987 constexpr const FieldElement&
y()
const {
return m_y; }
993 FieldElement::conditional_assign(m_x, m_y, cond, pt.
x(), pt.
y());
1010template <
typename FieldElement,
typename Params>
1016 static constexpr FieldElement
A = FieldElement::from_words(Params::AW);
1019 static constexpr bool A_is_minus_3 = (
A == FieldElement::constant(-3)).as_bool();
1037 const auto x = pt.
x();
1039 auto z = FieldElement::one();
1049 static constexpr Self identity() {
return Self(FieldElement::zero(), FieldElement::one(), FieldElement::zero()); }
1055 m_x(FieldElement::zero()), m_y(FieldElement::one()), m_z(FieldElement::zero()) {}
1061 m_x(
x), m_y(
y), m_z(FieldElement::one()) {}
1067 m_x(
x), m_y(
y), m_z(
z) {}
1082 (*this) = (*this) + other;
1087 (*this) = (*this) + other;
1096 FieldElement::conditional_assign(m_x, m_y, m_z, cond, pt.
x(), pt.
y(), pt.
z());
1131 const FieldElement& curve_a) {
1203 const auto r2 = r.square();
1204 const auto r3 = r2 * r;
1214 constexpr const FieldElement&
x()
const {
return m_x; }
1219 constexpr const FieldElement&
y()
const {
return m_y; }
1224 constexpr const FieldElement&
z()
const {
return m_z; }
1242template <StringLiteral PS,
1260 static constexpr int8_t
Z = ZI;
1266template <WordType WI,
size_t NI, std::array<WI, NI> PI>
1270 static constexpr size_t N = NI;
1271 static constexpr auto P = PI;
1279template <
typename Params,
template <
typename FieldParamsT>
typename FieldRep =
MontgomeryRep>
1282 typedef typename Params::W
W;
1286 static constexpr auto PW = Params::PW;
1287 static constexpr auto NW = Params::NW;
1288 static constexpr auto AW = Params::AW;
1291 static_assert(
PW.size() ==
NW.size());
1312 static_assert(
B.is_nonzero().as_bool(),
"B must be non-zero");
1344template <
typename C,
size_t WindowBits>
1347 typedef typename C::W W;
1351 static_assert(BlindingBits < C::Scalar::BITS);
1357 static constexpr size_t Bits = C::Scalar::BITS + BlindingBits;
1362 size_t bits()
const {
return m_bits; }
1367 template <
typename Randomness>
1370 if(BlindingBits > 0 && randomness.seeded()) {
1371 constexpr size_t n_words = C::Words;
1373 W mask[n_words] = {0};
1378 if constexpr(ExcessBits > 0) {
1379 constexpr W ExcessMask = (
static_cast<W
>(1) << (
WordInfo<W>::bits - ExcessBits)) - 1;
1385 mask[(BlindingBits - 1) /
WordInfo<W>::bits] |=
static_cast<W
>(1) << TopMaskBit;
1388 W mask_n[2 * n_words] = {0};
1390 const auto sw = scalar.to_words();
1394 bigint_add2(mask_n, 2 * n_words, sw.data(), sw.size());
1396 std::reverse(mask_n, mask_n + 2 * n_words);
1398 m_bits = C::Scalar::BITS + BlindingBits;
1401 m_bytes.resize(C::Scalar::BYTES);
1402 scalar.serialize_to(std::span{m_bytes}.template first<C::Scalar::BYTES>());
1403 m_bits = C::Scalar::BITS;
1420 std::vector<uint8_t> m_bytes;
1434template <
typename BlindedScalar,
size_t Scalars = 1>
1441 using C =
typename BlindedScalar::Curve;
1442 using FieldElement =
typename C::FieldElement;
1444 static constexpr size_t MaskBytes = BlindedScalar::MaskBytes;
1447 static constexpr size_t WideBytes = FieldElement::BYTES + 8;
1453 std::array<uint8_t, Scalars * MaskBytes + (
Rerandomizations + 1) * WideBytes> buf{};
1456 const std::span<const uint8_t> bytes(buf);
1458 copy_mem(m_masks, bytes.first<Scalars * MaskBytes>());
1461 const auto wide = bytes.subspan(Scalars * MaskBytes + i * WideBytes).first<WideBytes>();
1462 m_rerandomizers[i] = FieldElement::from_wide_bytes(wide);
1465 const auto iso = bytes.subspan(Scalars * MaskBytes +
Rerandomizations * WideBytes).first<WideBytes>();
1466 m_isomorphism = FieldElement::from_wide_bytes(iso);
1467 m_isomorphism.conditional_assign(m_isomorphism.is_zero(), FieldElement::one());
1473 std::span<const uint8_t, MaskBytes>
mask(
size_t idx)
const {
1475 return std::span{m_masks}.subspan(idx * MaskBytes).template first<MaskBytes>();
1485 pt.randomize_rep(m_rerandomizers[idx]);
1496 std::array<uint8_t, Scalars * MaskBytes> m_masks{};
1497 std::array<FieldElement, Rerandomizations> m_rerandomizers{};
1498 FieldElement m_isomorphism = FieldElement::one();
1501template <
typename C,
size_t WindowBits>
1504 static constexpr size_t Bits = C::Scalar::BITS;
1516 std::array<uint8_t, C::Scalar::BYTES> m_bytes;
1526template <
typename C,
size_t W>
1529 static_assert(W >= 2 && W <= 7);
1534 explicit WnafScalar(
const typename C::Scalar& scalar) : m_digits{}, m_len(0) {
1535 using Word =
typename C::W;
1537 constexpr Word WindowMask = (
static_cast<Word
>(1) << W) - 1;
1538 constexpr Word HalfWindow =
static_cast<Word
>(1) << (W - 1);
1541 std::array<Word, C::Words + 1> k = {};
1542 const auto sw = scalar.to_words();
1543 std::copy(sw.begin(), sw.end(), k.begin());
1548 bool k_is_zero =
true;
1549 for(
const auto w : k) {
1550 k_is_zero = k_is_zero && (w == 0);
1558 if((k[0] & 1) == 1) {
1561 const Word d = k[0] & WindowMask;
1563 if(d >= HalfWindow) {
1565 m_digits[i] =
static_cast<int8_t
>(
static_cast<int>(d) - (1 << W));
1566 Word carry = (
static_cast<Word
>(1) << W) - d;
1567 for(
size_t j = 0; j != k.size() && carry > 0; ++j) {
1568 const Word t = k[j] + carry;
1569 carry = (t < k[j]) ? 1 : 0;
1573 m_digits[i] =
static_cast<int8_t
>(d);
1575 for(
size_t j = 0; j != k.size() && borrow > 0; ++j) {
1576 const Word t = k[j] - borrow;
1577 borrow = (k[j] < borrow) ? 1 : 0;
1588 for(
size_t j = 0; j != k.size(); ++j) {
1590 if(j + 1 != k.size()) {
1591 k[j] |= k[j + 1] << (WordBits - shift);
1602 int8_t
digit(
size_t i)
const {
return m_digits[i]; }
1605 std::array<int8_t, MaxDigits> m_digits;
1609template <
typename C,
size_t W>
1644 std::vector<AffinePoint> m_table;
1650 return (sb - 1) / wb;
1660 return sb - (sb / wb) * wb;
1672template <
typename C,
size_t W>
1674 const typename C::Scalar& s,
1676 using ProjectivePoint =
typename C::ProjectivePoint;
1678 constexpr size_t TableBits = W;
1679 static_assert(TableBits >= 1 && TableBits <= 7);
1681 constexpr size_t WindowBits = TableBits + 1;
1687 constexpr size_t TableSize = 1 << TableBits;
1689 const Blinding blinding(rng);
1691 const BlindedScalar bits(s, blinding);
1693 const size_t scalar_bits = bits.bits();
1700 auto accum = ProjectivePoint::identity();
1702 for(
size_t i = 0; i != full_windows; ++i) {
1703 const size_t idx = scalar_bits - initial_shift - WindowBits * i;
1705 const size_t w_i = bits.get_window(idx);
1710 accum = ProjectivePoint::from_affine(table.
ct_select(tidx));
1711 accum.conditional_assign(tneg, accum.negate());
1713 accum = ProjectivePoint::add_or_sub_iso(accum, table.
ct_select(tidx), tneg, table.
a());
1716 accum = accum.dbl_n_iso(table.
a(), WindowBits);
1719 if(i < Blinding::Rerandomizations) {
1720 blinding.randomize_rep(accum, i);
1725 const size_t w_l = bits.get_window(0) & ((1 << WindowBits) - 1);
1727 accum = ProjectivePoint::add_or_sub_iso(accum, table.
ct_select(tidx), tneg, table.
a());
1730 return ProjectivePoint(accum.x(), accum.y(), accum.z() * table.
z());
1739template <
typename C,
size_t W>
1741 const typename C::Scalar& x,
1742 const typename C::AffinePoint& q,
1743 const typename C::Scalar& y,
1746 static_assert(W >= 1 && W <= 4);
1752 const BlindedScalar x_bits(x, blinding, 0);
1753 const BlindedScalar y_bits(y, blinding, 1);
1769template <
typename C,
size_t W>
1772 static_assert(W >= 2 && W <= 7);
1780 template <
size_t GW>
1785 if(x.is_zero().as_bool() && y.is_zero().as_bool()) {
1786 return ProjectivePoint::identity();
1789 return g_table.
mul_vartime(x, this->mul_vartime(y));
1797 size_t i = naf.length();
1801 return ProjectivePoint::identity();
1804 const auto lookup = [&](int8_t d) ->
const AffinePoint& {
1805 const size_t mag =
static_cast<size_t>((d < 0) ? -d : d);
1806 return m_table[(mag - 1) / 2];
1810 auto accum = ProjectivePoint::from_affine(
lookup(naf.digit(i)));
1811 if(naf.digit(i) < 0) {
1812 accum = accum.negate();
1815 size_t pending_dbl = 0;
1821 const int8_t d = naf.digit(i);
1823 accum = accum.dbl_n(pending_dbl);
1829 if(pending_dbl > 0) {
1830 accum = accum.dbl_n(pending_dbl);
1836 std::vector<AffinePoint> m_table;
1844template <
typename C>
1846 requires C::ValidForSswuHash
1858template <
typename C>
1860 requires C::ValidForSswuHash
1864 static const typename C::FieldElement C1 = (
SSWU_C2<C>() * C::SSWU_Z).negate();
1873template <
typename C>
1876 const auto z_u2 = C::SSWU_Z * u.square();
1877 const auto z2_u4 = z_u2.square();
1879 auto x1 =
SSWU_C1<C>() * (C::FieldElement::one() + tv1);
1880 x1.conditional_assign(tv1.is_zero(),
SSWU_C2<C>());
1881 const auto x2 = z_u2 * x1;
1889 const auto x = C::FieldElement::choose(use_y1, x1, x2);
1891 C::FieldElement::choose(use_y1, y1.
value_or(C::FieldElement::zero()), y2.
value_or(C::FieldElement::zero()));
1893 auto pt =
typename C::AffinePoint(x, y.correct_sign(u.is_even()));
1910template <
typename C,
bool RO, std::invocable<std::span<u
int8_t>> ExpandMsg>
1911 requires C::ValidForSswuHash
1913 -> std::conditional_t<RO, typename C::ProjectivePoint, typename C::AffinePoint> {
1914 constexpr size_t SecurityLevel = (C::OrderBits + 1) / 2;
1915 constexpr size_t L = (C::PrimeFieldBits + SecurityLevel + 7) / 8;
1916 constexpr size_t Cnt = RO ? 2 : 1;
1918 std::array<uint8_t, L * Cnt> uniform_bytes = {};
1919 expand_message(uniform_bytes);
1922 const auto u0 = C::FieldElement::from_wide_bytes(std::span<const uint8_t, L>(uniform_bytes.data(), L));
1923 const auto u1 = C::FieldElement::from_wide_bytes(std::span<const uint8_t, L>(uniform_bytes.data() + L, L));
1929 const auto u = C::FieldElement::from_wide_bytes(std::span<const uint8_t, L>(uniform_bytes.data(), L));
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_DEBUG_ASSERT(expr)
#define BOTAN_STATE_CHECK(expr)
constexpr Self negate() const
constexpr AffineCurvePoint()
constexpr void serialize_to(std::span< uint8_t, Self::BYTES > bytes) const
AffineCurvePoint(Self &&other)=default
constexpr void _const_time_unpoison() const
static constexpr Self identity()
constexpr void _const_time_poison() const
AffineCurvePoint & operator=(const Self &other)=default
constexpr const FieldElement & y() const
static constexpr Self identity(const Self &)
constexpr void conditional_assign(CT::Choice cond, const Self &pt)
AffineCurvePoint< FieldElement > Self
AffineCurvePoint & operator=(Self &&other)=default
constexpr AffineCurvePoint(const FieldElement &x, const FieldElement &y)
static constexpr auto ct_select(std::span< const Self > pts, size_t idx)
constexpr CT::Choice is_identity() const
AffineCurvePoint(const Self &other)=default
~AffineCurvePoint()=default
constexpr const FieldElement & x() const
static constexpr size_t BYTES
BlindedScalarBits(const BlindedScalarBits &other)=delete
BlindedScalarBits & operator=(BlindedScalarBits &&other)=delete
static constexpr size_t MaskBytes
size_t get_window(size_t offset) const
BlindedScalarBits(BlindedScalarBits &&other)=delete
BlindedScalarBits(const typename C::Scalar &scalar, const Randomness &randomness, size_t idx=0)
static constexpr size_t Bits
BlindedScalarBits & operator=(const BlindedScalarBits &other)=delete
static constexpr size_t MaskWords
const FieldElement & isomorphism() const
BlindingRandomness(RandomNumberGenerator &rng)
static constexpr size_t Rerandomizations
Each multiplication re-randomizes the accumulator this many times.
void randomize_rep(typename C::ProjectivePoint &pt, size_t idx) const
std::span< const uint8_t, MaskBytes > mask(size_t idx) const
Helper class to ease in-place marshalling of concatenated fixed-length values.
constexpr T into_bitmask() const
static constexpr Choice from_int(T v)
static constexpr Mask< T > expand(T v)
static constexpr Mask< T > is_equal(T x, T y)
constexpr Choice has_value() const
Return true if this Option contains a value.
constexpr T value_or(T other) const
static constexpr int8_t Z
static constexpr auto GXW
static constexpr auto GYW
static constexpr size_t PrimeFieldBits
static constexpr FieldElement SSWU_Z
IntMod< MontgomeryRep< ScalarParams > > Scalar
static constexpr bool ValidForSswuHash
static constexpr FieldElement x3_ax_b(const FieldElement &x)
static constexpr FieldElement A
static constexpr bool OrderIsLessThanField
static constexpr size_t Words
AffineCurvePoint< FieldElement > AffinePoint
ProjectiveCurvePoint< FieldElement, Params > ProjectivePoint
static constexpr size_t OrderBits
static constexpr AffinePoint G
IntMod< FieldRep< FieldParams > > FieldElement
static constexpr FieldElement B
static constexpr auto P_MOD_4
static constexpr void conditional_assign(Self &x, Self &y, CT::Choice cond, const Self &nx, const Self &ny)
static constexpr std::optional< Self > from_wide_bytes_varlen(std::span< const uint8_t > bytes)
constexpr void serialize_to(std::span< uint8_t, Self::BYTES > bytes) const
static constexpr size_t BITS
constexpr CT::Choice is_zero() const
static constexpr void _invert_vartime_div2_helper(Self &a, Self &x)
std::array< W, L > stash_value() const
constexpr CT::Choice is_nonzero() const
constexpr BOTAN_FORCE_INLINE Self & operator*=(const Self &other)
constexpr void _const_time_unpoison() const
IntMod(const Self &other)=default
friend constexpr BOTAN_FORCE_INLINE Self operator*(const Self &a, const Self &b)
constexpr Self correct_sign(CT::Choice even) const
constexpr void conditional_assign(CT::Choice cond, const Self &nx)
constexpr Self negate() const
constexpr Self invert_vartime() const
static consteval Self constant(int8_t x)
constexpr std::array< W, Self::N > to_words() const
constexpr BOTAN_FORCE_INLINE Self mul2() const
Return (*this) multiplied by 2.
static constexpr Self zero()
static Self from_stash(const std::array< W, L > &stash)
IntMod(Self &&other)=default
static std::optional< Self > deserialize(std::span< const uint8_t > bytes)
constexpr Self mul8() const
Return (*this) multiplied by 8.
constexpr Self pow_vartime(const std::array< W, N > &exp) const
constexpr void square_n(size_t n)
constexpr CT::Option< Self > sqrt() const
constexpr void _const_time_poison() const
static constexpr size_t BYTES
constexpr BOTAN_FORCE_INLINE Self square() const
static constexpr Self one()
static constexpr Self choose(CT::Choice choice, const Self &x, const Self &y)
constexpr CT::Choice operator==(const Self &other) const
constexpr Self invert() const
constexpr Self mul3() const
Return (*this) multiplied by 3.
friend constexpr BOTAN_FORCE_INLINE Self operator+(const Self &a, const Self &b)
static constexpr void conditional_assign(Self &x, Self &y, Self &z, CT::Choice cond, const Self &nx, const Self &ny, const Self &nz)
constexpr CT::Choice is_even() const
IntMod & operator=(const Self &other)=default
static constexpr Self from_words(std::array< W, L > w)
friend constexpr BOTAN_FORCE_INLINE Self operator-(const Self &a, const Self &b)
IntMod & operator=(Self &&other)=default
constexpr Self mul4() const
Return (*this) multiplied by 4.
static constexpr Self from_wide_bytes(std::span< const uint8_t, L > bytes)
static Self random(RandomNumberGenerator &rng)
constexpr CT::Choice is_one() const
static constexpr void conditional_swap(CT::Choice cond, Self &x, Self &y)
constexpr CT::Choice operator!=(const Self &other) const
static constexpr std::array< W, N > wide_to_rep(const std::array< W, 2 *N > &x)
static constexpr auto P_dash
static constexpr std::array< W, N > from_rep(const std::array< W, N > &z)
static constexpr size_t N
MontgomeryRep< Params > Self
static constexpr std::array< W, N > one()
static constexpr std::array< W, N > to_rep(const std::array< W, N > &x)
static constexpr std::array< W, N > redc(const std::array< W, 2 *N > &z)
C::AffinePoint AffinePoint
static constexpr size_t WindowBits
ProjectivePoint mul_vartime(const Scalar &s, const ProjectivePoint &accum) const
BlindedScalarBits< C, WindowBits+1 > BlindedScalar
PrecomputedBaseMulTable(const AffinePoint &p)
C::ProjectivePoint ProjectivePoint
ProjectivePoint mul(const Scalar &s, RandomNumberGenerator &rng) const
static constexpr Self add_or_sub(const Self &a, const AffinePoint &b, CT::Choice sub)
ProjectiveCurvePoint< FieldElement, Params > Self
~ProjectiveCurvePoint()=default
ProjectiveCurvePoint(const Self &other)=default
friend constexpr Self operator+(const AffinePoint &a, const Self &b)
ProjectiveCurvePoint(Self &&other)=default
static constexpr bool A_is_zero
ProjectiveCurvePoint & operator=(Self &&other)=default
constexpr Self dbl_n_iso(const FieldElement &a, size_t n) const
constexpr const FieldElement & x() const
constexpr ProjectiveCurvePoint()
friend constexpr Self operator-(const Self &a, const Self &b)
friend constexpr Self operator+(const Self &a, const AffinePoint &b)
static constexpr bool A_is_minus_3
ProjectiveCurvePoint & operator=(const Self &other)=default
static constexpr Self from_affine(const AffinePoint &pt)
static constexpr Self add(const Self &a, const Self &b)
constexpr Self & operator+=(const AffinePoint &other)
void randomize_rep(const FieldElement &r)
constexpr void conditional_assign(CT::Choice cond, const Self &pt)
constexpr void _const_time_unpoison() const
constexpr const FieldElement & z() const
constexpr const FieldElement & y() const
constexpr CT::Choice is_identity() const
constexpr Self negate() const
static constexpr Self add_or_sub_iso(const Self &a, const AffinePoint &b, CT::Choice sub, const FieldElement &curve_a)
AffineCurvePoint< FieldElement > AffinePoint
friend constexpr Self operator+(const Self &a, const Self &b)
static constexpr FieldElement A
constexpr ProjectiveCurvePoint(const FieldElement &x, const FieldElement &y)
static constexpr std::pair< Self, FieldElement > add_mixed_h(const Self &a, const AffinePoint &b)
static constexpr Self add_mixed(const Self &a, const AffinePoint &b)
constexpr Self dbl_iso(const FieldElement &a) const
static constexpr Self add_mixed_iso(const Self &a, const AffinePoint &b, const FieldElement &curve_a)
static constexpr Self identity()
constexpr void _const_time_poison() const
constexpr Self dbl_n(size_t n) const
constexpr ProjectiveCurvePoint(const FieldElement &x, const FieldElement &y, const FieldElement &z)
constexpr Self dbl() const
constexpr Self & operator+=(const Self &other)
void randomize(std::span< uint8_t > output)
const FieldElement & z() const
AffinePoint ct_select(size_t idx) const
const FieldElement & a() const
consteval StringLiteral(const char(&str)[N])
static constexpr size_t Bits
UnblindedScalarBits(const typename C::Scalar &scalar)
size_t get_window(size_t offset) const
ProjectivePoint mul2_vartime(const PrecomputedBaseMulTable< C, GW > &g_table, const Scalar &x, const Scalar &y) const
VartimeMul2Table(const AffinePoint &q)
typename C::AffinePoint AffinePoint
typename C::Scalar Scalar
typename C::ProjectivePoint ProjectivePoint
WnafScalar(const typename C::Scalar &scalar)
static constexpr size_t MaxDigits
size_t length() const
Return the number of digits, ie one more than the index of the top nonzero digit.
int8_t digit(size_t i) const
#define BOTAN_FORCE_INLINE
constexpr void poison_all(const Ts &... ts)
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
constexpr void unpoison_all(const Ts &... ts)
constexpr void unpoison(const T *p, size_t n)
constexpr CT::Mask< T > all_zeros(const T elem[], size_t len)
constexpr void poison(const T *p, size_t n)
std::string lookup(const OID &oid)
constexpr auto bigint_add2(W x[], size_t x_size, const W y[], size_t y_size) -> W
auto map_to_curve_sswu(const typename C::FieldElement &u) -> typename C::AffinePoint
consteval std::array< W, N > shanks_tonelli_c3(const std::array< W, N > &c2)
C::ProjectivePoint basemul_booth_exec(std::span< const typename C::AffinePoint > table, const BlindedScalar &scalar, const Blinding &blinding)
consteval std::array< W, N > p_plus_1_over_4(const std::array< W, N > &p)
constexpr auto bytes_to_words(std::span< const uint8_t, L > bytes)
constexpr W shift_left(std::array< W, N > &x)
constexpr auto word_sub(W x, W y, W *carry) -> W
consteval std::array< W, N > p_minus_1_over_2(const std::array< W, N > &p)
constexpr CT::Option< typename C::FieldElement > sqrt_field_element(const typename C::FieldElement &fe)
constexpr auto word_add(W x, W y, W *carry) -> W
C::ProjectivePoint varpoint_mul(const typename C::AffinePoint &p, const typename C::Scalar &s, RandomNumberGenerator &rng)
constexpr ProjectivePoint dbl_n_generic(const ProjectivePoint &pt, const FieldElement &A, size_t n)
constexpr void comba_sqr(W z[2 *N], const W x[N])
consteval auto shanks_tonelli_c4(const std::array< W, N > &p_minus_1_over_2) -> Z
constexpr size_t read_window_bits(std::span< const W, N > words, size_t offset)
constexpr ProjectivePoint dbl_a_minus_3(const ProjectivePoint &pt)
constexpr size_t scalar_blinding_bits(size_t scalar_bits)
constexpr std::pair< size_t, CT::Choice > booth_recode(size_t x, size_t window_bits)
constexpr void comba_mul(W z[2 *N], const W x[N], const W y[N])
consteval std::array< W, N > p_div_2_plus_1(const std::array< W, N > &p)
constexpr auto monty_redc(const std::array< W, 2 *N > &z, const std::array< W, N > &p, W p_dash) -> std::array< W, N >
constexpr auto bigint_sub3(W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
constexpr auto monty_inverse(W a) -> W
C::ProjectivePoint mul2_exec(const SharedZPointTable< C > &table, const BlindedScalar &x, const BlindedScalar &y, const Blinding &blinding)
constexpr ProjectivePoint dbl_n_a_zero(const ProjectivePoint &pt, size_t n)
constexpr ProjectivePoint dbl_a_zero(const ProjectivePoint &pt)
constexpr void copy_mem(T *out, const T *in, size_t n)
std::vector< typename C::ProjectivePoint > mul2_setup(const typename C::AffinePoint &p, const typename C::AffinePoint &q)
std::vector< typename C::AffinePoint > odd_multiples_setup_vartime(const typename C::AffinePoint &p)
consteval std::array< W, N > mul_mod(const std::array< W, N > &x, const std::array< W, N > &y, const std::array< W, N > &p)
constexpr int32_t bigint_cmp(const W x[], size_t x_size, const W y[], size_t y_size)
std::vector< typename C::AffinePoint > basemul_booth_setup(const typename C::AffinePoint &p, size_t max_scalar_bits)
constexpr void bigint_monty_maybe_sub(size_t N, W z[], W x0, const W x[], const W p[])
constexpr auto invert_field_element(const typename C::FieldElement &fe)
void secure_zeroize_buffer(void *ptr, size_t n)
BOTAN_FORCE_INLINE constexpr T choose(T mask, T a, T b)
C::ProjectivePoint basemul_booth_exec_vartime(std::span< const typename C::AffinePoint > table, const ScalarBits &scalar, typename C::ProjectivePoint accum)
constexpr ProjectivePoint point_add_or_sub_mixed(const ProjectivePoint &a, const AffinePoint &b, CT::Choice sub, const FieldElement &one, const FieldElement &curve_a)
constexpr ProjectivePoint dbl_n_a_minus_3(const ProjectivePoint &pt, size_t n)
auto hash_to_curve_sswu(const ExpandMsg &expand_message) -> std::conditional_t< RO, typename C::ProjectivePoint, typename C::AffinePoint >
constexpr auto load_le(ParamTs &&... params)
constexpr auto bigint_ct_is_lt(const W x[], size_t x_size, const W y[], size_t y_size, bool lt_or_equal=false) -> CT::Mask< W >
C::ProjectivePoint varpoint_mul2(const typename C::AffinePoint &p, const typename C::Scalar &x, const typename C::AffinePoint &q, const typename C::Scalar &y, RandomNumberGenerator &rng)
constexpr size_t booth_full_windows(size_t sb, size_t wb)
constexpr size_t booth_initial_shift(size_t sb, size_t wb)
constexpr auto hex_to_words(const char(&s)[N])
constexpr ProjectivePoint dbl_generic(const ProjectivePoint &pt, const FieldElement &A)
consteval std::array< W, N > p_minus(const std::array< W, N > &p)
constexpr ProjectivePoint point_add(const ProjectivePoint &a, const ProjectivePoint &b)
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
The native machine word, used as the limb type for multiprecision integers.
consteval size_t count_bits(const std::array< W, N > &p)
constexpr auto store_be(ParamTs &&... params)
constexpr std::pair< ProjectivePoint, FieldElement > point_add_mixed_h(const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one, const FieldElement &curve_a)
constexpr auto monty_redc_pdash1(const std::array< W, 2 *N > &z, const std::array< W, N > &p) -> std::array< W, N >
constexpr ProjectivePoint point_add_mixed(const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one, const FieldElement &curve_a)
consteval std::array< W, N > montygomery_r(const std::array< W, N > &p)
constexpr W shift_right(std::array< W, N > &x)
consteval std::pair< size_t, std::array< W, N > > shanks_tonelli_c1c2(const std::array< W, N > &p)
static constexpr size_t N