1

In the answer from this question Determine if private key belongs to certificate?

The proposed solution is to match a private key and a certificate by extracting and matching the public key of both.

While in this page: https://www.sslshopper.com/certificate-key-matcher.html

The proposed solution is to extract the modulus of the public key, apply a MD5 hash to it and then compare the hashes.

Is there any difference in both approaches ? Would the second approach be the same if I compare only the modulus of the public key and not the MD5 hash ?

2 Answers2

1

Well, yes. There is a difference between the approaches.

The approach described in Determine if private key belongs to certificate? uses the RSA cryptosystem, which is based on the factorization of large prime numbers and an information trapdoor using the modulus function. Yet, the same general approach may be used to orther public key cryptosystems (any scheme that has a difficult mathematical problem plus a trapdoor function can be a public key cryptosystem, e.g. you have the ElGamal scheme).

The solution proposed by sslhopper is limited to the RSA scheme (or any other scheme that uses the modulus function as the information trapdoor). If you look in the openssl manuals the -modulus option only exists in man rsa.

In summary, the first approach is more generic than the second. This is because any asymmetric encryption scheme must be capable of generating the public key from the private key, but not every scheme must use the modulus function as the information trapdoor.

grochmal
  • 5,677
  • 2
  • 19
  • 30
  • 1
    For the generalization, see http://security.stackexchange.com/questions/73127/how-can-you-check-if-a-private-key-and-certificate-match-in-openssl-with-ecdsa (already shown as linked on #56697). – dave_thompson_085 Sep 20 '16 at 09:39
1

In addition to @grochmal's point, if you're matching the public keys, then there is no way that a hash function vulnerability can affect you. It is probably also slightly faster to compare the bits directly, rather than hashing them.

Adam Shostack
  • 2,659
  • 1
  • 10
  • 12