cryptonite-0.23: Cryptography Primitives sink

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | unknown
Safe Haskell | None
Language | Haskell2010

Crypto.ECC

Description

Elliptic Curve Cryptography

Synopsis

- data Curve_P256R1 = Curve_P256R1
- data Curve_P384R1 = Curve_P384R1
- data Curve_P521R1 = Curve_P521R1
- data Curve_X25519 = Curve_X25519
- data Curve_X448 = Curve_X448
- class EllipticCurve curve where
  - type Point curve :: *
  - type Scalar curve :: *
- class EllipticCurve curve => EllipticCurveDH curve where
- class EllipticCurve curve => EllipticCurveArith curve where
- data KeyPair curve = KeyPair {
  - keypairGetPublic :: !(Point curve)
  - keypairGetPrivate :: !(Scalar curve)
  }
- newtype SharedSecret = SharedSecret ScrubbedBytes

# Documentation

data Curve_P256R1 Source #

P256 Curve

also known as P256

Constructors

Curve_P256R1 |

Instances

EllipticCurveArith Curve_P256R1 Source # |
Methods pointAdd :: proxy Curve_P256R1 -> Point Curve_P256R1 -> Point Curve_P256R1 -> Point Curve_P256R1 Source # pointSmul :: proxy Curve_P256R1 -> Scalar Curve_P256R1 -> Point Curve_P256R1 -> Point Curve_P256R1 Source #
EllipticCurveDH Curve_P256R1 Source # |
Methods ecdh :: proxy Curve_P256R1 -> Scalar Curve_P256R1 -> Point Curve_P256R1 -> SharedSecret Source #
EllipticCurve Curve_P256R1 Source # |

Associated Types

type Point Curve_P256R1 :: * Source #

type Scalar Curve_P256R1 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_P256R1 -> randomly (Scalar Curve_P256R1) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_P256R1 -> randomly (KeyPair Curve_P256R1) Source #

curveSizeBits :: proxy Curve_P256R1 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_P256R1 -> Point Curve_P256R1 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_P256R1 -> bs -> CryptoFailable (Point Curve_P256R1) Source #

type Point Curve_P256R1 Source # |
type Point Curve_P256R1 = Point
type Scalar Curve_P256R1 Source # |
type Scalar Curve_P256R1 = Scalar

data Curve_P384R1 Source #

Constructors

Curve_P384R1 |

Instances

EllipticCurveArith Curve_P384R1 Source # |
Methods pointAdd :: proxy Curve_P384R1 -> Point Curve_P384R1 -> Point Curve_P384R1 -> Point Curve_P384R1 Source # pointSmul :: proxy Curve_P384R1 -> Scalar Curve_P384R1 -> Point Curve_P384R1 -> Point Curve_P384R1 Source #
EllipticCurveDH Curve_P384R1 Source # |
Methods ecdh :: proxy Curve_P384R1 -> Scalar Curve_P384R1 -> Point Curve_P384R1 -> SharedSecret Source #
EllipticCurve Curve_P384R1 Source # |

Associated Types

type Point Curve_P384R1 :: * Source #

type Scalar Curve_P384R1 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_P384R1 -> randomly (Scalar Curve_P384R1) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_P384R1 -> randomly (KeyPair Curve_P384R1) Source #

curveSizeBits :: proxy Curve_P384R1 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_P384R1 -> Point Curve_P384R1 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_P384R1 -> bs -> CryptoFailable (Point Curve_P384R1) Source #

type Point Curve_P384R1 Source # |
type Point Curve_P384R1
type Scalar Curve_P384R1 Source # |
type Scalar Curve_P384R1

data Curve_P521R1 Source #

Constructors

Curve_P521R1 |

Instances

EllipticCurveArith Curve_P521R1 Source # |
Methods pointAdd :: proxy Curve_P521R1 -> Point Curve_P521R1 -> Point Curve_P521R1 -> Point Curve_P521R1 Source # pointSmul :: proxy Curve_P521R1 -> Scalar Curve_P521R1 -> Point Curve_P521R1 -> Point Curve_P521R1 Source #
EllipticCurveDH Curve_P521R1 Source # |
Methods ecdh :: proxy Curve_P521R1 -> Scalar Curve_P521R1 -> Point Curve_P521R1 -> SharedSecret Source #
EllipticCurve Curve_P521R1 Source # |

Associated Types

type Point Curve_P521R1 :: * Source #

type Scalar Curve_P521R1 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_P521R1 -> randomly (Scalar Curve_P521R1) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_P521R1 -> randomly (KeyPair Curve_P521R1) Source #

curveSizeBits :: proxy Curve_P521R1 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_P521R1 -> Point Curve_P521R1 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_P521R1 -> bs -> CryptoFailable (Point Curve_P521R1) Source #

type Point Curve_P521R1 Source # |
type Point Curve_P521R1
type Scalar Curve_P521R1 Source # |
type Scalar Curve_P521R1

data Curve_X25519 Source #

Constructors

Curve_X25519 |

Instances

EllipticCurveDH Curve_X25519 Source # |
Methods ecdh :: proxy Curve_X25519 -> Scalar Curve_X25519 -> Point Curve_X25519 -> SharedSecret Source #
EllipticCurve Curve_X25519 Source # |

Associated Types

type Point Curve_X25519 :: * Source #

type Scalar Curve_X25519 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_X25519 -> randomly (Scalar Curve_X25519) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_X25519 -> randomly (KeyPair Curve_X25519) Source #

curveSizeBits :: proxy Curve_X25519 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_X25519 -> Point Curve_X25519 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_X25519 -> bs -> CryptoFailable (Point Curve_X25519) Source #

type Point Curve_X25519 Source # |
type Point Curve_X25519 = PublicKey
type Scalar Curve_X25519 Source # |
type Scalar Curve_X25519 = SecretKey

data Curve_X448 Source #

Constructors

Curve_X448 |

Instances

EllipticCurveDH Curve_X448 Source # |
Methods ecdh :: proxy Curve_X448 -> Scalar Curve_X448 -> Point Curve_X448 -> SharedSecret Source #
EllipticCurve Curve_X448 Source # |

Associated Types

type Point Curve_X448 :: * Source #

type Scalar Curve_X448 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_X448 -> randomly (Scalar Curve_X448) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_X448 -> randomly (KeyPair Curve_X448) Source #

curveSizeBits :: proxy Curve_X448 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_X448 -> Point Curve_X448 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_X448 -> bs -> CryptoFailable (Point Curve_X448) Source #

type Point Curve_X448 Source # |
type Point Curve_X448 = PublicKey
type Scalar Curve_X448 Source # |
type Scalar Curve_X448 = SecretKey

class EllipticCurve curve where Source #

Minimal complete definition

curveGenerateScalar, curveGenerateKeyPair, curveSizeBits, encodePoint, decodePoint

Associated Types

type Point curve :: * Source #

Point on an Elliptic Curve

type Scalar curve :: * Source #

Scalar in the Elliptic Curve domain

Methods

curveGenerateScalar :: MonadRandom randomly => proxy curve -> randomly (Scalar curve) Source #

Generate a new random scalar on the curve. The scalar will represent a number between 1 and the order of the curve non included

curveGenerateKeyPair :: MonadRandom randomly => proxy curve -> randomly (KeyPair curve) Source #

Generate a new random keypair

curveSizeBits :: proxy curve -> Int Source #

Get the curve size in bits

encodePoint :: ByteArray bs => proxy curve -> Point curve -> bs Source #

Encode a elliptic curve point into binary form

decodePoint :: ByteArray bs => proxy curve -> bs -> CryptoFailable (Point curve) Source #

Try to decode the binary form of an elliptic curve point

Instances

EllipticCurve Curve_X448 Source # |

Associated Types

type Point Curve_X448 :: * Source #

type Scalar Curve_X448 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_X448 -> randomly (Scalar Curve_X448) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_X448 -> randomly (KeyPair Curve_X448) Source #

curveSizeBits :: proxy Curve_X448 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_X448 -> Point Curve_X448 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_X448 -> bs -> CryptoFailable (Point Curve_X448) Source #

EllipticCurve Curve_X25519 Source # |

Associated Types

type Point Curve_X25519 :: * Source #

type Scalar Curve_X25519 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_X25519 -> randomly (Scalar Curve_X25519) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_X25519 -> randomly (KeyPair Curve_X25519) Source #

curveSizeBits :: proxy Curve_X25519 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_X25519 -> Point Curve_X25519 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_X25519 -> bs -> CryptoFailable (Point Curve_X25519) Source #

EllipticCurve Curve_P521R1 Source # |

Associated Types

type Point Curve_P521R1 :: * Source #

type Scalar Curve_P521R1 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_P521R1 -> randomly (Scalar Curve_P521R1) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_P521R1 -> randomly (KeyPair Curve_P521R1) Source #

curveSizeBits :: proxy Curve_P521R1 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_P521R1 -> Point Curve_P521R1 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_P521R1 -> bs -> CryptoFailable (Point Curve_P521R1) Source #

EllipticCurve Curve_P384R1 Source # |

Associated Types

type Point Curve_P384R1 :: * Source #

type Scalar Curve_P384R1 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_P384R1 -> randomly (Scalar Curve_P384R1) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_P384R1 -> randomly (KeyPair Curve_P384R1) Source #

curveSizeBits :: proxy Curve_P384R1 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_P384R1 -> Point Curve_P384R1 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_P384R1 -> bs -> CryptoFailable (Point Curve_P384R1) Source #

EllipticCurve Curve_P256R1 Source # |

Associated Types

type Point Curve_P256R1 :: * Source #

type Scalar Curve_P256R1 :: * Source #

Methods

curveGenerateScalar :: MonadRandom randomly => proxy Curve_P256R1 -> randomly (Scalar Curve_P256R1) Source #

curveGenerateKeyPair :: MonadRandom randomly => proxy Curve_P256R1 -> randomly (KeyPair Curve_P256R1) Source #

curveSizeBits :: proxy Curve_P256R1 -> Int Source #

encodePoint :: ByteArray bs => proxy Curve_P256R1 -> Point Curve_P256R1 -> bs Source #

decodePoint :: ByteArray bs => proxy Curve_P256R1 -> bs -> CryptoFailable (Point Curve_P256R1) Source #

class EllipticCurve curve => EllipticCurveDH curve where Source #

Minimal complete definition

ecdh

Methods

ecdh :: proxy curve -> Scalar curve -> Point curve -> SharedSecret Source #

Generate a Diffie hellman secret value.

This is generally just the .x coordinate of the resulting point, that is not hashed.

use `pointSmul` to keep the result in Point format.

Instances

EllipticCurveDH Curve_X448 Source # |
Methods ecdh :: proxy Curve_X448 -> Scalar Curve_X448 -> Point Curve_X448 -> SharedSecret Source #
EllipticCurveDH Curve_X25519 Source # |
Methods ecdh :: proxy Curve_X25519 -> Scalar Curve_X25519 -> Point Curve_X25519 -> SharedSecret Source #
EllipticCurveDH Curve_P521R1 Source # |
Methods ecdh :: proxy Curve_P521R1 -> Scalar Curve_P521R1 -> Point Curve_P521R1 -> SharedSecret Source #
EllipticCurveDH Curve_P384R1 Source # |
Methods ecdh :: proxy Curve_P384R1 -> Scalar Curve_P384R1 -> Point Curve_P384R1 -> SharedSecret Source #
EllipticCurveDH Curve_P256R1 Source # |
Methods ecdh :: proxy Curve_P256R1 -> Scalar Curve_P256R1 -> Point Curve_P256R1 -> SharedSecret Source #

class EllipticCurve curve => EllipticCurveArith curve where Source #

Minimal complete definition

pointAdd, pointSmul

Methods

pointAdd :: proxy curve -> Point curve -> Point curve -> Point curve Source #

Add points on a curve

pointSmul :: proxy curve -> Scalar curve -> Point curve -> Point curve Source #

Scalar Multiplication on a curve

Instances

EllipticCurveArith Curve_P521R1 Source # |
Methods pointAdd :: proxy Curve_P521R1 -> Point Curve_P521R1 -> Point Curve_P521R1 -> Point Curve_P521R1 Source # pointSmul :: proxy Curve_P521R1 -> Scalar Curve_P521R1 -> Point Curve_P521R1 -> Point Curve_P521R1 Source #
EllipticCurveArith Curve_P384R1 Source # |
Methods pointAdd :: proxy Curve_P384R1 -> Point Curve_P384R1 -> Point Curve_P384R1 -> Point Curve_P384R1 Source # pointSmul :: proxy Curve_P384R1 -> Scalar Curve_P384R1 -> Point Curve_P384R1 -> Point Curve_P384R1 Source #
EllipticCurveArith Curve_P256R1 Source # |
Methods pointAdd :: proxy Curve_P256R1 -> Point Curve_P256R1 -> Point Curve_P256R1 -> Point Curve_P256R1 Source # pointSmul :: proxy Curve_P256R1 -> Scalar Curve_P256R1 -> Point Curve_P256R1 -> Point Curve_P256R1 Source #

data KeyPair curve Source #

An elliptic curve key pair composed of the private part (a scalar), and the associated point.

Constructors

KeyPair |

Fields

- keypairGetPublic :: !(Point curve)
- keypairGetPrivate :: !(Scalar curve)

newtype SharedSecret Source #

Constructors

SharedSecret ScrubbedBytes |

Instances

Eq SharedSecret Source # |
Methods (==) :: SharedSecret -> SharedSecret -> Bool # (/=) :: SharedSecret -> SharedSecret -> Bool #
ByteArrayAccess SharedSecret Source # |
Methods length :: SharedSecret -> Int # withByteArray :: SharedSecret -> (Ptr p -> IO a) -> IO a #