From 1b4a40bf767ad19813ddabfec1cbd7a21e7802d2 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Mon, 2 Jul 2018 11:51:19 +0200 Subject: [PATCH] Crypto: adapt code to new `bip39`, `pbkdf` --- src/lib_client_commands/client_keys_commands.ml | 6 +++--- src/lib_signer_backends/encrypted.ml | 5 +---- src/proto_alpha/lib_client/client_proto_context.ml | 5 +++-- src/proto_alpha/lib_protocol/test/activation.ml | 8 ++++++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib_client_commands/client_keys_commands.ml b/src/lib_client_commands/client_keys_commands.ml index 649cfe568..74945941f 100644 --- a/src/lib_client_commands/client_keys_commands.ml +++ b/src/lib_client_commands/client_keys_commands.ml @@ -146,9 +146,9 @@ let rec input_fundraiser_params (cctxt : #Client_context.io_wallet) = cctxt#prompt_password "Enter the password used for the paper wallet: " >>=? fun password -> (* TODO: unicode normalization (NFKD)... *) - let sk = - Bip39.to_seed ~passphrase:(email ^ MBytes.to_string password) t in - let sk = Cstruct.(to_bigarray (sub sk 0 32)) in + let passphrase = MBytes.(concat "" [of_string email ; password]) in + let sk = Bip39.to_seed ~passphrase t in + let sk = MBytes.sub sk 0 32 in let sk : Signature.Secret_key.t = Ed25519 (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in diff --git a/src/lib_signer_backends/encrypted.ml b/src/lib_signer_backends/encrypted.ml index 789aa0f99..da127093f 100644 --- a/src/lib_signer_backends/encrypted.ml +++ b/src/lib_signer_backends/encrypted.ml @@ -43,10 +43,7 @@ module Raw = struct let encrypted_size = Crypto_box.boxzerobytes + 32 let pbkdf ~salt ~password = - Cstruct.to_bigarray - (Pbkdf.pbkdf2 ~prf:`SHA512 ~count:32768 ~dk_len:32l - ~salt: (Cstruct.of_bigarray salt) - ~password: (Cstruct.of_bigarray password)) + Pbkdf.SHA512.pbkdf2 ~count:32768 ~dk_len:32l ~salt ~password let encrypt ~password sk = let salt = Rand.generate salt_len in diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 09fb24066..328208a78 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -305,8 +305,9 @@ let read_key key = failwith "" | Some t -> (* TODO: unicode normalization (NFKD)... *) - let sk = Bip39.to_seed ~passphrase:(key.email ^ key.password) t in - let sk = Cstruct.(to_bigarray (sub sk 0 32)) in + let passphrase = MBytes.(concat "" [of_string key.email ; of_string key.password]) in + let sk = Bip39.to_seed ~passphrase t in + let sk = MBytes.sub sk 0 32 in let sk : Signature.Secret_key.t = Ed25519 (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in let pk = Signature.Secret_key.to_public_key sk in diff --git a/src/proto_alpha/lib_protocol/test/activation.ml b/src/proto_alpha/lib_protocol/test/activation.ml index d91b348ba..4fc57e6ff 100644 --- a/src/proto_alpha/lib_protocol/test/activation.ml +++ b/src/proto_alpha/lib_protocol/test/activation.ml @@ -73,8 +73,12 @@ let secrets () = | None -> assert false | Some t -> (* TODO: unicode normalization (NFKD)... *) - let sk = Bip39.to_seed ~passphrase:(email ^ password) t in - let sk = Cstruct.(to_bigarray (sub sk 0 32)) in + let passphrase = MBytes.(concat "" [ + of_string email ; + of_string password ; + ]) in + let sk = Bip39.to_seed ~passphrase t in + let sk = MBytes.sub sk 0 32 in let sk : Signature.Secret_key.t = Ed25519 (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in let pk = Signature.Secret_key.to_public_key sk in