Botan 3.11.0
Crypto and TLS for C&
Botan::MontgomeryRep< Params > Class Template Referencefinal

#include <pcurves_impl.h>

Public Types

using Self = MontgomeryRep<Params>
typedef Params::W W

Static Public Member Functions

static constexpr std::array< W, Nfrom_rep (const std::array< W, N > &z)
static constexpr std::array< W, None ()
static constexpr std::array< W, Nredc (const std::array< W, 2 *N > &z)
static constexpr std::array< W, Nto_rep (const std::array< W, N > &x)
static constexpr std::array< W, Nwide_to_rep (const std::array< W, 2 *N > &x)

Static Public Attributes

static constexpr size_t N = Params::N
static constexpr auto P = Params::P
static constexpr auto P_dash = monty_inverse(P[0])
static constexpr auto R1 = montygomery_r(P)
static constexpr auto R2 = mul_mod(R1, R1, P)
static constexpr auto R3 = mul_mod(R1, R2, P)

Detailed Description

template<typename Params>
class Botan::MontgomeryRep< Params >

Montomgomery Representation of Integers

Integers modulo a prime (IntMod, see below) use some representation that allows for fast arithmetic.

The default representation used is Montgomery arithmetic. Curves with specialized fields (eg Mersenne primes, Solinas primes, or Crandall primes) provide a different type as the FieldRep parameter to the EllipticCurve template.

Since the curve parameters are public and known at compile time, we can similarly compute the Montgomery parameters at compile time.

Definition at line 80 of file pcurves_impl.h.

Member Typedef Documentation

◆ Self

template<typename Params>
using Botan::MontgomeryRep< Params >::Self = MontgomeryRep<Params>

Definition at line 82 of file pcurves_impl.h.

◆ W

template<typename Params>
typedef Params::W Botan::MontgomeryRep< Params >::W

Definition at line 86 of file pcurves_impl.h.

Member Function Documentation

◆ from_rep()

template<typename Params>
constexpr std::array< W, N > Botan::MontgomeryRep< Params >::from_rep ( const std::array< W, N > & z)
inlinestaticconstexpr

Convert an integer out of Montgomery representation

Definition at line 137 of file pcurves_impl.h.

137 {
139 copy_mem(std::span{ze}.template first<N>(), z);
140 return Self::redc(ze);
141 }
static constexpr std::array< W, N > redc(const std::array< W, 2 *N > &z)
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144

References Botan::copy_mem(), and redc().

◆ one()

template<typename Params>
constexpr std::array< W, N > Botan::MontgomeryRep< Params >::one ( )
inlinestaticconstexpr

Return the constant one, pre-converted into Montgomery form

Definition at line 99 of file pcurves_impl.h.

99{ return R1; }
static constexpr auto R1

References R1.

◆ redc()

template<typename Params>
constexpr std::array< W, N > Botan::MontgomeryRep< Params >::redc ( const std::array< W, 2 *N > & z)
inlinestaticconstexpr

Modular reduction

Definition at line 104 of file pcurves_impl.h.

104 {
105 if constexpr(P_dash == 1) {
106 return monty_redc_pdash1(z, P);
107 } else {
108 return monty_redc(z, P, P_dash);
109 }
110 }
static constexpr auto P_dash
static constexpr auto 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 monty_redc_pdash1(const std::array< W, 2 *N > &z, const std::array< W, N > &p) -> std::array< W, N >

References Botan::monty_redc(), Botan::monty_redc_pdash1(), P, and P_dash.

Referenced by from_rep(), to_rep(), and wide_to_rep().

◆ to_rep()

template<typename Params>
constexpr std::array< W, N > Botan::MontgomeryRep< Params >::to_rep ( const std::array< W, N > & x)
inlinestaticconstexpr

Convert an integer into Montgomery representation

Definition at line 115 of file pcurves_impl.h.

115 {
116 std::array<W, 2 * N> z; // NOLINT(*-member-init)
117 comba_mul<N>(z.data(), x.data(), R2.data());
118 return Self::redc(z);
119 }
static constexpr auto R2
constexpr void comba_mul(W z[2 *N], const W x[N], const W y[N])
Definition mp_core.h:801

References Botan::comba_mul(), R2, and redc().

◆ wide_to_rep()

template<typename Params>
constexpr std::array< W, N > Botan::MontgomeryRep< Params >::wide_to_rep ( const std::array< W, 2 *N > & x)
inlinestaticconstexpr

Wide reduction modulo the prime

Modular reduces an input of up to twice the length of the modulus, and converts it into Montgomery form.

Definition at line 127 of file pcurves_impl.h.

127 {
128 auto redc_x = Self::redc(x);
129 std::array<W, 2 * N> z; // NOLINT(*-member-init)
130 comba_mul<N>(z.data(), redc_x.data(), R3.data());
131 return Self::redc(z);
132 }
static constexpr auto R3

References Botan::comba_mul(), R3, and redc().

Member Data Documentation

◆ N

template<typename Params>
size_t Botan::MontgomeryRep< Params >::N = Params::N
staticconstexpr

Definition at line 85 of file pcurves_impl.h.

◆ P

template<typename Params>
auto Botan::MontgomeryRep< Params >::P = Params::P
staticconstexpr

Definition at line 84 of file pcurves_impl.h.

Referenced by redc().

◆ P_dash

template<typename Params>
auto Botan::MontgomeryRep< Params >::P_dash = monty_inverse(P[0])
staticconstexpr

Definition at line 90 of file pcurves_impl.h.

Referenced by redc().

◆ R1

template<typename Params>
auto Botan::MontgomeryRep< Params >::R1 = montygomery_r(P)
staticconstexpr

Definition at line 92 of file pcurves_impl.h.

Referenced by one().

◆ R2

template<typename Params>
auto Botan::MontgomeryRep< Params >::R2 = mul_mod(R1, R1, P)
staticconstexpr

Definition at line 93 of file pcurves_impl.h.

Referenced by to_rep().

◆ R3

template<typename Params>
auto Botan::MontgomeryRep< Params >::R3 = mul_mod(R1, R2, P)
staticconstexpr

Definition at line 94 of file pcurves_impl.h.

Referenced by wide_to_rep().


The documentation for this class was generated from the following file: