Key material. In elliptic curve terms, a scalar.
To generate a key pair, use gen_key.
In the usual setting, the private key only be generated and used for key exchange. But it can be useful to create values of type secret with a known value, for example to check against test vectors. One can use the following pattern to do this:
let (secret, _) = gen_key ~rng:(fun _ -> known_data) Generate a key pair. rng should return a Cstruct.t with the specified key length (in bytes) and fill it with random bytes.
If the cstruct returned by rng does not have the correct length, raises Failure _.
val pp_error : Stdlib.Format.formatter -> error -> unitPretty printer for errors
val key_exchange : secret -> Cstruct.t -> (Cstruct.t, error) Stdlib.resultPerform Diffie-Hellman key exchange between a private part and a public part.
It checks length of the pub key and returns an error if it has an incorrect length.
In DH terms, the private part corresponds to a scalar, and the public part corresponds to a point, and this computes the scalar multiplication.
The resulting shared secret is not truncated.
As described in RFC 7748, section 6.1, this function might internally generate an all-zero value. If this is the case Error `Low_order will be returned instead. This check is necessary in the context of TLS 1.3, but might not in other protocols.