Represent Diffie Hellman parameters namely P (prime), and G (generator).
Modulecrypton-2.1.7Haskell2010
Crypto.PubKey.ElGamal
ElGamal encryption and signature over the multiplicative group of integers modulo a prime, reusing the parameters of Crypto.PubKey.DH.
These are raw primitives, not a scheme. The encryption here is textbook
ElGamal: it applies no padding, so it is malleable by construction --
multiplying a ciphertext's second component by t multiplies the plaintext
by t -- and it is not IND-CCA secure. A message is an Integer below the
modulus rather than a byte string, and nothing here maps one to the other.
Use it to build a scheme that adds those, or prefer
Crypto.PubKey.RSA.OAEP or Crypto.PubKey.ECIES where a scheme is what is
wanted.
The signature primitive is likewise raw, and an ephemeral value must never
be reused between signatures: two signatures under the same k reveal the
private key.
What is kept from the clock, and what is not
Every exponentiation with a secret exponent is
expSafe. Decryption inverts the shared
secret by Fermat's little theorem rather than by the extended Euclidean
algorithm, whose steps follow the bits it is given. sign cannot do that
-- k is inverted modulo p-1, which is even -- so it blinds instead: the
algorithm is handed k times a fresh random unit, and the blinder is
divided out afterwards. signWith, having no randomness of its own, hands
it k.
What is left is the Integer arithmetic around all of that, whose cost follows the size of the numbers. See Crypto.PubKey.DSA for the same note at more length.
- 6 types
- 8 values
- Packagecrypton-2.1.7
- Exports14
- LanguageHaskell2010
- LicenceBSD-3-Clause AND MIT AND ISC
- SourceElGamal.hs
Represent Diffie Hellman public number Y.
Instances8Enum, Eq, Num, Ord, Read, Real, …
Enum PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHEq PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHNum PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHOrd PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHRead PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHReal PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHShow PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHNFData PublicNumberDefined in crypton-2.1.7 · Crypto.PubKey.DH
Represent Diffie Hellman private number X.
Instances9Enum, Eq, Num, Ord, Read, Real, …
Enum PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHEq PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHNum PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHOrd PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHRead PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHReal PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHShow PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHThe number is not shown. Use debugShow to see it.
NFData PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DHDebugShow PrivateNumberDefined in crypton-2.1.7 · Crypto.PubKey.DH
ElGamal Ephemeral key. also called Temporary key.
Constructors
Instances1NFData
NFData EphemeralKeyDefined in crypton-2.1.7 · Crypto.PubKey.ElGamal
Instances5Eq, Data, Read, Show, NFData
Eq SignatureDefined in crypton-2.1.7 · Crypto.PubKey.ElGamalData SignatureDefined in crypton-2.1.7 · Crypto.PubKey.ElGamalRead SignatureDefined in crypton-2.1.7 · Crypto.PubKey.ElGamalShow SignatureDefined in crypton-2.1.7 · Crypto.PubKey.ElGamalNFData SignatureDefined in crypton-2.1.7 · Crypto.PubKey.ElGamal
Generation
2 declarationsgenerate a private number, in [1, q-1] where q is the order of the
group. Zero is excluded: it would make the public number 1 and the shared
value constant.
generate a public number that is for the other party benefits. this number is usually called h=g^a
Encryption and decryption with no scheme
3 declarationsencrypt with a specified ephemeral key
The ephemeral key must lie in [1, p-2] and must never be reused: zero
would leave the message unmasked, and a repeat lets anyone who learns one
plaintext recover the other. A message must be below the modulus, or
decryption would return it reduced.
encrypt a message using params and public keys will generate b (called the ephemeral key)
decrypt message
c1 must be a unit modulo p; a ciphertext whose first component is zero
or out of range is rejected rather than raising.
Signature primitives
2 declarationssignWith :: (ByteArrayAccess msg, HashAlgorithm hash)=> Integerephemeral value k, in [1, p-2] and coprime with p-1
-> ParamsDH params (p,g)
-> PrivateNumberDH private key
-> hashcollision resistant hash algorithm
-> msgmessage to sign
-> Maybe Signature
sign a message with an explicit ephemeral value
k has to lie in [1, p-2] and be coprime with p-1. Nothing says the
value handed in cannot be used: either it fails one of those two conditions,
or it is one of the few that produce a second component of zero. Either way
the answer is to draw another k, which is what sign does.
k is an ephemeral private key. It has to be drawn uniformly at random,
kept secret, and used for one signature only: the private number follows
from a signature and its k, and equally from two signatures made with the
same k. None of that is visible to this function, which is why it takes
k from the caller and checks only what it can.
sign :: (ByteArrayAccess msg, HashAlgorithm hash, MonadRandom m)=> ParamsDH params (p,g)
-> PrivateNumberDH private key
-> hashcollision resistant hash algorithm
-> msgmessage to sign
-> m Signature
Verification primitives
1 declarationverify a signature