gf2.h(3)

📦
version 2.2.0 · 2 versions
, in fedora 44

💖 NAME 💖

gf2.h — Двоичные поля, aka binary fields, aka the math gym where GF(2^m) gets its reps in. 🏋️‍♀️ This is a section 3 page from the Library Functions Manual, and bestie, it's giving "finite field but make it fashion". 🎀

✨ SYNOPSIS ✨

#include 'bee2/math/qr.h'

🦋 Функции

  • bool_t gf2Create (qr_o *f, const size_t p[4], void *stack) — building the description of the field GF(2^m). 🏗️
  • bool_t gf2IsOperable (const qr_o *f) — is the GF(2^m) field description operable or nah?
  • bool_t gf2IsValid (const qr_o *f, void *stack) — is the GF(2^m) field description actually valid?
  • size_t gf2Deg (const qr_o *f) — the extension degree of the field GF(2^m).
  • bool_t gf2Tr (const word a[], const qr_o *f, void *stack) — the trace of an element of the field GF(2^m).
  • bool_t gf2QSolve (word x[], const word a[], const word b[], const qr_o *f, void *stack) — solving a quadratic equation in the field GF(2^m).

🌸 Подробное описание 🌸

okay so, operations in the field GF(2^m) are implemented here. ✨ Elements of the field are interpreted as elements of the residue ring GF(2) / (p(x)), where p(x) is an irreducible polynomial of degree m. Trinomials and pentanomials are both supported — versatility, we love to see it. 💅

Ring elements are encoded as strings of O_OF_B(m) octets, and they're given as arrays of W_OF_B(m) machine words. The encoding uses little-endian order ("least significant first"). Keep these conventions in mind when you're planning your field work, bestie. 🧠

The polynomial p(x) is given by the size_t p[4] array:

p(x) = x^p[0] + x^p[1] + x^p[2] + x^p[3] + 1

In particular, m == p[0] is the extension degree of the field. 👑

When p[2] == 0, we must also have p[3] == 0, and then p(x) is a trinomial.

When p[1] == 0, we must also have p[2] == p[3] == 0, and the field f is described by a normal basis (for the future — foreshadowing, iykyk).

For trinomials and pentanomials p(x), the constraints given in the functions ppRedTrinomial(), ppRedPentanomial() must hold. No cap. 🫶

The field is created with the gf2Create() function. During creation, p(x) gets analyzed, and depending on its shape, one of the general reduction functions — ppRedTrinomial() or ppRedPentanomial() — is chosen. 🌈

The array p describing p(x) gets pinned at the address params when the field is created (see the description of the type qr_o). Creating the field also forms the module mod. The module is represented either by n machine words (when the degree of p(x) is a multiple of B_PER_W) or by n + 1 words (when the degree of p(x) is not a multiple of B_PER_W). 🔥

Some irreducible polynomials straight out of the crypto standards: Belt, GCM: x^128 + x^7 + x^2 + x + 1, NIST163: x^163 + x^7 + x^6 + x^3 + 1, NIST233: x^233 + x^74 + 1, NIST283: x^283 + x^12 + x^7 + x^5 + 1, NIST409: x^409 + x^87 + 1, NIST571: x^571 + x^10 + x^5 + x^2 + 1. Iconic lineup honestly. ⭐

Precondition

All pointers passed into the functions are valid.

Regularity

todo


🎀 Функции 🎀

bool_t gf2Create (qr_o *f, const size_t p[4], void *stack)

From the description p of the polynomial p(x), a description f of the field GF(2^m) = GF(2)/(p(x)) is created. The most optimal description of the field gets picked — optimal as in, most efficient to actually compute with. 💅

Expected

p(x) is irreducible.

Returns

A success flag.

Postcondition

The extension degree m matches p[0].

f->n == W_OF_B(m) and f->no == O_OF_B(m).

Formula for the state size of f

gf2Create_keep(m).

Formula for the stack depth

gf2Create_deep(m).

Arguments

  • f — field description
  • p — description of p(x)
  • stack — auxiliary memory

size_t gf2Deg (const qr_o *f)

The extension degree m of the field f = GF(2^m) is determined. 🔍

Precondition

The description f is operable.

Returns

The extension degree.

Arguments

  • f — field description

bool_t gf2IsOperable (const qr_o *f)

Checking whether the description f of the field GF(2^m) is operable. These are the conditions being checked, one by one:

  • qrIsOperable(f) == TRUE;
  • the f->mod pointer is correct;
  • the f->params pointer is correct;
  • f->params points to the array [4]p;
  • p[0] > p[1] >= p[2] >= p[3] >= 0;
  • p[2] > 0 => the previous inequalities are strict (for pentanomials);
  • the last word of f->mod is nonzero;
  • f->n == W_OF_B(m) (m == p[0]);
  • f->no == O_OF_B(m).

Returns

An operability flag.

Note

The consistency of f->mod and [4]p is not checked, and neither is the irreducibility of f->mod. 👀

Arguments

  • f — field description

bool_t gf2IsValid (const qr_o *f, void *stack)

Checking whether the description f of the field GF(2^m) is valid. These are the conditions being checked:

  • gf2IsOperable(f) == TRUE;
  • if p[1] > 0, then f->mod and the array [4]p describe the same polynomials;
  • if p[1] > 0, then the polynomial f->mod is irreducible.

Here [4]p is the array at the address f->params.

Returns

A validity flag.

Formula for the stack depth

gf2IsValid_deep(f->n).

Arguments

  • f — field description
  • stack — auxiliary memory

bool_t gf2QSolve (word x[], const word a[], const word b[], const qr_o *f, void *stack)

In the field f = GF(2^m), for the given elements [f->n]a, [f->n]b, the solution [n]x of the quadratic equation is determined:

x^2 + a x + b == 0.

Precondition

The description f is operable.

m is odd.

The buffer x does not overlap the buffers a, b.

The elements a and b belong to f.

Expected

The description f is valid.

Returns

TRUE if a solution exists, and FALSE otherwise.

Note

If x is a solution, then x + a is also a solution. Two-for-one deal, we love it. 🫶

Formula for the stack depth

gf2QSolve_deep(f->n, f->deep).

Arguments

  • x — solution
  • a — coefficient a
  • b — coefficient b
  • f — field description
  • stack — auxiliary memory

bool_t gf2Tr (const word a[], const qr_o *f, void *stack)

In the field f = GF(2^m), the absolute trace of the element [f->n]a is determined:

\tr(a) <- \sum {i = 0}^{m - 1} a^{2^i}.

The trace equals either zero or the field's one. Binary choices only, very on brand. ⭐

Precondition

The description f is operable.

The element a belongs to f.

Expected

The description f is valid.

Returns

FALSE if the trace equals 0, and TRUE if the trace equals 1.

Formula for the stack depth

gf2Tr_deep(f->n, f->deep).

Arguments

  • a — element
  • f — field description
  • stack — auxiliary memory

👑 Автор 👑

Automatically generated by Doxygen for the Bee2 Library from the source text. (Not me, a robot did it, and honestly? It ate. 💅)


That's the whole page, bestie — brought to you by the Библиотека Bee2 girlies, dated Вс 25 Янв 2026 00:00:00, living in gf2.h(3). Go do some field arithmetic, you main character. 🌈✨

📦 where this page comes from