-1
$\begingroup$

I have some javascript, which generates new ECDSA public-private keypair. However all the resulting public keys which I generate seem to have fixed prefix.

This seems strange to me, since the beginning is always the same. Is this correct? Or should I expect all pub keys to be more random?

Here is example of generated public keys (base58 encoded):

aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTG9WCdoLJo5PbBdaXeKUGoXBiZWLoFszaWcRnyUmgo3jdUkAtnoJijjUooeKUvRcqp5y3w4cXN85dPhTFrGpYmXMG
aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTHWqMbneiD8TN5wntMvV8MgbZviYT3aiBCVUqmdxhNj7tFqRtJ6kdHB9qZsFv7py6Gn1cYQKSJouZKA2hayDrenrQ
aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTHMgQX5y6PNueefoCSiMP45C9nocEKsqHqoeXDkJYvdHUCS7zwSCjpw8E4ggBEp7z1jMTtLmy2PJRqgGGAuzskX7U
aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTJQ7HgMHUSamB9RmgnKBHQv6axkUwfvFc1PiHKq1SimHrh9CXPt8V3LwW3W5up6nettkhHkoQPCWTZYadPnkmgv8L
aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTJuVVHkx37iQeM9FYXymYkeuFEDGkytjQrkTkdCxkQtWzMt1qYPki77jcPbsQdYehDtirMMR8V1CSzLgynr8B4vaz
aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTGWhozoV5vzA5UbNKriS4uyV43S3oxGB1B5rHJKHN4LvtX1aSsQX7jL7dio5BdmDR68N2YZFLomnLyn82gETxFdUf
$\endgroup$
  • $\begingroup$ My guess would be that the prefix is some ASN.1 structuring that also indicates the used curve and byte lengths. $\endgroup$ – SEJPM Aug 26 '17 at 12:39
  • $\begingroup$ You will need to specify what library you're talking about. Otherwise, who knows what metadata it adds to its public key format? $\endgroup$ – Squeamish Ossifrage Aug 26 '17 at 12:57
  • $\begingroup$ I thought that a binary representation of the public key is given, platform-independant, library-independant. It is not? $\endgroup$ – Tomas M Aug 26 '17 at 13:29
  • $\begingroup$ There is one fairly commonly used standard, X.509's SubjectPublicKeyInfo more conveniently described in rfc 3279 et rel, and that is what you have, but there are quite a few other formats used by some program(s) or library(ies). $\endgroup$ – dave_thompson_085 Aug 27 '17 at 1:12
  • $\begingroup$ I'm sure this is just a encoding problem and is not "cryptographically" on-topic here. How can I flag it as such? $\endgroup$ – DannyNiu Aug 28 '17 at 4:31
2
$\begingroup$

Your keys are ASN.1 structures. I decoded first one to hex:

3059301306072A8648CE3D020106082A8648CE3D03010703420004405134B8399A666F12ADA32F19F646F85FB7D1FC3D9AA0688BF8984A35B86AD49FBB96CFAD78B994013D06D7B98C09B0104323DD0A2473CDCA79342277027D3F

When I gave this to ASN.1 parser, it shows me the next structure:

SEQUENCE
----SEQUENCE
--------ObjectIdentifier 1.2.840.10045.2.1 [ecPublicKey]
--------ObjectIdentifier 1.2.840.10045.3.1.7 [prime256v1]
----BITSTRING [04405134b8399a666f12ada32f19f646f85fb7d1fc3d9aa0688bf8984a35b86ad49fbb96cfad78b994013d06d7b98c09b0104323dd0a2473cdca79342277027d3f]

So, your keys have the same prefix, because they contain algorithm identifier and curve identifier. Public key is just EC point.

$\endgroup$
  • $\begingroup$ So, basically, if the software (javascript native crypto) generates the keys I have, is it safe to use them? Does it bring any security risk to publish the keys while they contain the identifiers? $\endgroup$ – Tomas M Aug 27 '17 at 11:11
  • $\begingroup$ No risks, secp256r1 is the most widely used curve. Even without these identifiers it is easy to guess them. $\endgroup$ – Zergatul Aug 27 '17 at 11:17

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.