HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Modulecrypton-2.1.7Haskell2010

Crypto.PubKey.Rabin.Basic

Rabin cryptosystem for public-key cryptography and digital signature.

What is kept from the clock, and what is not

The square roots modulo the secret primes are taken with expSafe, which does not read the exponent it is given. Two things here do read what they are given.

Signing asks for the Jacobi symbol of the hash modulo each of the two private primes, and the Jacobi symbol is computed by a sequence of reductions whose number follows both of its arguments -- so the work done per signature follows the primes. Key generation runs the extended Euclidean algorithm on the two primes for the same reason. Neither has a drop-in replacement here: a Jacobi symbol that does not read its arguments is a different algorithm, not a different call.

Around all of that is Integer arithmetic, whose cost follows the size of the numbers; see Crypto.PubKey.DSA for that note at more length.

  • 3 types
  • 7 values
  • Packagecrypton-2.1.7
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause AND MIT AND ISC
  • SourceBasic.hs
datadata PrivateKey
#

Represent a Rabin private key.

Instances5Eq, Data, Read, Show, DebugShow
  • Eq PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.Basic
  • Data PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.Basic
  • Read PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.Basic
  • Show PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.Basic

    The public part is shown; the secret fields are not. Use debugShow to see them.

  • DebugShow PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.Basic
valuegenerate :: MonadRandom m => Int -> m (PublicKey, PrivateKey)
#

Generate a pair of (private, public) key of size in bytes. Primes p and q are both congruent 3 mod 4.

See algorithm 8.11 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.

valuedecrypt
  1. :: HashAlgorithm hash
  2. => OAEPParams hash ByteString ByteString

    OAEP padding parameters

  3. -> PrivateKey

    private key

  4. -> ByteString

    ciphertext

  5. -> Maybe ByteString
#

Decrypt ciphertext using private key.

The ciphertext has to be what encrypt produces: the big-endian encoding, with no leading zero octet, of a value below the modulus. Squaring and the square roots that undo it work modulo n, so without that condition c and c + n -- and c with a zero octet in front of it -- would all decrypt to the same message, and a ciphertext would not be unique to its plaintext.

See algorithm 8.12 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.