liveBook · Manning

Fermat’s Little Theorem

As explained in Elliptic Curve Cryptography for Developers

Fermat's little theorem states that a number raised to the appropriate power modulo a prime satisfies a fixed congruence, and its field-extension analogue gives the corresponding finite-field exponent relation.

Fermat’s Little Theorem states that for a prime modulus p and an integer a not divisible by p, a^(p−1) ≡ 1 mod p. This exponent relation turns modular powers into practical tests and algorithms, especially for quadratic residues and finite-field square roots. section 2.4

Use the theorem operationally in these ways:

  • Test whether a value may have a square root modulo p by first checking its quadratic-residue status. section 2.4
  • For p ≡ 3 mod 4, compute a square root of a with x = a^((p+1)/4) mod p. section 2.5
  • For p ≡ 1 mod 4, use Tonelli–Shanks: factor p−1 as 2^e q, choose a quadratic nonresidue, initialize the state, and iteratively reduce the error term. section 2.5
  • Extend the exponent relation to a field with p^k elements: for a prime polynomial f of degree k, x^(p^k−1) ≡ 1 mod f. section 9.6

A degree-two extension over 43

Use the irreducible polynomial x² + x + 3 mod 43. The extension contains 43² = 1849 elements, so raising a nonzero polynomial to 1848 = 43²−1 produces 1. For example, (11x + 3)^1848 = 1. section 9.3

How Elliptic Curve Cryptography for Developers covers it

How deep it goes
Defines the congruence and translates it into direct exponentiation and Tonelli–Shanks, with detailed code but no proof.
Examples
Uses square roots modulo 23 and polynomial powers modulo x² + x + 3 over the prime 43.
What it assumes
Assumes modular arithmetic and prime fields, while defining quadratic residues and Legendre symbols before using them.
What you can do after
Apply modular exponentiation to test residues, compute selected square roots, and verify extension-field powers.
How it connects
Connects modular exponentiation, quadratic residues, Legendre symbols, Tonelli–Shanks, finite fields, and irreducible polynomials.

Also explained in

Compare how 2 books explain Fermat’s Little Theorem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elliptic Curve Cryptography for Developers. The section links point to the parts of the book it draws on.