cryptonite-0.24: 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 :: *
  - curveGenerateScalar :: MonadRandom randomly => proxy curve -> randomly (Scalar curve)
  - curveGenerateKeyPair :: MonadRandom randomly => proxy curve -> randomly (KeyPair curve)
  - curveSizeBits :: proxy curve -> Int
  - encodePoint :: ByteArray bs => proxy curve -> Point curve -> bs
  - decodePoint :: ByteArray bs => proxy curve -> bs -> CryptoFailable (Point curve)
- class EllipticCurve curve => EllipticCurveDH curve where
  - ecdhRaw :: proxy curve -> Scalar curve -> Point curve -> SharedSecret
  - ecdh :: proxy curve -> Scalar curve -> Point curve -> CryptoFailable SharedSecret
- class EllipticCurve curve => EllipticCurveArith curve where
  - pointAdd :: proxy curve -> Point curve -> Point curve -> Point curve
  - pointSmul :: proxy curve -> Scalar curve -> Point curve -> Point curve
- data KeyPair curve = KeyPair {
  - keypairGetPublic :: !(Point curve)
  - keypairGetPrivate :: !(Scalar curve)
  }
- newtype SharedSecret = SharedSecret ScrubbedBytes

# Documentation

data Curve_P256R1

P256 Curve

also known as P256

Constructors

Curve_P256R1 |

Instances

Data Curve_P256R1 |
Show Curve_P256R1 |
EllipticCurveArith Curve_P256R1 |
EllipticCurveDH Curve_P256R1 |
EllipticCurve Curve_P256R1 |
type Point Curve_P256R1 = Point |
type Scalar Curve_P256R1 = Scalar |

data Curve_P384R1

Constructors

Curve_P384R1 |

Instances

Data Curve_P384R1 |
Show Curve_P384R1 |
EllipticCurveArith Curve_P384R1 |
EllipticCurveDH Curve_P384R1 |
EllipticCurve Curve_P384R1 |
type Point Curve_P384R1 |
type Scalar Curve_P384R1 |

data Curve_P521R1

Constructors

Curve_P521R1 |

Instances

Data Curve_P521R1 |
Show Curve_P521R1 |
EllipticCurveArith Curve_P521R1 |
EllipticCurveDH Curve_P521R1 |
EllipticCurve Curve_P521R1 |
type Point Curve_P521R1 |
type Scalar Curve_P521R1 |

data Curve_X25519

Constructors

Curve_X25519 |

Instances

Data Curve_X25519 |
Show Curve_X25519 |
EllipticCurveDH Curve_X25519 |
EllipticCurve Curve_X25519 |
type Point Curve_X25519 = PublicKey |
type Scalar Curve_X25519 = SecretKey |

data Curve_X448

Constructors

Curve_X448 |

Instances

Data Curve_X448 |
Show Curve_X448 |
EllipticCurveDH Curve_X448 |
EllipticCurve Curve_X448 |
type Point Curve_X448 = PublicKey |
type Scalar Curve_X448 = SecretKey |

class EllipticCurve curve where

Associated Types

type Point curve :: *

Point on an Elliptic Curve

type Scalar curve :: *

Scalar in the Elliptic Curve domain

Methods

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

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)

Generate a new random keypair

curveSizeBits :: proxy curve -> Int

Get the curve size in bits

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

Encode a elliptic curve point into binary form

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

Try to decode the binary form of an elliptic curve point

Instances

EllipticCurve Curve_X448 |
EllipticCurve Curve_X25519 |
EllipticCurve Curve_P521R1 |
EllipticCurve Curve_P384R1 |
EllipticCurve Curve_P256R1 |

class EllipticCurve curve => EllipticCurveDH curve where

Minimal complete definition

ecdh

Methods

ecdhRaw :: proxy curve -> Scalar curve -> Point curve -> SharedSecret

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.

WARNING: Curve implementations may return a special value or an exception when the public point lies in a subgroup of small order. This function is adequate when the scalar is in expected range and contributory behaviour is not needed. Otherwise use `ecdh`.

ecdh :: proxy curve -> Scalar curve -> Point curve -> CryptoFailable SharedSecret

Generate a Diffie hellman secret value and verify that the result is not the point at infinity.

This additional test avoids risks existing with function `ecdhRaw`. Implementations always return a `CryptoError` instead of a special value or an exception.

Instances

EllipticCurveDH Curve_X448 |
EllipticCurveDH Curve_X25519 |
EllipticCurveDH Curve_P521R1 |
EllipticCurveDH Curve_P384R1 |
EllipticCurveDH Curve_P256R1 |

class EllipticCurve curve => EllipticCurveArith curve where

Methods

pointAdd :: proxy curve -> Point curve -> Point curve -> Point curve

Add points on a curve

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

Scalar Multiplication on a curve

Instances

EllipticCurveArith Curve_P521R1 |
EllipticCurveArith Curve_P384R1 |
EllipticCurveArith Curve_P256R1 |

data KeyPair curve

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

Constructors

SharedSecret ScrubbedBytes |

Instances

Eq SharedSecret |
ByteArrayAccess SharedSecret |