Author

Topic: How do i make sure my Bitcoin Private Key is Random and secure? (Read 275 times)

member
Activity: 126
Merit: 39
So this thing keeps giving me stress and i need answer  Huh

So i know bitcoin private key is secure and there are 2^256 private keys and i also understand that it's impossible for 2 people to generate the same btc private key.
BUT what i think is possible is a bitcoin wallet generating a bitcoin address whose private key is in the range of 1 to say 10000?? then it's vulnerable to attack right?
See basically a private key is an integer between 1 and 2^256 converted to hex right. So what's stopping Random number generator to pick a private key from say first few million integers??
Isn't this a vulnerability?
Of course, advanced user can simply convert their private key to hex and to decimal to check if it's a large enough integer but what about noobies?

Here -  https://privatekeys.pw/keys/bitcoin/1
You can see on the above link. Any attacker can easily brute force first few million private keys so how to prevent such attack?
If you want to check your key 🗝️ if it is not a secure and run on other platforms,
My mean go to the same big wallets that offer to open Bitcoin wallet. And if they unlcok than you should have to know that your key can be in Denver hands.
And also I have sent that in some wallets if we mischange words than we can open wallets and that could be so much easy to open.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
If you don't feel confident with your hardware, generate the entropy yourself in a provably random way. For example, make sure that a coin is fair enough[1], and toss it. You can use iancoleman's software for that (click on "Show entropy details"). Preferably use the entropy as a seed, and not as an individual private key.

[1] Simple trick to reduce coin bias: https://markd87.github.io/snippets/von_neumann_trick/
hero member
Activity: 862
Merit: 662
Use the next Linux command

Code:

Please read the next article if you have concerns about urandom

https://www.2uo.de/myths-about-urandom/
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
--snip--
The same applies to offline cold storage PC as well? If the system is not connected to internet.

Yes, internet usage is just one of many entropy source.

Then also there will be enough sources of entropy right?

Yes (assuming it's not headless or embedded device). But if you have very very very serious security concern, just run this command and make sure the value is either 256 (Linux kernel 5.10.119 or newer) or 4096 (Up to 5.10.118)[1].

Code:
cat /proc/sys/kernel/random/entropy_avail

[1] https://unix.stackexchange.com/a/704743
member
Activity: 77
Merit: 10
--snip--
so using CSPRNG on new OS installation and just after reboot is not secure enough?

An expert say it's not secure enough only when your device has very little activity (such as headless or embedded device)[1]. But his research was performed a decade ago, so i don't know if it's applicable in 2022. Besides, average customer PC have lots activity including mouse movement, keyboard input and various application which opened on background after you login. So i wouldn't worry about insufficient entropy.

So what time should i wait before booting system to make sure there's enough entropy?

According to research i mentioned earlier, at least 1 minute. Although i'd recommend to do some activity (such as checking system log, perform internet speed test or use file explorer) to increase the entropy instead.

Also i guess on live machine/VM it's not safe to use CSPRNG?

If both live machine and VM has lots of activity and you wait few minutes, i don't see reason why it's not safe.

[1] https://dl.acm.org/doi/10.5555/2362793.2362828

The same applies to offline cold storage PC as well? If the system is not connected to internet. Then also there will be enough sources of entropy right?
member
Activity: 77
Merit: 10
Here -  https://privatekeys.pw/keys/bitcoin/1
You can see on the above link. Any attacker can easily brute force first few million private keys so how to prevent such attack?

Private key/address on those website is generated on-demand (basically when you access the page). I would recommend you try clicking button "Random" or "Last" on that website. Actual attacker could brute force either from beginning, ending, other specific range of number or even randomly.

One last question. Is it more secure to generate a 24 word seed using dice/coins (manually) OR using CSPRNG present is software like electrum etc ?  Which is more secure?

People usually would say both option are secure enough. Although it's hard to say which one is more secure since there are many variable involved needed to answer the question (such as quality of the dice or whether you call CSPRNG just after boot on device with very little activity/input). But FYI, Electrum actually utilize CSPRNG provided by operating system through function os.random()[1]. Electrum would use /dev/urandom on linux/unix-based OS and CryptGenRandom() on Windows OS[1].

[1] https://github.com/spesmilo/electrum/blob/4.3.2/electrum/wallet.py#L433
[2] https://docs.python.org/3.10/library/os.html#os.urandom

so using CSPRNG on new OS installation and just after reboot is not secure enough? So what time should i wait before booting system to make sure there's enough entropy? Also i guess on live machine/VM it's not safe to use CSPRNG?
member
Activity: 77
Merit: 10

Sure. If you generate a private key that is a relatively small integer (or very close to the high end of the range, or one that coincides with a sha256 hash of any common phrase or password), then it would be vulnerable.


How do i specifically avoid this? If i generate a private key using secure wallet like hardware wallet or may be software wallet like electrum then how do i make sure it's not vulnerable to this? (a small integer/or coincides with SHA256 hash of common phrase) ? or the probability of this happening is not worth considering?
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
So i know bitcoin private key is secure and there are 2^256 private keys and i also understand that it's impossible for 2 people to generate the same btc private key.
BUT what i think is possible is a bitcoin wallet generating a bitcoin address whose private key is in the range of 1 to say 10000?? then it's vulnerable to attack right?

You would easily be able to notice that in an open-source wallet because the key would either be very tiny, very close to the maximum keys, or you would see a list of privkey hex characters the wallet selects from for no good reason. In closed source wallets you can't check this so that is another reason why to avoid such wallets.
legendary
Activity: 3472
Merit: 4801
So this thing keeps giving me stress and i need answer  Huh

It's going to be ok. Take some deep breaths. No need to stress.

So i know bitcoin private key is secure and there are 2^256 private keys and i also understand that it's impossible for 2 people to generate the same btc private key.

You're off to a good start. Already you understand more than the majority of crypto users.

BUT what i think is possible is a bitcoin wallet generating a bitcoin address whose private key is in the range of 1 to say 10000??

That depends on what you mean when you say "possible".

then it's vulnerable to attack right?

Sure. If you generate a private key that is a relatively small integer (or very close to the high end of the range, or one that coincides with a sha256 hash of any common phrase or password), then it would be vulnerable.

See basically a private key is an integer between 1 and 2^256 converted to hex right.

Effectively, yes.  Perhaps a better way to think of it is that a private key is an element of data that can be represented by a computer as a set of 256 binary digits.  Any set of binary digits can technically also be represented as a base10 integer, so therefore your private key (just like EVERYTHING a computer stores) can be represented as a base10 integer.

So what's stopping Random number generator to pick a private key from say first few million integers??

Probability.

If your private key is generated randomly, then what you are saying is that it is generated by randomly choosing either a 1 or a 0 for each one of the 256 binary digits. Ending up with a private key that translates to an integer less than 1,000,000,000,000 is equivalent to randomly flipping a completely balanced coin and having it come up the exact same way 216 TIMES IN A ROW, and then for the remaining 40 flips it sometimes comes up one way and sometimes the other.  Think about that for a bit, maybe even try it yourself with a coin.  How many lifetimes of the universe do you think you'd need to continuously flip that perfect coin before it would come up the same way 216 times in a row? Is it realistic that it will ever happen?  Is it "possible" the way a normal person would think of things being possible?

Isn't this a vulnerability?

No.

Of course, advanced user can simply convert their private key to hex and to decimal to check if it's a large enough integer

You could if you're actually concerned about it.

but what about noobies?

Regarding this concern, they'll be fine. There are MUCH more common problems for them to worry about and mess up.
legendary
Activity: 2380
Merit: 5213
One last question. Is it more secure to generate a 24 word seed using dice/coins (manually) OR using CSPRNG present is software like electrum etc ?  Which is more secure?
In both cases the seed phrase is generated completely randomly (assuming your dice is balanced and all the numbers have the same probability to be chosen) and is secure enough.
It may worth mentioning that, if you want 100% security, you should generate your seed phrase on an air-gapped device.
member
Activity: 77
Merit: 10
Regarding your answer to second question. I was not saying i am using brain wallet. Please read again.
I fully understood you.

I meant i generate a bitcoin private key using secure wallet say for example mycellium wallet which is completely random key BUT the private key that i got now is 100% a SHA256 hash of some random 'text'. so that text might be a 'word' from the dictionary. There's a chance for that. This is what i meant to ask.
There's a chance of that, but that's almost impossible.
If you know that any bitcoin address can be generated by 2^96 private keys on average, you may worry even more. But as I said in my previous post, a bitcoin private key provides enough security and there's nothing to worry about.


Ok thanks
One last question. Is it more secure to generate a 24 word seed using dice/coins (manually) OR using CSPRNG present is software like electrum etc ?  Which is more secure?
legendary
Activity: 2380
Merit: 5213
Regarding your answer to second question. I was not saying i am using brain wallet. Please read again.
I fully understood you.

I meant i generate a bitcoin private key using secure wallet say for example mycellium wallet which is completely random key BUT the private key that i got now is 100% a SHA256 hash of some random 'text'. so that text might be a 'word' from the dictionary. There's a chance for that. This is what i meant to ask.
There's a chance of that, but that's almost impossible.
If you know that any bitcoin address can be generated by 2^96 private keys on average, you may worry even more. But as I said in my previous post, a bitcoin private key provides enough security and there's nothing to worry about.
member
Activity: 77
Merit: 10
1.)I checked the electrum code and it also uses RNG that just picks a random number between 1 and 2^256 so therotically RNG can a pick a 10 digit number too? or am i missing something here?
That's true only in theory. The probability of getting a 10 digit number is almost zero.


2.) Second question i have is. We all know how SHA256 can be used to convert any 'text' to a hash which is a valid private key right a.k.a brain wallets.
It's not recommended to use brain wallets. It's recommended to generate a random private key.


So my question is what if my wallet generate a key which is secure but what if that key is SHA256 hash of some 'poor dictionary word'?
No. There is no risk. What you worry about can happen only in theory. A private key generated properly provides enough security.

Regarding your answer to second question. I was not saying i am using brain wallet. Please read again.
I meant i generate a bitcoin private key using secure wallet say for example mycellium wallet which is completely random key BUT the private key that i got now is 100% a SHA256 hash of some random 'text'. so that text might be a 'word' from the dictionary. There's a chance for that. This is what i meant to ask.
legendary
Activity: 2380
Merit: 5213
1.)I checked the electrum code and it also uses RNG that just picks a random number between 1 and 2^256 so therotically RNG can a pick a 10 digit number too? or am i missing something here?
That's true only in theory. The probability of getting a 10 digit number is almost zero.


2.) Second question i have is. We all know how SHA256 can be used to convert any 'text' to a hash which is a valid private key right a.k.a brain wallets.
It's not recommended to use brain wallets. It's recommended to generate a random private key.


So my question is what if my wallet generate a key which is secure but what if that key is SHA256 hash of some 'poor dictionary word'?
No. There is no risk. What you worry about can happen only in theory. A private key generated properly provides enough security.
member
Activity: 77
Merit: 10
ou can see on the above link. Any attacker can easily brute force first few million private keys so how to prevent such attack?

Use a good software. Never use a bad wallet when generating your private keys.

What are good software? The most recommended ones:
Electrum, ledger nano, trezor, blue wallet...

You may be using a bad software,  which might have a pior randomness and your private keys might be insecure. That is possible.
But if you generated your private keys using the software I suggested,  there is no risk of poor randomness

1.)I checked the electrum code and it also uses RNG that just picks a random number between 1 and 2^256 so therotically RNG can a pick a 10 digit number too? or am i missing something here?

2.) Second question i have is. We all know how SHA256 can be used to convert any 'text' to a hash which is a valid private key right a.k.a brain wallets.
So say i generate a very secure private key using very secure hardware wallet. so that private key is the hash of "some text" which we don't know because SHA256 is one way function but indeed there is "some text" on which we do SHA256 will give the same private key. So my question is what if my wallet generate a key which is secure but what if that key is SHA256 hash of some 'poor dictionary word'? There's no way to check this except comparing with all SHA256 of dictionary words. It's indeed a risk right? Am i being paranoid here?
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
See basically a private key is an integer between 1 and 2^256 converted to hex right. So what's stopping Random number generator to pick a private key from say first few million integers??
What's stopping the random number generator from doing that, is chance probability. What you're suggesting has a chance of 1 in (give or take) 100000000000000000000000000000000000000000000000000000000000000000000000 to happen. It's not going to happen, don't worry about it.
legendary
Activity: 2352
Merit: 6089
bitcoindata.science
ou can see on the above link. Any attacker can easily brute force first few million private keys so how to prevent such attack?

Use a good software. Never use a bad wallet when generating your private keys.

What are good software? The most recommended ones:
Electrum, ledger nano, trezor, blue wallet...

You may be using a bad software,  which might have a pior randomness and your private keys might be insecure. That is possible.
But if you generated your private keys using the software I suggested,  there is no risk of poor randomness
legendary
Activity: 2380
Merit: 5213
So i know bitcoin private key is secure and there are 2^256 private keys
Number of valid private keys is slightly less than 2256


it's impossible for 2 people to generate the same btc private key.
Not completely impossible. Almost impossible and very very unlikely.


BUT what i think is possible is a bitcoin wallet generating a bitcoin address whose private key is in the range of 1 to say 10000?? then it's vulnerable to attack right?
Yes, that's possible if the wallet hasn't been coded properly and that's why you should use always an open-source wallet to know how the keys are generated.


See basically a private key is an integer between 1 and 2^256 converted to hex right.
That's between 1 and FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140
member
Activity: 77
Merit: 10
So this thing keeps giving me stress and i need answer  Huh

So i know bitcoin private key is secure and there are 2^256 private keys and i also understand that it's impossible for 2 people to generate the same btc private key.
BUT what i think is possible is a bitcoin wallet generating a bitcoin address whose private key is in the range of 1 to say 10000?? then it's vulnerable to attack right?
See basically a private key is an integer between 1 and 2^256 converted to hex right. So what's stopping Random number generator to pick a private key from say first few million integers??
Isn't this a vulnerability?
Of course, advanced user can simply convert their private key to hex and to decimal to check if it's a large enough integer but what about noobies?

Here -  https://privatekeys.pw/keys/bitcoin/1
You can see on the above link. Any attacker can easily brute force first few million private keys so how to prevent such attack?
Jump to: