X509_CMP(3ossl)
π X509_CMP β bestie edition π
okay so this is the X509_CMP(3ossl) page from the OpenSSL manual, and we're about to get so good at comparing certificates. buckle up π
β¨ NAME β¨
X509_cmp, X509_NAME_cmp, X509_issuer_and_serial_cmp, X509_issuer_name_cmp, X509_subject_name_cmp, X509_CRL_cmp, X509_CRL_match β the little squad of functions that compare X509 certificates and all the related values that come with them π¦
πΈ SYNOPSIS πΈ
#include <openssl/x509.h>
int X509_cmp(const X509 *a, const X509 *b);
int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
int X509_issuer_name_cmp(const X509 *a, const X509 *b);
int X509_subject_name_cmp(const X509 *a, const X509 *b);
int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
int X509_CRL_match(const X509_CRL *a, const X509_CRL *b);
π DESCRIPTION π
so this whole friend group exists to compare X509 objects β that's X509 certificates, X509 CRL objects, and all the lil values that live inside an X509 certificate. it's giving matchmaker energy but for crypto objects, fr fr.
X509_cmp() compares two X509 objects, pointed at by the params a and b. the comparison is based on the memcmp result of the hash values of the two X509 objects and the canonical (DER) encoding values. both. not one. periodt. π
X509_NAME_cmp() compares two X509_NAME objects, pointed at by a and b β and plot twist: either of them may be NULL. the comparison is based on the memcmp result of the canonical (DER) encoding values of the two objects, using i2d_X509_NAME(3). this procedure adheres to the matching rules for Distinguished Names (DN) given in RFC 4517 section 4.2.15 and RFC 5280 section 7.1. in particular, the order of Relative Distinguished Names (RDNs) is relevant π β so if you were thinking you could just shuffle those around, no bestie. on the other hand, if an RDN is multi-valued, i.e., it contains a set of AttributeValueAssertions (AVAs), its members are effectively not ordered β so that part genuinely doesn't care. the way that nuance is everything π
X509_issuer_and_serial_cmp() compares the serial number and issuer values in the given X509 objects a and b. two things, one function, slay.
X509_issuer_name_cmp(), X509_subject_name_cmp() and X509_CRL_cmp() are effectively wrappers of X509_NAME_cmp() β iconic behaviour honestly. these functions compare issuer names and subject names of the objects, or issuers of X509_CRL objects, respectively.
X509_CRL_match() compares two X509_CRL objects. unlike the X509_CRL_cmp() function, this one compares the whole CRL content instead of just the issuer name. it's the overachiever of the group, no cap π₯
π RETURN VALUES π
the X509 comparison functions return -1, 0, or 1 if object a is found to be less than, to match, or be greater than object b, respectively. it's giving very simple, very demure πΈ
X509_NAME_cmp(), X509_issuer_and_serial_cmp(), X509_issuer_name_cmp(), X509_subject_name_cmp(), X509_CRL_cmp(), and X509_CRL_match() may return -2 to indicate an error. yes, a whole extra number. she contains multitudes π
π«Ά NOTES π«Ά
these functions in fact utilize the underlying memcmp of the C library to do the comparison job. the data to be compared varies β it could be DER encoding data, a hash value, or an ASN1_STRING. the sign of the comparison can be used to order the objects, but it does not have a special meaning in some cases. so like, use it for sorting, don't read too deep into it, iykyk.
β οΈX509_NAME_cmp()and its wrappers utilize the value-2to indicate errors in some circumstances, which could cause confusion for the applications. bestie. be aware. that-2is lurking π
π SEE ALSO π
π COPYRIGHT π
Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie π this was version 3.5.9, dated 2026-09-29, and it's part of the OpenSSL collection. go forth and compare responsibly π
β¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms