cryptonite-0.10: Cryptography Primitives sink

License | BSD-style
Maintainer | Danny Navarro <j@dannynavarro.net>
Stability | experimental
Portability | Good
Safe Haskell | None
Language | Haskell2010

Crypto.Number.F2m

Description

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.

Synopsis

- type BinaryPolynomial = Integer
- addF2m :: Integer -> Integer -> Integer
- mulF2m :: BinaryPolynomial -> Integer -> Integer -> Integer
- squareF2m :: BinaryPolynomial -> Integer -> Integer
- modF2m :: BinaryPolynomial -> Integer -> Integer
- invF2m :: BinaryPolynomial -> Integer -> Maybe Integer
- divF2m :: BinaryPolynomial -> Integer -> Integer -> Maybe Integer

# Documentation

type BinaryPolynomial = Integer Source

Binary Polynomial represented by an integer

addF2m :: Integer -> Integer -> Integer Source

Addition over F₂m. This is just a synonym of `xor`.

mulF2m Source

Arguments

:: BinaryPolynomial | Irreducible binary polynomial
-> Integer |
-> Integer |
-> Integer |

Multiplication over F₂m.

n1 * n2 (in F(2^m))

squareF2m Source

Arguments

:: BinaryPolynomial | Irreducible binary polynomial
-> Integer |
-> Integer |

Squaring over F₂m. TODO: This is still slower than `mulF2m`.

modF2m Source

Arguments

:: BinaryPolynomial | Irreducible binary polynomial
-> Integer |
-> Integer |

Binary polynomial reduction modulo using long division algorithm.

invF2m Source

Arguments

:: BinaryPolynomial | Irreducible binary polynomial
-> Integer |
-> Maybe Integer |

Inversion of @n over F₂m using extended Euclidean algorithm.

If @n doesn't have an inverse, Nothing is returned.

divF2m Source

Arguments

:: BinaryPolynomial | Irreducible binary polynomial
-> Integer | Dividend
-> Integer | Quotient
-> Maybe Integer |

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

Compute n1 / n2