Crypto.PubKey.ECC.P256

cryptonite-0.19: Cryptography Primitives sink

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | unknown
Safe Haskell | None
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
- pointMul :: Scalar -> Point -> Point
- pointsMulVarTime :: Scalar -> Scalar -> Point -> Point
- pointIsValid :: Point -> Bool
- toPoint :: Scalar -> Point
- pointToIntegers :: Point -> (Integer, Integer)
- pointFromIntegers :: (Integer, Integer) -> Point
- pointToBinary :: ByteArray ba => Point -> ba
- pointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point
- scalarGenerate :: MonadRandom randomly => randomly Scalar
- scalarZero :: Scalar
- scalarIsZero :: Scalar -> Bool
- scalarAdd :: Scalar -> Scalar -> Scalar
- scalarSub :: Scalar -> Scalar -> Scalar
- scalarInv :: 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 #

A P256 scalar

Instances

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

data Point #

A P256 point

Instances

Eq Point # |
Methods (==) :: Point -> Point -> Bool # (/=) :: Point -> Point -> Bool #
Show Point # |
Methods showsPrec :: Int -> Point -> ShowS # show :: Point -> String # showList :: [Point] -> ShowS #

# point arithmetic

pointBase :: Point #

Get the base point for the P256 Curve

pointAdd :: Point -> Point -> Point #

Add a point to another point

pointMul :: Scalar -> Point -> Point #

Multiply a point by a scalar

warning: variable time

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

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

    n1 * G + n2 * p

warning: variable time

pointIsValid :: Point -> Bool #

Check if a `Point` is valid

toPoint :: Scalar -> Point #

Lift to curve a scalar

Using the curve generator as base point compute:

    scalar * G

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

Convert a point to (x,y) Integers

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

Convert from (x,y) Integers to a point

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

Convert a point to a binary representation

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

Convert from binary to a point

# scalar arithmetic

scalarGenerate :: MonadRandom randomly => randomly Scalar #

Generate a randomly generated new scalar

scalarZero :: Scalar #

The scalar representing 0

scalarIsZero :: Scalar -> Bool #

Check if the scalar is 0

scalarAdd :: Scalar -> Scalar -> Scalar #

Perform addition between two scalars

    a + b

scalarSub :: Scalar -> Scalar -> Scalar #

Perform subtraction between two scalars

    a - b

scalarInv :: Scalar -> Scalar #

Give the inverse of the scalar

    1 / a

warning: variable time

scalarCmp :: Scalar -> Scalar -> Ordering #

Compare 2 Scalar

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

convert a scalar from binary

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

convert a scalar to binary

scalarFromInteger :: Integer -> CryptoFailable Scalar #

Convert from an Integer to a P256 Scalar

scalarToInteger :: Scalar -> Integer #

Convert from a P256 Scalar to an Integer