summaryrefslogtreecommitdiffstats
path: root/crypto/x509/x_pubkey.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-05-21 10:37:22 +0200
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-05-26 09:35:32 +0200
commit93f99b681ab5a1cf7062053323e09b0cad5ff854 (patch)
treefb5ead50ddbb6cb871c0240648d9036d2dfbf486 /crypto/x509/x_pubkey.c
parent7674e92324648b59786d86d8e9014bbaed4e6d07 (diff)
Fix X509_PUBKEY_cmp(), move to crypto/x509/x_pubkey.c, rename, export, and document it
Fixes #11870 Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/11894)
Diffstat (limited to 'crypto/x509/x_pubkey.c')
-rw-r--r--crypto/x509/x_pubkey.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/crypto/x509/x_pubkey.c b/crypto/x509/x_pubkey.c
index c240a5f567..14893adb2f 100644
--- a/crypto/x509/x_pubkey.c
+++ b/crypto/x509/x_pubkey.c
@@ -472,3 +472,24 @@ ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x)
return NULL;
return x->cert_info.key->public_key;
}
+
+/* Returns 1 for equal, 0, for non-equal, < 0 on error */
+int X509_PUBKEY_eq(const X509_PUBKEY *a, const X509_PUBKEY *b)
+{
+ X509_ALGOR *algA, *algB;
+ EVP_PKEY *pA, *pB;
+
+ if (a == b)
+ return 1;
+ if (a == NULL || b == NULL)
+ return 0;
+ if (!X509_PUBKEY_get0_param(NULL, NULL, NULL, &algA, a) || algA == NULL
+ || !X509_PUBKEY_get0_param(NULL, NULL, NULL, &algB, b) || algB == NULL)
+ return -2;
+ if (X509_ALGOR_cmp(algA, algB) != 0)
+ return 0;
+ if ((pA = X509_PUBKEY_get0(a)) == NULL
+ || (pB = X509_PUBKEY_get0(b)) == NULL)
+ return -2;
+ return EVP_PKEY_cmp(pA, pB);
+}