Crypto: adapt code to new bip39, pbkdf

This commit is contained in:
Vincent Bernardoff 2018-07-02 11:51:19 +02:00 committed by Grégoire Henry
parent b9eba66b4c
commit 1b4a40bf76
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2
4 changed files with 13 additions and 11 deletions

View File

@ -146,9 +146,9 @@ let rec input_fundraiser_params (cctxt : #Client_context.io_wallet) =
cctxt#prompt_password cctxt#prompt_password
"Enter the password used for the paper wallet: " >>=? fun password -> "Enter the password used for the paper wallet: " >>=? fun password ->
(* TODO: unicode normalization (NFKD)... *) (* TODO: unicode normalization (NFKD)... *)
let sk = let passphrase = MBytes.(concat "" [of_string email ; password]) in
Bip39.to_seed ~passphrase:(email ^ MBytes.to_string password) t in let sk = Bip39.to_seed ~passphrase t in
let sk = Cstruct.(to_bigarray (sub sk 0 32)) in let sk = MBytes.sub sk 0 32 in
let sk : Signature.Secret_key.t = let sk : Signature.Secret_key.t =
Ed25519 Ed25519
(Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in

View File

@ -43,10 +43,7 @@ module Raw = struct
let encrypted_size = Crypto_box.boxzerobytes + 32 let encrypted_size = Crypto_box.boxzerobytes + 32
let pbkdf ~salt ~password = let pbkdf ~salt ~password =
Cstruct.to_bigarray Pbkdf.SHA512.pbkdf2 ~count:32768 ~dk_len:32l ~salt ~password
(Pbkdf.pbkdf2 ~prf:`SHA512 ~count:32768 ~dk_len:32l
~salt: (Cstruct.of_bigarray salt)
~password: (Cstruct.of_bigarray password))
let encrypt ~password sk = let encrypt ~password sk =
let salt = Rand.generate salt_len in let salt = Rand.generate salt_len in

View File

@ -305,8 +305,9 @@ let read_key key =
failwith "" failwith ""
| Some t -> | Some t ->
(* TODO: unicode normalization (NFKD)... *) (* TODO: unicode normalization (NFKD)... *)
let sk = Bip39.to_seed ~passphrase:(key.email ^ key.password) t in let passphrase = MBytes.(concat "" [of_string key.email ; of_string key.password]) in
let sk = Cstruct.(to_bigarray (sub sk 0 32)) in let sk = Bip39.to_seed ~passphrase t in
let sk = MBytes.sub sk 0 32 in
let sk : Signature.Secret_key.t = let sk : Signature.Secret_key.t =
Ed25519 (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in Ed25519 (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in
let pk = Signature.Secret_key.to_public_key sk in let pk = Signature.Secret_key.to_public_key sk in

View File

@ -73,8 +73,12 @@ let secrets () =
| None -> assert false | None -> assert false
| Some t -> | Some t ->
(* TODO: unicode normalization (NFKD)... *) (* TODO: unicode normalization (NFKD)... *)
let sk = Bip39.to_seed ~passphrase:(email ^ password) t in let passphrase = MBytes.(concat "" [
let sk = Cstruct.(to_bigarray (sub sk 0 32)) in 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 = let sk : Signature.Secret_key.t =
Ed25519 (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in Ed25519 (Data_encoding.Binary.of_bytes_exn Ed25519.Secret_key.encoding sk) in
let pk = Signature.Secret_key.to_public_key sk in let pk = Signature.Secret_key.to_public_key sk in