Module type Rfc7748.DH
Signature of the modules implementing the Diffie-Hellman functions for RFC 7748.
Types
Constants
val base : public_key
The base point of the curve.
Key Conversion
val public_key_of_string : string -> public_key
Create a public key from a given string. The key is assumed to be encoded in hexadecimal and must have a length of
2*key_size
. The string is silently truncated (if too long) or padded (if too short). An exception is raised if the string contains characters that are not valid hexadecimal digits. The curves in RFC 7748 are specially crafted such that public keys received from untrusted sources can be used safely without validation.Note that the creation includes a canonicalization step and thus, in general,
string_of_public_key (public_key_of_string s) <> s
.
val private_key_of_string : string -> private_key
Create a private key from a given string. The key is assumed to be encoded in hexadecimal and must have a length of
2*key_size
. The string is silently truncated (if too long) or padded (if too short). An exception is raised if the string contains characters that are not valid hexadecimal digits. The curves in RFC 7748 are specially crafted such that any random sequence of bytes of the correct length can be used to create a private key.Note that the creation includes a canonicalization step and thus, in general,
string_of_private_key (private_key_of_string s) <> s
.
val string_of_public_key : public_key -> string
Convert the public key to its hex-encoded string representation.
val string_of_private_key : private_key -> string
Convert the private key to its hex-encoded string representation.
val public_key_of_bytes : Stdlib.Bytes.t -> public_key
Create a public key from a byte array of length
key_size
. An exception is raised if the array has the wrong size. Besides that, the function behaves likepublic_key_of_string
after hex-decoding. The array is not modified by this module, and it must not be modified externally while thepublic_key
object is in scope.
val private_key_of_bytes : Stdlib.Bytes.t -> private_key
Create a private key from a byte array of length
key_size
. An exception is raised if the array has the wrong size. Besides that, the function behaves likeprivate_key_of_string
after hex-decoding. The array is not modified by this module, and it must not be modified externally while thepublic_key
object is in scope.
val bytes_of_public_key : public_key -> Stdlib.Bytes.t
Create a byte array from the given public key.
val bytes_of_private_key : private_key -> Stdlib.Bytes.t
Create a byte array from the given private key.
Curve Operations
val scale : private_key -> public_key -> public_key
scale priv pub
is the scalar multiplication ofpub
bypriv
.
val public_key_of_private_key : private_key -> public_key
public_key_of_private_key priv
is equal toscale priv base