0
$\begingroup$

I am building a cryptocurrency wallet online where everything is stored in the browser (No servers).

At this moment I am storing all private keys encrypted using AES-128-CTR I've chosen this method because is the standard for Ethereum keystore file format.

Is this algorithm secure to encrypt any other private key such Bitcoin (which is not hexadecimal)?

Would it be also secure to encrypt 12 words mnemonic or any other string?

Here is my implementation: https://github.com/elevenyellow/coinfy/blob/master/miscellaneous/experiments/aes-ctr-128.js


Edit: @SAI Peregrinus says on his response that my implementation is completely insecure which make me think, is the same for myetherwallet.com? Because my code is just a refactor of this: https://github.com/kvhnuke/etherwallet/blob/44074daeef3f98ca15410158b5a5403ac734a08a/app/scripts/myetherwallet.js#L196


Edit2: Studiying the geth (Ethereum go) client implementation I don't see any difference except for the parameter kdf.n where their value is 262144 and mine is 1024:

https://github.com/ethereum/go-ethereum/blob/bedf6f40aff0dd14bfab533a37c329ddc9a4bdd5/accounts/keystore/keystore_passphrase.go#L118

$\endgroup$

closed as off-topic by e-sushi Jan 25 '18 at 6:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ As noted in the “put on hold” reason: requests for reviewing full cryptographic designs (and sourcecode) are off-topic. $\endgroup$ – e-sushi Jan 25 '18 at 14:22
2
$\begingroup$

This is not secure at all. It's technically off-topic since it's a coding question, but this implementation contains many basic errors. One example is using an insecure random number generator, which utterly destroys the security of the encryption. Another is using AES-128-CTR without authentication. Do not try to implement your own cryptographic primitives, it takes a ton of work and is prone to obscure errors causing total failure. Use an existing library that provides constructions based on secure primitives that do what you need. That pretty much means libsodium, libhydrogen, tweetnacl-js, or a similar library.

If you use libsodium there's a version compiled to JS: https://github.com/jedisct1/libsodium.js

Documentation here: https://download.libsodium.org/doc/

You're looking for the authenticated encryption functions (crypto_secretbox_easy and its helpers).

Libsodium can encrypt whatever you want. Also the bitcoin private keys are just bitstrings, just like the Ethereum private keys. They can be represented in hexadecimal just as easily as any other encoding.

$\endgroup$
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$ – e-sushi Jan 25 '18 at 14:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.