Author

Topic: Encrypt Wallet (Read 1043 times)

hero member
Activity: 672
Merit: 504
a.k.a. gurnec on GitHub
July 27, 2014, 12:08:36 PM
#10
This is exactly what I want to know. It is very helpful and thanks a lot!

But then I came up with a question (probably very silly), what if this wallet.dat file is manually being deleted, is there any backup itself ?

Bitcoin Core does not make any automated backups. You need to either backup the wallet.dat file yourself (but only when Bitcoin isn't running), or use the Backup Wallet option in the menu. Backups should be created at least once for every 100 new receiving addresses created.

Some clients do perform automated backups (of course, backups to the same hard drive aren't all that useful...):
  • Armory maintains one backup file.
  • MultiBit Classic creates new backup files after each new receiving address is created.
  • Blockchain.info by default keeps a local backup in addition to encrypted wallet stored on their servers, and they have options for other types of off-site backups as well.
  • Armory and Electrum, being deterministic, both have backup-to-paper options which only need be done once at wallet creation.
hero member
Activity: 784
Merit: 500
July 27, 2014, 10:52:56 AM
#9

Thanks a lot! But what is IIRC?

"If I remember correctly". It's not actually a crypto term that applies to the algo.
newbie
Activity: 10
Merit: 0
July 27, 2014, 10:52:17 AM
#8
I assume you are talking about the wallet.dat bitcoin core uses, other clients might work differently.

The wallet.dat contains (among other data) your private keys, thus it is essential for the security of yours coin that they are protected. The algorithm used is AES256 IIRC.

This will indeed make the file unreadable while encrypted.

Thanks a lot! But what is IIRC?
newbie
Activity: 10
Merit: 0
July 27, 2014, 10:41:38 AM
#7
It's complicated  Wink

The wallet.dat file itself is a set of key/value pairs in Berkeley DB BTREE v9 format. Most of it is not encrypted, except for certain values including the private keys themselves and the master key. More specifically:

A 32-byte random master key or "mkey" is generated using OpenSSL's RAND_bytes(). This PRNG is seeded by /dev/urandom on Linux or by CryptGenRandom() on Windows. Additionally on Windows, Bitcoin adds additional entropy from a screen shot and from Windows perfmon counters (possibly because OpenSSL didn't use CryptGenRandom() in early versions?).

The mkey is used as an encryption key to encrypt each individual Bitcoin private key using AES-256 in CBC mode with PKCS7 padding and an initialization vector of SHA-256(SHA-256(the respective public key)).

Your password, plus an 8-byte salt which is initially generated using RAND_bytes() and stored in wallet.dat, is fed into PBKDF1-SHA-512 (normal PBKDF1 doesn't use SHA-512) with a certain number of iterations (stored in wallet.dat) to generate 512 bits of derived key data. The iteration count is initially set such that it will take about 1/10th of a second to run the iterations on whichever CPU the password is added (or modified).

This derived data is divided into three parts. The first 256 bits are used as an encryption key, the next 128 bits are used as in initialization vector, and the remaining bits are discarded. This encryption key and initialization vector are then used to encrypt the mkey (again using using AES-256 in CBC mode with PKCS7 padding), and the encrypted mkey is stored in wallet.dat.

Upon a password change, only the encrypted mkey needs to be recomputed and written back to wallet.dat, while it's unencrypted value and all of the Bitcoin private keys which it encrypts remain unchanged.

This is exactly what I want to know. It is very helpful and thanks a lot!

But then I came up with a question (probably very silly), what if this wallet.dat file is manually being deleted, is there any backup itself ?
hero member
Activity: 672
Merit: 504
a.k.a. gurnec on GitHub
July 27, 2014, 08:54:29 AM
#6
We have backed up the wallet

Why should we encrypt the wallet?

Thanks !

Back up the wallet to avoid being locked out. Encrypt it to avoid having your coins stolen.

Malware (viruses) has become very clever (it's big business these days). If malware does manage to find its way onto your computer, it can easily steal your wallet if you don't encrypt it. Even if you do encrypt it, more sophisticated malware can still steal your wallet (read up on "keyloggers" for more details).

If this concerns you, and it should if you have a lot of Bitcoin stored in your wallet that you can't afford to lose, read up on how to use cold storage.
hero member
Activity: 784
Merit: 500
July 26, 2014, 08:00:48 PM
#5
We have backed up the wallet

Why should we encrypt the wallet?

Thanks !

Back up the wallet to avoid being locked out. Encrypt it to avoid having your coins stolen.
member
Activity: 62
Merit: 10
July 26, 2014, 07:52:11 PM
#4
What do encrypt wallet actually do in the Bitcoin code?

More specifically, I am curious what it encrypts, what algorithm it use and the outcome of the encryption (maybe just a unreadable file?).



We have backed up the wallet

Why should we encrypt the wallet?

Thanks !
hero member
Activity: 672
Merit: 504
a.k.a. gurnec on GitHub
July 26, 2014, 01:17:19 PM
#3
It's complicated  Wink

The wallet.dat file itself is a set of key/value pairs in Berkeley DB BTREE v9 format. Most of it is not encrypted, except for certain values including the private keys themselves and the master key. More specifically:

A 32-byte random master key or "mkey" is generated using OpenSSL's RAND_bytes(). This PRNG is seeded by /dev/urandom on Linux or by CryptGenRandom() on Windows. Additionally on Windows, Bitcoin adds additional entropy from a screen shot and from Windows perfmon counters (possibly because OpenSSL didn't use CryptGenRandom() in early versions?).

The mkey is used as an encryption key to encrypt each individual Bitcoin private key using AES-256 in CBC mode with PKCS7 padding and an initialization vector of SHA-256(SHA-256(the respective public key)).

Your password, plus an 8-byte salt which is initially generated using RAND_bytes() and stored in wallet.dat, is fed into PBKDF1-SHA-512 (normal PBKDF1 doesn't use SHA-512) with a certain number of iterations (stored in wallet.dat) to generate 512 bits of derived key data. The iteration count is initially set such that it will take about 1/10th of a second to run the iterations on whichever CPU the password is added (or modified).

This derived data is divided into three parts. The first 256 bits are used as an encryption key, the next 128 bits are used as in initialization vector, and the remaining bits are discarded. This encryption key and initialization vector are then used to encrypt the mkey (again using using AES-256 in CBC mode with PKCS7 padding), and the encrypted mkey is stored in wallet.dat.

Upon a password change, only the encrypted mkey needs to be recomputed and written back to wallet.dat, while it's unencrypted value and all of the Bitcoin private keys which it encrypts remain unchanged.
copper member
Activity: 1498
Merit: 1528
No I dont escrow anymore.
July 26, 2014, 04:34:21 AM
#2
I assume you are talking about the wallet.dat bitcoin core uses, other clients might work differently.

The wallet.dat contains (among other data) your private keys, thus it is essential for the security of yours coin that they are protected. The algorithm used is AES256 IIRC.

This will indeed make the file unreadable while encrypted.
newbie
Activity: 10
Merit: 0
July 26, 2014, 03:26:56 AM
#1
What do encrypt wallet actually do in the Bitcoin code?

More specifically, I am curious what it encrypts, what algorithm it use and the outcome of the encryption (maybe just a unreadable file?).

Jump to: