Verified Commit 1b4a40bf authored by Vincent Bernardoff's avatar Vincent Bernardoff Committed by Grégoire Henry

Crypto: adapt code to new `bip39`, `pbkdf`

parent b9eba66b
Pipeline #28250957 passed with stages
in 18 minutes and 55 seconds
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment