7#ifndef BOTAN_BLS12_381_H_
8#define BOTAN_BLS12_381_H_
10#include <botan/types.h>
32 static constexpr size_t BITS = 255;
55 Scalar(
Scalar&& other) noexcept : m_val(other.m_val) { other.wipe(); }
69 static Scalar from_u32(uint32_t v);
86 static std::optional<Scalar> deserialize(std::span<const uint8_t> bytes);
94 static Scalar from_bytes_wide(std::span<const uint8_t, 64> bytes);
106 static Scalar hash(std::span<const uint8_t> input, std::span<const uint8_t> dst);
109 void serialize_to(std::span<uint8_t, Scalar::BYTES> bytes)
const;
113 std::array<uint8_t, Scalar::BYTES> buf{};
129 (*this) = this->
add(x);
135 (*this) = this->
sub(x);
141 (*this) = this->
mul(x);
156 void square_n(
size_t n);
160 constexpr const std::array<word, N>& value()
const {
return m_val; }
162 constexpr const word* data()
const {
return m_val.data(); }
164 static Scalar from_words(std::array<word, Scalar::N> v);
166 explicit constexpr Scalar(std::array<word, Scalar::N> v) : m_val(v) {}
168 std::array<word, Scalar::N> m_val;
217 static std::optional<G1Affine>
deserialize(std::span<const uint8_t> bytes);
224 std::array<uint8_t, G1Affine::BYTES>
serialize()
const;
243 template <
typename Group>
248 static constexpr size_t FE_WORDS = 48 /
sizeof(
word);
250 std::array<word, FE_WORDS> m_x;
251 std::array<word, FE_WORDS> m_y;
313 bool is_identity()
const;
320 static G1Projective hash_to_curve_ro(std::span<const uint8_t> input, std::span<const uint8_t> dst);
328 static G1Projective hash_to_curve_nu(std::span<const uint8_t> input, std::span<const uint8_t> dst);
340 static G1Projective msm_vartime(std::span<const G1Affine> points, std::span<const Scalar> scalars);
348 static std::vector<G1Affine>
to_affine_batch(std::span<const G1Projective> points);
364 void conditional_negate(uint32_t negate);
368 template <
typename Pt>
371 template <
typename Group>
374 static constexpr size_t FE_WORDS = 48 /
sizeof(
word);
376 std::array<word, FE_WORDS> m_x;
377 std::array<word, FE_WORDS> m_y;
378 std::array<word, FE_WORDS> m_z;
412 static std::optional<G2Affine>
deserialize(std::span<const uint8_t> bytes);
419 std::array<uint8_t, G2Affine::BYTES>
serialize()
const;
438 template <
typename Group>
443 static constexpr size_t FE2_WORDS = 96 /
sizeof(
word);
445 std::array<word, FE2_WORDS> m_x;
446 std::array<word, FE2_WORDS> m_y;
508 bool is_identity()
const;
515 static G2Projective hash_to_curve_ro(std::span<const uint8_t> input, std::span<const uint8_t> dst);
523 static G2Projective hash_to_curve_nu(std::span<const uint8_t> input, std::span<const uint8_t> dst);
535 static G2Projective msm_vartime(std::span<const G2Affine> points, std::span<const Scalar> scalars);
543 static std::vector<G2Affine>
to_affine_batch(std::span<const G2Projective> points);
559 void conditional_negate(uint32_t negate);
574 template <
typename Pt>
577 template <
typename Group>
580 static constexpr size_t FE2_WORDS = 96 /
sizeof(
word);
582 std::array<word, FE2_WORDS> m_x;
583 std::array<word, FE2_WORDS> m_y;
584 std::array<word, FE2_WORDS> m_z;
596 static constexpr size_t BYTES = 576;
611 static Gt
multi_pairing(std::span<const G1Affine> p, std::span<const G2Affine> q);
633 std::array<uint8_t, BYTES>
serialize()
const;
636 explicit Gt(
const Fp12& v);
638 Fp12 _to_fp12()
const;
640 static constexpr size_t WORDS = 12 * (48 /
sizeof(
word));
642 std::array<word, WORDS> m_coeffs;
#define BOTAN_PUBLIC_API(maj, min)
friend class G1Projective
static G1Affine identity()
static std::optional< G1Affine > deserialize(std::span< const uint8_t > bytes)
std::array< uint8_t, G1Affine::BYTES > serialize() const
static G1Affine generator()
static constexpr size_t BYTES
static G1Projective identity()
static G1Projective from_affine(const G1Affine &affine)
static G2Affine generator()
static constexpr size_t BYTES
std::array< uint8_t, G2Affine::BYTES > serialize() const
static G2Affine identity()
static std::optional< G2Affine > deserialize(std::span< const uint8_t > bytes)
friend class G2Projective
static G2Projective identity()
static G2Projective from_affine(const G2Affine &affine)
std::array< uint8_t, BYTES > serialize() const
static Gt pairing(const G1Affine &p, const G2Affine &q)
static Gt multi_pairing(std::span< const G1Affine > p, std::span< const G2Affine > q)
bool operator==(const Gt &other) const
static constexpr size_t BYTES
Scalar(const Scalar &other)=default
static constexpr size_t BITS
static constexpr size_t N
Scalar & operator-=(const Scalar &x)
Scalar & operator+=(const Scalar &x)
Scalar mul(const Scalar &x) const
void serialize_to(std::span< uint8_t, Scalar::BYTES > bytes) const
Scalar(Scalar &&other) noexcept
static constexpr size_t BYTES
Scalar & operator*=(const Scalar &x)
Scalar & operator=(Scalar &&other) noexcept
std::array< uint8_t, Scalar::BYTES > serialize() const
Scalar sub(const Scalar &x) const
Scalar & operator=(const Scalar &other)=default
Scalar add(const Scalar &x) const
Scalar operator-(const Scalar &a, const Scalar &b)
Scalar operator+(const Scalar &a, const Scalar &b)
Scalar operator*(const Scalar &a, const Scalar &b)
BigInt square(const BigInt &x)
auto to_affine_batch(std::span< const typename C::ProjectivePoint > projective)
constexpr auto to_affine(const typename C::ProjectivePoint &pt)
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
The native machine word, used as the limb type for multiprecision integers.