Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: behindtext on March 09, 2013, 01:21:18 PM



Title: why did bitcoin choose secp256k1 over secp256r1?
Post by: behindtext on March 09, 2013, 01:21:18 PM
something i find rather disconcerting about bitcoin is a lack of justification/explanation for some of the design decisions, in particular the choice of doing 256-bit ecdsa keypairs over secp256k1 vs secp256r1 (a.k.a. P-256) for wallets.

the best i could find on the forum is this thread from 2011 - https://bitcointalk.org/?topic=2699.0

NIST recommends use of secp256r1, and more generally prefers random curve parameters to the Koblitz ones. i can only speculate why this choice was made, here are a couple possible reasons:

* NIST sets standards for NSA / US govt crypto and is genuinely concerned about everyone's security. they have found that random curves are more secure than Koblitz ones.
* NIST has made an intentionally poor suggestion to use secp256r1, so it acts as a honeypot. they have found that Koblitz curves are actually more secure than the random ones.

with those reasons in mind i could see bitcoin having analogous justifications:

* Satoshi had information which led him/them to believe that secp256r1 was indeed a honeypot and that secp256k1 was the better choice for real security
* Satoshi knew that secp256k1 was weak and intentionally included it in bitcoin to make bitcoin into a honeypot

considering that the design decisions for both BTC and NIST ciphers are both entirely opaque, it is difficult to make a good guess as to their motivation. i have similar reservations about using base58 everywhere, but that is less a concern from a security perspective.

can anyone provide a justification for using secp256k1 over secp256r1 besides "that's just the way it is" or "so it was written in the great book"?


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: Mike Hearn on March 09, 2013, 01:43:23 PM
The random curves aren't really any more or less secure than the other curves, they are merely more conservative. Given some arbitrary constants with which to initialize the algorithms, choosing random numbers (or more specifically, nothing-up-my-sleeve numbers) is one way to build trust that there are no funny games being played with the specific choices.

However, the GLV method allows for much faster computations when these constants are not randomly chosen but rather chosen according to some criteria. It opens up the possibility that by selecting values in this way, some unknown weakness is introduced, but nobody has ever been able to show that the non-random curves actually are more insecure.

There have been no further discussions of this topic since the original thread you linked to.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: behindtext on March 09, 2013, 01:51:54 PM
However, the GLV method allows for much faster computations when these constants are not randomly chosen but rather chosen according to some criteria. It opens up the possibility that by selecting values in this way, some unknown weakness is introduced, but nobody has ever been able to show that the non-random curves actually are more insecure.

yeah, i had seen that it does offer some speed advantages. i don't believe signature checking speed is currently a bottleneck, but extra cpu cycles always help.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gmaxwell on March 09, 2013, 01:57:37 PM
yeah, i had seen that it does offer some speed advantages. i don't believe signature checking speed is currently a bottleneck, but extra cpu cycles always help.
Signature checking is, in fact, a major bottleneck. It didn't use to be but it is now. Sadly, Ed25519 didn't exist back then...


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: Mike Hearn on March 09, 2013, 03:40:49 PM
sipa was saying that he thinks it's possible to maybe double the speed of signature checking by using an implementation specifically created just for that curve (this is beyond the GLV optimizations). But we'll see.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: ShadowOfHarbringer on March 09, 2013, 06:40:14 PM
yeah, i had seen that it does offer some speed advantages. i don't believe signature checking speed is currently a bottleneck, but extra cpu cycles always help.
Signature checking is, in fact, a major bottleneck. It didn't use to be but it is now. Sadly, Ed25519 didn't exist back then...

Perhaps somebody should start selling some kind of PCI-Express slot dedicated ASIC coprocessor for such computations to mitigate that bottleneck ?

If Bitcoin becomes really popular, such needs may arise in the future - i can see a market for that then.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: behindtext on March 09, 2013, 07:03:57 PM
yeah, i had seen that it does offer some speed advantages. i don't believe signature checking speed is currently a bottleneck, but extra cpu cycles always help.
Signature checking is, in fact, a major bottleneck. It didn't use to be but it is now. Sadly, Ed25519 didn't exist back then...

i've always been a bit wary of djb crypto, despite the guy being a pretty big producer idea-wise. his algos are not nearly as well-studied as the standard ones and he has a tendency to assign "frankenlicenses" on his code.

i guess any change to bitcoin crypto would require a hard fork in the absence of plumbing that would facilitate smooth cipher changes.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: justusranvier on March 09, 2013, 07:12:43 PM
i've always been a bit wary of djb crypto, despite the guy being a pretty big producer idea-wise. his algos are not nearly as well-studied as the standard ones and he has a tendency to assign "frankenlicenses" on his code.
Everything he does is non-standard. He invented his own FHS and init implementation, just because. Integrating his software with any system vaguely unix-like is an enormous pain in the ass that people only ever tolerated because the alternatives to his software (Bind) sucked that much at the time.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gmaxwell on March 09, 2013, 07:31:39 PM
i've always been a bit wary of djb crypto, despite the guy being a pretty big producer idea-wise. his algos are not nearly as well-studied as the standard ones and he has a tendency to assign "frankenlicenses" on his code.
Ed25519 is not curve25519. Ed25519 is the work of Daniel J. Bernstein, Niels Duif, Tanja Lange, Peter Schwabe, Bo-Yin Yang..

"frankenlicenses" on some code are irrelevant, as no one is married to a particular implementation... though the reference Ed25519 implementation is public domain.

Quote
i guess any change to bitcoin crypto would require a hard fork in the absence of plumbing that would facilitate smooth cipher changes.
Bitcoin can smoothly pick up new signature methods. We've even done a deployment of this with P2SH.  But the big speedup of Ed25519 is perhaps not the cost and risk which is why no one is proposing it at least now.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gafter on September 11, 2013, 08:26:43 PM
something i find rather disconcerting about bitcoin is a lack of justification/explanation for some of the design decisions, in particular the choice of doing 256-bit ecdsa keypairs over secp256k1 vs secp256r1 (a.k.a. P-256) for wallets...

can anyone provide a justification for using secp256k1 over secp256r1 besides "that's just the way it is" or "so it was written in the great book"?

Since 2007 there is evidence that the supposedly random constants in secp256r1 may have been manipulated by the NSA to provide a backdoor.  See http://www.wired.com/politics/security/commentary/securitymatters/2007/11/securitymatters_1115 (http://www.wired.com/politics/security/commentary/securitymatters/2007/11/securitymatters_1115).  Presumably Satoshi was aware of this.  The Koblitz curves cannot have been so "cooked"; see http://crypto.stackexchange.com/questions/10263/should-we-trust-the-nist-recommended-ecc-parameters/10273#10273 (http://crypto.stackexchange.com/questions/10263/should-we-trust-the-nist-recommended-ecc-parameters/10273#10273).


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gmaxwell on September 11, 2013, 08:33:34 PM
That thread is a _little_ misleading.  The author is writing about the traditional characteristic 2 koblitz curves (e.g. NIST k curves). SECP256k1 is a curve which is not part of the nist standard. It is a generalization of the koblitz but with a prime field that admits similar optimizations. The design freedom for it is this generalization is somewhat larger than than that available for characteristic 2 koblitz. ... but the design space still is substantially constrained, and I agree with the conclusion that it reduces the room for carefully selected values.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: jdbtracker on September 12, 2013, 03:16:10 PM
I don't think satoshi did things lightly, I've started understanding Bitcoin more and more and now I'm looking into C++ code and I think he had very carefully thought out systems but brushed off the questions to encourage exploration.

This algorithm is fast and not implemented widely so it would be less exploited, and the internal structure could have something to do with it... but what would the insight have been? I'm intrigued to find out.

I also thought about the size of ecdsa... it's tiny when compared to similar schemes.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: cnd on December 03, 2013, 01:00:17 PM
Thanks to Snowden & Bruce Schneier, we now know the answer. secp256r1 has an NSA backdoor - see http://www.linuxadvocates.com/2013/09/is-openssls-cryptography-broken.html

So - while a backdoor is not really a "honeypot" this is the best answer:-
* NIST has made an intentionally poor suggestion to use secp256r1, so it acts as a honeypot. they have found that Koblitz curves are actually more secure than the random ones.

* Satoshi had information which led him/them to believe that secp256r1 was indeed a honeypot and that secp256k1 was the better choice for real security


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: samson on December 03, 2013, 01:06:50 PM
Thanks to Snowden & Bruce Schneier, we now know the answer. secp256r1 has an NSA backdoor - see http://www.linuxadvocates.com/2013/09/is-openssls-cryptography-broken.html

So - while a backdoor is not really a "honeypot" this is the best answer:-
* NIST has made an intentionally poor suggestion to use secp256r1, so it acts as a honeypot. they have found that Koblitz curves are actually more secure than the random ones.

* Satoshi had information which led him/them to believe that secp256r1 was indeed a honeypot and that secp256k1 was the better choice for real security

RedHat have consistently refused to include ECC in their products for a long time now.

They won't discuss why apart from saying 'possible patents' which in my opinion is bullshit.

However they have recently decided that these patent issues have been resolved after so many years of bullshit and in the next version of RedHat Enterprise Linux they will include the OpenSSL version with ECC support it's been lacking for so long.

It's worth mentioning that they made it into quite a complex job to upgrade to an ECC compliant OpenSSL without potentially wrecking your linux installation.

The whole thing stinks of a secret court order to me.

Does this give more credence to Ed25519 ?


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: oakpacific on December 03, 2013, 01:17:05 PM
Why have I found nobody, before gmaxwell, trying to verify if the secp256r1 constants make sense? Why?


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gmaxwell on December 03, 2013, 02:25:12 PM
Why have I found nobody, before gmaxwell, trying to verify if the secp256r1 constants make sense? Why?
The spec described it as random, and if you looked at and didn't think too hard the claim of random sounded pretty good... "They used a cryptographic hash to set the values, not really any algebraic structure going to be found there!".

Like a lot of things, its seems completely obvious in hindsight, but personally I only thought to reconsider it while I was in the middle of blabbering off to someone "there is no real reason to be concerned, they set them randomly using ... wait a minute!",  ... and even then I'd been spending time dorking around with zero knoweldge proofs based on the fiat-shamir heuristic, in which an attacker grinds at a hash hoping to get a lucky value the has him make successful validation probes.

I wasn't the first person to express some reservations about the methodology used for the NIST curves (e.g. the Brainpool curve RFC shows the NIST curves no love), though I'm not aware of anyone pointing out that someone could have tested seeds until they got a weaker (or stronger) one until I did, though I sure others _must_ have realized it. It's also more obvious in contrast to secp256k1 and ed25519 which have fewer— almost no— degrees of freedom.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: Mike Hearn on December 03, 2013, 02:30:53 PM
It was recognised in a presentation by djb and Tanja Lange in May:

   http://www.hyperelliptic.org/tanja/vortraege/20130531.pdf

Search the slides for the name Jerry Solinas. Also see the slide containing the phrase "But what if the NSA knows a weakness". And as you note, the Brainpool RFC says explicitly that the NIST curves don't provide any justification for their seed values.

I would guess that there were probably only 10-15 people in the world who knew about this issue before the Snowden blowup though.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: oakpacific on December 03, 2013, 02:44:43 PM
Why have I found nobody, before gmaxwell, trying to verify if the secp256r1 constants make sense? Why?
The spec described it as random, and if you looked at and didn't think too hard the claim of random sounded pretty good... "They used a cryptographic hash to set the values, not really any algebraic structure going to be found there!".

Like a lot of things, its seems completely obvious in hindsight, but personally I only thought to reconsider it while I was in the middle of blabbering off to someone "there is no real reason to be concerned, they set them randomly using ... wait a minute!",  ... and even then I'd been spending time dorking around with zero knoweldge proofs based on the fiat-shamir heuristic, in which an attacker grinds at a hash hoping to get a lucky value the has him make successful validation probes.

I wasn't the first person to express some reservations about the methodology used for the NIST curves (e.g. the Brainpool curve RFC shows the NIST curves no love), though I'm not aware of anyone pointing out that someone could have tested seeds until they got a weaker (or stronger) one until I did, though I sure others _must_ have realized it. It's also more obvious in contrast to secp256k1 and ed25519 which have fewer— almost no— degrees of freedom.

The NSA had our psychology nailed, it knows well that we won't be bothered to run some tests over its constants, even if millions of us depend on ECC everyday.

Otoh, it's pretty fortunate to be trained and spanked in the Bitcoin world everyday, the "nothing between you and your enemy but cryptography" design makes sure no one should cease being paranoid(or at least vigilant) without getting punished.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: oakpacific on December 03, 2013, 02:52:30 PM
It was recognised in a presentation by djb and Tanja Lange in May:

   http://www.hyperelliptic.org/tanja/vortraege/20130531.pdf

Search the slides for the name Jerry Solinas. Also see the slide containing the phrase "But what if the NSA knows a weakness". And as you note, the Brainpool RFC says explicitly that the NIST curves don't provide any justification for their seed values.

I would guess that there were probably only 10-15 people in the world who knew about this issue before the Snowden blowup though.

I saw this presentation, but I haven't seen careful examination of the constants other than what gmaxwell did, also the slide mentions Apple's usage of Curve25519 rather than a NIST curve, I wonder if they are also aware of their problems.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: e4xit on December 16, 2013, 04:08:18 PM
Some basic google-fu still turns up surprisingly little about the secp256k1 curves used for this protocol, even after so many years.

Does anybody have any good articles/reviews/demos on this curve which might help reveal why it was chosen for bitcoin, or indeed, if it is suitable for long-term bitcoin use?

http://www.secg.org/collateral/sec2_final.pdf (2.7.1) provided a small amount of info on this but I guess what I would really be looking for is sources proving that using Koblitz curves is more secure (or the security/limitation thereof is better understood) than using "provably random" curves...?


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: neoKushan on January 28, 2014, 04:11:14 PM
Thanks to Snowden & Bruce Schneier, we now know the answer. secp256r1 has an NSA backdoor - see http://www.linuxadvocates.com/2013/09/is-openssls-cryptography-broken.html

So - while a backdoor is not really a "honeypot" this is the best answer:-
* NIST has made an intentionally poor suggestion to use secp256r1, so it acts as a honeypot. they have found that Koblitz curves are actually more secure than the random ones.

* Satoshi had information which led him/them to believe that secp256r1 was indeed a honeypot and that secp256k1 was the better choice for real security

something i find rather disconcerting about bitcoin is a lack of justification/explanation for some of the design decisions, in particular the choice of doing 256-bit ecdsa keypairs over secp256k1 vs secp256r1 (a.k.a. P-256) for wallets...

can anyone provide a justification for using secp256k1 over secp256r1 besides "that's just the way it is" or "so it was written in the great book"?

Since 2007 there is evidence that the supposedly random constants in secp256r1 may have been manipulated by the NSA to provide a backdoor.  See http://www.wired.com/politics/security/commentary/securitymatters/2007/11/securitymatters_1115 (http://www.wired.com/politics/security/commentary/securitymatters/2007/11/securitymatters_1115).  Presumably Satoshi was aware of this.  The Koblitz curves cannot have been so "cooked"; see http://crypto.stackexchange.com/questions/10263/should-we-trust-the-nist-recommended-ecc-parameters/10273#10273 (http://crypto.stackexchange.com/questions/10263/should-we-trust-the-nist-recommended-ecc-parameters/10273#10273).


I know this is a somewhat old thread, but as this comes up as a top answer when searching for secp256r1 , I feel some of the above points need to be clarified.

Firstly, people are comparing secp256r1 to Dual_EC_DRBG as if they're interchangeable (And some even seem to think that they're the same thing). They're not. They're two completely different algorithms that serve completely different purposes. Dual_EC_DRBG has been suspicious from the second it was published and plenty of people from the security industry have warned against using it. I believe someone recently was able to demonstrate a proof of concept of breaking the encryption when using their own curve parameters. The issue is that the specification gives a default curve that doesn't indicate where those parameters came from - it should be random.

However, secp256r1 has no such proof. There is a theoretical issue with it, though - its curve parameters are taken from a SHA1 hash (unlike Dual_EC_DRBG) of a seed value. It's very, very difficult to reverse a hash like that, which is what the NSA will have to have done in order to "trap" the algorithm. It's still theoretical and relies on them having undisclosed exploits that we're unaware of (unlike Dual_EC_DRBG which doesn't) - certainly a possibility and if you value your privacy, don't use it, but it's not quite as obvious as Dual_EC_DRBG. That doesn't make it "safe" per se, but then again it requires a much bigger leap for the NSA to have compromised. There hasn't been a "leak" (from Snowdon or otherwise) that I am aware of that indicates that secp256r1 is a honeypot, but there has for Dual_EC_DRBG.

By all means, if you're sceptical then don't use secp256r1 but let's not confuse it with a completely different algorithm.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gmaxwell on January 28, 2014, 04:32:48 PM
No one here was claiming that and if they were they would have been promptly corrected.  The the selection power in the 'random' parameter procedure would have required unknown attacks is something that has been pointed out before.  If you're going to bump an old thread, please at least refrain from insulting everyone on in the subforum.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: hashman on January 28, 2014, 09:38:38 PM
More discussion please, thanks contributors :)

I'm too lazy to give you the link in this forum, but I believe satoshi was asked directly and his response was:  "It was lying around". 


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: davispuh on February 28, 2014, 07:15:03 AM
based on this site http://safecurves.cr.yp.to/ (http://safecurves.cr.yp.to/) secp256r1 (P-256) is not safe, but neither is secp256k1. Of course, it's debatable how trustable this claim is.

Curve25519 is said to be safe and there's also some other new ones assumed to be safe.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: kjj on February 28, 2014, 12:00:18 PM
based on this site http://safecurves.cr.yp.to/ (http://safecurves.cr.yp.to/) secp256r1 (P-256) is not safe, but neither is secp256k1. Of course, it's debatable how trustable this claim is.

Curve25519 is said to be safe and there's also some other new ones assumed to be safe.

If you search this board for that URL, you'll find at least one thread, maybe more.  The short version is that djb has a huge ego.  The long version is that the things he dislikes about secp256k1 don't matter, or at the very least, don't matter to us.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: Come-from-Beyond on March 07, 2014, 08:19:06 AM
The short version is that djb has a huge ego.

Hm. It's the 2nd time for today when u use a personal insult as a counter-argument. "Bitcoin Foundation - Lifetime Member" under ur avatar explains the behavior though...


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: ripper234 on September 04, 2014, 10:27:28 AM
I took the question to crypto.stackexchange.

http://crypto.stackexchange.com/questions/18965/is-secp256r1-more-secure-than-secp256k1


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gmaxwell on September 04, 2014, 10:39:33 AM
I took the question to crypto.stackexchange.

http://crypto.stackexchange.com/questions/18965/is-secp256r1-more-secure-than-secp256k1
Why would you do that (and bump this old thread) except for pure trolling purposes?  Considering that fact that secp256r1 has unexplainable mystery parameters I can't imagine anyone outside of the NSA promoting it.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: ripper234 on September 04, 2014, 11:57:02 AM
I took the question to crypto.stackexchange.

http://crypto.stackexchange.com/questions/18965/is-secp256r1-more-secure-than-secp256k1
Why would you do that (and bump this old thread) except for pure trolling purposes?  Considering that fact that secp256r1 has unexplainable mystery parameters I can't imagine anyone outside of the NSA promoting it.

Because I haven't been able to piece together that the issue brought in this thread was fully resolved (maybe I missed something / read too quickly), and wanted to expose the matter at hand to more eyes.

Since then I also posted to reddit (http://www.reddit.com/r/Bitcoin/comments/2ffy7k/is_secp256r1_more_secure_than_secp256k1/) and via it found this other bitcointalk thread (https://bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975) that sheds more light on the matter.

No trolling intended I assure you.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: BurtW on September 04, 2014, 12:20:55 PM
I believe that the ECC/NSA thread you referenced did eventually nail down every parameter used to create secp256k1 and answers most if not all concerns.


Title: Re: why did bitcoin choose secp256k1 over secp256r1?
Post by: gmaxwell on September 04, 2014, 04:46:36 PM
I believe that the ECC/NSA thread you referenced did eventually nail down every parameter used to create secp256k1 and answers most if not all concerns.
Yes, There is a python script that produces every parameter for secp256k1 from first principles, except the generator— and both myself and D. J. Bernstein have given the proof that in-advance choice of the generator is harmless outside of restricted conditions that aren't relevant to normal Bitcoin usage.