Crypto: adapt code to new bip39
, pbkdf
This commit is contained in:
parent
b9eba66b4c
commit
1b4a40bf76
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user