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

GHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11

Modulecrypton-2.1.7Haskell2010

Crypto.PubKey.RSA.PKCS15

  • 1 class
  • 9 values
  • Packagecrypton-2.1.7
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause AND MIT AND ISC
  • SourcePKCS15.hs

Padding and unpadding

3 declarations
valueunpad :: ByteArray bytearray => bytearray -> Either Error bytearray
#

Try to remove a standard PKCS1.5 encryption padding.

The block is scanned in full rather than up to the octet ending the padding string, so how long that string is does not show up in how long this takes.

What remains visible is the result itself: whether the padding was well formed, and the length of the message when it was. That is inherent to the scheme, and it is the signal Bleichenbacher's attack needs, so a caller that decrypts attacker-supplied ciphertext must not pass the distinction on -- TLS, for instance, continues with a random premaster secret and reports nothing.

Private key operations

4 declarations
valuedecrypt
  1. :: ByteArray ba
  2. => Maybe Blinder

    optional blinder

  3. -> PrivateKey

    RSA private key

  4. -> ByteString

    cipher text

  5. -> Either Error ba
#

decrypt message using the private key.

The blinder is optional and Nothing is accepted, but see Blinder for what it covers and when leaving it out is a decision rather than a default. decryptSafer generates one for you.

The message is returned un-padded.

Following RFC 8017, the ciphertext is rejected unless it is exactly as long as the modulus (section 7.2.2, step 1) and its integer representative is below the modulus (RSADP, section 5.1.2, step 1). The decryption primitive normalises any multiple of the modulus away, so without the second check c + n would decrypt to the same message as c, and a ciphertext would not be unique to its plaintext. Both checks are made on the ciphertext alone, which is public, and report MessageSizeIncorrect.

Public key operations

2 declarations
valueverify
  1. :: HashAlgorithmASN1 hashAlg
  2. => Maybe hashAlg
  3. -> PublicKey
  4. -> ByteString

    Message

  5. -> ByteString

    Signature

  6. -> Bool
#

verify message with the signed message

Following RFC 8017, the signature is rejected unless it is exactly as long as the modulus (section 8.2.2, step 1) and its integer representative is below the modulus (section 5.2.2, step 1). Verification works by re-encoding the expected signature and comparing it with the result of the public-key operation, and that operation normalises away both the length of the encoding and any multiple of the modulus; without these checks a zero-padded signature, or s + n, would verify just as well as s.

Hash ASN1 description

1 declaration
classclass HashAlgorithm hashAlg => HashAlgorithmASN1 hashAlg where
#

A specialized class for hash algorithm that can product a ASN1 wrapped description the algorithm plus the content of the digest.

Instances14HashAlgorithmASN1, …