add secmod sign_with_xx
This commit is contained in:
parent
f69f393abb
commit
5ef99e7099
2 changed files with 33 additions and 0 deletions
|
|
@ -20,6 +20,30 @@ type t = {
|
||||||
Hashtbl.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_priv t = t.sm_key_priv
|
||||||
let get_sm_key_pub t = t.sm_key_pub
|
let get_sm_key_pub t = t.sm_key_pub
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,15 @@ open Crypto
|
||||||
|
|
||||||
type t
|
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_priv : t -> eddsa_priv
|
||||||
val get_sm_key_pub : t -> eddsa_pub
|
val get_sm_key_pub : t -> eddsa_pub
|
||||||
val get_signkeys : t -> Signkey_data.t list
|
val get_signkeys : t -> Signkey_data.t list
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue