Botan 3.14.1
Crypto and TLS for C&
Botan::BLS12_381 Namespace Reference

Classes

class  FieldElement
class  FieldElement2
class  Fp12
class  Fp6
class  G1Affine
class  G1Projective
class  G2Affine
class  G2Projective
class  GroupOps
class  Gt
class  PointMul
class  Scalar

Functions

FieldElement operator* (const FieldElement &a, const FieldElement &b)
FieldElement2 operator* (const FieldElement2 &a, const FieldElement2 &b)
Fp12 operator* (const Fp12 &a, const Fp12 &b)
Fp6 operator* (const Fp6 &a, const Fp6 &b)
Scalar operator* (const Scalar &a, const Scalar &b)
FieldElement operator+ (const FieldElement &a, const FieldElement &b)
FieldElement2 operator+ (const FieldElement2 &a, const FieldElement2 &b)
Fp12 operator+ (const Fp12 &a, const Fp12 &b)
Fp6 operator+ (const Fp6 &a, const Fp6 &b)
Scalar operator+ (const Scalar &a, const Scalar &b)
FieldElement operator- (const FieldElement &a, const FieldElement &b)
FieldElement2 operator- (const FieldElement2 &a, const FieldElement2 &b)
Fp12 operator- (const Fp12 &a, const Fp12 &b)
Fp6 operator- (const Fp6 &a, const Fp6 &b)
Scalar operator- (const Scalar &a, const Scalar &b)
size_t pippenger_window_bits (size_t n)
template<typename FE, size_t N>
FE pow_msb (const FE &x, const std::array< word, N > &exp)
FieldElement2 pow_p2_minus_9_over_16 (const FieldElement2 &x)
std::pair< size_t, CT::Choice > scalar_booth_window (std::span< const uint8_t, Scalar::BYTES > bytes, size_t window, size_t window_bits)
size_t scalar_window_at (std::span< const uint8_t, Scalar::BYTES > bytes, size_t bit, size_t c)

Variables

constexpr uint64_t BLS_Z_ABS = 0xD201000000010000

Function Documentation

◆ operator*() [1/5]

FieldElement Botan::BLS12_381::operator* ( const FieldElement & a,
const FieldElement & b )
inline

Definition at line 147 of file bls12_381_fields.h.

147 {
148 return a.mul(b);
149}
FieldElement mul(const FieldElement &x) const

References Botan::BLS12_381::FieldElement::mul().

◆ operator*() [2/5]

FieldElement2 Botan::BLS12_381::operator* ( const FieldElement2 & a,
const FieldElement2 & b )
inline

Definition at line 282 of file bls12_381_fields.h.

282 {
283 return a.mul(b);
284}
FieldElement2 mul(const FieldElement2 &x) const

References Botan::BLS12_381::FieldElement2::mul().

◆ operator*() [3/5]

Fp12 Botan::BLS12_381::operator* ( const Fp12 & a,
const Fp12 & b )
inline

Definition at line 187 of file bls12_381_tower.h.

187 {
188 return a.mul(b);
189}
Fp12 mul(const Fp12 &x) const

References Botan::BLS12_381::Fp12::mul().

◆ operator*() [4/5]

Fp6 Botan::BLS12_381::operator* ( const Fp6 & a,
const Fp6 & b )
inline

Definition at line 92 of file bls12_381_tower.h.

92 {
93 return a.mul(b);
94}
Fp6 mul(const Fp6 &x) const

References Botan::BLS12_381::Fp6::mul().

◆ operator*() [5/5]

Scalar Botan::BLS12_381::operator* ( const Scalar & a,
const Scalar & b )
inline

Multiplication modulo r

Definition at line 182 of file bls12_381.h.

182 {
183 return a.mul(b);
184}
Scalar mul(const Scalar &x) const

References Botan::BLS12_381::Scalar::mul().

◆ operator+() [1/5]

FieldElement Botan::BLS12_381::operator+ ( const FieldElement & a,
const FieldElement & b )
inline

Definition at line 139 of file bls12_381_fields.h.

139 {
140 return a.add(b);
141}
FieldElement add(const FieldElement &x) const

References Botan::BLS12_381::FieldElement::add().

◆ operator+() [2/5]

FieldElement2 Botan::BLS12_381::operator+ ( const FieldElement2 & a,
const FieldElement2 & b )
inline

Definition at line 274 of file bls12_381_fields.h.

274 {
275 return a.add(b);
276}
FieldElement2 add(const FieldElement2 &x) const

References Botan::BLS12_381::FieldElement2::add().

◆ operator+() [3/5]

Fp12 Botan::BLS12_381::operator+ ( const Fp12 & a,
const Fp12 & b )
inline

Definition at line 179 of file bls12_381_tower.h.

179 {
180 return a.add(b);
181}
Fp12 add(const Fp12 &x) const

References Botan::BLS12_381::Fp12::add().

◆ operator+() [4/5]

Fp6 Botan::BLS12_381::operator+ ( const Fp6 & a,
const Fp6 & b )
inline

Definition at line 84 of file bls12_381_tower.h.

84 {
85 return a.add(b);
86}
Fp6 add(const Fp6 &x) const

References Botan::BLS12_381::Fp6::add().

◆ operator+() [5/5]

Scalar Botan::BLS12_381::operator+ ( const Scalar & a,
const Scalar & b )
inline

Addition modulo r

Definition at line 172 of file bls12_381.h.

172 {
173 return a.add(b);
174}
Scalar add(const Scalar &x) const

References Botan::BLS12_381::Scalar::add().

◆ operator-() [1/5]

FieldElement Botan::BLS12_381::operator- ( const FieldElement & a,
const FieldElement & b )
inline

Definition at line 143 of file bls12_381_fields.h.

143 {
144 return a.sub(b);
145}
FieldElement sub(const FieldElement &x) const

References Botan::BLS12_381::FieldElement::sub().

◆ operator-() [2/5]

FieldElement2 Botan::BLS12_381::operator- ( const FieldElement2 & a,
const FieldElement2 & b )
inline

Definition at line 278 of file bls12_381_fields.h.

278 {
279 return a.sub(b);
280}
FieldElement2 sub(const FieldElement2 &x) const

References Botan::BLS12_381::FieldElement2::sub().

◆ operator-() [3/5]

Fp12 Botan::BLS12_381::operator- ( const Fp12 & a,
const Fp12 & b )
inline

Definition at line 183 of file bls12_381_tower.h.

183 {
184 return a.sub(b);
185}
Fp12 sub(const Fp12 &x) const

References Botan::BLS12_381::Fp12::sub().

◆ operator-() [4/5]

Fp6 Botan::BLS12_381::operator- ( const Fp6 & a,
const Fp6 & b )
inline

Definition at line 88 of file bls12_381_tower.h.

88 {
89 return a.sub(b);
90}
Fp6 sub(const Fp6 &x) const

References Botan::BLS12_381::Fp6::sub().

◆ operator-() [5/5]

Scalar Botan::BLS12_381::operator- ( const Scalar & a,
const Scalar & b )
inline

Subtraction modulo r

Definition at line 177 of file bls12_381.h.

177 {
178 return a.sub(b);
179}
Scalar sub(const Scalar &x) const

References Botan::BLS12_381::Scalar::sub().

◆ pippenger_window_bits()

size_t Botan::BLS12_381::pippenger_window_bits ( size_t n)
inline

Window size heuristic for the Pippenger bucket method, approximately ln(n) + 2

Definition at line 29 of file bls12_381_point_mul.h.

29 {
30 if(n < 32) {
31 return 3;
32 }
33 size_t log2n = 5;
34 while(n >= (static_cast<size_t>(2) << log2n)) {
35 ++log2n;
36 }
37 return std::min<size_t>((log2n * 69) / 100 + 2, 16);
38}

Referenced by Botan::BLS12_381::PointMul< Pt >::msm_vartime().

◆ pow_msb()

template<typename FE, size_t N>
FE Botan::BLS12_381::pow_msb ( const FE & x,
const std::array< word, N > & exp )

Generic MSB-first exponentiation with a fixed public exponent

Since every exponent used is a fixed constant, each user could instead use an addchain generated chain (as invert does), reducing the multiplication count roughly 3x; the sqrts during G1 and especially G2 deserialization would benefit the most.

Definition at line 297 of file bls12_381_fields.h.

297 {
298 auto r = FE::one();
299 for(size_t i = 0; i != N; ++i) {
300 const word w = exp[N - 1 - i];
301 for(size_t b = 0; b != WordInfo<word>::bits; ++b) {
302 r = r.square();
303 // The exponent is a public constant so this branch leaks nothing
304 if(((w >> (WordInfo<word>::bits - 1 - b)) & 1) == 1) {
305 r = r * x;
306 }
307 }
308 }
309 return r;
310}
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
The native machine word, used as the limb type for multiprecision integers.
Definition types.h:131

Referenced by Botan::BLS12_381::FieldElement2::sqrt(), and Botan::BLS12_381::FieldElement::sqrt().

◆ pow_p2_minus_9_over_16()

FieldElement2 Botan::BLS12_381::pow_p2_minus_9_over_16 ( const FieldElement2 & x)

Definition at line 144 of file bls12_381_fp2.cpp.

144 {
145 const auto t = pow_p_minus_11_over_16(x);
146 const auto t2 = t.square();
147 const auto t4 = t2.square();
148 const auto t8 = t4.square();
149 const auto t11 = t8 * t2 * t;
150
151 const auto x2 = x.square();
152 const auto x3 = x2 * x;
153 const auto x6 = x3.square();
154 const auto x7 = x6 * x;
155
156 // (p^2-9)/16 = q*p + 11*q + 7 for q = (p-11)/16
157 return t.conjugate() * t11 * x7;
158}
FieldElement2 conjugate() const

References Botan::BLS12_381::FieldElement2::conjugate(), and Botan::BLS12_381::FieldElement2::square().

◆ scalar_booth_window()

std::pair< size_t, CT::Choice > Botan::BLS12_381::scalar_booth_window ( std::span< const uint8_t, Scalar::BYTES > bytes,
size_t window,
size_t window_bits )
inline

Extract the Booth recoded window of a serialized scalar; constant time with respect to the scalar bytes

Definition at line 61 of file bls12_381_point_mul.h.

63 {
64 const size_t raw = (window == 0) ? (scalar_window_at(bytes, 0, window_bits) << 1)
65 : scalar_window_at(bytes, window * window_bits - 1, window_bits + 1);
66 return booth_recode(raw, window_bits);
67}
size_t scalar_window_at(std::span< const uint8_t, Scalar::BYTES > bytes, size_t bit, size_t c)
constexpr std::pair< size_t, CT::Choice > booth_recode(size_t x, size_t window_bits)
Definition mp_core.h:1312

References Botan::booth_recode(), and scalar_window_at().

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().

◆ scalar_window_at()

size_t Botan::BLS12_381::scalar_window_at ( std::span< const uint8_t, Scalar::BYTES > bytes,
size_t bit,
size_t c )
inline

Extract the c-bit window starting at bit offset bit (counted from the least significant end) of a big-endian encoded scalar

Definition at line 44 of file bls12_381_point_mul.h.

44 {
45 size_t digit = 0;
46 for(size_t k = 0; k != c; ++k) {
47 const size_t b = bit + k;
48 if(b >= 8 * Scalar::BYTES) {
49 break;
50 }
51 const uint8_t byte = bytes[Scalar::BYTES - 1 - (b / 8)];
52 digit |= static_cast<size_t>((byte >> (b % 8)) & 1) << k;
53 }
54 return digit;
55}
static constexpr size_t BYTES
Definition bls12_381.h:35

References Botan::BLS12_381::Scalar::BYTES.

Referenced by scalar_booth_window().

Variable Documentation

◆ BLS_Z_ABS

uint64_t Botan::BLS12_381::BLS_Z_ABS = 0xD201000000010000
constexpr