2018-06-29 16:08:08 +04:00
|
|
|
(*****************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Open Source License *)
|
|
|
|
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
|
|
|
(* copy of this software and associated documentation files (the "Software"),*)
|
|
|
|
(* to deal in the Software without restriction, including without limitation *)
|
|
|
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
|
|
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
|
|
|
(* Software is furnished to do so, subject to the following conditions: *)
|
|
|
|
(* *)
|
|
|
|
(* The above copyright notice and this permission notice shall be included *)
|
|
|
|
(* in all copies or substantial portions of the Software. *)
|
|
|
|
(* *)
|
|
|
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
|
|
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
|
|
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
|
|
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
|
|
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
|
|
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
|
|
|
(* DEALINGS IN THE SOFTWARE. *)
|
|
|
|
(* *)
|
|
|
|
(*****************************************************************************)
|
2016-11-03 22:15:31 +04:00
|
|
|
|
|
|
|
(** Tezos - X25519/XSalsa20-Poly1305 cryptography *)
|
|
|
|
|
2018-04-06 01:22:30 +04:00
|
|
|
type nonce = Bigstring.t
|
|
|
|
val nonce_size : int
|
2016-11-03 22:15:31 +04:00
|
|
|
|
2018-02-06 22:16:26 +04:00
|
|
|
val zero_nonce : nonce
|
2016-11-03 22:15:31 +04:00
|
|
|
val random_nonce : unit -> nonce
|
|
|
|
val increment_nonce : ?step:int -> nonce -> nonce
|
2016-11-16 04:19:13 +04:00
|
|
|
|
2018-05-18 18:57:43 +04:00
|
|
|
(** [generate_nonces ~incoming ~sent_msg ~recv_msg] generates two
|
|
|
|
nonces by hashing (Blake2B) the arguments. The nonces should be
|
|
|
|
used to initialize the encryption on the communication
|
|
|
|
channels. Because an attacker cannot control both messages,
|
|
|
|
it cannot determine the nonces that will be used to encrypt
|
|
|
|
the messages. The sent message should contains a random nonce,
|
|
|
|
and we should never send the exact same message twice. *)
|
|
|
|
val generate_nonces :
|
|
|
|
incoming:bool -> sent_msg:MBytes.t -> recv_msg:MBytes.t -> nonce * nonce
|
|
|
|
|
2018-02-06 22:16:26 +04:00
|
|
|
module Secretbox : sig
|
|
|
|
type key
|
|
|
|
|
2018-04-06 01:22:30 +04:00
|
|
|
val unsafe_of_bytes : MBytes.t -> key
|
2018-02-06 22:16:26 +04:00
|
|
|
|
2018-04-06 01:22:30 +04:00
|
|
|
val box_noalloc : key -> nonce -> MBytes.t -> unit
|
|
|
|
val box_open_noalloc : key -> nonce -> MBytes.t -> bool
|
2018-02-06 22:16:26 +04:00
|
|
|
|
|
|
|
val box : key -> MBytes.t -> nonce -> MBytes.t
|
|
|
|
val box_open : key -> MBytes.t -> nonce -> MBytes.t option
|
|
|
|
end
|
|
|
|
|
2016-11-18 00:02:32 +04:00
|
|
|
type target
|
2016-11-19 02:07:27 +04:00
|
|
|
val default_target : target
|
2017-01-23 14:09:51 +04:00
|
|
|
val make_target : float -> target
|
2016-11-18 00:02:32 +04:00
|
|
|
|
2016-11-16 04:19:13 +04:00
|
|
|
type secret_key
|
|
|
|
type public_key
|
2018-02-08 13:51:01 +04:00
|
|
|
module Public_key_hash : S.HASH
|
2017-01-14 16:13:49 +04:00
|
|
|
type channel_key
|
2016-11-16 04:19:13 +04:00
|
|
|
|
2017-01-14 16:13:49 +04:00
|
|
|
val hash : public_key -> Public_key_hash.t
|
2018-02-04 21:39:34 +04:00
|
|
|
|
|
|
|
val zerobytes : int
|
|
|
|
val boxzerobytes : int
|
|
|
|
|
2017-01-14 16:13:49 +04:00
|
|
|
val random_keypair : unit -> secret_key * public_key * Public_key_hash.t
|
2016-11-16 04:19:13 +04:00
|
|
|
|
2017-01-14 16:13:49 +04:00
|
|
|
val precompute : secret_key -> public_key -> channel_key
|
2018-02-04 21:39:34 +04:00
|
|
|
|
2017-01-14 16:13:49 +04:00
|
|
|
val fast_box : channel_key -> MBytes.t -> nonce -> MBytes.t
|
|
|
|
val fast_box_open : channel_key -> MBytes.t -> nonce -> MBytes.t option
|
|
|
|
|
2018-02-04 21:39:34 +04:00
|
|
|
val fast_box_noalloc : channel_key -> nonce -> MBytes.t -> unit
|
|
|
|
val fast_box_open_noalloc : channel_key -> nonce -> MBytes.t -> bool
|
|
|
|
|
2016-11-18 00:02:32 +04:00
|
|
|
val check_proof_of_work : public_key -> nonce -> target -> bool
|
2017-01-23 14:09:48 +04:00
|
|
|
val generate_proof_of_work : ?max:int -> public_key -> target -> nonce
|
2017-01-14 16:13:49 +04:00
|
|
|
|
2018-02-08 13:51:01 +04:00
|
|
|
val public_key_to_bigarray : public_key -> Cstruct.buffer
|
|
|
|
val public_key_of_bigarray : Cstruct.buffer -> public_key
|
|
|
|
val public_key_size : int
|
|
|
|
|
|
|
|
val secret_key_to_bigarray : secret_key -> Cstruct.buffer
|
|
|
|
val secret_key_of_bigarray : Cstruct.buffer -> secret_key
|
|
|
|
val secret_key_size : int
|
2018-02-04 21:39:34 +04:00
|
|
|
|
2018-04-03 13:44:11 +04:00
|
|
|
val public_key_encoding : public_key Data_encoding.t
|
|
|
|
val secret_key_encoding : secret_key Data_encoding.t
|
|
|
|
val nonce_encoding : nonce Data_encoding.t
|