Safe Haskell | None |
---|---|
Language | Haskell2010 |
Arithmetic
Synopsis
- class Additive a where
- class Additive a => Negable a where
- class Multiplicative a where
- class Multiplicative a => Invertible a where
- (^) :: forall crypto c. Reifies c crypto => Multiplicative (G crypto c) => G crypto c -> E crypto c -> G crypto c
- class (Multiplicative (G crypto c), Invertible (G crypto c), FromNatural (G crypto c), ToNatural (G crypto c), Eq (G crypto c), Ord (G crypto c), Show (G crypto c), NFData (G crypto c), FromJSON (G crypto c), ToJSON (G crypto c), Reifies c crypto) => GroupParams crypto c where
- groupGen :: G crypto c
- groupOrder :: Proxy c -> Natural
- groupGenPowers :: [G crypto c]
- groupGenInverses :: [G crypto c]
- class ReifyCrypto crypto where
- reifyCrypto :: crypto -> (forall c. Reifies c crypto => GroupParams crypto c => Proxy c -> r) -> r
- newtype G crypto c = G {
- unG :: FieldElement crypto
- type family FieldElement crypto :: *
- 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 :: GroupParams 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
- 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
Class Additive
class Additive a where Source #
Instances
Additive Int Source # | |
Additive Integer Source # | |
Additive Natural Source # | |
GroupParams crypto c => Additive (E crypto c) Source # | |
Reifies c FFC => Additive (G FFC c) Source # | |
GroupParams crypto c => Additive (Encryption crypto v c) Source # | Additive homomorphism.
Using the fact that: |
Defined in Voting.Protocol.Election 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 Multiplicative
class Multiplicative a where Source #
Instances
Multiplicative Int Source # | |
Multiplicative Integer Source # | |
Multiplicative Natural Source # | |
GroupParams crypto c => Multiplicative (E crypto c) Source # | |
Reifies c FFC => Multiplicative (G FFC c) Source # | |
Class Invertible
class Multiplicative a => Invertible a where Source #
(^) :: forall crypto c. Reifies c crypto => Multiplicative (G 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
.
Class GroupParams
where
class (Multiplicative (G crypto c), Invertible (G crypto c), FromNatural (G crypto c), ToNatural (G crypto c), Eq (G crypto c), Ord (G crypto c), Show (G crypto c), NFData (G crypto c), FromJSON (G crypto c), ToJSON (G crypto c), Reifies c crypto) => GroupParams crypto c where Source #
groupGen :: G crypto c Source #
A generator of the subgroup.
groupOrder :: Proxy c -> Natural Source #
The order of the subgroup.
groupGenPowers :: [G crypto c] Source #
groupGenPowers
returns the infinite list
of powers of groupGen
.
NOTE: In the GroupParams
class to keep
computed values in memory across calls to groupGenPowers
.
groupGenInverses :: [G crypto c] Source #
groupGenInverses
returns the infinite list
of inv
erse powers of groupGen
:
[
,
but by computing each value from the previous one.groupGen
^
neg
i | i <- [0..]]
NOTE: In the GroupParams
class to keep
computed values in memory across calls to groupGenInverses
.
Used by intervalDisjunctions
.
Class ReifyCrypto
class ReifyCrypto crypto where Source #
reifyCrypto :: crypto -> (forall c. Reifies c crypto => GroupParams crypto c => Proxy c -> r) -> r Source #
Like reify
but augmented with the GroupParams
constraint.
Instances
ReifyCrypto FFC Source # | |
Defined in Voting.Protocol.FFC reifyCrypto :: FFC -> (forall c. (Reifies c FFC, GroupParams FFC c) => Proxy c -> r) -> r Source # |
Type G
The type of the elements of a subgroup of a field.
G | |
|
Instances
Eq (G FFC c) Source # | |
Ord (G FFC c) Source # | |
Show (G FFC c) Source # | |
ToJSON (G FFC c) Source # | |
Reifies c FFC => FromJSON (G FFC c) Source # | |
NFData (G FFC c) Source # | |
Defined in Voting.Protocol.FFC | |
Reifies c FFC => Random (G FFC c) Source # | |
Defined in Voting.Protocol.FFC | |
ToNatural (G FFC c) Source # | |
Reifies c FFC => FromNatural (G FFC c) Source # | |
Defined in Voting.Protocol.FFC | |
Reifies c FFC => Invertible (G FFC c) Source # | |
Reifies c FFC => Multiplicative (G FFC c) Source # | |
Reifies c FFC => Negable (G FFC c) Source # | |
Reifies c FFC => Additive (G FFC c) Source # | |
Type family FieldElement
type family FieldElement crypto :: * Source #
Instances
type FieldElement FFC Source # | The type of the elements of a Finite Prime Field. A field must satisfy the following properties:
The |
Defined in Voting.Protocol.FFC |
Type E
An exponent of a (cyclic) subgroup of a field.
The value is always in [0..
.groupOrder
-1]
Instances
GroupParams crypto c => Enum (E crypto c) Source # | |
Defined in Voting.Protocol.Arith 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 # | |
Show (E crypto c) Source # | |
ToJSON (E crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
GroupParams crypto c => FromJSON (E crypto c) Source # | |
NFData (E crypto c) Source # | |
Defined in Voting.Protocol.Arith | |
GroupParams crypto c => Random (E crypto c) Source # | |
Defined in Voting.Protocol.Arith 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 # | |
GroupParams crypto c => FromNatural (E crypto c) Source # | |
Defined in Voting.Protocol.Arith fromNatural :: Natural -> E crypto c Source # | |
GroupParams crypto c => Multiplicative (E crypto c) Source # | |
GroupParams crypto c => Negable (E crypto c) Source # | |
GroupParams crypto c => Additive (E crypto c) Source # | |
Class FromNatural
class FromNatural a where Source #
fromNatural :: Natural -> a Source #
Instances
GroupParams crypto c => FromNatural (E crypto c) Source # | |
Defined in Voting.Protocol.Arith fromNatural :: Natural -> E crypto c Source # | |
Reifies c FFC => FromNatural (G FFC c) Source # | |
Defined in Voting.Protocol.FFC |
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 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 :: GroupParams 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 #
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 # | |
Defined in Voting.Protocol.Arith | |
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.
Random
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
)