mte/src/secmod_keys.ml
2025-10-17 15:09:50 +02:00

46 lines
1.1 KiB
OCaml

type t = {
pub: Mirage_crypto_ec.Ed25519.pub;
sign:
(* TODO sig type
should be
string -> EddsaSignature.t
+ b32 *)
string ->
string;
stamp_start: Ptime.t;
stamp_expire: Ptime.t;
stamp_end: Ptime.t;
}
let make ~name =
let finally _key = () in
Vif.Device.v ~name ~finally [] @@ fun () ->
(* TODO
- look if it exists
- if not, create it (TOFU initialization scheme)
- write it *)
(* TODO time
correctly set those: *)
let stamp_start = Ptime_clock.now () in
let stamp_expire =
match Ptime.add_span stamp_start Config.Exchange.signkey_legal_duration with
| None ->
Fmt.failwith "Ptime.add_span: result is not in the range [min;max]"
| Some v -> v
in
let stamp_end = stamp_expire in
let priv, pub = Mirage_crypto_ec.Ed25519.generate () in
{
pub;
sign= Mirage_crypto_ec.Ed25519.sign ~key:priv;
stamp_start;
stamp_expire;
stamp_end;
}
let signkey_device = make ~name:"signkey"
(* the actual exchange's signing key
signed by the secmod signkey *)
let exchange_device = make ~name:"exchange"
let denom_device = make ~name:"denom"