better secmod
This commit is contained in:
parent
77d5327745
commit
283ad65a10
24 changed files with 1231 additions and 1022 deletions
|
|
@ -119,6 +119,7 @@ module EddsaPrivateKey = struct
|
|||
|
||||
type t = priv
|
||||
|
||||
let generate = generate
|
||||
let pub_of_priv = pub_of_priv
|
||||
let to_octets t = priv_to_octets t
|
||||
|
||||
|
|
@ -159,37 +160,35 @@ end = struct
|
|||
binary-encoded objects with just the R and S values *)
|
||||
type t = string
|
||||
|
||||
(* mirage_crypto: "The result is the concatenation of r and s, as specified in RFC 8032." *)
|
||||
(* mirage_crypto:
|
||||
"The result is the concatenation of r and s, as specified in RFC 8032." *)
|
||||
let sign ~key s = Mirage_crypto_ec.Ed25519.sign ~key s
|
||||
|
||||
let verify ~key s ~msg =
|
||||
let b = Mirage_crypto_ec.Ed25519.verify ~key s ~msg in
|
||||
match b with
|
||||
| false -> Error "signature verification failure: invalid signature"
|
||||
| false -> Error "EddsaSignature verification: invalid signature"
|
||||
| true -> Ok ()
|
||||
|
||||
let to_octets t = t
|
||||
|
||||
let check_size t =
|
||||
match String.length t = 64 with
|
||||
| false -> Error "EddsaSignature of_octets: data is not 64 bytes."
|
||||
| true -> Ok ()
|
||||
|
||||
let of_octets v =
|
||||
match String.length v = 64 with
|
||||
| false ->
|
||||
Fmt.error "EddsaSignature.of_octets failure: data is not 64 bytes."
|
||||
| true -> Ok v
|
||||
let+ () = check_size v in
|
||||
v
|
||||
|
||||
let bin =
|
||||
let of_octets_exn t = of_octets t |> Result.get_ok in
|
||||
Bin.map (Bin.bytes 64) of_octets_exn to_octets
|
||||
|
||||
let check_size t =
|
||||
match String.length t = 64 with
|
||||
| false -> Error "EddsaSignature: invalid string length"
|
||||
| true -> Ok ()
|
||||
|
||||
let jsont =
|
||||
let of_b32 s =
|
||||
let* t = B32.decode s in
|
||||
let+ () = check_size t in
|
||||
t
|
||||
of_octets t
|
||||
in
|
||||
let to_b32 = B32.encode in
|
||||
Jsont.of_of_string ~kind:"EddsaSignature" of_b32 ~enc:to_b32
|
||||
|
|
@ -208,6 +207,7 @@ module RsaPublicKey = struct
|
|||
|
||||
let to_octets = Binary_format_rsa.pub_to_octets
|
||||
let of_octets = Binary_format_rsa.pub_of_octets
|
||||
let to_b32 t = B32.encode (to_octets t)
|
||||
|
||||
let jsont =
|
||||
let of_b32 s =
|
||||
|
|
@ -215,7 +215,6 @@ module RsaPublicKey = struct
|
|||
let+ v = of_octets s in
|
||||
v
|
||||
in
|
||||
let to_b32 t = B32.encode (to_octets t) in
|
||||
Jsont.of_of_string ~kind:"RsaPublicKey" of_b32 ~enc:to_b32
|
||||
|
||||
let caqti : t Caqti_type.t =
|
||||
|
|
@ -253,9 +252,14 @@ module RsaSignature : sig
|
|||
type t
|
||||
|
||||
val jsont : t Jsont.t
|
||||
val sign : key:RsaPrivateKey.t -> string -> t
|
||||
end = struct
|
||||
type t = string
|
||||
|
||||
(* TODO crypto
|
||||
this is a placeholder signature algorithm *)
|
||||
let sign ~key s = Mirage_crypto_pk.Rsa.PKCS1.sig_encode ~key s
|
||||
|
||||
let jsont =
|
||||
let of_b32 s = B32.decode s in
|
||||
let to_b32 t = B32.encode t in
|
||||
|
|
@ -269,7 +273,7 @@ type eddsa_sig = EddsaSignature.t
|
|||
type rsa_priv = RsaPrivateKey.t
|
||||
type rsa_pub = RsaPublicKey.t
|
||||
type rsa_sig = RsaSignature.t
|
||||
type denomination_hash = Hash.DenominationHash.t
|
||||
type denom_hash = Hash.DenominationHash.t
|
||||
|
||||
(* WIP *)
|
||||
module FDH_RSA = struct
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue