Crypto: replace nocrypto sha256 with hacl

This commit is contained in:
Marco Stronati 2018-05-05 00:27:15 +02:00 committed by Vincent Bernardoff
parent b619b29483
commit 5a26d23cf7
4 changed files with 12 additions and 16 deletions

View File

@ -65,20 +65,20 @@ module Step : sig
end = struct
type state = int * int * Cstruct.t
type state = int * int * MBytes.t
let init seed head =
let seed =
Nocrypto.Hash.digest `SHA256 @@
Cstruct.concat
[ Cstruct.of_bigarray @@ P2p_peer.Id.to_bytes seed.sender_id ;
Cstruct.of_bigarray @@ P2p_peer.Id.to_bytes seed.receiver_id ;
Cstruct.of_bigarray @@ Block_hash.to_bytes head ] in
(1, 9, seed)
let open Hacl.Hash in
let st = SHA256.init () in
List.iter (SHA256.update st) [
P2p_peer.Id.to_bytes seed.sender_id ;
P2p_peer.Id.to_bytes seed.receiver_id ;
Block_hash.to_bytes head ] ;
(1, 9, SHA256.finish st)
let draw seed n =
Int32.to_int (MBytes.get_int32 (Cstruct.to_bigarray seed) 0) mod n,
Nocrypto.Hash.digest `SHA256 seed
Int32.to_int (MBytes.get_int32 seed 0) mod n,
Hacl.Hash.SHA256.digest seed
let next (step, counter, seed) =
let random_gap, seed =

View File

@ -112,11 +112,9 @@ let raw_decode ?(alphabet=Alphabet.default) s =
let checksum s =
let hash =
Nocrypto.Hash.digest `SHA256 @@
Nocrypto.Hash.digest `SHA256 @@
Cstruct.of_string s in
Hacl.Hash.SHA256.(digest (digest (Bigstring.of_string s))) in
let res = Bytes.make 4 '\000' in
Cstruct.blit_to_bytes hash 0 res 0 4 ;
Bigstring.blit_to_bytes hash 0 res 0 4 ;
Bytes.to_string res
(* Append a 4-bytes cryptographic checksum before encoding string s *)

View File

@ -15,7 +15,6 @@
tezos-rpc
tezos-clic
lwt
nocrypto
blake2
hacl
secp256k1

View File

@ -15,7 +15,6 @@ depends: [
"tezos-rpc"
"tezos-clic"
"lwt"
"nocrypto"
"blake2"
"hacl"
"zarith"