crypton-1.0.0: Cryptography Primitives sink

License | BSD-style
Maintainer | Olivier Chéron <olivier.cheron@gmail.com>
Stability | experimental
Portability | unknown
Safe Haskell | None
Language | Haskell2010

Crypto.PubKey.EdDSA

Contents

- Curves with EdDSA implementation
- Smart constructors
- Methods

Description

EdDSA signature generation and verification, implemented in Haskell and parameterized with elliptic curve and hash algorithm. Only edwards25519 is supported at the moment.

The module provides "context" and "prehash" variants defined in RFC 8032.

This implementation is most useful when wanting to customize the hash algorithm. See module Crypto.PubKey.Ed25519 for faster Ed25519 with SHA-512.

Synopsis

- data SecretKey curve
- data PublicKey curve hash
- data Signature curve hash
- class (EllipticCurveBasepointArith curve, KnownNat (CurveDigestSize curve)) => EllipticCurveEdDSA curve where
  - type CurveDigestSize curve :: Nat
- publicKeySize :: EllipticCurveEdDSA curve => proxy curve -> Int
- secretKeySize :: EllipticCurveEdDSA curve => proxy curve -> Int
- signatureSize :: forall proxy curve. EllipticCurveEdDSA curve => proxy curve -> Int
- signature :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ba) => proxy curve -> hash -> ba -> CryptoFailable (Signature curve hash)
- publicKey :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ba) => proxy curve -> hash -> ba -> CryptoFailable (PublicKey curve hash)
- secretKey :: (EllipticCurveEdDSA curve, ByteArrayAccess ba) => proxy curve -> ba -> CryptoFailable (SecretKey curve)
- toPublic :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve) => proxy curve -> hash -> SecretKey curve -> PublicKey curve hash
- sign :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess msg) => proxy curve -> SecretKey curve -> PublicKey curve hash -> msg -> Signature curve hash
- signCtx :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx, ByteArrayAccess msg) => proxy curve -> ctx -> SecretKey curve -> PublicKey curve hash -> msg -> Signature curve hash
- signPh :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx) => proxy curve -> ctx -> SecretKey curve -> PublicKey curve hash -> Digest prehash -> Signature curve hash
- verify :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess msg) => proxy curve -> PublicKey curve hash -> msg -> Signature curve hash -> Bool
- verifyCtx :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx, ByteArrayAccess msg) => proxy curve -> ctx -> PublicKey curve hash -> msg -> Signature curve hash -> Bool
- verifyPh :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx) => proxy curve -> ctx -> PublicKey curve hash -> Digest prehash -> Signature curve hash -> Bool
- generateSecretKey :: (EllipticCurveEdDSA curve, MonadRandom m) => proxy curve -> m (SecretKey curve)

# Documentation

data SecretKey curve #

An EdDSA Secret key

#### Instances

Instances details

Show (SecretKey curve) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods showsPrec :: Int -> SecretKey curve -> ShowS # show :: SecretKey curve -> String # showList :: [SecretKey curve] -> ShowS #
NFData (SecretKey curve) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods rnf :: SecretKey curve -> () #
Eq (SecretKey curve) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods (==) :: SecretKey curve -> SecretKey curve -> Bool # (/=) :: SecretKey curve -> SecretKey curve -> Bool #
ByteArrayAccess (SecretKey curve) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods length :: SecretKey curve -> Int # withByteArray :: SecretKey curve -> (Ptr p -> IO a) -> IO a # copyByteArrayToPtr :: SecretKey curve -> Ptr p -> IO () #

data PublicKey curve hash #

An EdDSA public key

#### Instances

Instances details

Show (PublicKey curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods showsPrec :: Int -> PublicKey curve hash -> ShowS # show :: PublicKey curve hash -> String # showList :: [PublicKey curve hash] -> ShowS #
NFData (PublicKey curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods rnf :: PublicKey curve hash -> () #
Eq (PublicKey curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods (==) :: PublicKey curve hash -> PublicKey curve hash -> Bool # (/=) :: PublicKey curve hash -> PublicKey curve hash -> Bool #
ByteArrayAccess (PublicKey curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods length :: PublicKey curve hash -> Int # withByteArray :: PublicKey curve hash -> (Ptr p -> IO a) -> IO a # copyByteArrayToPtr :: PublicKey curve hash -> Ptr p -> IO () #

data Signature curve hash #

An EdDSA signature

#### Instances

Instances details

Show (Signature curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods showsPrec :: Int -> Signature curve hash -> ShowS # show :: Signature curve hash -> String # showList :: [Signature curve hash] -> ShowS #
NFData (Signature curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods rnf :: Signature curve hash -> () #
Eq (Signature curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods (==) :: Signature curve hash -> Signature curve hash -> Bool # (/=) :: Signature curve hash -> Signature curve hash -> Bool #
ByteArrayAccess (Signature curve hash) # |
Instance details Defined in Crypto.PubKey.EdDSA Methods length :: Signature curve hash -> Int # withByteArray :: Signature curve hash -> (Ptr p -> IO a) -> IO a # copyByteArrayToPtr :: Signature curve hash -> Ptr p -> IO () #

# Curves with EdDSA implementation

class (EllipticCurveBasepointArith curve, KnownNat (CurveDigestSize curve)) => EllipticCurveEdDSA curve #

Elliptic curves with an implementation of EdDSA

Minimal complete definition

secretKeySize, hashWithDom, pointPublic, publicPoint, encodeScalarLE, decodeScalarLE, scheduleSecret

Associated Types

type CurveDigestSize curve :: Nat #

Size of the digest for this curve (in bytes)

#### Instances

Instances details

EllipticCurveEdDSA Curve_Edwards25519 # |
Instance details Defined in Crypto.PubKey.EdDSA Associated Types
type CurveDigestSize Curve_Edwards25519 |
Instance details Defined in Crypto.PubKey.EdDSA type CurveDigestSize Curve_Edwards25519 = 64
Methods secretKeySize :: proxy Curve_Edwards25519 -> Int # hashWithDom :: (HashAlgorithm hash, ByteArrayAccess ctx, ByteArrayAccess msg) => proxy Curve_Edwards25519 -> hash -> Bool -> ctx -> Builder -> msg -> Bytes pointPublic :: proxy Curve_Edwards25519 -> Point Curve_Edwards25519 -> PublicKey Curve_Edwards25519 hash publicPoint :: proxy Curve_Edwards25519 -> PublicKey Curve_Edwards25519 hash -> CryptoFailable (Point Curve_Edwards25519) encodeScalarLE :: ByteArray bs => proxy Curve_Edwards25519 -> Scalar Curve_Edwards25519 -> bs decodeScalarLE :: ByteArrayAccess bs => proxy Curve_Edwards25519 -> bs -> CryptoFailable (Scalar Curve_Edwards25519) scheduleSecret :: (HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize Curve_Edwards25519) => proxy Curve_Edwards25519 -> hash -> SecretKey Curve_Edwards25519 -> (Scalar Curve_Edwards25519, View Bytes)

publicKeySize :: EllipticCurveEdDSA curve => proxy curve -> Int #

Size of public keys for this curve (in bytes)

secretKeySize :: EllipticCurveEdDSA curve => proxy curve -> Int #

Size of secret keys for this curve (in bytes)

signatureSize :: forall proxy curve. EllipticCurveEdDSA curve => proxy curve -> Int #

Size of signatures for this curve (in bytes)

# Smart constructors

signature :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ba) => proxy curve -> hash -> ba -> CryptoFailable (Signature curve hash) #

Try to build a signature from a bytearray

publicKey :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ba) => proxy curve -> hash -> ba -> CryptoFailable (PublicKey curve hash) #

Try to build a public key from a bytearray

secretKey :: (EllipticCurveEdDSA curve, ByteArrayAccess ba) => proxy curve -> ba -> CryptoFailable (SecretKey curve) #

Try to build a secret key from a bytearray

# Methods

toPublic :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve) => proxy curve -> hash -> SecretKey curve -> PublicKey curve hash #

Create a public key from a secret key

sign :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess msg) => proxy curve -> SecretKey curve -> PublicKey curve hash -> msg -> Signature curve hash #

Sign a message using the key pair

signCtx :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx, ByteArrayAccess msg) => proxy curve -> ctx -> SecretKey curve -> PublicKey curve hash -> msg -> Signature curve hash #

Sign a message using the key pair under context `ctx`

signPh :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx) => proxy curve -> ctx -> SecretKey curve -> PublicKey curve hash -> Digest prehash -> Signature curve hash #

Sign a prehashed message using the key pair under context `ctx`

verify :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess msg) => proxy curve -> PublicKey curve hash -> msg -> Signature curve hash -> Bool #

Verify a message

verifyCtx :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx, ByteArrayAccess msg) => proxy curve -> ctx -> PublicKey curve hash -> msg -> Signature curve hash -> Bool #

Verify a message under context `ctx`

verifyPh :: (EllipticCurveEdDSA curve, HashAlgorithm hash, HashDigestSize hash ~ CurveDigestSize curve, ByteArrayAccess ctx) => proxy curve -> ctx -> PublicKey curve hash -> Digest prehash -> Signature curve hash -> Bool #

Verify a prehashed message under context `ctx`

generateSecretKey :: (EllipticCurveEdDSA curve, MonadRandom m) => proxy curve -> m (SecretKey curve) #

Generate a secret key