Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been using OpenSSL as the library of choice. I created ONE set of ECC parameters via

openssl ecparam -out ecparams.pem -name secp521r1 -genkey

I then created two certificate requests, with each certificate generating it's own set of public/private keys.

openssl req -x509 -newkey ec:ecparams.pem -keyform PEM -keyout ECCParam1Key1.pem -out LocalCACert1.pem -outform PEM -days 3650
openssl req -x509 -newkey ec:ecparams.pem -keyform PEM -keyout ECCParam1Key2.pem -out LocalCACert2.pem -outform PEM -days 3650

I was expecting the generated keys to be identical given that the ecparams.pem I used was same and defines everything very specifically:

-----BEGIN EC PARAMETERS-----
BgUrgQQAIw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MIHbAgEBBEF6N74mfCh946N1seJUjTrkmjSTRUKgWGqqCkNlZgwauNQD0dAHRJ9Y
PePxH1eIxOC8jDO85OUUawrP2j4n0kijbqAHBgUrgQQAI6GBiQOBhgAEAewexGGT
v3Dl40W0pTH1sWKPWhohPOo4pMDIbUJDZjtmwY9qvylU5JvtU2yvHBolMzxaHKFl
D0K7+agglcbT58dkASVYeOCK+bt7VrqtdJFuUm+TCr9vOmuWxR3bnVMuZWR+4fh5
z7XcIqRMYXO/gYdEX9bc8hPW/bdD9PDPZwZf62LC
-----END EC PRIVATE KEY-----

private key section. However, when I dump the keys back via

openssl ec -in ECCParam1Key1.pem -text -param_out
openssl ec -in ECCParam1Key2.pem -text -param_out

I can see that they are different despite having the same keying bits. I'm copy-pasting the output below at the end of the question.

Question: It seems not all the parameters are actually "fixed" when the ECC parameters are created; some seem to be fixed but others seem to be randomly generated later one during key creation. Which one(s) are left for generation later? And why is that so?

Thanks

Key dumps follow (these keys are generated just for this demonstration, not used anywhere)

$ openssl ec -in ECCParam1Key1.pem -text -param_out
read EC key
Enter PEM pass phrase:
Private-Key: (521 bit)
priv:
    6a:ef:af:bf:73:85:0f:aa:4a:92:7a:1e:ac:da:a8:
    38:ee:17:b7:c1:3e:45:ae:2d:e6:ac:4b:d6:18:19:
    f6:e5:3a:89:d2:3c:b6:79:4a:2e:e4:30:2e:74:62:
    8c:87:b0:88:a7:93:82:57:e3:0c:b9:bf:af:89:ae:
    85:94:76:3a:e1
pub:
    04:00:db:e4:59:e9:9f:f8:98:9d:31:96:69:af:e0:
    89:41:c2:8d:b0:4b:00:b4:83:31:61:c9:96:ba:22:
    88:49:5f:cc:25:87:fd:75:a4:21:ac:11:a4:f2:bf:
    08:a0:1b:ff:e2:66:5e:08:3e:21:11:d4:0e:a0:32:
    7a:17:cb:11:2a:87:e7:01:90:92:7a:b2:26:1b:5b:
    84:01:c3:7e:8f:81:1d:35:bc:59:58:ef:e3:95:5e:
    72:30:16:8c:f6:06:46:dc:34:fd:b6:33:cf:46:61:
    ec:ea:64:3f:90:0a:3a:f9:e6:78:2d:55:32:ab:00:
    b2:32:4f:be:48:82:3f:c0:09:9f:6f:cc:de
ASN1 OID: secp521r1
writing EC key
-----BEGIN EC PARAMETERS-----
BgUrgQQAIw==
-----END EC PARAMETERS-----    


$ openssl ec -in ECCParam1Key2.pem -text -param_out
read EC key
Enter PEM pass phrase:
Private-Key: (521 bit)
priv:
    01:6e:f7:03:33:18:1f:32:82:41:35:ca:11:4b:23:
    0d:1f:7b:78:9d:13:39:0a:ec:0a:f2:f9:24:09:06:
    f3:86:17:9b:20:05:a6:88:07:ed:0b:e6:c6:83:41:
    6c:87:93:57:f7:cd:8f:21:eb:3b:24:46:d4:c6:8f:
    ee:95:f5:8d:c3:01
pub:
    04:00:bd:ae:f7:8b:c4:39:6c:e0:01:ba:26:9a:a9:
    8c:72:85:cf:15:d0:24:78:a0:d2:08:a4:e8:36:f1:
    15:cd:c4:00:a9:0d:43:cc:e3:23:c0:cb:18:d3:5c:
    a7:9b:84:1e:c1:4e:3a:a8:bf:83:0f:3a:4b:11:c9:
    f1:4a:0e:ae:60:27:79:01:2f:d7:44:51:11:d2:b5:
    d1:ab:f5:a0:af:e2:eb:1e:7d:c6:b8:60:91:3e:c3:
    52:4a:a7:83:12:75:59:62:f2:15:59:b4:0f:0d:52:
    46:41:2e:29:00:94:26:49:37:5e:36:29:30:ae:fa:
    a9:2b:2b:5b:74:c4:b0:80:03:2e:ea:61:b0
ASN1 OID: secp521r1
writing EC key
-----BEGIN EC PARAMETERS-----
BgUrgQQAIw==
-----END EC PARAMETERS-----
share|improve this question

migrated from crypto.stackexchange.com Feb 4 '13 at 1:10

This question came from our site for software developers, mathematicians and others interested in cryptography.

    
The first command generates ECC domain parameters (see en.wikipedia.org/wiki/…) AND a new private key using these parameters. Next commands generate two new private keys with the given parameters. The final two commands output two previously generated private keys and the same parameters. What did you expect to see? You didn't tell us what you were trying to do, you only told what results you got. –  dchest Feb 3 '13 at 21:42
    
I've marked in bold what I was expecting. It looks like I'm telling OpenSSL "Use the private key and params inside ecparams.pem" incorrectly in my certificate generation command? –  DeepSpace101 Feb 3 '13 at 21:56
    
See openssl.org/docs/apps/req.html. -newkey option: "this option creates a new certificate request and a new private key." -key option: "This specifies the file to read the private key from." Anyway, this question is best asked on, perhaps, Superuser StackExchange. –  dchest Feb 3 '13 at 22:32
    
Based on that, it does indeed appear it's a usage issue and NOT a crypto/math issue. Thanks, voted to move it. –  DeepSpace101 Feb 3 '13 at 22:45
add comment

1 Answer

up vote 1 down vote accepted

It should be

openssl ecparam -out ecparamAndKey.pem -name secp521r1 -genkey

then

openssl req -x509 -new key -sha256 ecparamAndKey.pem -keyform PEM -out LocalCACert1.pem -outform PEM -days 3650
openssl req -x509 -new key -sha256 ecparamAndKey.pem -keyform PEM -out LocalCACert2.pem -outform PEM -days 3650

The -sha256 (or -sha512) is recommended otherwise it falls back to the broken SHA1

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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