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

View Source

Base field Fq for BLS12-381.

This is the base field over which the BLS12-381 elliptic curves are defined. Modulus: 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787

Summary

Functions

Adds two field elements.

Checks if two field elements are equal.

Computes the Frobenius endomorphism φ: Fq → Fq where φ(x) = x^p. For the base field Fq, this is the identity function since x^p ≡ x (mod p).

Creates a field element from a binary (48 bytes, big-endian).

Creates a field element from an integer. Negative integers are converted to their positive modular equivalent.

Computes the modular inverse of a field element. Returns {:ok, inverse} or {:error, :not_invertible} if the element is zero.

Checks if a field element is one.

Checks if a field element is zero.

Returns the field modulus.

Multiplies two field elements.

Negates a field element.

One element of the field.

Raises a field element to a power.

Generates a random field element.

Computes the square root of a field element if it exists.

Squares a field element.

Subtracts two field elements (a - b).

Converts a field element to 48-byte big-endian binary.

Converts a field element to integer.

Zero element of the field.

Types

t()

@type t() :: binary()

Functions

add(a, b)

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

Adds two field elements.

eq?(a, a)

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

Checks if two field elements are equal.

frobenius(a)

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

Computes the Frobenius endomorphism φ: Fq → Fq where φ(x) = x^p. For the base field Fq, this is the identity function since x^p ≡ x (mod p).

from_bytes(bytes)

@spec from_bytes(binary()) :: {:ok, t()} | {:error, :invalid_size}

Creates a field element from a binary (48 bytes, big-endian).

from_integer(n)

@spec from_integer(integer()) :: t()

Creates a field element from an integer. Negative integers are converted to their positive modular equivalent.

inv(a)

@spec inv(t()) :: {:ok, t()} | {:error, :not_invertible}

Computes the modular inverse of a field element. Returns {:ok, inverse} or {:error, :not_invertible} if the element is zero.

is_one?(fq)

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

Checks if a field element is one.

is_zero?(fq)

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

Checks if a field element is zero.

modulus()

@spec modulus() :: non_neg_integer()

Returns the field modulus.

mul(a, b)

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

Multiplies two field elements.

neg(a)

@spec neg(t()) :: t()

Negates a field element.

one()

@spec one() :: t()

One element of the field.

pow(base, exp)

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

Raises a field element to a power.

random()

@spec random() :: t()

Generates a random field element.

sqrt(a)

@spec sqrt(t()) :: {:ok, t()} | {:error, :no_sqrt}

Computes the square root of a field element if it exists.

square(a)

@spec square(t()) :: t()

Squares a field element.

sub(a, b)

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

Subtracts two field elements (a - b).

to_bytes(fq)

@spec to_bytes(t()) :: binary()

Converts a field element to 48-byte big-endian binary.

to_integer(arg)

@spec to_integer(t()) :: non_neg_integer()

Converts a field element to integer.

zero()

@spec zero() :: t()

Zero element of the field.