cryptonite-0.21: Cryptography Primitives sink

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
PortabilityGood
Safe HaskellNone
LanguageHaskell2010

Crypto.Number.ModArithmetic

Contents

Description

 

Synopsis

exponentiation

expSafe #

Arguments

:: Integer

base

-> Integer

exponant

-> Integer

modulo

-> Integer

result

Compute the modular exponentiation of base^exponant using algorithms design to avoid side channels and timing measurement

Modulo need to be odd otherwise the normal fast modular exponentiation is used.

When used with integer-simple, this function is not different from expFast, and thus provide the same unstudied and dubious timing and side channels claims.

with GHC 7.10, the powModSecInteger is missing from integer-gmp (which is now integer-gmp2), so is has the same security as old ghc version.

expFast #

Arguments

:: Integer

base

-> Integer

exponant

-> Integer

modulo

-> Integer

result

Compute the modular exponentiation of base^exponant using the fastest algorithm without any consideration for hiding parameters.

Use this function when all the parameters are public, otherwise expSafe should be prefered.

inverse computing

inverse :: Integer -> Integer -> Maybe Integer #

inverse computes the modular inverse as in g^(-1) mod m

inverseCoprimes :: Integer -> Integer -> Integer #

Compute the modular inverse of 2 coprime numbers. This is equivalent to inverse except that the result is known to exists.

if the numbers are not defined as coprime, this function will raise a CoprimesAssertionError.