| License | BSD-style |
|---|---|
| Maintainer | Vincent Hanquez <vincent@snarc.org> |
| Stability | experimental |
| Portability | Good |
| Safe Haskell | None |
| Language | Haskell2010 |
Crypto.PubKey.RSA.PKCS15
Description
Synopsis
- pad :: (MonadRandom m, ByteArray message) => Int -> message -> m (Either Error message)
- padSignature :: ByteArray signature => Int -> signature -> Either Error signature
- unpad :: ByteArray bytearray => bytearray -> Either Error bytearray
- decrypt :: ByteArray ba => Maybe Blinder -> PrivateKey -> ByteString -> Either Error ba
- decryptSafer :: (MonadRandom m, ByteArray ba) => PrivateKey -> ByteString -> m (Either Error ba)
- sign :: HashAlgorithmASN1 hashAlg => Maybe Blinder -> Maybe hashAlg -> PrivateKey -> ByteString -> Either Error ByteString
- signSafer :: (HashAlgorithmASN1 hashAlg, MonadRandom m) => Maybe hashAlg -> PrivateKey -> ByteString -> m (Either Error ByteString)
- signDigest :: HashAlgorithmASN1 hashAlg => Maybe Blinder -> PrivateKey -> Digest hashAlg -> Either Error ByteString
- signSaferDigest :: (HashAlgorithmASN1 hashAlg, MonadRandom m) => PrivateKey -> Digest hashAlg -> m (Either Error ByteString)
- signDigestInfo :: Maybe Blinder -> PrivateKey -> ByteString -> Either Error ByteString
- signSaferDigestInfo :: MonadRandom m => PrivateKey -> ByteString -> m (Either Error ByteString)
- decryptBlinded :: (MonadRandom m, ByteArray ba) => BlindedKey -> ByteString -> m (Either Error ba, BlindedKey)
- signDigestBlinded :: (HashAlgorithmASN1 hashAlg, MonadRandom m) => BlindedKey -> Digest hashAlg -> m (Either Error ByteString, BlindedKey)
- signDigestInfoBlinded :: MonadRandom m => BlindedKey -> ByteString -> m (Either Error ByteString, BlindedKey)
- encrypt :: (MonadRandom m, ByteArray ba) => PublicKey -> ba -> m (Either Error ByteString)
- verify :: HashAlgorithmASN1 hashAlg => Maybe hashAlg -> PublicKey -> ByteString -> ByteString -> Bool
- verifyDigest :: HashAlgorithmASN1 hashAlg => PublicKey -> Digest hashAlg -> ByteString -> Bool
- verifyDigestInfo :: PublicKey -> ByteString -> ByteString -> Bool
- class HashAlgorithm hashAlg => HashAlgorithmASN1 hashAlg
Padding and unpadding
pad :: (MonadRandom m, ByteArray message) => Int -> message -> m (Either Error message) Source #
This produce a standard PKCS1.5 padding for encryption
padSignature :: ByteArray signature => Int -> signature -> Either Error signature Source #
Produce a standard PKCS1.5 padding for signature
unpad :: ByteArray bytearray => bytearray -> Either Error bytearray Source #
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
Arguments
| :: ByteArray ba | |
| => Maybe Blinder | optional blinder |
| -> PrivateKey | RSA private key |
| -> ByteString | cipher text |
| -> 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.
Arguments
| :: (MonadRandom m, ByteArray ba) | |
| => PrivateKey | RSA private key |
| -> ByteString | cipher text |
| -> m (Either Error ba) |
decrypt message using the private key, blinded with the pair kept for this key; see Crypto.PubKey.RSA.Blinded.
Arguments
| :: HashAlgorithmASN1 hashAlg | |
| => Maybe Blinder | optional blinder |
| -> Maybe hashAlg | hash algorithm |
| -> PrivateKey | private key |
| -> ByteString | message to sign |
| -> Either Error ByteString |
Deprecated: Use signDigest, or signDigestInfo when the message is already a DigestInfo
sign message using private key, a hash and its ASN1 description
Deprecated. Use signDigest, or signDigestInfo where this would
have been given Nothing. The Maybe hashAlg argument says both "hash
it with this" and "do not hash it", and down the first path the value
inside the Just is never read: it is there to fix the type, which
leaves a caller that has only a type with nothing to pass.
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.
signSafer generates one for you.
Arguments
| :: (HashAlgorithmASN1 hashAlg, MonadRandom m) | |
| => Maybe hashAlg | Hash algorithm |
| -> PrivateKey | private key |
| -> ByteString | message to sign |
| -> m (Either Error ByteString) |
Deprecated: Use signSaferDigest, or signSaferDigestInfo when the message is already a DigestInfo
sign message using the private key, blinded with the pair kept for this key; see Crypto.PubKey.RSA.Blinded.
Deprecated. Use signSaferDigest, or signSaferDigestInfo.
Arguments
| :: HashAlgorithmASN1 hashAlg | |
| => Maybe Blinder | optional blinder |
| -> PrivateKey | private key |
| -> Digest hashAlg | digest of the message to sign |
| -> Either Error ByteString |
Sign a digest.
The digest's type says which algorithm made it, so this needs nothing
else to name one: the ASN.1 DigestInfo prefix comes from the
HashAlgorithmASN1 instance that type selects. sign takes Maybe
hashAlg and never reads the value inside the Just -- it is there only
to fix the type -- which is no burden when the caller has a value and
leaves nothing to pass when the caller is itself polymorphic in the
algorithm.
signDigest blinder key (hashWith SHA256 message)
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. signSaferDigest generates one for you.
Arguments
| :: (HashAlgorithmASN1 hashAlg, MonadRandom m) | |
| => PrivateKey | private key |
| -> Digest hashAlg | digest of the message to sign |
| -> m (Either Error ByteString) |
signDigest blinded with the pair kept for this key, as signSafer is
to sign; see Crypto.PubKey.RSA.Blinded.
Arguments
| :: Maybe Blinder | optional blinder |
| -> PrivateKey | private key |
| -> ByteString | a DigestInfo, encoded |
| -> Either Error ByteString |
Sign something that is already a DigestInfo, the ASN.1 structure naming a hash algorithm and carrying a digest under it.
This is what does. It needs no
sign blinder NothingHashAlgorithmASN1 constraint, because nothing here hashes or encodes:
the caller has done both. carries the
constraint anyway, and since the type variable then appears nowhere else
the caller has to name an algorithm that is never used --
sign blinder Nothing -- to say
which one it is not using.sign blinder (Nothing :: Maybe SHA256)
Arguments
| :: MonadRandom m | |
| => PrivateKey | private key |
| -> ByteString | a DigestInfo, encoded |
| -> m (Either Error ByteString) |
signDigestInfo blinded with the pair kept for this key.
Private key operations with a kept blinding
Arguments
| :: (MonadRandom m, ByteArray ba) | |
| => BlindedKey | |
| -> ByteString | cipher text |
| -> m (Either Error ba, BlindedKey) |
decrypt with the blinding a BlindedKey keeps, and the key for the
next operation.
Arguments
| :: (HashAlgorithmASN1 hashAlg, MonadRandom m) | |
| => BlindedKey | |
| -> Digest hashAlg | digest of the message to sign |
| -> m (Either Error ByteString, BlindedKey) |
signDigest with the blinding a BlindedKey keeps, and the key for the
next operation.
signDigestInfoBlinded Source #
Arguments
| :: MonadRandom m | |
| => BlindedKey | |
| -> ByteString | a DigestInfo, encoded |
| -> m (Either Error ByteString, BlindedKey) |
signDigestInfo with the blinding a BlindedKey keeps, and the key for
the next operation.
Public key operations
encrypt :: (MonadRandom m, ByteArray ba) => PublicKey -> ba -> m (Either Error ByteString) Source #
encrypt a bytestring using the public key.
The message needs to be smaller than the key size - 11. The message should not be padded.
Arguments
| :: HashAlgorithmASN1 hashAlg | |
| => Maybe hashAlg | |
| -> PublicKey | |
| -> ByteString | Message |
| -> ByteString | Signature |
| -> Bool |
Deprecated: Use verifyDigest, or verifyDigestInfo when the message is already a DigestInfo
verify message with the signed message
Deprecated. Use verifyDigest, or verifyDigestInfo where this
would have been given Nothing.
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.
Arguments
| :: HashAlgorithmASN1 hashAlg | |
| => PublicKey | |
| -> Digest hashAlg | digest of the message |
| -> ByteString | signature |
| -> Bool |
Verify a signature over a digest. The checks are verifys.
Arguments
| :: PublicKey | |
| -> ByteString | a DigestInfo, encoded |
| -> ByteString | signature |
| -> Bool |
Hash ASN1 description
class HashAlgorithm hashAlg => HashAlgorithmASN1 hashAlg Source #
A specialized class for hash algorithm that can product a ASN1 wrapped description the algorithm plus the content of the digest.
Minimal complete definition
hashDigestASN1