spake2-0.1.0: Implementation of the SPAKE2 Password-Authenticated Key Exchange algorithm

Safe HaskellNone
LanguageHaskell2010

Crypto.Spake2.Group

Description

 

Synopsis

Documentation

class Group group where Source #

A mathematical group intended to be used with SPAKE2.

Notes:

  • This is a much richer interface than one would expect from a group purely derived from abstract algebra
  • jml thinks this is relevant to all Diffie-Hellman cryptography, but too ignorant to say for sure
  • Is this group automatically abelian? cyclic? Must it have these properties?

Associated Types

type Element group :: * Source #

An element of the group.

type Scalar group :: * Source #

A scalar for this group. Mathematically equivalent to an integer, but possibly stored differently for computational reasons.

Methods

elementAdd :: group -> Element group -> Element group -> Element group Source #

Group addition.

\x y z -> elementAdd group (elementAdd group x y) z == elementAdd group x (elementAdd group y z)

elementNegate :: group -> Element group -> Element group Source #

Inverse with respect to group addition.

\x -> (elementAdd group x (elementNegate group x)) == groupIdentity
\x -> (elementNegate group (elementNegate group x)) == x

elementSubtract :: group -> Element group -> Element group -> Element group Source #

Subtract one element from another.

\x y -> (elementSubtract group x y) == (elementAdd group x (elementNegate group y))

groupIdentity :: group -> Element group Source #

Identity of the group.

Note [Added for completeness]

\x -> (elementAdd group x groupIdentity) == x
\x -> (elementAdd group groupIdentity x) == x

scalarMultiply :: group -> Scalar group -> Element group -> Element group Source #

Multiply an element of the group with respect to a scalar.

This is equivalent to adding the element to itself N times, where N is a scalar.

integerToScalar :: group -> Integer -> Scalar group Source #

Get the scalar that corresponds to an integer.

Note [Added for completeness]

\x -> scalarToInteger group (integerToScalar group x) == x

scalarToInteger :: group -> Scalar group -> Integer Source #

Get the integer that corresponds to a scalar.

Note [Added for completeness]

\x -> integerToScalar group (scalarToInteger group x) == x

encodeElement :: ByteArray bytes => group -> Element group -> bytes Source #

Encode an element of the group into bytes.

Note [Byte encoding in Group]

\x -> decodeElement group (encodeElement group x) == CryptoPassed x

decodeElement :: ByteArray bytes => group -> bytes -> CryptoFailable (Element group) Source #

Decode an element into the group from some bytes.

Note [Byte encoding in Group]

generateElement :: MonadRandom randomly => group -> randomly (KeyPair group) Source #

Encode a scalar into bytes. | Generate a new random element of the group, with corresponding scalar.

elementSizeBits :: group -> Int Source #

Size of elements, in bits

scalarSizeBits :: group -> Int Source #

Size of scalars, in bits

arbitraryElement :: ByteArrayAccess bytes => group -> bytes -> Element group Source #

Deterministically create an arbitrary element from a seed bytestring.

XXX: jml would much rather this take a scalar, an element, or even an integer, rather than bytes because bytes mean that the group instances have to know about hash algorithms and HKDF. If the IntegerGroup class in SPAKE2 also oversized its input, then it and the ed25519 implementation would have identical decoding.

Instances

Group Ed25519 Source # 
Group IntegerAddition Source # 
Group IntegerGroup Source # 

decodeScalar :: (ByteArrayAccess bytes, Group group) => group -> bytes -> Scalar group Source #

Map some arbitrary bytes into a scalar in a group.

elementSizeBytes :: Group group => group -> Int Source #

Size of elements in a group, in bits.

scalarSizeBytes :: Group group => group -> Int Source #

Size of scalars in a group, in bytes.

data KeyPair group Source #

A group key pair composed of the private part (a scalar) and a public part (associated group element).

Constructors

KeyPair 

Fields