crypton
LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Crypto.PubKey.ECC.DH

Description

Elliptic curve Diffie Hellman

Synopsis

Documentation

data Curve Source #

Define either a binary curve or a prime curve.

Instances

Instances details
Eq Curve Source # 
Instance details

Defined in Crypto.PubKey.ECC.Types

Methods

(==) :: Curve -> Curve -> Bool

(/=) :: Curve -> Curve -> Bool

Data Curve Source # 
Instance details

Defined in Crypto.PubKey.ECC.Types

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Curve -> c Curve

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Curve

toConstr :: Curve -> Constr

dataTypeOf :: Curve -> DataType

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Curve)

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Curve)

gmapT :: (forall b. Data b => b -> b) -> Curve -> Curve

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Curve -> r

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Curve -> r

gmapQ :: (forall d. Data d => d -> u) -> Curve -> [u]

gmapQi :: Int -> (forall d. Data d => d -> u) -> Curve -> u

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Curve -> m Curve

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Curve -> m Curve

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Curve -> m Curve

Read Curve Source # 
Instance details

Defined in Crypto.PubKey.ECC.Types

Methods

readsPrec :: Int -> ReadS Curve

readList :: ReadS [Curve]

readPrec :: ReadPrec Curve

readListPrec :: ReadPrec [Curve]

Show Curve Source # 
Instance details

Defined in Crypto.PubKey.ECC.Types

Methods

showsPrec :: Int -> Curve -> ShowS

show :: Curve -> String

showList :: [Curve] -> ShowS

type PublicPoint = Point Source #

ECC Public Point

type PrivateNumber = Integer Source #

ECC Private Number

newtype SharedKey Source #

Represent Diffie Hellman shared secret.

Constructors

SharedKey ScrubbedBytes 

Instances

Instances details
NFData SharedKey Source # 
Instance details

Defined in Crypto.PubKey.DH

Methods

rnf :: SharedKey -> ()

Eq SharedKey Source # 
Instance details

Defined in Crypto.PubKey.DH

Methods

(==) :: SharedKey -> SharedKey -> Bool

(/=) :: SharedKey -> SharedKey -> Bool

Show SharedKey Source # 
Instance details

Defined in Crypto.PubKey.DH

Methods

showsPrec :: Int -> SharedKey -> ShowS

show :: SharedKey -> String

showList :: [SharedKey] -> ShowS

ByteArrayAccess SharedKey Source # 
Instance details

Defined in Crypto.PubKey.DH

Methods

length :: SharedKey -> Int

withByteArray :: SharedKey -> (Ptr p -> IO a) -> IO a

copyByteArrayToPtr :: SharedKey -> Ptr p -> IO ()

generatePrivate :: MonadRandom m => Curve -> m PrivateNumber Source #

Generating a private number d.

calculatePublic :: Curve -> PrivateNumber -> PublicPoint Source #

Generating a public point Q.

getShared :: Curve -> PrivateNumber -> PublicPoint -> SharedKey Source #

Generating a shared key using our private number and the other party public point.

This raises the CryptoError that tryGetShared reports. Use tryGetShared where the failure has to be handled.

tryGetShared :: Curve -> PrivateNumber -> PublicPoint -> CryptoFailable SharedKey Source #

Generating a shared key using our private number and the other party public point, reporting a rejected point instead of raising.

The public point comes from the other party, so it is checked before it is multiplied. A point that does not satisfy the curve equation is reported as CryptoError_PointCoordinatesInvalid.

Satisfying the equation is not by itself membership of the subgroup the base point generates; the two coincide only when the cofactor is 1. On a curve whose cofactor is above 1 the other party can offer a point of small order, and the value that comes back then depends on our private number only through its residue modulo that order, which hands them those bits. So the point is also required to be in the subgroup, by isPointInSubgroup, and is reported as CryptoError_PointSubgroupInvalid when it is not. That check costs one further scalar multiplication, and is skipped where the cofactor is 1 and it cannot fail.

An exchange that yields the point at infinity, and so has no x coordinate to derive the key from, is reported as CryptoError_ScalarMultiplicationInvalid.