HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulecryptonite-0.30Haskell2010

Crypto.PubKey.RSA

  • 4 types
  • 3 values
  • Packagecryptonite-0.30
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceTypes.hs
datadata Error
#

error possible during encryption, decryption or signing.

Constructors

Instances2Eq, Show
  • Eq ErrorDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
  • Show ErrorDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
datadata PublicKey
#

Represent a RSA public key

Constructors

Instances5Eq, Data, Read, Show, NFData
  • Eq PublicKeyDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
  • Data PublicKeyDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
  • Read PublicKeyDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
  • Show PublicKeyDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
  • NFData PublicKeyDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
datadata PrivateKey
#

Represent a RSA private key.

Only the pub, d fields are mandatory to fill.

p, q, dP, dQ, qinv are by-product during RSA generation, but are useful to record here to speed up massively the decrypt and sign operation.

implementations can leave optional fields to 0.

Constructors

Instances5Eq, Data, Read, Show, NFData
datadata Blinder
#

Blinder which is used to obfuscate the timing of the decryption primitive (used by decryption and signing).

Constructors

Instances2Eq, Show
  • Eq BlinderDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types
  • Show BlinderDefined in cryptonite-0.30 · Crypto.PubKey.RSA.Types

Generation function

3 declarations
valuegenerateWith
  1. :: (Integer, Integer)

    chosen distinct primes p and q

  2. -> Int

    size in bytes

  3. -> Integer

    RSA public exponent e

  4. -> Maybe (PublicKey, PrivateKey)
#

Generate a key pair given p and q.

p and q need to be distinct prime numbers.

e need to be coprime to phi=(p-1)*(q-1). If that's not the case, the function will not return a key pair. A small hamming weight results in better performance.

  • e=0x10001 is a popular choice

  • e=3 is popular as well, but proven to not be as secure for some cases.

valuegenerateBlinder
  1. :: MonadRandom m
  2. => Integer

    RSA public N parameter.

  3. -> m Blinder
#

Generate a blinder to use with decryption and signing operation

the unique parameter apart from the random number generator is the public key value N.