Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class ToNatural a where
- class FromNatural a where
- fromNatural :: Natural -> a
- data BeleniosParams
- data WeakParams
- type RandomGen = RandomGen
- newtype E q = E {}
- class (PrimeField (P q), Multiplicative (F (P q))) => SubGroup q where
- type P q :: *
- groupGen :: G q
- groupOrder :: F (P q)
- groupGenInverses :: [G q]
- newtype G q = G {}
- class Multiplicative a => Invertible a where
- class Multiplicative a where
- class Additive a => Negable a where
- class Additive a where
- class PrimeField p where
- newtype F p = F {}
- hash :: SubGroup q => ByteString -> [G q] -> E q
- (^) :: SubGroup q => G q -> E q -> G q
- 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
- bytesNat :: ToNatural n => n -> ByteString
- data Natural
Documentation
class FromNatural a where Source #
fromNatural :: Natural -> a Source #
Instances
SubGroup q => FromNatural (E q) Source # | |
Defined in Protocol.Arithmetic fromNatural :: Natural -> E q Source # | |
PrimeField (P q) => FromNatural (G q) Source # | |
Defined in Protocol.Arithmetic fromNatural :: Natural -> G q Source # | |
PrimeField p => FromNatural (F p) Source # | |
Defined in Protocol.Arithmetic fromNatural :: Natural -> F p Source # |
data BeleniosParams Source #
Parameters used in Belenios.
A 2048-bit fieldCharac
of a PrimeField
,
with a 256-bit groupOrder
for a Multiplicative
SubGroup
generated by groupGen
.
Instances
SubGroup BeleniosParams Source # | |
Defined in Protocol.Arithmetic type P BeleniosParams :: Type Source # groupGen :: G BeleniosParams Source # groupOrder :: F (P BeleniosParams) Source # | |
PrimeField BeleniosParams Source # | |
Defined in Protocol.Arithmetic | |
type P BeleniosParams Source # | |
Defined in Protocol.Arithmetic |
data WeakParams Source #
Weak parameters for debugging purposes only.
Instances
SubGroup WeakParams Source # | |
Defined in Protocol.Arithmetic type P WeakParams :: Type Source # groupGen :: G WeakParams Source # groupOrder :: F (P WeakParams) Source # groupGenInverses :: [G WeakParams] Source # | |
PrimeField WeakParams Source # | |
Defined in Protocol.Arithmetic | |
type P WeakParams Source # | |
Defined in Protocol.Arithmetic |
An exponent of a (necessarily cyclic) SubGroup
of a PrimeField
.
The value is always in [0..
.groupOrder
-1]
Instances
SubGroup q => Enum (E q) Source # | |
Eq (E q) Source # | |
Ord (E q) Source # | |
Show (E q) Source # | |
SubGroup q => Random (E q) Source # | |
ToNatural (E q) Source # | |
SubGroup q => FromNatural (E q) Source # | |
Defined in Protocol.Arithmetic fromNatural :: Natural -> E q Source # | |
(SubGroup q, Multiplicative (F (P q))) => Multiplicative (E q) Source # | |
(SubGroup q, Negable (F (P q))) => Negable (E q) Source # | |
(SubGroup q, Additive (F (P q))) => Additive (E q) Source # | |
class (PrimeField (P q), Multiplicative (F (P q))) => SubGroup q where Source #
A SubGroup
of a Multiplicative
group of a PrimeField
.
Used for signing (Schnorr) and encrypting (ElGamal).
A generator of the SubGroup
.
NOTE: since F p
is a PrimeField
,
the Multiplicative
SubGroup
is cyclic,
and there are phi(fieldCharac
-1) many choices for the generator of the group,
where phi is the Euler totient function.
groupOrder :: F (P q) Source #
The order of the SubGroup
.
WARNING: groupOrder
MUST be a prime number dividing (
to ensure that ElGamal is secure in terms of the DDH assumption.fieldCharac
-1)
groupGenInverses :: [G q] 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: groupGenInverses
is in the SubGroup
class in order to keep
computed terms in memory across calls to groupGenInverses
.
Used by intervalDisjunctions
.
Instances
SubGroup BeleniosParams Source # | |
Defined in Protocol.Arithmetic type P BeleniosParams :: Type Source # groupGen :: G BeleniosParams Source # groupOrder :: F (P BeleniosParams) Source # | |
SubGroup WeakParams Source # | |
Defined in Protocol.Arithmetic type P WeakParams :: Type Source # groupGen :: G WeakParams Source # groupOrder :: F (P WeakParams) Source # groupGenInverses :: [G WeakParams] Source # |
The type of the elements of a Multiplicative
SubGroup
of a PrimeField
.
Instances
Eq (G q) Source # | |
Ord (G q) Source # | |
Show (G q) Source # | |
ToNatural (G q) Source # | |
PrimeField (P q) => FromNatural (G q) Source # | |
Defined in Protocol.Arithmetic fromNatural :: Natural -> G q Source # | |
(SubGroup q, Multiplicative (F (P q))) => Invertible (G q) Source # | |
(SubGroup q, Multiplicative (F (P q))) => Multiplicative (G q) Source # | |
class Multiplicative a => Invertible a where Source #
class Multiplicative a where Source #
Instances
Multiplicative Int Source # | |
Multiplicative Integer Source # | |
Multiplicative Natural Source # | |
(SubGroup q, Multiplicative (F (P q))) => Multiplicative (E q) Source # | |
(SubGroup q, Multiplicative (F (P q))) => Multiplicative (G q) Source # | |
PrimeField p => Multiplicative (F p) Source # | |
class Additive a where Source #
Instances
Additive Int Source # | |
Additive Integer Source # | |
Additive Natural Source # | |
(SubGroup q, Additive (F (P q))) => Additive (E q) Source # | |
PrimeField p => Additive (F p) Source # | |
SubGroup q => Additive (Encryption q) Source # | Additive homomorphism.
Using the fact that: |
Defined in Protocol.Election zero :: Encryption q Source # (+) :: Encryption q -> Encryption q -> Encryption q Source # sum :: Foldable f => f (Encryption q) -> Encryption q Source # |
class PrimeField p where Source #
Parameter for a prime field.
fieldCharac :: Natural Source #
The prime number characteristic of a PrimeField
.
ElGamal's hardness to decrypt requires a large prime number
to form the Multiplicative
SubGroup
.
Instances
PrimeField BeleniosParams Source # | |
Defined in Protocol.Arithmetic | |
PrimeField WeakParams Source # | |
Defined in Protocol.Arithmetic |
The type of the elements of a PrimeField
.
A field must satisfy the following properties:
(f, (
forms an abelian group, called the+
),zero
)Additive
group off
.(
forms an abelian group, called theNonNull
f, (*
),one
)Multiplicative
group off
.- (
*
) is associative:(a
and*
b)*
c == a*
(b*
c)a
.*
(b*
c) == (a*
b)*
c - (
*
) and (+
) are both commutative:a
and*
b == b*
aa
+
b == b+
a - (
*
) and (+
) are both left and right distributive:a
and*
(b+
c) == (a*
b)+
(a*
c)(a
+
b)*
c == (a*
c)+
(b*
c)
The Natural
is always within [0..
.fieldCharac
-1]
Instances
Eq (F p) Source # | |
Ord (F p) Source # | |
Show (F p) Source # | |
PrimeField p => Random (F p) Source # | |
ToNatural (F p) Source # | |
PrimeField p => FromNatural (F p) Source # | |
Defined in Protocol.Arithmetic fromNatural :: Natural -> F p Source # | |
PrimeField p => Multiplicative (F p) Source # | |
PrimeField p => Negable (F p) Source # | |
PrimeField p => Additive (F p) Source # | |
hash :: SubGroup q => ByteString -> [G q] -> E q Source #
(
returns as a number in hash
bs gs)E
the SHA256 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
.
(^) :: SubGroup q => G q -> E q -> G q infixr 8 Source #
(b
returns the modular exponentiation of base ^
e)b
by exponent e
.
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 representing arbitrary-precision non-negative integers.
>>>
2^100 :: Natural
1267650600228229401496703205376
Operations whose result would be negative
,throw
(Underflow
:: ArithException
)
>>>
-1 :: Natural
*** Exception: arithmetic underflow
Since: base-4.8.0.0