libdecaf
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
decaf::Ed448Goldilocks::Scalar Class Reference

A scalar modulo the curve order. More...

Inheritance diagram for decaf::Ed448Goldilocks::Scalar:
decaf::Serializable< Scalar >

Public Types

typedef decaf_448_scalar_t Wrapped
 wrapped C type
 

Public Member Functions

 Scalar (uint64_t w) DECAF_NOEXCEPT
 Set to an unsigned word.
 
 Scalar (int64_t w) DECAF_NOEXCEPT
 Set to a signed word.
 
 Scalar (unsigned int w) DECAF_NOEXCEPT
 Set to an unsigned word.
 
 Scalar (int w) DECAF_NOEXCEPT
 Set to a signed word.
 
 Scalar (Rng &rng) DECAF_NOEXCEPT
 Construct from RNG.
 
 Scalar (const Wrapped &t=decaf_448_scalar_zero) DECAF_NOEXCEPT
 Construct from decaf_scalar_t object. More...
 
 Scalar (const Scalar &x) DECAF_NOEXCEPT
 Copy constructor. More...
 
 Scalar (const Block &buffer) DECAF_NOEXCEPT
 Construct from arbitrary-length little-endian byte sequence. More...
 
size_t ser_size () const DECAF_NOEXCEPT
 Serializable instance.
 
void serialize_into (unsigned char *buffer) const DECAF_NOEXCEPT
 Serializable instance.
 
Scalaroperator= (const Scalar &x) DECAF_NOEXCEPT
 Assignment. More...
 
Scalaroperator= (uint64_t w) DECAF_NOEXCEPT
 Assign from unsigned 64-bit integer. More...
 
Scalaroperator= (int64_t w) DECAF_NOEXCEPT
 Assign from signed int. More...
 
Scalaroperator= (unsigned int w) DECAF_NOEXCEPT
 Assign from unsigned int. More...
 
Scalaroperator= (int w) DECAF_NOEXCEPT
 Assign from signed int. More...
 
 ~Scalar () DECAF_NOEXCEPT
 Destructor securely zeorizes the scalar. More...
 
Scalaroperator= (const Block &bl) DECAF_NOEXCEPT
 Assign from arbitrary-length little-endian byte sequence in a Block. More...
 
Scalar operator+ (const Scalar &q) const DECAF_NOEXCEPT
 Add. More...
 
Scalaroperator+= (const Scalar &q) DECAF_NOEXCEPT
 Add to this. More...
 
Scalar operator- (const Scalar &q) const DECAF_NOEXCEPT
 Subtract. More...
 
Scalaroperator-= (const Scalar &q) DECAF_NOEXCEPT
 Subtract from this. More...
 
Scalar operator* (const Scalar &q) const DECAF_NOEXCEPT
 Multiply.
 
Scalaroperator*= (const Scalar &q) DECAF_NOEXCEPT
 Multiply into this. More...
 
Scalar operator- () const DECAF_NOEXCEPT
 Negate.
 
Scalar inverse () const
 Return 1/this. More...
 
decaf_error_t DECAF_WARN_UNUSED inverse_noexcept (Scalar &r) const DECAF_NOEXCEPT
 Invert with Fermat's Little Theorem (slow!). More...
 
Scalar operator/ (const Scalar &q) const
 Return this/q. More...
 
Scalaroperator/= (const Scalar &q)
 Set this to this/q. More...
 
Scalar half () const
 Return half this scalar. More...
 
bool operator!= (const Scalar &q) const DECAF_NOEXCEPT
 Compare in constant time.
 
bool operator== (const Scalar &q) const DECAF_NOEXCEPT
 Compare in constant time.
 
Point operator* (const Point &q) const DECAF_NOEXCEPT
 Scalarmul with scalar on left. More...
 
Point operator* (const Precomputed &q) const DECAF_NOEXCEPT
 Scalarmul-precomputed with scalar on left. More...
 
SecureBuffer direct_scalarmul (const FixedBlock< SER_BYTES > &in, decaf_bool_t allow_identity=DECAF_FALSE, decaf_bool_t short_circuit=DECAF_TRUE) const
 Direct scalar multiplication. More...
 
decaf_error_t DECAF_WARN_UNUSED direct_scalarmul_noexcept (FixedBuffer< SER_BYTES > &out, const FixedBlock< SER_BYTES > &in, decaf_bool_t allow_identity=DECAF_FALSE, decaf_bool_t short_circuit=DECAF_TRUE) const DECAF_NOEXCEPT
 Direct scalar multiplication. More...
 
- Public Member Functions inherited from decaf::Serializable< Scalar >
size_t ser_size () const DECAF_NOEXCEPT
 Return the number of bytes needed to serialize this object.
 
void serialize_into (unsigned char *buf) const DECAF_NOEXCEPT
 Serialize this object into a buffer.
 
SecureBuffer serialize () const
 Serialize this object into a SecureBuffer and return it.
 

Static Public Member Functions

static decaf_error_t DECAF_WARN_UNUSED decode (Scalar &sc, const FixedBlock< SER_BYTES > buffer) DECAF_NOEXCEPT
 Decode from correct-length little-endian byte sequence. More...
 

Public Attributes

Wrapped s
 access to the underlying scalar object
 

Static Public Attributes

static const size_t SER_BYTES = DECAF_448_SCALAR_BYTES
 Size of a serialized element.
 

Detailed Description

A scalar modulo the curve order.

Supports the usual arithmetic operations, all in constant time.

Constructor & Destructor Documentation

◆ Scalar() [1/3]

decaf::Ed448Goldilocks::Scalar::Scalar ( const Wrapped t = decaf_448_scalar_zero)
inline

Construct from decaf_scalar_t object.

◆ Scalar() [2/3]

decaf::Ed448Goldilocks::Scalar::Scalar ( const Scalar x)
inline

Copy constructor.

◆ Scalar() [3/3]

decaf::Ed448Goldilocks::Scalar::Scalar ( const Block buffer)
inline

Construct from arbitrary-length little-endian byte sequence.

◆ ~Scalar()

decaf::Ed448Goldilocks::Scalar::~Scalar ( )
inline

Destructor securely zeorizes the scalar.

Member Function Documentation

◆ decode()

static decaf_error_t DECAF_WARN_UNUSED decaf::Ed448Goldilocks::Scalar::decode ( Scalar sc,
const FixedBlock< SER_BYTES buffer 
)
inlinestatic

Decode from correct-length little-endian byte sequence.

Returns
DECAF_FAILURE if the scalar is greater than or equal to the group order q.

◆ direct_scalarmul()

SecureBuffer decaf::Ed448Goldilocks::Scalar::direct_scalarmul ( const FixedBlock< SER_BYTES > &  in,
decaf_bool_t  allow_identity = DECAF_FALSE,
decaf_bool_t  short_circuit = DECAF_TRUE 
) const
inline

Direct scalar multiplication.

Exceptions
CryptoExceptionif the input didn't decode.

◆ direct_scalarmul_noexcept()

decaf_error_t DECAF_WARN_UNUSED decaf::Ed448Goldilocks::Scalar::direct_scalarmul_noexcept ( FixedBuffer< SER_BYTES > &  out,
const FixedBlock< SER_BYTES > &  in,
decaf_bool_t  allow_identity = DECAF_FALSE,
decaf_bool_t  short_circuit = DECAF_TRUE 
) const
inline

Direct scalar multiplication.

◆ half()

Scalar decaf::Ed448Goldilocks::Scalar::half ( ) const
inline

Return half this scalar.

Much faster than /2.

◆ inverse()

Scalar decaf::Ed448Goldilocks::Scalar::inverse ( ) const
inline

Return 1/this.

Exceptions
CryptoExceptionif this is 0.

◆ inverse_noexcept()

decaf_error_t DECAF_WARN_UNUSED decaf::Ed448Goldilocks::Scalar::inverse_noexcept ( Scalar r) const
inline

Invert with Fermat's Little Theorem (slow!).

If *this == 0, set r=0 and return DECAF_FAILURE.

◆ operator*() [1/2]

Point decaf::Ed448Goldilocks::Scalar::operator* ( const Point q) const
inline

Scalarmul with scalar on left.

◆ operator*() [2/2]

Point decaf::Ed448Goldilocks::Scalar::operator* ( const Precomputed q) const
inline

Scalarmul-precomputed with scalar on left.

◆ operator*=()

Scalar& decaf::Ed448Goldilocks::Scalar::operator*= ( const Scalar q)
inline

Multiply into this.

◆ operator+()

Scalar decaf::Ed448Goldilocks::Scalar::operator+ ( const Scalar q) const
inline

Add.

◆ operator+=()

Scalar& decaf::Ed448Goldilocks::Scalar::operator+= ( const Scalar q)
inline

Add to this.

◆ operator-()

Scalar decaf::Ed448Goldilocks::Scalar::operator- ( const Scalar q) const
inline

Subtract.

◆ operator-=()

Scalar& decaf::Ed448Goldilocks::Scalar::operator-= ( const Scalar q)
inline

Subtract from this.

◆ operator/()

Scalar decaf::Ed448Goldilocks::Scalar::operator/ ( const Scalar q) const
inline

Return this/q.

Exceptions
CryptoExceptionif q == 0.

◆ operator/=()

Scalar& decaf::Ed448Goldilocks::Scalar::operator/= ( const Scalar q)
inline

Set this to this/q.

Exceptions
CryptoExceptionif q == 0.

◆ operator=() [1/6]

Scalar& decaf::Ed448Goldilocks::Scalar::operator= ( const Scalar x)
inline

Assignment.

◆ operator=() [2/6]

Scalar& decaf::Ed448Goldilocks::Scalar::operator= ( uint64_t  w)
inline

Assign from unsigned 64-bit integer.

◆ operator=() [3/6]

Scalar& decaf::Ed448Goldilocks::Scalar::operator= ( int64_t  w)
inline

Assign from signed int.

◆ operator=() [4/6]

Scalar& decaf::Ed448Goldilocks::Scalar::operator= ( unsigned int  w)
inline

Assign from unsigned int.

◆ operator=() [5/6]

Scalar& decaf::Ed448Goldilocks::Scalar::operator= ( int  w)
inline

Assign from signed int.

◆ operator=() [6/6]

Scalar& decaf::Ed448Goldilocks::Scalar::operator= ( const Block bl)
inline

Assign from arbitrary-length little-endian byte sequence in a Block.


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