cardano-crypto-1.3.0: Cryptography primitives for cardano
Maintainervincent@typed.io
Safe HaskellSafe-Inferred
LanguageHaskell2010

Crypto.Math.Edwards25519

Description

Simple module to play with the arithmetics of the twisted edwards curve Ed25519 using Extended Twisted Edwards Coordinates. Compared to the normal implementation this allow to use standard DH property:

for all valid s1 and s2 scalar:

scalarToPoint (s1 + s2) = pointAdd (scalarToPoint s1) (scalarToPoint s2)

For further useful references about Ed25519:

Synopsis

Basic types

data Scalar Source #

Represent a scalar in the base field

newtype Signature Source #

Represent a signature

Constructors

Signature 

Instances

Instances details
Show Signature Source # 
Instance details

Defined in Crypto.Math.Edwards25519

NFData Signature Source # 
Instance details

Defined in Crypto.Math.Edwards25519

Methods

rnf :: Signature -> () #

Eq Signature Source # 
Instance details

Defined in Crypto.Math.Edwards25519

Ord Signature Source # 
Instance details

Defined in Crypto.Math.Edwards25519

Hashable Signature Source # 
Instance details

Defined in Crypto.Math.Edwards25519

smart constructor & destructor

scalar :: ByteString -> Scalar Source #

Create a Ed25519 scalar

Only check that the length is of expected size (32 bytes), no effort is made for the scalar to be in the right base field range on purpose.

pointCompressed :: HasCallStack => ByteString -> PointCompressed Source #

Check if a scalar is valid and all the bits properly set/cleared scalarValid :: Scalar -> Bool scalarValid _s = True -- TODO

Smart constructor to create a compress point binary

Check if the length is of expected size

Arithmetic

scalarFromInteger :: Integer -> Scalar Source #

Create a scalar from integer. mainly for debugging purpose.

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

Add 2 scalar in the base field together

scalarToPoint :: Scalar -> PointCompressed Source #

Lift a scalar to the curve, and returning a compressed point

Signature & Verify

sign :: ByteArrayAccess msg => Scalar -> ByteString -> msg -> Signature Source #

Create a signature using a variant of ED25519 signature

we don't hash the secret key to derive a key + prefix, but instead we take an explicit salt and compute a prefix using the secret key + salt.

verify :: ByteArrayAccess msg => PointCompressed -> msg -> Signature -> Bool Source #

Verify a signature