Represent a Rabin public key.
Constructors
PublicKeypublic_size :: Intsize of key in bytes
public_n :: Integerpublic p*q
:: a typeCtrl KGHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11
Modulecrypton-2.1.7Haskell2010
Rabin cryptosystem for public-key cryptography and digital signature.
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.
Represent a Rabin public key.
PublicKeypublic_size :: Intsize of key in bytes
public_n :: Integerpublic p*q
Represent a Rabin private key.
Eq PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.BasicData PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.BasicRead PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.BasicShow PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.BasicThe public part is shown; the secret fields are not. Use debugShow to see them.
DebugShow PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.BasicGenerate 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.
encrypt :: (HashAlgorithm hash, MonadRandom m)=> OAEPParams hash ByteString ByteStringOAEP padding parameters
-> PublicKeypublic key
-> ByteStringplaintext
-> m (Either Error ByteString)Encrypt plaintext using public key.
encryptWithSeed :: HashAlgorithm hash=> ByteStringSeed
-> OAEPParams hash ByteString ByteStringOAEP padding
-> PublicKeypublic key
-> ByteStringplaintext
-> Either Error ByteStringEncrypt plaintext using public key an a predefined OAEP seed.
See algorithm 8.11 in "Handbook of Applied Cryptography" by Alfred J. Menezes et al.
decrypt :: HashAlgorithm hash=> OAEPParams hash ByteString ByteStringOAEP padding parameters
-> PrivateKeyprivate key
-> ByteStringciphertext
-> Maybe ByteStringDecrypt 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.
sign :: (MonadRandom m, HashAlgorithm hash)=> PrivateKeyprivate key
-> hashhash function
-> ByteStringmessage to sign
-> m (Either Error Signature)Sign message using hash algorithm and private key.
See https://en.wikipedia.org/wiki/Rabin_signature_algorithm.
signWith :: HashAlgorithm hash=> ByteStringpadding
-> PrivateKeyprivate key
-> hashhash function
-> ByteStringmessage to sign
-> Either Error SignatureSign message using padding, hash algorithm and private key.
See https://en.wikipedia.org/wiki/Rabin_signature_algorithm.
verify :: HashAlgorithm hash=> PublicKeyprivate key
-> hashhash function
-> ByteStringmessage
-> Signaturesignature
-> BoolVerify signature using hash algorithm and public key.
See https://en.wikipedia.org/wiki/Rabin_signature_algorithm.