crypton-0.33: Cryptography Primitives sink

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

Crypto.PubKey.ECC.P256

Contents

- Point arithmetic
- Scalar arithmetic

Description

P256 support

Synopsis

- data Scalar
- data Point
- pointBase :: Point
- pointAdd :: Point -> Point -> Point
- pointNegate :: Point -> Point
- pointMul :: Scalar -> Point -> Point
- pointDh :: ByteArray binary => Scalar -> Point -> binary
- pointsMulVarTime :: Scalar -> Scalar -> Point -> Point
- pointIsValid :: Point -> Bool
- pointIsAtInfinity :: Point -> Bool
- toPoint :: Scalar -> Point
- pointX :: Point -> Maybe Scalar
- pointToIntegers :: Point -> (Integer, Integer)
- pointFromIntegers :: (Integer, Integer) -> Point
- pointToBinary :: ByteArray ba => Point -> ba
- pointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point
- unsafePointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point
- scalarGenerate :: MonadRandom randomly => randomly Scalar
- scalarZero :: Scalar
- scalarN :: Scalar
- scalarIsZero :: Scalar -> Bool
- scalarAdd :: Scalar -> Scalar -> Scalar
- scalarSub :: Scalar -> Scalar -> Scalar
- scalarMul :: Scalar -> Scalar -> Scalar
- scalarInv :: Scalar -> Scalar
- scalarInvSafe :: Scalar -> Scalar
- scalarCmp :: Scalar -> Scalar -> Ordering
- scalarFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Scalar
- scalarToBinary :: ByteArray ba => Scalar -> ba
- scalarFromInteger :: Integer -> CryptoFailable Scalar
- scalarToInteger :: Scalar -> Integer

# Documentation

data Scalar Source #

A P256 scalar

#### Instances

Instances details

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

data Point Source #

A P256 point

#### Instances

Instances details

Show Point Source # |
Instance details Defined in Crypto.PubKey.ECC.P256 Methods showsPrec :: Int -> Point -> ShowS Source # show :: Point -> String Source # showList :: [Point] -> ShowS Source #
NFData Point Source # |
Instance details Defined in Crypto.PubKey.ECC.P256 Methods rnf :: Point -> () Source #
Eq Point Source # |
Instance details Defined in Crypto.PubKey.ECC.P256 Methods (==) :: Point -> Point -> Bool Source # (/=) :: Point -> Point -> Bool Source #

# Point arithmetic

pointBase :: Point Source #

Get the base point for the P256 Curve

pointAdd :: Point -> Point -> Point Source #

Add a point to another point

pointNegate :: Point -> Point Source #

Negate a point

pointMul :: Scalar -> Point -> Point Source #

Multiply a point by a scalar

warning: variable time

pointDh :: ByteArray binary => Scalar -> Point -> binary Source #

Similar to `pointMul`, serializing the x coordinate as binary. When scalar is multiple of point order the result is all zero.

pointsMulVarTime :: Scalar -> Scalar -> Point -> Point Source #

multiply the point `p with` n2 and add a lifted to curve value @n1

    n1 * G + n2 * p

warning: variable time

pointIsValid :: Point -> Bool Source #

Check if a `Point` is valid

pointIsAtInfinity :: Point -> Bool Source #

Check if a `Point` is the point at infinity

toPoint :: Scalar -> Point Source #

Lift to curve a scalar

Using the curve generator as base point compute:

    scalar * G

pointX :: Point -> Maybe Scalar Source #

Return the x coordinate as a `Scalar` if the point is not at infinity

pointToIntegers :: Point -> (Integer, Integer) Source #

Convert a point to (x,y) Integers

pointFromIntegers :: (Integer, Integer) -> Point Source #

Convert from (x,y) Integers to a point

pointToBinary :: ByteArray ba => Point -> ba Source #

Convert a point to a binary representation

pointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point Source #

Convert from binary to a valid point

unsafePointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point Source #

Convert from binary to a point, possibly invalid

# Scalar arithmetic

scalarGenerate :: MonadRandom randomly => randomly Scalar Source #

Generate a randomly generated new scalar

scalarZero :: Scalar Source #

The scalar representing 0

scalarN :: Scalar Source #

The scalar representing the curve order

scalarIsZero :: Scalar -> Bool Source #

Check if the scalar is 0

scalarAdd :: Scalar -> Scalar -> Scalar Source #

Perform addition between two scalars

    a + b

scalarSub :: Scalar -> Scalar -> Scalar Source #

Perform subtraction between two scalars

    a - b

scalarMul :: Scalar -> Scalar -> Scalar Source #

Perform multiplication between two scalars

    a * b

scalarInv :: Scalar -> Scalar Source #

Give the inverse of the scalar

    1 / a

warning: variable time

scalarInvSafe :: Scalar -> Scalar Source #

Give the inverse of the scalar using safe exponentiation

    1 / a

scalarCmp :: Scalar -> Scalar -> Ordering Source #

Compare 2 Scalar

scalarFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Scalar Source #

convert a scalar from binary

scalarToBinary :: ByteArray ba => Scalar -> ba Source #

convert a scalar to binary

scalarFromInteger :: Integer -> CryptoFailable Scalar Source #

Convert from an Integer to a P256 Scalar

scalarToInteger :: Scalar -> Integer Source #

Convert from a P256 Scalar to an Integer