Represent a Rabin-Williams public key.
Constructors
PublicKeypublic_size :: Intsize of key in bytes
public_n :: Integerpublic p*q
:: a typeCtrl KGHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11
Modulecrypton-2.1.7Haskell2010
Rabin-Williams cryptosystem for public-key encryption and digital signature. See pages 323 - 324 in "Computational Number Theory and Modern Cryptography" by Song Y. Yan. Also inspired by https://github.com/vanilala/vncrypt/blob/master/vncrypt/vnrw_gmp.c. The Jacobi symbols here are taken modulo the public modulus, not the private primes, so what Crypto.PubKey.Rabin.Basic says about that does not apply; the note there about Integer arithmetic does.
Represent a Rabin-Williams public key.
PublicKeypublic_size :: Intsize of key in bytes
public_n :: Integerpublic p*q
Represent a Rabin-Williams private key.
Eq PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.RWData PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.RWRead PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.RWShow PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.RWThe public part is shown; the secret fields are not. Use debugShow to see them.
DebugShow PrivateKeyDefined in crypton-2.1.7 · Crypto.PubKey.Rabin.RWGenerate a pair of (private, public) key of size in bytes. Prime p is congruent 3 mod 8 and prime q is congruent 7 mod 8.
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. The primitives
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.
sign :: HashAlgorithm hash=> PrivateKeyprivate key
-> hashhash function
-> ByteStringmessage to sign
-> Either Error IntegerSign message using hash algorithm and private key.
verify :: HashAlgorithm hash=> PublicKeypublic key
-> hashhash function
-> ByteStringmessage
-> Integersignature
-> BoolVerify signature using hash algorithm and public key.