package tls

  1. Overview
  2. Docs
include module type of struct include X509.Private_key end

Private keys

The type for private keys

type t = [
  1. | `RSA of Mirage_crypto_pk.Rsa.priv
  2. | `ED25519 of Mirage_crypto_ec.Ed25519.priv
  3. | `P224 of Mirage_crypto_ec.P224.Dsa.priv
  4. | `P256 of Mirage_crypto_ec.P256.Dsa.priv
  5. | `P384 of Mirage_crypto_ec.P384.Dsa.priv
  6. | `P521 of Mirage_crypto_ec.P521.Dsa.priv
]

The polymorphic variant of private keys.

Constructing private keys

val generate : ?seed:Cstruct.t -> ?bits:int -> X509.Key_type.t -> t

generate ~seed ~bits type generates a private key of the given key type. The argument bits is only used for the bit length of RSA keys. If seed is provided, this is used to seed the random number generator.

val of_cstruct : Cstruct.t -> X509.Key_type.t -> (t, [> Rresult.R.msg ]) Rresult.result

of_cstruct data decodes the buffer as private key. Only supported for elliptic curve keys.

Operations on private keys

val key_type : t -> X509.Key_type.t

key_type priv is the key type of priv.

val public : t -> X509.Public_key.t

public priv is the corresponding public key of priv.

Cryptographic sign operation

val sign : Mirage_crypto.Hash.hash -> ?scheme:X509.Key_type.signature_scheme -> t -> [ `Digest of Cstruct.t | `Message of Cstruct.t ] -> (Cstruct.t, [> Rresult.R.msg ]) Rresult.result

sign hash ~scheme key data signs data with key using hash and scheme. If data is `Message _, the hash will be applied before the signature. The scheme defaults to `RSA_PSS for RSA keys, `ED25519 for ED25519, and `ECDSA for other EC keys.

Decoding and encoding in ASN.1 DER and PEM format

val decode_der : Cstruct.t -> (t, [> Rresult.R.msg ]) Rresult.result

decode_der der is t, where the private key of der is extracted. It must be in PKCS8 (RFC 5208, Section 5) PrivateKeyInfo structure.

val encode_der : t -> Cstruct.t

encode_der key is der, the encoded private key as PKCS8 (RFC 5208, Section 5) PrivateKeyInfo structure.

val decode_pem : Cstruct.t -> (t, [> Rresult.R.msg ]) Rresult.result

decode_pem pem is t, where the private key of pem is extracted. Both RSA PRIVATE KEY and PRIVATE KEY stanzas are supported.

val encode_pem : t -> Cstruct.t

encode_pem key is pem, the encoded private key (using PRIVATE KEY).

val sexp_of_t : 'a -> Sexplib.Sexp.t
OCaml

Innovation. Community. Security.