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

A scalar modulo the curve order. More...

#include <point_255.hxx>

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

Public Types

typedef decaf_255_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_255_scalar_zero) DECAF_NOEXCEPT
 Construct from decaf_scalar_t object.
 
 Scalar (const Scalar &x) DECAF_NOEXCEPT
 Copy constructor.
 
 Scalar (const Block &buffer) DECAF_NOEXCEPT
 Construct from arbitrary-length little-endian byte sequence.
 
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.
 
Scalaroperator= (uint64_t w) DECAF_NOEXCEPT
 Assign from unsigned 64-bit integer.
 
Scalaroperator= (int64_t w) DECAF_NOEXCEPT
 Assign from signed int.
 
Scalaroperator= (unsigned int w) DECAF_NOEXCEPT
 Assign from unsigned int.
 
Scalaroperator= (int w) DECAF_NOEXCEPT
 Assign from signed int.
 
 ~Scalar () DECAF_NOEXCEPT
 Destructor securely zeorizes the scalar.
 
Scalaroperator= (const Block &bl) DECAF_NOEXCEPT
 Assign from arbitrary-length little-endian byte sequence in a Block.
 
Scalar operator+ (const Scalar &q) const DECAF_NOEXCEPT
 Add.
 
Scalaroperator+= (const Scalar &q) DECAF_NOEXCEPT
 Add to this.
 
Scalar operator- (const Scalar &q) const DECAF_NOEXCEPT
 Subtract.
 
Scalaroperator-= (const Scalar &q) DECAF_NOEXCEPT
 Subtract from this.
 
Scalar operator* (const Scalar &q) const DECAF_NOEXCEPT
 Multiply.
 
Scalaroperator*= (const Scalar &q) DECAF_NOEXCEPT
 Multiply into this.
 
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.
 
Point operator* (const Precomputed &q) const DECAF_NOEXCEPT
 Scalarmul-precomputed with scalar on left.
 
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.
 
- 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_255_SCALAR_BYTES
 Size of a serialized element.
 

Detailed Description

A scalar modulo the curve order.

Supports the usual arithmetic operations, all in constant time.

Member Function Documentation

◆ decode()

static decaf_error_t DECAF_WARN_UNUSED decaf::Ristretto::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::Ristretto::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.

◆ half()

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

Return half this scalar.

Much faster than /2.

◆ inverse()

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

Return 1/this.

Exceptions
CryptoExceptionif this is 0.

◆ inverse_noexcept()

decaf_error_t DECAF_WARN_UNUSED decaf::Ristretto::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/()

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

Return this/q.

Exceptions
CryptoExceptionif q == 0.

◆ operator/=()

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

Set this to this/q.

Exceptions
CryptoExceptionif q == 0.

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