~
This commit is contained in:
parent
1e30753ba9
commit
7bba7ebd9a
2 changed files with 16 additions and 19 deletions
|
|
@ -159,37 +159,35 @@ end = struct
|
||||||
binary-encoded objects with just the R and S values *)
|
binary-encoded objects with just the R and S values *)
|
||||||
type t = string
|
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 sign ~key s = Mirage_crypto_ec.Ed25519.sign ~key s
|
||||||
|
|
||||||
let verify ~key s ~msg =
|
let verify ~key s ~msg =
|
||||||
let b = Mirage_crypto_ec.Ed25519.verify ~key s ~msg in
|
let b = Mirage_crypto_ec.Ed25519.verify ~key s ~msg in
|
||||||
match b with
|
match b with
|
||||||
| false -> Error "signature verification failure: invalid signature"
|
| false -> Error "EddsaSignature verification: invalid signature"
|
||||||
| true -> Ok ()
|
| true -> Ok ()
|
||||||
|
|
||||||
let to_octets t = t
|
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 =
|
let of_octets v =
|
||||||
match String.length v = 64 with
|
let+ () = check_size v in
|
||||||
| false ->
|
v
|
||||||
Fmt.error "EddsaSignature.of_octets failure: data is not 64 bytes."
|
|
||||||
| true -> Ok v
|
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let of_octets_exn t = of_octets t |> Result.get_ok in
|
let of_octets_exn t = of_octets t |> Result.get_ok in
|
||||||
Bin.map (Bin.bytes 64) of_octets_exn to_octets
|
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 jsont =
|
||||||
let of_b32 s =
|
let of_b32 s =
|
||||||
let* t = B32.decode s in
|
let* t = B32.decode s in
|
||||||
let+ () = check_size t in
|
of_octets t
|
||||||
t
|
|
||||||
in
|
in
|
||||||
let to_b32 = B32.encode in
|
let to_b32 = B32.encode in
|
||||||
Jsont.of_of_string ~kind:"EddsaSignature" of_b32 ~enc:to_b32
|
Jsont.of_of_string ~kind:"EddsaSignature" of_b32 ~enc:to_b32
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
(* TODO signatures
|
(* TODO signatures
|
||||||
check with taler-wallet-core/src/crypto/cryptoImplementation.js
|
check with taler-wallet
|
||||||
check signed/unsigned ints
|
check signed/unsigned ints
|
||||||
check endianness
|
check endianness *)
|
||||||
|
|
||||||
better handling of decoding failure *)
|
|
||||||
open Hash
|
open Hash
|
||||||
|
|
||||||
module Aliases = struct
|
module Aliases = struct
|
||||||
|
|
@ -177,8 +175,9 @@ end = struct
|
||||||
type r = R.r
|
type r = R.r
|
||||||
type t = EddsaSignature.t
|
type t = EddsaSignature.t
|
||||||
|
|
||||||
let sign_f ~f r = f (Bin.to_string R.bin r)
|
let to_string = Bin.to_string R.bin
|
||||||
let verify_f ~f t r = f t ~msg:(Bin.to_string R.bin r)
|
let sign_f ~f r = f (to_string r)
|
||||||
|
let verify_f ~f t r = f t ~msg:(to_string r)
|
||||||
let jsont = EddsaSignature.jsont
|
let jsont = EddsaSignature.jsont
|
||||||
let caqti : EddsaSignature.t Caqti_type.t = EddsaSignature.caqti
|
let caqti : EddsaSignature.t Caqti_type.t = EddsaSignature.caqti
|
||||||
let to_octets t = EddsaSignature.to_octets t
|
let to_octets t = EddsaSignature.to_octets t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue