module DH:sig
..end
DH
module implements Diffie-Hellman key agreement.
Key agreement is a protocol by which two parties can establish
a shared secret (typically a key for a symmetric cipher or MAC)
by exchanging messages, with the guarantee that even if an attacker
eavesdrop on the messages, he cannot recover the shared secret.
Diffie-Hellman is one such key agreement protocol, relying on
the difficulty of computing discrete logarithms. Notice that
the Diffie-Hellman protocol is vulnerable to active attacks
(man-in-the-middle attacks).
The protocol executes as follows:
Cryptokit.DH.parameters
). Suitable parameters
can be generated by calling Cryptokit.DH.new_parameters
,
or fixed parameters taken from the literature can be used.Cryptokit.DH.private_secret
.Cryptokit.DH.message
,
and sends it to the other party.Cryptokit.DH.shared_secret
to its private secret and to the
message received from the other party.Cryptokit.DH.derive_key
.type
parameters = {
|
p : |
(* | Large prime number | *) |
|
g : |
(* | Generator of Z/pZ | *) |
|
privlen : |
(* | Length of private secrets in bits | *) |
val new_parameters : ?rng:Cryptokit.Random.rng -> ?privlen:int -> int -> parameters
p
parameter.
It must be large enough that the discrete logarithm problem modulo
p
is computationally unsolvable. 1024 is a reasonable value.
The optional rng
argument specifies a random number generator
to use for generating the parameters; it defaults to
Cryptokit.Random.secure_rng
. The optional privlen
argument
is the size in bits of the private secrets that are generated
during the key agreement protocol; the default is 160.type
private_secret
val private_secret : ?rng:Cryptokit.Random.rng ->
parameters -> private_secret
rng
argument specifies a random number generator
to use; it defaults to Cryptokit.Random.secure_rng
.val message : parameters -> private_secret -> string
parameters -> private_secret -> string -> string
: p
parameter. The private secret is destroyed and can no
longer be used afterwards.val derive_key : ?diversification:string -> string -> int -> string
derive_key shared_secret numbytes
derives a secret string
(typically, a key for symmetric encryption) from the given shared
secret. numbytes
is the desired length for the returned string.
The optional diversification
argument is an arbitrary string
that defaults to the empty string. Different secret strings can
be obtained from the same shared secret by supplying different
diversification
argument. The computation of the secret
string is performed by SHA-1 hashing of the diversification
string, followed by the shared secret, followed by an integer
counter. The hashing is repeated with increasing values of the
counter until numbytes
bytes have been obtained.