HsOpenSSL-0.11.7.9: Partial OpenSSL binding for Haskell

Safe Haskell | None
Language | Haskell2010

OpenSSL.DSA

Contents

- Type
- Key and parameter generation
- Signing and verification
- Extracting fields of DSA objects

Description

The Digital Signature Algorithm (FIPS 186-2). See http://www.openssl.org/docs/crypto/dsa.html

Synopsis

- class DSAKey k where
  - dsaSize :: k -> Int
  - dsaP :: k -> Integer
  - dsaQ :: k -> Integer
  - dsaG :: k -> Integer
  - dsaPublic :: k -> Integer
  - withDSAPtr :: k -> (Ptr DSA -> IO a) -> IO a
  - peekDSAPtr :: Ptr DSA -> IO (Maybe k)
  - absorbDSAPtr :: Ptr DSA -> IO (Maybe k)
- data DSAPubKey
- data DSAKeyPair
- generateDSAParameters :: Int -> Maybe ByteString -> IO (Int, Int, Integer, Integer, Integer)
- generateDSAKey :: Integer -> Integer -> Integer -> IO DSAKeyPair
- generateDSAParametersAndKey :: Int -> Maybe ByteString -> IO DSAKeyPair
- signDigestedDataWithDSA :: DSAKeyPair -> ByteString -> IO (Integer, Integer)
- verifyDigestedDataWithDSA :: DSAKey k => k -> ByteString -> (Integer, Integer) -> IO Bool
- dsaPrivate :: DSAKeyPair -> Integer
- dsaPubKeyToTuple :: DSAKeyPair -> (Integer, Integer, Integer, Integer)
- dsaKeyPairToTuple :: DSAKeyPair -> (Integer, Integer, Integer, Integer, Integer)
- tupleToDSAPubKey :: (Integer, Integer, Integer, Integer) -> DSAPubKey
- tupleToDSAKeyPair :: (Integer, Integer, Integer, Integer, Integer) -> DSAKeyPair

# Type

class DSAKey k where Source #

``DSAKey` a` is either `DSAPubKey` or `DSAKeyPair`.

Minimal complete definition

withDSAPtr, peekDSAPtr, absorbDSAPtr

Methods

dsaSize :: k -> Int Source #

Return the length of key.

dsaP :: k -> Integer Source #

Return the public prime number of the key.

dsaQ :: k -> Integer Source #

Return the public 160-bit subprime, `q | p - 1` of the key.

dsaG :: k -> Integer Source #

Return the public generator of subgroup of the key.

dsaPublic :: k -> Integer Source #

Return the public key `y = g^x`.

withDSAPtr :: k -> (Ptr DSA -> IO a) -> IO a Source #

peekDSAPtr :: Ptr DSA -> IO (Maybe k) Source #

absorbDSAPtr :: Ptr DSA -> IO (Maybe k) Source #

#### Instances

Instances details

DSAKey DSAKeyPair Source # |

Instance details

Defined in OpenSSL.DSA

Methods

dsaSize :: DSAKeyPair -> Int Source #

dsaP :: DSAKeyPair -> Integer Source #

dsaQ :: DSAKeyPair -> Integer Source #

dsaG :: DSAKeyPair -> Integer Source #

dsaPublic :: DSAKeyPair -> Integer Source #

withDSAPtr :: DSAKeyPair -> (Ptr DSA -> IO a) -> IO a Source #

peekDSAPtr :: Ptr DSA -> IO (Maybe DSAKeyPair) Source #

absorbDSAPtr :: Ptr DSA -> IO (Maybe DSAKeyPair) Source #

DSAKey DSAPubKey Source # |

Instance details

Defined in OpenSSL.DSA

Methods

dsaSize :: DSAPubKey -> Int Source #

dsaP :: DSAPubKey -> Integer Source #

dsaQ :: DSAPubKey -> Integer Source #

dsaG :: DSAPubKey -> Integer Source #

dsaPublic :: DSAPubKey -> Integer Source #

withDSAPtr :: DSAPubKey -> (Ptr DSA -> IO a) -> IO a Source #

peekDSAPtr :: Ptr DSA -> IO (Maybe DSAPubKey) Source #

absorbDSAPtr :: Ptr DSA -> IO (Maybe DSAPubKey) Source #

data DSAPubKey Source #

The type of a DSA public key, includes parameters p, q, g and public.

#### Instances

Instances details

DSAKey DSAPubKey Source # |

Instance details

Defined in OpenSSL.DSA

Methods

dsaSize :: DSAPubKey -> Int Source #

dsaP :: DSAPubKey -> Integer Source #

dsaQ :: DSAPubKey -> Integer Source #

dsaG :: DSAPubKey -> Integer Source #

dsaPublic :: DSAPubKey -> Integer Source #

withDSAPtr :: DSAPubKey -> (Ptr DSA -> IO a) -> IO a Source #

peekDSAPtr :: Ptr DSA -> IO (Maybe DSAPubKey) Source #

absorbDSAPtr :: Ptr DSA -> IO (Maybe DSAPubKey) Source #

PKey DSAPubKey Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods toPKey :: DSAPubKey -> IO VaguePKey Source # fromPKey :: VaguePKey -> IO (Maybe DSAPubKey) Source # pkeySize :: DSAPubKey -> Int Source # pkeyDefaultMD :: DSAPubKey -> IO Digest Source #
PublicKey DSAPubKey Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods fromPublicKey :: DSAPubKey -> SomePublicKey Source # toPublicKey :: SomePublicKey -> Maybe DSAPubKey Source #
Show DSAPubKey Source # |
Instance details Defined in OpenSSL.DSA Methods showsPrec :: Int -> DSAPubKey -> ShowS Source # show :: DSAPubKey -> String Source # showList :: [DSAPubKey] -> ShowS Source #
Eq DSAPubKey Source # |
Instance details Defined in OpenSSL.DSA Methods (==) :: DSAPubKey -> DSAPubKey -> Bool Source # (/=) :: DSAPubKey -> DSAPubKey -> Bool Source #
Ord DSAPubKey Source # |
Instance details Defined in OpenSSL.DSA Methods compare :: DSAPubKey -> DSAPubKey -> Ordering Source # (<) :: DSAPubKey -> DSAPubKey -> Bool Source # (<=) :: DSAPubKey -> DSAPubKey -> Bool Source # (>) :: DSAPubKey -> DSAPubKey -> Bool Source # (>=) :: DSAPubKey -> DSAPubKey -> Bool Source # max :: DSAPubKey -> DSAPubKey -> DSAPubKey Source # min :: DSAPubKey -> DSAPubKey -> DSAPubKey Source #

data DSAKeyPair Source #

The type of a DSA keypair, includes parameters p, q, g, public and private.

#### Instances

Instances details

DSAKey DSAKeyPair Source # |

Instance details

Defined in OpenSSL.DSA

Methods

dsaSize :: DSAKeyPair -> Int Source #

dsaP :: DSAKeyPair -> Integer Source #

dsaQ :: DSAKeyPair -> Integer Source #

dsaG :: DSAKeyPair -> Integer Source #

dsaPublic :: DSAKeyPair -> Integer Source #

withDSAPtr :: DSAKeyPair -> (Ptr DSA -> IO a) -> IO a Source #

peekDSAPtr :: Ptr DSA -> IO (Maybe DSAKeyPair) Source #

absorbDSAPtr :: Ptr DSA -> IO (Maybe DSAKeyPair) Source #

PKey DSAKeyPair Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods toPKey :: DSAKeyPair -> IO VaguePKey Source # fromPKey :: VaguePKey -> IO (Maybe DSAKeyPair) Source # pkeySize :: DSAKeyPair -> Int Source # pkeyDefaultMD :: DSAKeyPair -> IO Digest Source #
KeyPair DSAKeyPair Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods fromKeyPair :: DSAKeyPair -> SomeKeyPair Source # toKeyPair :: SomeKeyPair -> Maybe DSAKeyPair Source #
PublicKey DSAKeyPair Source # |
Instance details Defined in OpenSSL.EVP.PKey Methods fromPublicKey :: DSAKeyPair -> SomePublicKey Source # toPublicKey :: SomePublicKey -> Maybe DSAKeyPair Source #
Show DSAKeyPair Source # |
Instance details Defined in OpenSSL.DSA Methods showsPrec :: Int -> DSAKeyPair -> ShowS Source # show :: DSAKeyPair -> String Source # showList :: [DSAKeyPair] -> ShowS Source #
Eq DSAKeyPair Source # |
Instance details Defined in OpenSSL.DSA Methods (==) :: DSAKeyPair -> DSAKeyPair -> Bool Source # (/=) :: DSAKeyPair -> DSAKeyPair -> Bool Source #
Ord DSAKeyPair Source # |

Instance details

Defined in OpenSSL.DSA

Methods

compare :: DSAKeyPair -> DSAKeyPair -> Ordering Source #

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

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

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

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

max :: DSAKeyPair -> DSAKeyPair -> DSAKeyPair Source #

min :: DSAKeyPair -> DSAKeyPair -> DSAKeyPair Source #

# Key and parameter generation

generateDSAParameters Source #

Arguments

:: Int | The number of bits in the generated prime: 512 <= x <= 1024
-> Maybe ByteString | optional seed, its length must be 20 bytes
-> IO (Int, Int, Integer, Integer, Integer) | (iteration count, generator count, p, q, g)

Generate DSA parameters (*not* a key, but required for a key). This is a compute intensive operation. See FIPS 186-2, app 2. This agrees with the test vectors given in FIP 186-2, app 5

generateDSAKey Source #

Arguments

:: Integer | p
-> Integer | q
-> Integer | g
-> IO DSAKeyPair |

Generate a new DSA keypair, given valid parameters

generateDSAParametersAndKey Source #

Arguments

:: Int | The number of bits in the generated prime: 512 <= x <= 1024
-> Maybe ByteString | optional seed, its length must be 20 bytes
-> IO DSAKeyPair |

A utility function to generate both the parameters and the key pair at the same time. Saves serialising and deserialising the parameters too

# Signing and verification

signDigestedDataWithDSA :: DSAKeyPair -> ByteString -> IO (Integer, Integer) Source #

Sign pre-digested data. The DSA specs call for SHA1 to be used so, if you use anything else, YMMV. Returns a pair of Integers which, together, are the signature

verifyDigestedDataWithDSA :: DSAKey k => k -> ByteString -> (Integer, Integer) -> IO Bool Source #

Verify pre-digested data given a signature.

# Extracting fields of DSA objects

dsaPrivate :: DSAKeyPair -> Integer Source #

Return the private key `x`.

dsaPubKeyToTuple :: DSAKeyPair -> (Integer, Integer, Integer, Integer) Source #

Convert a DSAPubKey object to a tuple of its members in the order p, q, g, and public.

dsaKeyPairToTuple :: DSAKeyPair -> (Integer, Integer, Integer, Integer, Integer) Source #

Convert a DSAKeyPair object to a tuple of its members in the order p, q, g, public and private.

tupleToDSAPubKey :: (Integer, Integer, Integer, Integer) -> DSAPubKey Source #

Convert a tuple of members (in the same format as from `dsaPubKeyToTuple`) into a DSAPubKey object

tupleToDSAKeyPair :: (Integer, Integer, Integer, Integer, Integer) -> DSAKeyPair Source #

Convert a tuple of members (in the same format as from `dsaPubKeyToTuple`) into a DSAPubKey object