Safe Haskell  None 

Language  Haskell2010 
 class Group group => AbelianGroup group where
 class Group group where
 decodeScalar :: (ByteArrayAccess bytes, AbelianGroup group) => group > bytes > Scalar group
 elementSizeBytes :: Group group => group > Int
 scalarSizeBytes :: AbelianGroup group => group > Int
 data KeyPair group = KeyPair {
 keyPairPublic :: !(Element group)
 keyPairPrivate :: !(Scalar group)
Documentation
class Group group => AbelianGroup group where Source #
A group where elementAdd
is commutative.
That is, where
\x y > elementAdd group x y == elementAdd group y x
This property leads to a natural \(\mathbb{Z}\)module,
where scalar multiplication is defined as repeatedly calling elementAdd
.
Definitions
Warning: this gets algebraic.
A module is a ring \(R\) together with an abelian group \((G, +)\), and a new operator \(\cdot\) (i.e. scalar multiplication) such that:
 \(r \cdot (x + y) = r \cdot x + r \cdot y\)
 \((r + s) \cdot x = r \cdot x + s \cdot x\)
 \((rs) \cdot x = r \cdot (s \cdot x)\)
 \(1_R \cdot x = x\)
for all \(x, y\) in \(G\), and \(r, s\) in \(R\), where \(1_R\) is the identity of the ring.
A ring \(R, +, \cdot\) a set \(R\) with two operators such that:
 \(R\) is an abelian group under \(+\)
 \(R\) is a monoid under \(\cdot\)
 \(cdot\) is _distributive_ with respect to \(+\). That is,
 (a cdot (b + c) = (a cdot b) + (a cdot c) (left distributivity)
 ((b + c) cdot a) = (b cdot a) + (c cdot a) (right distributivity)
Note we have to define left & right distributivity, because \(\cdot\) might not be commutative.
A monoid is a group without the notion of inverse. See Haskell's Monoid
typeclass.
A \(\mathbb{Z}\)module is a module where the ring \(R\) is the integers with normal addition and multiplication.
type Scalar group :: * Source #
A scalar for this group. Mathematically equivalent to an integer, but possibly stored differently for computational reasons.
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. The default implementation does exactly that.
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
scalarSizeBits :: group > Int Source #
Size of scalars, in bits
generateElement :: MonadRandom randomly => group > randomly (KeyPair group) Source #
Encode a scalar into bytes.  Generate a new random element of the group, with corresponding scalar.
class Group group where Source #
A mathematical group intended to be used with SPAKE2.
elementAdd, elementNegate, groupIdentity, encodeElement, decodeElement, elementSizeBits, arbitraryElement
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
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]
elementSizeBits :: group > Int Source #
Size of elements, 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.
decodeScalar :: (ByteArrayAccess bytes, AbelianGroup 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 :: AbelianGroup group => group > Int Source #
Size of scalars in a group, in bytes.
A group key pair composed of the private part (a scalar) and a public part (associated group element).
KeyPair  
