diff --git a/src/secmod.ml b/src/secmod.ml index 548338b6..79b13fae 100644 --- a/src/secmod.ml +++ b/src/secmod.ml @@ -20,6 +20,30 @@ type t = { Hashtbl.t; } +let sign_with_sm_key t s = EddsaSignature.sign ~key:t.sm_key_priv s + +let verify_with_sm_key t s ~msg = + match EddsaSignature.verify ~key:t.sm_key_pub s ~msg with + | false -> Error "signature verification failure: invalid signature" + | true -> Ok () + +let sign_with_signkey t ~pub s = + Miou.Mutex.protect t.lock @@ fun () -> + match Hashtbl.find_opt t.sk_ht pub with + | None -> Error "secmod failure: public key not found." + | Some signkey -> + let v = EddsaSignature.sign ~key:signkey.priv s in + Ok v + +let verify_with_signkey t ~pub s ~msg = + Miou.Mutex.protect t.lock @@ fun () -> + match Hashtbl.find_opt t.sk_ht pub with + | None -> Error "secmod failure: public key not found." + | Some signkey -> ( + match EddsaSignature.verify ~key:signkey.pub s ~msg with + | false -> Error "signature verification failure: invalid signature" + | true -> Ok ()) + let get_sm_key_priv t = t.sm_key_priv let get_sm_key_pub t = t.sm_key_pub diff --git a/src/secmod.mli b/src/secmod.mli index ba897b50..2d1b289d 100644 --- a/src/secmod.mli +++ b/src/secmod.mli @@ -2,6 +2,15 @@ open Crypto type t +val sign_with_sm_key : t -> string -> eddsa_sig +val verify_with_sm_key : t -> eddsa_sig -> msg:string -> (unit, string) result + +val sign_with_signkey : + t -> pub:eddsa_pub -> string -> (eddsa_sig, string) result + +val verify_with_signkey : + t -> pub:eddsa_pub -> eddsa_sig -> msg:string -> (unit, string) result + val get_sm_key_priv : t -> eddsa_priv val get_sm_key_pub : t -> eddsa_pub val get_signkeys : t -> Signkey_data.t list