Shell: add Crypto_box.Public_key_hash
This commit is contained in:
parent
0b6aa16ca7
commit
7f091b38b9
@ -773,7 +773,7 @@ module Make (P: PARAMS) = struct
|
|||||||
let init_peers () =
|
let init_peers () =
|
||||||
let my_gid =
|
let my_gid =
|
||||||
fresh_gid () in
|
fresh_gid () in
|
||||||
let (my_secret_key, my_public_key) =
|
let (my_secret_key, my_public_key, _) =
|
||||||
Crypto_box.random_keypair () in
|
Crypto_box.random_keypair () in
|
||||||
let my_proof_of_work =
|
let my_proof_of_work =
|
||||||
Crypto_box.generate_proof_of_work
|
Crypto_box.generate_proof_of_work
|
||||||
|
@ -230,6 +230,7 @@ module Prefix = struct
|
|||||||
let operation_hash = "\001"
|
let operation_hash = "\001"
|
||||||
let protocol_hash = "\002"
|
let protocol_hash = "\002"
|
||||||
let ed25519_public_key_hash = "\003"
|
let ed25519_public_key_hash = "\003"
|
||||||
|
let cryptobox_public_key_hash = "\004"
|
||||||
let ed25519_public_key = "\012"
|
let ed25519_public_key = "\012"
|
||||||
let ed25519_secret_key = "\013"
|
let ed25519_secret_key = "\013"
|
||||||
let ed25519_signature = "\014"
|
let ed25519_signature = "\014"
|
||||||
|
@ -37,6 +37,9 @@ module Prefix : sig
|
|||||||
val ed25519_public_key_hash: string
|
val ed25519_public_key_hash: string
|
||||||
(** Prefix for Ed25519 public key hashes: "\003". *)
|
(** Prefix for Ed25519 public key hashes: "\003". *)
|
||||||
|
|
||||||
|
val cryptobox_public_key_hash: string
|
||||||
|
(** Prefix for Ed25519 public key hashes: "\004". *)
|
||||||
|
|
||||||
val ed25519_public_key: string
|
val ed25519_public_key: string
|
||||||
(** Prefix for Ed25519 public key: "\012". *)
|
(** Prefix for Ed25519 public key: "\012". *)
|
||||||
|
|
||||||
|
@ -18,7 +18,19 @@ type nonce = Sodium.Box.nonce
|
|||||||
type target = int64 list (* used as unsigned intergers... *)
|
type target = int64 list (* used as unsigned intergers... *)
|
||||||
exception TargetNot256Bit
|
exception TargetNot256Bit
|
||||||
|
|
||||||
let random_keypair = Sodium.Box.random_keypair
|
module Public_key_hash = Hash.Make_Blake2B (Base48) (struct
|
||||||
|
let name = "Crypto_box.Public_key_hash"
|
||||||
|
let title = "A Cryptobox public key ID"
|
||||||
|
let b48check_prefix = Base48.Prefix.cryptobox_public_key_hash
|
||||||
|
let size = Some 16
|
||||||
|
end)
|
||||||
|
|
||||||
|
let hash pk =
|
||||||
|
Public_key_hash.hash_bytes [Sodium.Box.Bigbytes.of_public_key pk]
|
||||||
|
|
||||||
|
let random_keypair () =
|
||||||
|
let sk, pk = Sodium.Box.random_keypair () in
|
||||||
|
sk, pk, hash pk
|
||||||
let random_nonce = Sodium.Box.random_nonce
|
let random_nonce = Sodium.Box.random_nonce
|
||||||
let increment_nonce = Sodium.Box.increment_nonce
|
let increment_nonce = Sodium.Box.increment_nonce
|
||||||
let box = Sodium.Box.Bigbytes.box
|
let box = Sodium.Box.Bigbytes.box
|
||||||
@ -26,6 +38,12 @@ let box_open sk pk msg nonce =
|
|||||||
try Some (Sodium.Box.Bigbytes.box_open sk pk msg nonce) with
|
try Some (Sodium.Box.Bigbytes.box_open sk pk msg nonce) with
|
||||||
| Sodium.Verification_failure -> None
|
| Sodium.Verification_failure -> None
|
||||||
|
|
||||||
|
let precompute = Sodium.Box.precompute
|
||||||
|
let fast_box = Sodium.Box.Bigbytes.fast_box
|
||||||
|
let fast_box_open ck msg nonce =
|
||||||
|
try Some (Sodium.Box.Bigbytes.fast_box_open ck msg nonce) with
|
||||||
|
| Sodium.Verification_failure -> None
|
||||||
|
|
||||||
let make_target target =
|
let make_target target =
|
||||||
if List.length target > 8 then raise TargetNot256Bit ;
|
if List.length target > 8 then raise TargetNot256Bit ;
|
||||||
target
|
target
|
||||||
|
@ -21,15 +21,22 @@ val default_target : target
|
|||||||
|
|
||||||
type secret_key
|
type secret_key
|
||||||
type public_key
|
type public_key
|
||||||
|
module Public_key_hash : Hash.HASH
|
||||||
|
type channel_key
|
||||||
|
|
||||||
val public_key_encoding : public_key Data_encoding.t
|
val public_key_encoding : public_key Data_encoding.t
|
||||||
val secret_key_encoding : secret_key Data_encoding.t
|
val secret_key_encoding : secret_key Data_encoding.t
|
||||||
|
|
||||||
val random_keypair : unit -> secret_key * public_key
|
val hash : public_key -> Public_key_hash.t
|
||||||
|
val random_keypair : unit -> secret_key * public_key * Public_key_hash.t
|
||||||
|
|
||||||
val box : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
|
val box : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
|
||||||
|
|
||||||
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t option
|
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t option
|
||||||
|
|
||||||
|
val precompute : secret_key -> public_key -> channel_key
|
||||||
|
val fast_box : channel_key -> MBytes.t -> nonce -> MBytes.t
|
||||||
|
val fast_box_open : channel_key -> MBytes.t -> nonce -> MBytes.t option
|
||||||
|
|
||||||
val check_proof_of_work : public_key -> nonce -> target -> bool
|
val check_proof_of_work : public_key -> nonce -> target -> bool
|
||||||
val generate_proof_of_work : public_key -> target -> nonce
|
val generate_proof_of_work : public_key -> target -> nonce
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user