Botan 3.8.1
Crypto and TLS for C&
Botan::Modular_Reducer Class Referencefinal

#include <reducer.h>

Public Member Functions

BigInt cube (const BigInt &x) const
 
const BigIntget_modulus () const
 
bool initialized () const
 
 Modular_Reducer ()
 
 Modular_Reducer (const BigInt &mod)
 
BigInt multiply (const BigInt &x, const BigInt &y) const
 
BigInt multiply (const BigInt &x, const BigInt &y, const BigInt &z) const
 
void reduce (BigInt &out, const BigInt &x, secure_vector< word > &) const
 
BigInt reduce (const BigInt &x) const
 
BigInt square (const BigInt &x) const
 

Static Public Member Functions

static Modular_Reducer for_public_modulus (const BigInt &m)
 
static Modular_Reducer for_secret_modulus (const BigInt &m)
 

Detailed Description

Modular Reducer

This class is deprecated without replacement

Definition at line 22 of file reducer.h.

Constructor & Destructor Documentation

◆ Modular_Reducer() [1/2]

Botan::Modular_Reducer::Modular_Reducer ( )
inline

Definition at line 69 of file reducer.h.

69{ m_mod_words = 0; }

References Modular_Reducer().

Referenced by for_public_modulus(), for_secret_modulus(), and Modular_Reducer().

◆ Modular_Reducer() [2/2]

Botan::Modular_Reducer::Modular_Reducer ( const BigInt & mod)
explicit

Accepts m == 0 and leaves the Modular_Reducer in an uninitialized state

Definition at line 14 of file reducer.cpp.

14 {
15 if(mod < 0) {
16 throw Invalid_Argument("Modular_Reducer: modulus must be positive");
17 }
18
19 m_modulus = mod;
20}

Member Function Documentation

◆ cube()

BigInt Botan::Modular_Reducer::cube ( const BigInt & x) const
inline

Cube mod p

Parameters
xthe value to cube
Returns
(x * x * x) % p

Definition at line 54 of file reducer.h.

54{ return multiply(x, this->square(x)); }
BigInt square(const BigInt &x) const
Definition reducer.h:47
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition reducer.h:34

References multiply(), and square().

◆ for_public_modulus()

static Modular_Reducer Botan::Modular_Reducer::for_public_modulus ( const BigInt & m)
inlinestatic

Requires that m > 0

Definition at line 79 of file reducer.h.

79{ return Modular_Reducer(m); }

References Modular_Reducer().

◆ for_secret_modulus()

static Modular_Reducer Botan::Modular_Reducer::for_secret_modulus ( const BigInt & m)
inlinestatic

Requires that m > 0

Definition at line 84 of file reducer.h.

84{ return Modular_Reducer(m); }

References Modular_Reducer().

◆ get_modulus()

const BigInt & Botan::Modular_Reducer::get_modulus ( ) const
inline

Definition at line 24 of file reducer.h.

24{ return m_modulus; }

◆ initialized()

bool Botan::Modular_Reducer::initialized ( ) const
inline

Definition at line 67 of file reducer.h.

67{ return (m_mod_words != 0); }

◆ multiply() [1/2]

BigInt Botan::Modular_Reducer::multiply ( const BigInt & x,
const BigInt & y ) const
inline

Multiply mod p

Parameters
xthe first operand
ythe second operand
Returns
(x * y) % p

Definition at line 34 of file reducer.h.

34{ return reduce(x * y); }
BigInt reduce(const BigInt &x) const
Definition reducer.cpp:22

References reduce().

Referenced by cube().

◆ multiply() [2/2]

BigInt Botan::Modular_Reducer::multiply ( const BigInt & x,
const BigInt & y,
const BigInt & z ) const
inline

Multiply mod p

Returns
(x * y * z) % p

Definition at line 40 of file reducer.h.

40{ return multiply(x, multiply(y, z)); }

References multiply().

Referenced by multiply().

◆ reduce() [1/2]

void Botan::Modular_Reducer::reduce ( BigInt & out,
const BigInt & x,
secure_vector< word > &  ) const
inline

Low level reduction function. Mostly for internal use. Sometimes useful for performance by reducing temporaries Reduce x mod p and place the output in out.

Warning
X and out must not reference each other

ws is an (ignored) a temporary workspace.

Definition at line 65 of file reducer.h.

65{ out = reduce(x); }

References reduce().

Referenced by reduce().

◆ reduce() [2/2]

BigInt Botan::Modular_Reducer::reduce ( const BigInt & x) const

Definition at line 22 of file reducer.cpp.

22 {
23 return ct_modulo(x, m_modulus);
24}
BigInt ct_modulo(const BigInt &x, const BigInt &y)
Definition divide.cpp:192

References Botan::ct_modulo().

Referenced by multiply(), and square().

◆ square()

BigInt Botan::Modular_Reducer::square ( const BigInt & x) const
inline

Square mod p

Parameters
xthe value to square
Returns
(x * x) % p

Definition at line 47 of file reducer.h.

47{ return reduce(x * x); }

References reduce().

Referenced by cube().


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