Module Nocrypto.Dh

module Dh: sig .. end
Diffie-Hellman, MODP version.


Diffie-Hellman key exchange


exception Invalid_public_key
Raised if the public key is degenerate. Implies either badly malfunctioning DH on the other side, or an attack attempt.
type group = {
   p : Z.t; (*
modulus
*)
   gg : Z.t; (*
generator
*)
   q : Z.t option; (*
subgroup order; potentially unknown
*)
}
A DH group.

Sexplib convertible.

type secret = private {
   x : Z.t;
}
A private secret.

Sexplib convertible.

val modulus_size : group -> int
Bit size of the modulus.
val key_of_secret : group -> s:Cstruct.t -> secret * Cstruct.t
key_of_secret group s is the Nocrypto.Dh.secret and the corresponding public key which use s as the secret exponent.
Raises Invalid_public_key if s is degenerate.
val gen_key : ?g:Nocrypto.Rng.g ->
?bits:int -> group -> secret * Cstruct.t
Generate a random Nocrypto.Dh.secret and the corresponding public key. bits is the exact bit-size of Nocrypto.Dh.secret and defaults to a value dependent on the Nocrypto.Dh.group's p.
val shared : group -> secret -> Cstruct.t -> Cstruct.t option
shared group secret message is Some key, the shared key, given a group, a previously generated Nocrypto.Dh.secret and the other party's public message. It is None if message is degenerate.
val gen_group : ?g:Nocrypto.Rng.g -> int -> group
gen_group bits generates a random Nocrypto.Dh.group with modulus size bits. Uses a safe prime p = 2q + 1 (with q prime) for the modulus and 2 for the generator, such that 2^q = 1 mod p. Runtime is on the order of minute for 1024 bits.
Raises Invalid_argument if bits is ridiculously small.
module Group: sig .. end
A small catalog of standardized Nocrypto.Dh.groups.