| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Voting.Protocol.FFC
Contents
Description
Finite Field Cryptography (FFC) is a method of implementing discrete logarithm cryptography using finite field mathematics.
Synopsis
- class ToNatural a where
- class FromNatural a where
- fromNatural :: Natural -> a
- newtype E c = E {}
- newtype G c = G {}
- class Multiplicative a => Invertible a where
- class Multiplicative a where
- class Additive a => Negable a where
- class Additive a where
- newtype F c = F {}
- data FFC = FFC {
- ffc_name :: Text
- ffc_fieldCharac :: !Natural
- ffc_groupGen :: !Natural
- ffc_groupOrder :: !Natural
- fieldCharac :: forall c. Reifies c FFC => Natural
- groupGen :: forall c. Reifies c FFC => G c
- groupOrder :: forall c. Reifies c FFC => Natural
- weakFFC :: FFC
- beleniosFFC :: FFC
- groupGenInverses :: forall c. Reifies c FFC => [G c]
- groupGenPowers :: forall c. Reifies c FFC => [G c]
- hash :: Reifies c FFC => ByteString -> [G c] -> E c
- (^) :: Reifies c FFC => G c -> E c -> G 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
- bytesNat :: ToNatural n => n -> ByteString
- data Natural
- class RandomGen g
- class Reifies (s :: k) a | s -> a where
- reflect :: proxy s -> a
- reify :: a -> (forall s. Reifies s a => Proxy s -> r) -> r
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
Documentation
class FromNatural a where Source #
Methods
fromNatural :: Natural -> a Source #
Instances
| Reifies c FFC => FromNatural (E c) Source # | |
Defined in Voting.Protocol.FFC Methods fromNatural :: Natural -> E c Source # | |
| Reifies c FFC => FromNatural (G c) Source # | |
Defined in Voting.Protocol.FFC Methods fromNatural :: Natural -> G c Source # | |
| Reifies c FFC => FromNatural (F c) Source # | |
Defined in Voting.Protocol.FFC Methods fromNatural :: Natural -> F c Source # | |
An exponent of a (necessarily cyclic) subgroup of a Finite Prime Field.
The value is always in [0...groupOrder-1]
Instances
| Reifies c FFC => Enum (E c) Source # | |
| Eq (E c) Source # | |
| Ord (E c) Source # | |
| Show (E c) Source # | |
| ToJSON (E c) Source # | |
Defined in Voting.Protocol.FFC | |
| Reifies c FFC => FromJSON (E c) Source # | |
| NFData (E c) Source # | |
Defined in Voting.Protocol.FFC | |
| Reifies c FFC => Random (E c) Source # | |
| ToNatural (E c) Source # | |
| Reifies c FFC => FromNatural (E c) Source # | |
Defined in Voting.Protocol.FFC Methods fromNatural :: Natural -> E c Source # | |
| Reifies c FFC => Multiplicative (E c) Source # | |
| Reifies c FFC => Negable (E c) Source # | |
| Reifies c FFC => Additive (E c) Source # | |
The type of the elements of a Multiplicative subgroup of a Finite Prime Field.
Instances
| Eq (G c) Source # | |
| Ord (G c) Source # | |
| Show (G c) Source # | |
| ToJSON (G c) Source # | |
Defined in Voting.Protocol.FFC | |
| Reifies c FFC => FromJSON (G c) Source # | |
| NFData (G c) Source # | |
Defined in Voting.Protocol.FFC | |
| ToNatural (G c) Source # | |
| Reifies c FFC => FromNatural (G c) Source # | |
Defined in Voting.Protocol.FFC Methods fromNatural :: Natural -> G c Source # | |
| Reifies c FFC => Invertible (G c) Source # | |
| Reifies c FFC => Multiplicative (G c) Source # | |
class Multiplicative a => Invertible a where Source #
Minimal complete definition
class Multiplicative a where Source #
Instances
| Multiplicative Int Source # | |
| Multiplicative Integer Source # | |
| Multiplicative Natural Source # | |
| Reifies c FFC => Multiplicative (E c) Source # | |
| Reifies c FFC => Multiplicative (G c) Source # | |
| Reifies c FFC => Multiplicative (F c) Source # | |
class Additive a => Negable a where Source #
Minimal complete definition
class Additive a where Source #
Instances
| Additive Int Source # | |
| Additive Integer Source # | |
| Additive Natural Source # | |
| Reifies c FFC => Additive (E c) Source # | |
| Reifies c FFC => Additive (F c) Source # | |
| Reifies c FFC => Additive (Encryption c) Source # | Additive homomorphism.
Using the fact that: |
Defined in Voting.Protocol.Election Methods zero :: Encryption c Source # (+) :: Encryption c -> Encryption c -> Encryption c Source # sum :: Foldable f => f (Encryption c) -> Encryption c Source # | |
The type of the elements of a Finite Prime Field.
A field must satisfy the following properties:
(f, (forms an abelian group, called the+),zero)Additivegroup off.(forms an abelian group, called theNonNullf, (*),one)Multiplicativegroup off.- (
*) is associative:(aand*b)*c == a*(b*c)a.*(b*c) == (a*b)*c - (
*) and (+) are both commutative:aand*b == b*aa+b == b+a - (
*) and (+) are both left and right distributive:aand*(b+c) == (a*b)+(a*c)(a+b)*c == (a*c)+(b*c)
The Natural is always within [0...fieldCharac-1]
Instances
| Eq (F c) Source # | |
| Ord (F c) Source # | |
| Show (F c) Source # | |
| ToJSON (F c) Source # | |
Defined in Voting.Protocol.FFC | |
| Reifies c FFC => FromJSON (F c) Source # | |
| NFData (F c) Source # | |
Defined in Voting.Protocol.FFC | |
| Reifies c FFC => Random (F c) Source # | |
| ToNatural (F c) Source # | |
| Reifies c FFC => FromNatural (F c) Source # | |
Defined in Voting.Protocol.FFC Methods fromNatural :: Natural -> F c Source # | |
| Reifies c FFC => Multiplicative (F c) Source # | |
| Reifies c FFC => Negable (F c) Source # | |
| Reifies c FFC => Additive (F c) Source # | |
Mutiplicative Sub-Group of a Finite Prime Field.
NOTE: an FFC term-value is brought into the context of many functions
through a type-variable c whose Reifies constraint enables to reflect
that FFC at the term-level (a surprising technique but a very useful one).
Doing like this is simpler than working in a Monad (like a Reader),
and enables that FFC term to be used simply in instances' methods
not supporting an inner Monad, like parseJSON, randomR, fromEnum or arbitrary.
Aside from that, the sharing of FFC amongst several types
is encoded at the type-level by including c
as a phantom type of F, G and E.
Constructors
| FFC | |
Fields
| |
Instances
| Eq FFC Source # | |
| Show FFC Source # | |
| Generic FFC Source # | |
| ToJSON FFC Source # | |
Defined in Voting.Protocol.FFC | |
| FromJSON FFC Source # | |
| NFData FFC Source # | |
Defined in Voting.Protocol.FFC | |
| type Rep FFC Source # | |
Defined in Voting.Protocol.FFC type Rep FFC = D1 (MetaData "FFC" "Voting.Protocol.FFC" "hjugement-protocol-0.0.0.20190519-C0jAKryjQbCA8A0oOhdfpH" False) (C1 (MetaCons "FFC" PrefixI True) ((S1 (MetaSel (Just "ffc_name") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text) :*: S1 (MetaSel (Just "ffc_fieldCharac") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Natural)) :*: (S1 (MetaSel (Just "ffc_groupGen") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Natural) :*: S1 (MetaSel (Just "ffc_groupOrder") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Natural)))) | |
beleniosFFC :: FFC Source #
Parameters used in Belenios.
A 2048-bit fieldCharac of a Finite Prime Field,
with a 256-bit groupOrder for a Multiplicative subgroup
generated by groupGen.
hash :: Reifies c FFC => ByteString -> [G c] -> E c 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.
(^) :: Reifies c FFC => G c -> E c -> G c 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 :: Natural1267650600228229401496703205376
Operations whose result would be negative ,throw (Underflow :: ArithException)
>>>-1 :: Natural*** Exception: arithmetic underflow
Since: base-4.8.0.0
Instances
The class RandomGen provides a common interface to random number
generators.
class Reifies (s :: k) a | s -> a where #
Methods
Recover a value inside a reify context, given a proxy for its
reified type.
Instances
| KnownNat n => Reifies (n :: Nat) Integer | |
Defined in Data.Reflection | |
| KnownSymbol n => Reifies (n :: Symbol) String | |
Defined in Data.Reflection | |
| Reifies Z Int | |
Defined in Data.Reflection | |
| Reifies n Int => Reifies (D n :: Type) Int | |
Defined in Data.Reflection | |
| Reifies n Int => Reifies (SD n :: Type) Int | |
Defined in Data.Reflection | |
| Reifies n Int => Reifies (PD n :: Type) Int | |
Defined in Data.Reflection | |
| (B b0, B b1, B b2, B b3, B b4, B b5, B b6, B b7, w0 ~ W b0 b1 b2 b3, w1 ~ W b4 b5 b6 b7) => Reifies (Stable w0 w1 a :: Type) a | |
Defined in Data.Reflection | |
reify :: a -> (forall s. Reifies s a => Proxy s -> r) -> r #
Reify a value at the type level, to be recovered with reflect.
data Proxy (t :: k) :: forall k. k -> Type #
Proxy is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically, is a safer alternative to the
Proxy :: Proxy a'undefined :: a' idiom.
>>>Proxy :: Proxy (Void, Int -> Int)Proxy
Proxy can even hold types of higher kinds,
>>>Proxy :: Proxy EitherProxy
>>>Proxy :: Proxy FunctorProxy
>>>Proxy :: Proxy complicatedStructureProxy
Constructors
| Proxy |
Instances
| Generic1 (Proxy :: k -> Type) | |
| Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
| Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| ToJSON1 (Proxy :: Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Proxy a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Proxy a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Proxy a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Proxy a] -> Encoding # | |
| FromJSON1 (Proxy :: Type -> Type) | |
| Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
| Bounded (Proxy t) | Since: base-4.7.0.0 |
| Enum (Proxy s) | Since: base-4.7.0.0 |
| Eq (Proxy s) | Since: base-4.7.0.0 |
| Ord (Proxy s) | Since: base-4.7.0.0 |
| Read (Proxy t) | Since: base-4.7.0.0 |
| Show (Proxy s) | Since: base-4.7.0.0 |
| Ix (Proxy s) | Since: base-4.7.0.0 |
Defined in Data.Proxy | |
| Generic (Proxy t) | |
| Semigroup (Proxy s) | Since: base-4.9.0.0 |
| Monoid (Proxy s) | Since: base-4.7.0.0 |
| Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
| ToJSON (Proxy a) | |
Defined in Data.Aeson.Types.ToJSON | |
| FromJSON (Proxy a) | |
| NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
| type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
| type Rep (Proxy t) | Since: base-4.6.0.0 |