HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulecrypton-1.0.4Haskell2010

Crypto.Number.F2m

This module provides basic arithmetic operations over F₂m. Performance is not optimal and it doesn't provide protection against timing attacks. The m parameter is implicitly derived from the irreducible polynomial where applicable.

  • 1 type
  • 10 values
  • Packagecrypton-1.0.4
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceF2m.hs
valuemulF2m
  1. :: BinaryPolynomial

    Modulus

  2. -> Integer
  3. -> Integer
  4. -> Integer
#

Multiplication over F₂m.

This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited.

valuesquareF2m' :: Integer -> Integer
#

Squaring over F₂m without reduction by modulo.

The implementation utilizes the fact that for binary polynomial S(x) we have S(x)^2 = S(x^2). In other words, insert a zero bit between every bits of argument: 1101 -> 1010001.

This function is undefined for negative arguments, because their bit representation is platform-dependent.

valuesquareF2m
  1. :: BinaryPolynomial

    Modulus

  2. -> Integer
  3. -> Integer
#

Squaring over F₂m.

This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited.

valuepowF2m
  1. :: BinaryPolynomial

    Modulus

  2. -> Integer

    a

  3. -> Integer

    b

  4. -> Integer
#

Exponentiation in F₂m by computing a^b mod fx.

This implements an exponentiation by squaring based solution. It inherits the same restrictions as squareF2m. Negative exponents are disallowed.

valuemodF2m
  1. :: BinaryPolynomial

    Modulus

  2. -> Integer
  3. -> Integer
#

Reduction by modulo over F₂m.

This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited.

valuesqrtF2m
  1. :: BinaryPolynomial

    Modulus

  2. -> Integer

    a

  3. -> Integer
#

Square rooot in F₂m.

We exploit the fact that a^(2^m) = a, or in particular, a^(2^m - 1) = 1 from a classical result by Lagrange. Thus the square root is simply a^(2^(m - 1)).

valueinvF2m
  1. :: BinaryPolynomial

    Modulus

  2. -> Integer
  3. -> Maybe Integer
#

Modular inversion over F₂m. If n doesn't have an inverse, Nothing is returned.

This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited.

valuedivF2m
  1. :: BinaryPolynomial

    Modulus

  2. -> Integer

    Dividend

  3. -> Integer

    Divisor

  4. -> Maybe Integer

    Quotient

#

Division over F₂m. If the dividend doesn't have an inverse it returns Nothing.

This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited.