|
Botan 3.14.1
Crypto and TLS for C&
|
#include <bls12_381.h>
Public Member Functions | |
| Scalar | add (const Scalar &x) const |
| Scalar | invert () const |
| Scalar | mul (const Scalar &x) const |
| Scalar | negate () const |
| Scalar & | operator*= (const Scalar &x) |
| Scalar & | operator+= (const Scalar &x) |
| Scalar & | operator-= (const Scalar &x) |
| Scalar & | operator= (const Scalar &other)=default |
| Scalar & | operator= (Scalar &&other) noexcept |
| constexpr | Scalar () |
| Scalar (const Scalar &other)=default | |
| Scalar (Scalar &&other) noexcept | |
| std::array< uint8_t, Scalar::BYTES > | serialize () const |
| void | serialize_to (std::span< uint8_t, Scalar::BYTES > bytes) const |
| Scalar | square () const |
| Scalar | sub (const Scalar &x) const |
| ~Scalar () | |
Static Public Member Functions | |
| static std::optional< Scalar > | deserialize (std::span< const uint8_t > bytes) |
| static Scalar | from_bytes_wide (std::span< const uint8_t, 64 > bytes) |
| static Scalar | from_u32 (uint32_t v) |
| static Scalar | hash (std::span< const uint8_t > input, std::span< const uint8_t > dst) |
| static Scalar | one () |
| static Scalar | zero () |
Static Public Attributes | |
| static constexpr size_t | BITS = 255 |
| static constexpr size_t | BYTES = (BITS + 7) / 8 |
| static constexpr size_t | N = (BYTES + sizeof(word) - 1) / sizeof(word) |
A BLS12-381 scalar
Integer modulo 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
Definition at line 29 of file bls12_381.h.
|
inlineconstexpr |
Default constructed as zero
Definition at line 43 of file bls12_381.h.
Referenced by add(), from_bytes_wide(), from_u32(), hash(), invert(), mul(), negate(), one(), operator*=(), operator+=(), operator-=(), operator=(), operator=(), Scalar(), Scalar(), square(), sub(), and zero().
|
default |
Copy constructor
References Scalar().
|
inlinenoexcept |
Scalars are commonly secrets, so they are zeroized on destruction, and moving from a Scalar zeroizes the source
Definition at line 55 of file bls12_381.h.
References Scalar().
|
inline |
Definition at line 66 of file bls12_381.h.
Addition modulo r
Definition at line 112 of file bls12_381_scalar.cpp.
References Botan::bigint_monty_maybe_sub(), N, Scalar(), and Botan::word_add().
Referenced by Botan::BLS12_381::operator+(), and operator+=().
|
static |
Deserialize a scalar from a 32-byte long big-endian encoding
Returns nullopt unless the encoding is a canonical integer in the range [1, r). In particular the zero scalar is rejected, since a zero scalar is almost always a mistake; this matches EC_Scalar::deserialize.
Definition at line 80 of file bls12_381_scalar.cpp.
References Botan::CT::all_zeros(), Botan::bigint_ct_is_lt(), BYTES, Botan::bytes_to_words(), and N.
|
static |
Reduce a 64 byte big-endian integer modulo r
Suitable for deriving a uniformly distributed scalar from an RNG or hash output
Definition at line 100 of file bls12_381_scalar.cpp.
References Botan::bytes_to_words(), and Scalar().
Referenced by hash().
|
static |
Return the scalar equal to the small integer v
Definition at line 69 of file bls12_381_scalar.cpp.
References Scalar().
|
static |
Hash an input to a scalar
Uses the hash_to_field construction of RFC 9380, namely expand_message_xmd with SHA-256 followed by wide reduction. The distribution of the result is uniform (negligibly biased). The domain separation tag dst distinguishes different uses of the hash; see RFC 9380 section 3.1 for the requirements.
Throws Invalid_Argument if dst is empty.
Definition at line 484 of file bls12_381_h2c.cpp.
References Botan::copy_mem(), from_bytes_wide(), Botan::CT::poison(), Scalar(), Botan::secure_scrub_memory(), and Botan::CT::unpoison_all().
| Scalar Botan::BLS12_381::Scalar::invert | ( | ) | const |
Return the multiplicative inverse of this scalar, or zero for zero
Definition at line 169 of file bls12_381_scalar.cpp.
Multiplication modulo r
Definition at line 140 of file bls12_381_scalar.cpp.
References Botan::comba_mul(), and Scalar().
Referenced by Botan::BLS12_381::operator*(), and operator*=().
| Scalar Botan::BLS12_381::Scalar::negate | ( | ) | const |
Return the negation of this scalar
Definition at line 160 of file bls12_381_scalar.cpp.
References Botan::CT::all_zeros(), Botan::bigint_sub3(), N, and Scalar().
|
static |
Multiplication modulo r
Definition at line 140 of file bls12_381.h.
Addition modulo r
Definition at line 128 of file bls12_381.h.
Subtraction modulo r
Definition at line 134 of file bls12_381.h.
Copy assignment
References Scalar().
Move assignment; the moved-from scalar is zeroized
Definition at line 58 of file bls12_381.h.
References Scalar().
|
inline |
Return the 32 byte big-endian encoding
Definition at line 112 of file bls12_381.h.
References serialize_to().
Referenced by Botan::BLS12_381::PointMul< Pt >::mul(), Botan::BLS12_381::PointMul< Pt >::mul2(), Botan::BLS12_381::PointMul< Pt >::mul2_vartime(), and Botan::BLS12_381::PointMul< Pt >::mul_vartime().
| void Botan::BLS12_381::Scalar::serialize_to | ( | std::span< uint8_t, Scalar::BYTES > | bytes | ) | const |
Serialize to a 32 byte big-endian encoding
Definition at line 104 of file bls12_381_scalar.cpp.
References Botan::secure_scrub_memory(), and Botan::store_be().
Referenced by serialize().
| Scalar Botan::BLS12_381::Scalar::square | ( | ) | const |
Return the square of this scalar
Definition at line 146 of file bls12_381_scalar.cpp.
References Botan::comba_sqr(), and Scalar().
Referenced by invert().
Subtraction modulo r
Definition at line 124 of file bls12_381_scalar.cpp.
References Botan::CT::Mask< T >::expand(), N, Scalar(), Botan::word_add(), and Botan::word_sub().
Referenced by Botan::BLS12_381::operator-(), and operator-=().
|
inlinestatic |
|
staticconstexpr |
The bit length of the group order r
Definition at line 32 of file bls12_381.h.
Referenced by Botan::BLS12_381::PointMul< Pt >::msm_vartime(), Botan::BLS12_381::PointMul< Pt >::mul(), Botan::BLS12_381::PointMul< Pt >::mul2(), Botan::BLS12_381::PointMul< Pt >::mul2_vartime(), and Botan::BLS12_381::PointMul< Pt >::mul_vartime().
|
staticconstexpr |
The byte length of the canonical scalar encoding
Definition at line 35 of file bls12_381.h.
Referenced by deserialize(), Botan::BLS12_381::PointMul< Pt >::msm_vartime(), and Botan::BLS12_381::scalar_window_at().
The word length of the internal representation
Definition at line 38 of file bls12_381.h.
Referenced by add(), deserialize(), negate(), and sub().