HsOpenSSL-0.11.7.9: Partial OpenSSL binding for Haskell

Safe Haskell | None
Language | Haskell2010

OpenSSL.RSA

Contents

- Type
- Generating keypair
- Exploring keypair

Description

An interface to RSA public key generator.

Synopsis

- class RSAKey k where
  - rsaSize :: k -> Int
  - rsaN :: k -> Integer
  - rsaE :: k -> Integer
  - withRSAPtr :: k -> (Ptr RSA -> IO a) -> IO a
  - peekRSAPtr :: Ptr RSA -> IO (Maybe k)
  - absorbRSAPtr :: Ptr RSA -> IO (Maybe k)
- data RSAPubKey
- data RSAKeyPair
- type RSAGenKeyCallback = Int -> Int -> IO ()
- generateRSAKey :: Int -> Int -> Maybe RSAGenKeyCallback -> IO RSAKeyPair
- generateRSAKey' :: Int -> Int -> IO RSAKeyPair
- rsaD :: RSAKeyPair -> Integer
- rsaP :: RSAKeyPair -> Integer
- rsaQ :: RSAKeyPair -> Integer
- rsaDMP1 :: RSAKeyPair -> Maybe Integer
- rsaDMQ1 :: RSAKeyPair -> Maybe Integer
- rsaIQMP :: RSAKeyPair -> Maybe Integer
- rsaCopyPublic :: RSAKey key => key -> IO RSAPubKey

# Type

class RSAKey k where Source #

``RSAKey` a` is either `RSAPubKey` or `RSAKeyPair`.

Minimal complete definition

withRSAPtr, peekRSAPtr, absorbRSAPtr

Methods

rsaSize :: k -> Int Source #

``rsaSize` key` returns the length of key.

rsaN :: k -> Integer Source #

``rsaN` key` returns the public modulus of the key.

rsaE :: k -> Integer Source #

``rsaE` key` returns the public exponent of the key.

withRSAPtr :: k -> (Ptr RSA -> IO a) -> IO a Source #

peekRSAPtr :: Ptr RSA -> IO (Maybe k) Source #

absorbRSAPtr :: Ptr RSA -> IO (Maybe k) Source #

#### Instances

Instances details

RSAKey RSAKeyPair Source # |
Instance details Defined in OpenSSL.RSA Methods rsaSize :: RSAKeyPair -> Int Source # rsaN :: RSAKeyPair -> Integer Source # rsaE :: RSAKeyPair -> Integer Source # withRSAPtr :: RSAKeyPair -> (Ptr RSA -> IO a) -> IO a Source # peekRSAPtr :: Ptr RSA -> IO (Maybe RSAKeyPair) Source # absorbRSAPtr :: Ptr RSA -> IO (Maybe RSAKeyPair) Source #
RSAKey RSAPubKey Source # |
Instance details Defined in OpenSSL.RSA Methods rsaSize :: RSAPubKey -> Int Source # rsaN :: RSAPubKey -> Integer Source # rsaE :: RSAPubKey -> Integer Source # withRSAPtr :: RSAPubKey -> (Ptr RSA -> IO a) -> IO a Source # peekRSAPtr :: Ptr RSA -> IO (Maybe RSAPubKey) Source # absorbRSAPtr :: Ptr RSA -> IO (Maybe RSAPubKey) Source #

data RSAPubKey Source #

``RSAPubKey`` is an opaque object that represents RSA public key.

#### Instances

Instances details

PKey RSAPubKey Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods toPKey :: RSAPubKey -> IO VaguePKey Source # fromPKey :: VaguePKey -> IO (Maybe RSAPubKey) Source # pkeySize :: RSAPubKey -> Int Source # pkeyDefaultMD :: RSAPubKey -> IO Digest Source #
PublicKey RSAPubKey Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods fromPublicKey :: RSAPubKey -> SomePublicKey Source # toPublicKey :: SomePublicKey -> Maybe RSAPubKey Source #
RSAKey RSAPubKey Source # |
Instance details Defined in OpenSSL.RSA Methods rsaSize :: RSAPubKey -> Int Source # rsaN :: RSAPubKey -> Integer Source # rsaE :: RSAPubKey -> Integer Source # withRSAPtr :: RSAPubKey -> (Ptr RSA -> IO a) -> IO a Source # peekRSAPtr :: Ptr RSA -> IO (Maybe RSAPubKey) Source # absorbRSAPtr :: Ptr RSA -> IO (Maybe RSAPubKey) Source #
Show RSAPubKey Source # |
Instance details Defined in OpenSSL.RSA Methods showsPrec :: Int -> RSAPubKey -> ShowS Source # show :: RSAPubKey -> String Source # showList :: [RSAPubKey] -> ShowS Source #
Eq RSAPubKey Source # |
Instance details Defined in OpenSSL.RSA Methods (==) :: RSAPubKey -> RSAPubKey -> Bool Source # (/=) :: RSAPubKey -> RSAPubKey -> Bool Source #
Ord RSAPubKey Source # |
Instance details Defined in OpenSSL.RSA Methods compare :: RSAPubKey -> RSAPubKey -> Ordering Source # (<) :: RSAPubKey -> RSAPubKey -> Bool Source # (<=) :: RSAPubKey -> RSAPubKey -> Bool Source # (>) :: RSAPubKey -> RSAPubKey -> Bool Source # (>=) :: RSAPubKey -> RSAPubKey -> Bool Source # max :: RSAPubKey -> RSAPubKey -> RSAPubKey Source # min :: RSAPubKey -> RSAPubKey -> RSAPubKey Source #

data RSAKeyPair Source #

``RSAKeyPair`` is an opaque object that represents RSA keypair.

#### Instances

Instances details

PKey RSAKeyPair Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods toPKey :: RSAKeyPair -> IO VaguePKey Source # fromPKey :: VaguePKey -> IO (Maybe RSAKeyPair) Source # pkeySize :: RSAKeyPair -> Int Source # pkeyDefaultMD :: RSAKeyPair -> IO Digest Source #
KeyPair RSAKeyPair Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods fromKeyPair :: RSAKeyPair -> SomeKeyPair Source # toKeyPair :: SomeKeyPair -> Maybe RSAKeyPair Source #
PublicKey RSAKeyPair Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods fromPublicKey :: RSAKeyPair -> SomePublicKey Source # toPublicKey :: SomePublicKey -> Maybe RSAKeyPair Source #
RSAKey RSAKeyPair Source # |
Instance details Defined in OpenSSL.RSA Methods rsaSize :: RSAKeyPair -> Int Source # rsaN :: RSAKeyPair -> Integer Source # rsaE :: RSAKeyPair -> Integer Source # withRSAPtr :: RSAKeyPair -> (Ptr RSA -> IO a) -> IO a Source # peekRSAPtr :: Ptr RSA -> IO (Maybe RSAKeyPair) Source # absorbRSAPtr :: Ptr RSA -> IO (Maybe RSAKeyPair) Source #
Show RSAKeyPair Source # |
Instance details Defined in OpenSSL.RSA Methods showsPrec :: Int -> RSAKeyPair -> ShowS Source # show :: RSAKeyPair -> String Source # showList :: [RSAKeyPair] -> ShowS Source #
Eq RSAKeyPair Source # |
Instance details Defined in OpenSSL.RSA Methods (==) :: RSAKeyPair -> RSAKeyPair -> Bool Source # (/=) :: RSAKeyPair -> RSAKeyPair -> Bool Source #
Ord RSAKeyPair Source # |

Instance details

Defined in OpenSSL.RSA

Methods

compare :: RSAKeyPair -> RSAKeyPair -> Ordering Source #

(<) :: RSAKeyPair -> RSAKeyPair -> Bool Source #

(<=) :: RSAKeyPair -> RSAKeyPair -> Bool Source #

(>) :: RSAKeyPair -> RSAKeyPair -> Bool Source #

(>=) :: RSAKeyPair -> RSAKeyPair -> Bool Source #

max :: RSAKeyPair -> RSAKeyPair -> RSAKeyPair Source #

min :: RSAKeyPair -> RSAKeyPair -> RSAKeyPair Source #

# Generating keypair

type RSAGenKeyCallback = Int -> Int -> IO () Source #

``RSAGenKeyCallback`` represents a callback function to get informed the progress of RSA key generation.

- `callback 0 i` is called after generating the `i`-th potential prime number.
- While the number is being tested for primality, `callback 1 j` is called after the `j`-th iteration (j = 0, 1, ...).
- When the `n`-th randomly generated prime is rejected as not suitable for the key, `callback 2 n` is called.
- When a random `p` has been found with `p`-1 relatively prime to `e`, it is called as `callback 3 0`.
- The process is then repeated for prime `q` with `callback 3 1`.

generateRSAKey Source #

Arguments

:: Int | The number of bits of the public modulus (i.e. key size). Key sizes with `n < 1024` should be considered insecure.
-> Int | The public exponent. It is an odd number, typically 3, 17 or 65537.
-> Maybe RSAGenKeyCallback | A callback function.
-> IO RSAKeyPair | The generated keypair.

``generateRSAKey`` generates an RSA keypair.

generateRSAKey' Source #

Arguments

:: Int | The number of bits of the public modulus (i.e. key size). Key sizes with `n < 1024` should be considered insecure.
-> Int | The public exponent. It is an odd number, typically 3, 17 or 65537.
-> IO RSAKeyPair | The generated keypair.

A simplified alternative to `generateRSAKey`

# Exploring keypair

rsaD :: RSAKeyPair -> Integer Source #

``rsaD` privKey` returns the private exponent of the key.

rsaP :: RSAKeyPair -> Integer Source #

``rsaP` privkey` returns the secret prime factor `p` of the key.

rsaQ :: RSAKeyPair -> Integer Source #

``rsaQ` privkey` returns the secret prime factor `q` of the key.

rsaDMP1 :: RSAKeyPair -> Maybe Integer Source #

``rsaDMP1` privkey` returns `d mod (p-1)` of the key.

rsaDMQ1 :: RSAKeyPair -> Maybe Integer Source #

``rsaDMQ1` privkey` returns `d mod (q-1)` of the key.

rsaIQMP :: RSAKeyPair -> Maybe Integer Source #

``rsaIQMP` privkey` returns `q^-1 mod p` of the key.

rsaCopyPublic :: RSAKey key => key -> IO RSAPubKey Source #

Make a copy of the public parameters of the given key.