Tezex.Crypto.BLS.Fq12 (tezex v3.2.0)

View Source

The 12th-degree extension field Fq12 for BLS12-381. This is the target field for pairings: GT = Fq12.

The field is constructed as Fq12 = Fq[x]/(x^12 + 2 - 2*x^6).

Summary

Functions

Adds two Fq12 elements.

Checks if two Fq12 elements are equal.

Divides two Fq12 elements (a / b = a * b^(-1)).

Computes the Frobenius endomorphism φ: Fq12 → Fq12 where φ(x) = x^p. This raises each coefficient to the power p and applies the precomputed basis transformation.

Creates an Fq12 element from integers.

Computes the modular inverse of an Fq12 element. Uses the FqP inverse implementation.

Checks if an Fq12 element is one.

Checks if an Fq12 element is zero.

Multiplies two Fq12 elements.

Creates an Fq12 element from a list of 12 Fq coefficients.

Creates an Fq12 element from a list of coefficients and modulus coefficients. This is used for testing compatibility.

Returns the one element in Fq12.

Returns the one element with custom modulus (for testing).

Optimized final exponentiation for BLS12-381.

Raises an Fq12 element to a power.

Multiplies an Fq12 element by a scalar Fq element.

Subtracts two Fq12 elements.

Types

t()

@type t() :: Tezex.Crypto.BLS.FqP.t()

Functions

add(a, b)

@spec add(t(), t()) :: t()

Adds two Fq12 elements.

eq?(a, b)

@spec eq?(t(), t()) :: boolean()

Checks if two Fq12 elements are equal.

field_div(a, b)

@spec field_div(t(), t()) :: t()

Divides two Fq12 elements (a / b = a * b^(-1)).

frobenius(map)

@spec frobenius(t()) :: t()

Computes the Frobenius endomorphism φ: Fq12 → Fq12 where φ(x) = x^p. This raises each coefficient to the power p and applies the precomputed basis transformation.

from_integers(integers)

@spec from_integers([integer()]) :: t()

Creates an Fq12 element from integers.

inv(a)

@spec inv(t()) :: t()

Computes the modular inverse of an Fq12 element. Uses the FqP inverse implementation.

is_one?(a)

@spec is_one?(t()) :: boolean()

Checks if an Fq12 element is one.

is_zero?(a)

@spec is_zero?(t()) :: boolean()

Checks if an Fq12 element is zero.

mul(a, b)

@spec mul(t(), t()) :: t()

Multiplies two Fq12 elements.

new(coeffs)

@spec new([Tezex.Crypto.BLS.Fq.t()]) :: t()

Creates an Fq12 element from a list of 12 Fq coefficients.

new(coeffs, modulus_coeffs)

@spec new([Tezex.Crypto.BLS.Fq.t()], [integer()]) :: t()

Creates an Fq12 element from a list of coefficients and modulus coefficients. This is used for testing compatibility.

one()

@spec one() :: t()

Returns the one element in Fq12.

one(modulus_coeffs)

@spec one([integer()]) :: t()

Returns the one element with custom modulus (for testing).

optimized_final_exponentiation(f)

@spec optimized_final_exponentiation(t()) :: t()

Optimized final exponentiation for BLS12-381.

Instead of computing f^((p^12-1)/r) directly (~4314 bits), this computes:

  1. f^(p^2 + 1) using 2 Frobenius operations + 1 multiplication
  2. (f^(p^2 + 1))^(p^6 - 1) using 6 Frobenius operations + 1 inversion
  3. result^((p^4-p^2+1)/r) using optimized exponentiation (~1268 bits)

This gives the same result as the naive approach but is much faster. Total: 8 Frobenius + 1 mul + 1 inv + 1 pow(1268 bits) vs 1 pow(4314 bits)

pow(base, exponent)

@spec pow(t(), integer()) :: t()

Raises an Fq12 element to a power.

scalar_mul(map, scalar)

@spec scalar_mul(t(), Tezex.Crypto.BLS.Fq.t()) :: t()

Multiplies an Fq12 element by a scalar Fq element.

sub(a, b)

@spec sub(t(), t()) :: t()

Subtracts two Fq12 elements.