0

Currently I am trying to make my web server as secure as possible and I am testing different cipher suites on the server side, some of them using ECDHE key exchange.

When generating private EC keys, I noticed that most of the generated data is identical when generating two keys. The raw output:

root@spock:/etc/letsencrypt/live/binarus.home.omeganet.de# openssl ecparam -name secp256k1 -param_enc explicit -genkey
-----BEGIN EC PARAMETERS-----
MIGiAgEBMCwGByqGSM49AQECIQD////////////////////////////////////+
///8LzAGBAEABAEHBEEEeb5mfvncu6xVoGKVzocLBwKb/NstzijZWfKBWxb4F5hI
Otp3JqPEZV2k+/wOEQio/Re0SKaFVBmcR9CP+xDUuAIhAP//////////////////
//66rtzmr0igO7/SXozQNkFBAgEB
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MIIBEwIBAQQgpCZwVgJpH7t70lK0V1MSGvCe8IcOtXPP+S/luqFsr/eggaUwgaIC
AQEwLAYHKoZIzj0BAQIhAP////////////////////////////////////7///wv
MAYEAQAEAQcEQQR5vmZ++dy7rFWgYpXOhwsHApv82y3OKNlZ8oFbFvgXmEg62ncm
o8RlXaT7/A4RCKj9F7RIpoVUGZxH0I/7ENS4AiEA/////////////////////rqu
3OavSKA7v9JejNA2QUECAQGhRANCAASXlnk1RIp1fKlGxcZMsm0mJLJ6xoIG4Z8t
AYn30X5pA3P00BpweidnzeqLlytPBuFeqwbJBuH3rXnpIvMe2W89
-----END EC PRIVATE KEY-----

root@spock:/etc/letsencrypt/live/binarus.home.omeganet.de# openssl ecparam -name secp256k1 -param_enc explicit -genkey
-----BEGIN EC PARAMETERS-----
MIGiAgEBMCwGByqGSM49AQECIQD////////////////////////////////////+
///8LzAGBAEABAEHBEEEeb5mfvncu6xVoGKVzocLBwKb/NstzijZWfKBWxb4F5hI
Otp3JqPEZV2k+/wOEQio/Re0SKaFVBmcR9CP+xDUuAIhAP//////////////////
//66rtzmr0igO7/SXozQNkFBAgEB
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MIIBEwIBAQQgXccG/nHnL17f60wwQq7zwngdSIg9c+ATwy2CSMY+2PWggaUwgaIC
AQEwLAYHKoZIzj0BAQIhAP////////////////////////////////////7///wv
MAYEAQAEAQcEQQR5vmZ++dy7rFWgYpXOhwsHApv82y3OKNlZ8oFbFvgXmEg62ncm
o8RlXaT7/A4RCKj9F7RIpoVUGZxH0I/7ENS4AiEA/////////////////////rqu
3OavSKA7v9JejNA2QUECAQGhRANCAASzr/OIB4ab1o6++PPJCg/TdbdmDHIiYxOD
Gi7hfp5VGe8d++PrAb3B5Pnvn2TmrDsbNzeysGp0IPjpH+ns56vn
-----END EC PRIVATE KEY-----

As you can see, most of the private key is identical. But my understanding of generating a private key always has been that every private key should be unique. Could anybody shed some light onto this?

Please note that I have observed this with different version of OpenSSL, amongst them the most recent one (OpenSSL 1.0.2e). Please note also that the result is the same if I let away the command line switch -param_enc explicit.

While at least there are a few bytes different in the results above, I am completely lost when letting OpenSSL translate the generated data into human readable form:

root@spock:/etc/letsencrypt/live/binarus.home.omeganet.de# openssl ecparam -name secp256k1 -param_enc explicit -genkey | openssl asn1parse
    0:d=0  hl=3 l= 162 cons: SEQUENCE          
    3:d=1  hl=2 l=   1 prim: INTEGER           :01
    6:d=1  hl=2 l=  44 cons: SEQUENCE          
    8:d=2  hl=2 l=   7 prim: OBJECT            :prime-field
   17:d=2  hl=2 l=  33 prim: INTEGER           :FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
   52:d=1  hl=2 l=   6 cons: SEQUENCE          
   54:d=2  hl=2 l=   1 prim: OCTET STRING      [HEX DUMP]:00
   57:d=2  hl=2 l=   1 prim: OCTET STRING      [HEX DUMP]:07
   60:d=1  hl=2 l=  65 prim: OCTET STRING      [HEX DUMP]:0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
  127:d=1  hl=2 l=  33 prim: INTEGER           :FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
  162:d=1  hl=2 l=   1 prim: INTEGER           :01

root@spock:/etc/letsencrypt/live/binarus.home.omeganet.de# openssl ecparam -name secp256k1 -param_enc explicit -genkey | openssl asn1parse
    0:d=0  hl=3 l= 162 cons: SEQUENCE          
    3:d=1  hl=2 l=   1 prim: INTEGER           :01
    6:d=1  hl=2 l=  44 cons: SEQUENCE          
    8:d=2  hl=2 l=   7 prim: OBJECT            :prime-field
   17:d=2  hl=2 l=  33 prim: INTEGER           :FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
   52:d=1  hl=2 l=   6 cons: SEQUENCE          
   54:d=2  hl=2 l=   1 prim: OCTET STRING      [HEX DUMP]:00
   57:d=2  hl=2 l=   1 prim: OCTET STRING      [HEX DUMP]:07
   60:d=1  hl=2 l=  65 prim: OCTET STRING      [HEX DUMP]:0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
  127:d=1  hl=2 l=  33 prim: INTEGER           :FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
  162:d=1  hl=2 l=   1 prim: INTEGER           :01

Now all OCTET STRINGS are exactly the same. To my understanding, one of these should be the private key, shouldn't it?

I would be grateful for any explanation. I have a mathematical and programming background, and I have understood the concepts behind RSA base asymmetric cryptography. But I have nearly no knowledge about elliptic curve cryptography. I just want to use it for ECDHE key exchange in order to harden HTTPS queries with perfect forward secrecy.

Thank you very much in advance ...

1

Deceiving PEM

These keys are not identical. They are very different. They all start with 'MI' but that is just a property of the PEM Base-64 encoding.

Also: I guess your ASN1PARSE only parses the FIRST PEM OBJECT in that output. And that is the named curve you wanted. So that is supposed to be identical. Parse the second PEM object (the actual private key) and you will see that the privkeys (the CURVE POINTS) are NOT identical.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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