| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Voting.Protocol.Arith
Contents
Description
Finite Field Cryptography (FFC) is a method of implementing discrete logarithm cryptography using finite field mathematics.
Synopsis
- class Additive a where
- class Additive a => Negable a where
- class Multiplicative a where
- class Multiplicative a => Invertible a where
- (^) :: Reifies c crypto => Multiplicative (FieldElement crypto c) => G crypto c -> E crypto c -> G crypto c
- groupGenInverses :: forall crypto c. Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => [G crypto c]
- groupGenPowers :: forall crypto c. Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => [G crypto c]
- randomR :: Monad m => RandomGen r => Random i => Negable i => Multiplicative i => i -> StateT r m i
- random :: Monad m => RandomGen r => Random i => Negable i => Multiplicative i => StateT r m i
- type family FieldElement crypto :: * -> *
- class Group crypto where
- newtype G crypto c = G {
- unG :: FieldElement crypto c
- newtype E crypto c = E {}
- class FromNatural a where
- fromNatural :: Natural -> a
- class ToNatural a where
- bytesNat :: ToNatural n => n -> ByteString
- newtype Hash crypto c = Hash (E crypto c)
- hash :: Reifies c crypto => Group crypto => ToNatural (FieldElement crypto c) => ByteString -> [G crypto c] -> E crypto c
- decodeBigEndian :: ByteString -> Natural
- newtype Base64SHA256 = Base64SHA256 Text
- base64SHA256 :: ByteString -> Base64SHA256
- newtype HexSHA256 = HexSHA256 Text
- hexSHA256 :: ByteString -> Text
Class Additive
class Additive a where Source #
Instances
| Additive Int Source # | |
| Additive Integer Source # | |
| Additive Natural Source # | |
| Reifies c FFC => Additive (F c) Source # | |
| (Reifies c crypto, Group crypto) => Additive (E crypto c) Source # | |
| (Reifies c crypto, Multiplicative (FieldElement crypto c)) => Additive (Encryption crypto v c) Source # | Additive homomorphism.
Using the fact that: |
Defined in Voting.Protocol.Election Methods zero :: Encryption crypto v c Source # (+) :: Encryption crypto v c -> Encryption crypto v c -> Encryption crypto v c Source # sum :: Foldable f => f (Encryption crypto v c) -> Encryption crypto v c Source # | |
Class Negable
class Additive a => Negable a where Source #
Minimal complete definition
Class Multiplicative
class Multiplicative a where Source #
Instances
| Multiplicative Int Source # | |
| Multiplicative Integer Source # | |
| Multiplicative Natural Source # | |
| Reifies c FFC => Multiplicative (F c) Source # | |
| (Reifies c crypto, Group crypto) => Multiplicative (E crypto c) Source # | |
| Multiplicative (FieldElement crypto c) => Multiplicative (G crypto c) Source # | |
Class Invertible
class Multiplicative a => Invertible a where Source #
Minimal complete definition
Instances
| (Reifies c crypto, Group crypto, Multiplicative (FieldElement crypto c)) => Invertible (G crypto c) Source # | |
(^) :: Reifies c crypto => Multiplicative (FieldElement crypto c) => G crypto c -> E crypto c -> G crypto c infixr 8 Source #
(b returns the modular exponentiation of base ^ e)b by exponent e.
groupGenInverses :: forall crypto c. Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => [G crypto c] Source #
groupGenPowers :: forall crypto c. Reifies c crypto => Group crypto => Multiplicative (FieldElement crypto c) => [G crypto c] Source #
randomR :: Monad m => RandomGen r => Random i => Negable i => Multiplicative i => i -> StateT r m i Source #
( returns a random integer in randomR i)[0..i-1].
random :: Monad m => RandomGen r => Random i => Negable i => Multiplicative i => StateT r m i Source #
( returns a random integer
in the range determined by its type.random)
Type family FieldElement
type family FieldElement crypto :: * -> * Source #
Instances
| type FieldElement FFC Source # | |
Defined in Voting.Protocol.FFC | |
Class Group where
Type G
The type of the elements of a subgroup of a field.
Constructors
| G | |
Fields
| |
Instances
| Eq (FieldElement crypto c) => Eq (G crypto c) Source # | |
| Ord (FieldElement crypto c) => Ord (G crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
| Show (FieldElement crypto c) => Show (G crypto c) Source # | |
| ToJSON (FieldElement crypto c) => ToJSON (G crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
| Reifies c FFC => FromJSON (G FFC c) Source # | |
| NFData (FieldElement crypto c) => NFData (G crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
| ToNatural (FieldElement crypto c) => ToNatural (G crypto c) Source # | |
| FromNatural (FieldElement crypto c) => FromNatural (G crypto c) Source # | |
Defined in Voting.Protocol.Arith Methods fromNatural :: Natural -> G crypto c Source # | |
| (Reifies c crypto, Group crypto, Multiplicative (FieldElement crypto c)) => Invertible (G crypto c) Source # | |
| Multiplicative (FieldElement crypto c) => Multiplicative (G crypto c) Source # | |
Type E
An exponent of a (cyclic) subgroup of a field.
The value is always in [0...groupOrder-1]
Instances
| (Reifies c crypto, Group crypto) => Enum (E crypto c) Source # | |
Defined in Voting.Protocol.Arith Methods succ :: E crypto c -> E crypto c # pred :: E crypto c -> E crypto c # fromEnum :: E crypto c -> Int # enumFrom :: E crypto c -> [E crypto c] # enumFromThen :: E crypto c -> E crypto c -> [E crypto c] # enumFromTo :: E crypto c -> E crypto c -> [E crypto c] # enumFromThenTo :: E crypto c -> E crypto c -> E crypto c -> [E crypto c] # | |
| Eq (E crypto c) Source # | |
| Ord (E crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
| Show (E crypto c) Source # | |
| ToJSON (E crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
| (Reifies c crypto, Group crypto) => FromJSON (E crypto c) Source # | |
| NFData (E crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
| (Reifies c crypto, Group crypto) => Random (E crypto c) Source # | |
Defined in Voting.Protocol.Arith Methods randomR :: RandomGen g => (E crypto c, E crypto c) -> g -> (E crypto c, g) # random :: RandomGen g => g -> (E crypto c, g) # randomRs :: RandomGen g => (E crypto c, E crypto c) -> g -> [E crypto c] # randoms :: RandomGen g => g -> [E crypto c] # | |
| ToNatural (E crypto c) Source # | |
| (Reifies c crypto, Group crypto) => FromNatural (E crypto c) Source # | |
Defined in Voting.Protocol.Arith Methods fromNatural :: Natural -> E crypto c Source # | |
| (Reifies c crypto, Group crypto) => Multiplicative (E crypto c) Source # | |
| (Reifies c crypto, Group crypto) => Negable (E crypto c) Source # | |
| (Reifies c crypto, Group crypto) => Additive (E crypto c) Source # | |
Class FromNatural
class FromNatural a where Source #
Methods
fromNatural :: Natural -> a Source #
Instances
| Reifies c FFC => FromNatural (F c) Source # | |
Defined in Voting.Protocol.FFC Methods fromNatural :: Natural -> F c Source # | |
| (Reifies c crypto, Group crypto) => FromNatural (E crypto c) Source # | |
Defined in Voting.Protocol.Arith Methods fromNatural :: Natural -> E crypto c Source # | |
| FromNatural (FieldElement crypto c) => FromNatural (G crypto c) Source # | |
Defined in Voting.Protocol.Arith Methods fromNatural :: Natural -> G crypto c Source # | |
Class ToNatural
Type Hash
newtype Hash crypto c Source #
Instances
| Eq (Hash crypto c) Source # | |
| Ord (Hash crypto c) Source # | |
Defined in Voting.Protocol.Arith Methods compare :: Hash crypto c -> Hash crypto c -> Ordering # (<) :: Hash crypto c -> Hash crypto c -> Bool # (<=) :: Hash crypto c -> Hash crypto c -> Bool # (>) :: Hash crypto c -> Hash crypto c -> Bool # (>=) :: Hash crypto c -> Hash crypto c -> Bool # | |
| Show (Hash crypto c) Source # | |
| NFData (Hash crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
hash :: Reifies c crypto => Group crypto => ToNatural (FieldElement crypto c) => ByteString -> [G crypto c] -> E crypto c Source #
( returns as a number in hash bs gs)GroupExponent
the SHA256 hash of the given ByteString bs
prefixing the decimal representation of given subgroup elements gs,
with a comma (",") intercalated between them.
NOTE: to avoid any collision when the hash function is used in different contexts,
a message gs is actually prefixed by a bs indicating the context.
Used by proveEncryption and verifyEncryption,
where the bs usually contains the statement to be proven,
and the gs contains the commitments.
decodeBigEndian :: ByteString -> Natural Source #
( interpret decodeBigEndian bs)bs as big-endian number.
Type Base64SHA256
newtype Base64SHA256 Source #
Constructors
| Base64SHA256 Text |
Instances
base64SHA256 :: ByteString -> Base64SHA256 Source #
( returns the base64SHA256 bs)SHA256 hash
of the given ByteString bs,
as a Text escaped in base64 encoding
(RFC 4648).
Type HexSHA256
Instances
| Eq HexSHA256 Source # | |
| Ord HexSHA256 Source # | |
| Show HexSHA256 Source # | |
| Generic HexSHA256 Source # | |
| ToJSON HexSHA256 Source # | |
Defined in Voting.Protocol.Arith | |
| FromJSON HexSHA256 Source # | |
| NFData HexSHA256 Source # | |
Defined in Voting.Protocol.Arith | |
| type Rep HexSHA256 Source # | |
Defined in Voting.Protocol.Arith | |
hexSHA256 :: ByteString -> Text Source #
( returns the hexSHA256 bs)SHA256 hash
of the given ByteString bs, escaped in hexadecimal
into a Text of 32 lowercase characters.
Used (in retro-dependencies of this library) to hash
the PublicKey of a voter or a trustee.