On Friday, July 18, 2014 6:35:47 AM UTC-4, Jeffrey Walton wrote: > > I've got an EC key pair. I need to save it using DEREncodePublicKey ( > http://www.cryptopp.com/docs/ref/class_d_l___public_key___e_c.html). > > Crypto++ writes out the full domain parameters: > > $ openssl ec -in ec-pub-xxx.pem -text -noout -pubin > read EC key > Private-Key: (256 bit) > pub: > 04:3e:cb:d0:fb:9d:8d:30:fd:69:a0:42:d8:b6:93: > 47:8b:b2:64:2e:bd:d8:27:70:f4:80:85:24:3d:3a: > a5:23:a8:db:05:67:da:62:66:53:ee:a1:31:f8:0c: > 7f:45:23:72:d0:89:97:c3:90:cb:d5:15:c9:1c:13: > 86:5d:a6:8d:80 > Field Type: prime-field > Prime: > 00:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff: > ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:fe:ff: > ff:fc:2f > A: 0 > B: 7 (0x7) > ... > > But I need the OID of the curve (i.e., the named curve), and not the > domain parameters: > > $ openssl ec -in ec-pub.pem -text -noout -pubin > read EC key > Private-Key: (256 bit) > pub: > 04:3e:cb:d0:fb:9d:8d:30:fd:69:a0:42:d8:b6:93: > 47:8b:b2:64:2e:bd:d8:27:70:f4:80:85:24:3d:3a: > a5:23:a8:db:05:67:da:62:66:53:ee:a1:31:f8:0c: > 7f:45:23:72:d0:89:97:c3:90:cb:d5:15:c9:1c:13: > 86:5d:a6:8d:80 > ASN1 OID: secp256k1 > > The two outputs above are really the same key. The program read a public > key written by OpenSSL (ec-pub.pem), and then saved the key using Crypto++ > (ec-pub-xxx.pem). So the above is the result of attempting to round trip > the key. > > Does anyone know how to make Crypto++ use the named curve rather than the > domain parameters? >
Found it on DL_GroupParameters_EC< EC > (http://www.cryptopp.com/docs/ref/class_d_l___group_parameters___e_c.html). Here's the function to get it: bool PEM_GetNamedCurve(const DL_PublicKey_EC<ECP>& key) { const DL_GroupParameters_EC<EC2N>& params = key.GetGroupParameters(); return params.GetEncodeAsOID(); } And set it: void PEM_SetNamedCurve(const DL_PublicKey_EC<ECP>& key, bool flag) { DL_PublicKey_EC<ECP>& kk = const_cast<DL_PublicKey_EC<ECP>&>(key); DL_GroupParameters_EC<ECP>& params = kk.AccessGroupParameters(); params.SetEncodeAsOID(flag); } Its too bad its not a mutable property. Changing the print format does not change the object, so it does not seem to be a violation of const-ness.... -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to [email protected]. More information about Crypto++ and this group is available at http://www.cryptopp.com. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
