Crypto: sign 32 bytes message hash
This commit is contained in:
parent
47f9c2460b
commit
54bbc71c1b
@ -265,12 +265,6 @@ let sign key msg = Sign.detached ~key msg
|
|||||||
let check public_key signature msg =
|
let check public_key signature msg =
|
||||||
Sign.verify_detached ~key:public_key ~signature msg
|
Sign.verify_detached ~key:public_key ~signature msg
|
||||||
|
|
||||||
let append key msg =
|
|
||||||
MBytes.concat msg (sign key msg)
|
|
||||||
|
|
||||||
let concat msg signature =
|
|
||||||
MBytes.concat msg signature
|
|
||||||
|
|
||||||
module Seed = struct
|
module Seed = struct
|
||||||
|
|
||||||
type t = Bigstring.t
|
type t = Bigstring.t
|
||||||
|
@ -203,14 +203,8 @@ module type SIGNATURE = sig
|
|||||||
|
|
||||||
val zero: t
|
val zero: t
|
||||||
|
|
||||||
(** Check a signature *)
|
|
||||||
val check: Public_key.t -> t -> MBytes.t -> bool
|
|
||||||
|
|
||||||
(** Append a signature *)
|
|
||||||
val append: Secret_key.t -> MBytes.t -> MBytes.t
|
|
||||||
val concat: MBytes.t -> t -> MBytes.t
|
|
||||||
|
|
||||||
val sign: Secret_key.t -> MBytes.t -> t
|
val sign: Secret_key.t -> MBytes.t -> t
|
||||||
|
val check: Public_key.t -> t -> MBytes.t -> bool
|
||||||
|
|
||||||
val generate_key: unit -> (Public_key_hash.t * Public_key.t * Secret_key.t)
|
val generate_key: unit -> (Public_key_hash.t * Public_key.t * Secret_key.t)
|
||||||
|
|
||||||
|
@ -245,12 +245,6 @@ let sign sk msg =
|
|||||||
let check public_key signature msg =
|
let check public_key signature msg =
|
||||||
Sign.verify_exn context ~pk:public_key ~msg ~signature
|
Sign.verify_exn context ~pk:public_key ~msg ~signature
|
||||||
|
|
||||||
let concat msg t =
|
|
||||||
MBytes.concat msg (Sign.to_bytes ~der:false context t)
|
|
||||||
|
|
||||||
let append sk msg =
|
|
||||||
concat msg (Sign.sign_exn context ~sk msg)
|
|
||||||
|
|
||||||
let generate_key () =
|
let generate_key () =
|
||||||
let sk = Key.read_sk_exn context (Rand.generate 32) in
|
let sk = Key.read_sk_exn context (Rand.generate 32) in
|
||||||
let pk = Key.neuterize_exn context sk in
|
let pk = Key.neuterize_exn context sk in
|
||||||
|
@ -432,12 +432,17 @@ let of_ed25519 s = Ed25519 s
|
|||||||
|
|
||||||
let zero = of_ed25519 Ed25519.zero
|
let zero = of_ed25519 Ed25519.zero
|
||||||
|
|
||||||
|
let hash msg =
|
||||||
|
Blake2B.(to_bytes (hash_bytes [msg]))
|
||||||
|
|
||||||
let sign secret_key message =
|
let sign secret_key message =
|
||||||
|
let message = hash message in
|
||||||
match secret_key with
|
match secret_key with
|
||||||
| Secret_key.Ed25519 sk -> of_ed25519 (Ed25519.sign sk message)
|
| Secret_key.Ed25519 sk -> of_ed25519 (Ed25519.sign sk message)
|
||||||
| Secret_key.Secp256k1 sk -> of_secp256k1 (Secp256k1.sign sk message)
|
| Secret_key.Secp256k1 sk -> of_secp256k1 (Secp256k1.sign sk message)
|
||||||
|
|
||||||
let check public_key signature message =
|
let check public_key signature message =
|
||||||
|
let message = hash message in
|
||||||
match public_key, signature with
|
match public_key, signature with
|
||||||
| Public_key.Ed25519 pk, Unknown signature -> begin
|
| Public_key.Ed25519 pk, Unknown signature -> begin
|
||||||
match Ed25519.of_bytes_opt signature with
|
match Ed25519.of_bytes_opt signature with
|
||||||
@ -456,10 +461,8 @@ let check public_key signature message =
|
|||||||
| Public_key.Ed25519 _, Secp256k1 _ -> false
|
| Public_key.Ed25519 _, Secp256k1 _ -> false
|
||||||
| Public_key.Secp256k1 _, Ed25519 _ -> false
|
| Public_key.Secp256k1 _, Ed25519 _ -> false
|
||||||
|
|
||||||
let append sk bytes =
|
let append sk msg =
|
||||||
match sk with
|
MBytes.concat msg (to_bytes (sign sk msg))
|
||||||
| Secret_key.Ed25519 s -> Ed25519.append s bytes
|
|
||||||
| Secret_key.Secp256k1 s -> Secp256k1.append s bytes
|
|
||||||
|
|
||||||
let concat msg signature =
|
let concat msg signature =
|
||||||
MBytes.concat msg (to_bytes signature)
|
MBytes.concat msg (to_bytes signature)
|
||||||
|
@ -23,6 +23,14 @@ include S.SIGNATURE with type Public_key_hash.t = public_key_hash
|
|||||||
and type Public_key.t = public_key
|
and type Public_key.t = public_key
|
||||||
and type Secret_key.t = secret_key
|
and type Secret_key.t = secret_key
|
||||||
|
|
||||||
|
val append : secret_key -> MBytes.t -> MBytes.t
|
||||||
|
(** [append sk buf] is the concatenation of [buf] and the
|
||||||
|
serialization of the signature of [buf] signed by [sk]. *)
|
||||||
|
|
||||||
|
val concat : MBytes.t -> t -> MBytes.t
|
||||||
|
(** [concat buf t] is the concatenation of [buf] and the serialization
|
||||||
|
of [t]. *)
|
||||||
|
|
||||||
include S.RAW_DATA with type t := t
|
include S.RAW_DATA with type t := t
|
||||||
|
|
||||||
type algo =
|
type algo =
|
||||||
|
@ -247,7 +247,5 @@ module type SIGNATURE = sig
|
|||||||
(** Check a signature *)
|
(** Check a signature *)
|
||||||
val check: Public_key.t -> t -> MBytes.t -> bool
|
val check: Public_key.t -> t -> MBytes.t -> bool
|
||||||
|
|
||||||
val concat: MBytes.t -> t -> MBytes.t
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -315,8 +315,6 @@ module Make (Context : CONTEXT) = struct
|
|||||||
(** Check a signature *)
|
(** Check a signature *)
|
||||||
val check: Public_key.t -> t -> MBytes.t -> bool
|
val check: Public_key.t -> t -> MBytes.t -> bool
|
||||||
|
|
||||||
val concat: MBytes.t -> t -> MBytes.t
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user