# `Tezex.Crypto.BLS.Fq2`
[🔗](https://github.com/objkt-com/tezex/blob/v4.0.0/lib/crypto/bls/fq2.ex#L1)

Quadratic extension field Fq2 for BLS12-381.

Fq2 = Fq[u] / (u^2 + 1) where Fq is the base field.
Elements are represented as a + b*u where a, b ∈ Fq.

# `t`

```elixir
@type t() :: {Tezex.Crypto.BLS.Fq.t(), Tezex.Crypto.BLS.Fq.t()}
```

# `add`

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

Adds two Fq2 elements.

# `conjugate`

```elixir
@spec conjugate(t()) :: t()
```

Computes the conjugate of an Fq2 element.
conj(a + b*u) = a - b*u

# `eq?`

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

Checks if two Fq2 elements are equal.

# `from_integers`

```elixir
@spec from_integers(non_neg_integer(), non_neg_integer()) :: t()
```

Creates an Fq2 element from integers.

# `inv`

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

Computes the modular inverse of an Fq2 element.
inv(a + b*u) = conj(a + b*u) / norm(a + b*u)

# `is_one?`

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

Checks if an Fq2 element is one.

# `is_zero?`

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

Checks if an Fq2 element is zero.

# `modulus`

```elixir
@spec modulus() :: non_neg_integer()
```

Returns the field modulus.

# `mul`

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

Multiplies two Fq2 elements.
(a1 + b1*u) * (a2 + b2*u) = (a1*a2 - b1*b2) + (a1*b2 + b1*a2)*u

# `mul_scalar`

```elixir
@spec mul_scalar(t(), non_neg_integer()) :: t()
```

Multiplies an Fq2 element by a scalar.

# `neg`

```elixir
@spec neg(t()) :: t()
```

Negates an Fq2 element.

# `new`

```elixir
@spec new(Tezex.Crypto.BLS.Fq.t(), Tezex.Crypto.BLS.Fq.t()) :: t()
```

Creates an Fq2 element from two Fq elements (a + b*u).

# `norm`

```elixir
@spec norm(t()) :: Tezex.Crypto.BLS.Fq.t()
```

Computes the norm of an Fq2 element.
norm(a + b*u) = (a + b*u) * (a - b*u) = a^2 + b^2

# `one`

```elixir
@spec one() :: t()
```

One element of Fq2.

# `pow`

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

Raises an Fq2 element to a power.

# `sgn0`

```elixir
@spec sgn0(t()) :: 0 | 1
```

Sign function sgn0(x) = 1 when x is 'negative'; otherwise, sgn0(x) = 0.
For Fq2, this is optimized for m = 2 as defined in the hash-to-curve spec.

# `sqrt`

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

Computes the square root of an Fq2 element using modular square root algorithm.

# `square`

```elixir
@spec square(t()) :: t()
```

Squares an Fq2 element.
(a + b*u)^2 = a^2 + 2*a*b*u + b^2*u^2 = (a^2 - b^2) + (2*a*b)*u

# `sub`

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

Subtracts two Fq2 elements (x - y).

# `to_integers`

```elixir
@spec to_integers(t()) :: {non_neg_integer(), non_neg_integer()}
```

Extracts the coefficients of an Fq2 element as a tuple of integers.

# `zero`

```elixir
@spec zero() :: t()
```

Zero element of Fq2.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
