aiken/crypto/bls12_381/scalar
This module implements arithmetic operations in the scalar field associated with the BLS12-381 elliptic curve.
The scalar field, defined over a prime number q
, is derived from the order of the subgroup G1.
More explicitly, we have the identity:
builtin.bls12_381_g1_scalar_mul(q, bls12_381_g1_generator) == 1
where,
q = 52435875175126190479447740508185965837690552500527637822603658699938581184513
This module provides functionality for basic arithmetic operations (addition, subtraction, multiplication, division) within this scalar field. Additionally, it includes advanced operations such as exponentiation and calculation of multiplicative inverses, tailored for cryptographic applications.
Types
Opaque type representing an element of the finite field Scalar
.
Constants
The prime number defining the scalar field of the BLS12-381 curve.
Functions
Constructing
Constructs a new Scalar
element from an integer, ensuring it’s within the valid range of the field.
Returns None
if the integer is negative or greater than the prime number defining the field.
Constructs a new Scalar
element from a Big-Endian (most-significant bits first) ByteArray
.
Constructs a new Scalar
element from a Little-Endian (least-significant bits first) ByteArray
.
Modifying
Exponentiates an Scalar
element by a non-negative integer exponent, using repeated squaring.
Note that this function returns scalar.zero
for negative exponents.
A dedicated builtin function for this is in the making, see CIP 109.
A faster version of scale
for the case where the exponent is a power of two.
That is, the exponent e = 2^k
for some non-negative integer k
. Which is used alot in zk-SNARKs.
Combining
Adds two Scalar
elements, ensuring the result stays within the finite field range.
Divides one Scalar
element by another, returning None
if the divisor is zero.
Multiplies two Scalar
elements, with the result constrained within the finite field.
Calculates the multiplicative inverse of an Scalar
element, returning None
if the element is zero.
Subtracts one Scalar
element from another, with the result wrapped within the finite field range.
Transforming
Converts a Scalar
element to a Big-Endian (most-significant bits first) ByteArray
.
Constructs a new Scalar
element from an integer, ensuring it’s within the valid range of the field.
Returns None
if the integer is negative or greater than the prime number defining the field.
Constructs a new Scalar
element from a Big-Endian (most-significant bits first) ByteArray
.
Constructs a new Scalar
element from a Little-Endian (least-significant bits first) ByteArray
.
Exponentiates an Scalar
element by a non-negative integer exponent, using repeated squaring.
Note that this function returns scalar.zero
for negative exponents.
A dedicated builtin function for this is in the making, see CIP 109.
A faster version of scale
for the case where the exponent is a power of two.
That is, the exponent e = 2^k
for some non-negative integer k
. Which is used alot in zk-SNARKs.
Combining
Adds two Scalar
elements, ensuring the result stays within the finite field range.
Divides one Scalar
element by another, returning None
if the divisor is zero.
Multiplies two Scalar
elements, with the result constrained within the finite field.
Calculates the multiplicative inverse of an Scalar
element, returning None
if the element is zero.
Subtracts one Scalar
element from another, with the result wrapped within the finite field range.
Transforming
Converts a Scalar
element to a Big-Endian (most-significant bits first) ByteArray
.
Adds two Scalar
elements, ensuring the result stays within the finite field range.
Divides one Scalar
element by another, returning None
if the divisor is zero.
Multiplies two Scalar
elements, with the result constrained within the finite field.
Calculates the multiplicative inverse of an Scalar
element, returning None
if the element is zero.
Subtracts one Scalar
element from another, with the result wrapped within the finite field range.
Converts a Scalar
element to a Big-Endian (most-significant bits first) ByteArray
.