X509_ALGOR_DUP(3)
π X509_ALGOR_DUP(3) β like, the whole algorithm-identifier squad
okay so bestie, this little page lives in the Library Functions Manual and honestly? it's giving "the glue that holds every certificate together." it's X509_ALGOR_DUP(3), and it's about algorithm identifiers. buckle up, it's actually kind of iconic π
β¨ NAME β¨
X509_ALGOR_new, X509_ALGOR_free, X509_ALGOR_dup, X509_ALGOR_set0, X509_ALGOR_get0, X509_ALGOR_cmp β create, change, and inspect algorithm identifiers π«
πΈ SYNOPSIS πΈ
so you're pulling from the library βlibcryptoβ and you gotta grab this header first:
#include <openssl/x509.h>
then the whole friend group shows up like this:
X509_ALGOR *
X509_ALGOR_new(void);
void
X509_ALGOR_free(X509_ALGOR *alg);
X509_ALGOR *
X509_ALGOR_dup(X509_ALGOR *alg);
int
X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype,
void *pval);
void
X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype,
const void **ppval, const X509_ALGOR *alg);
int
X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b);
π¦ DESCRIPTION π¦
okay so an X509_ALGOR object represents an ASN.1 AlgorithmIdentifier structure, and that's the one defined in RFC 5280 section 4.1.1.2 β yes, the real one, no cap. what it does is specify a cryptographic algorithm using an ASN.1 object identifier (OID) that you can get from OBJ_nid2obj(3), plus optional algorithm-specific parameters of the type ASN1_TYPE β peep ASN1_TYPE_set(3) for that. and like, X509_ALGOR objects are used by sooo many other objects β for example certificates, certificate revocation lists, and certificate requests. main character energy honestly π
X509_ALGOR_new() allocates a whole new X509_ALGOR object, and it comes pre-loaded with the object that OBJ_nid2obj(3) returns for NID_undef as the algorithm, plus a NULL pointer as the parameters. blank slate, clean girl aesthetic β¨
X509_ALGOR_free() frees alg and any data contained in it. if alg is NULL, no action occurs β nothing happens, we simply don't β
X509_ALGOR_dup() creates a deep copy of alg. like a full clone, not just a link to the same post π it's implemented by calling ASN1_item_dup(3) with arguments of X509_ALGOR_it and alg, which is equivalent to calling i2d_X509_ALGOR(3) and d2i_X509_ALGOR(3).
X509_ALGOR_set0() sets the algorithm OID of alg to aobj, and the associated parameter type to ptype with value pval. now the details, because this is where it gets juicy:
- If
ptypeisV_ASN1_UNDEF, the parameter is omitted andpvalis ignored. - If
ptypeis zero,pvalis ignored and the existing parameter is left unchanged β or, ifalgdoes not contain a parameter, a new, empty parameter of typeV_ASN1_UNDEFis added. - Otherwise
ptypeandpvalhave the same meaning as the type and value parameters toASN1_TYPE_set(3).
ownership of aobj and, unless it is ignored, of pval is transferred to alg on success. so like, hand them over, they're hers now π
X509_ALGOR_get0() returns alg's algorithm OID in *paobj, its parameter type in *pptype, and its parameter value in *ppval. any of paobj, pptype, and ppval can be NULL. and heads up β if pptype is NULL or if *pptype is V_ASN1_UNDEF, then *ppval's value is undefined β οΈ so don't go reading it, bestie.
X509_ALGOR_cmp() compares a and b. that's it, that's the vibe check π
π RETURN VALUES π
X509_ALGOR_new()andX509_ALGOR_dup()return a newX509_ALGORobject orNULLif an error occurs.X509_ALGOR_set0()returns1for success or0ifalgisNULLor memory allocation fails.X509_ALGOR_cmp()returns0ifaandbhave identical encodings or non-zero otherwise.
π SEE ALSO π
go read these next, they're all linked up like a little friend group π«Ά
ASN1_TYPE_set(3), d2i_X509_ALGOR(3), EVP_DigestInit(3), OBJ_nid2obj(3), X509_get0_signature(3), X509_new(3), X509_PUBKEY_get0_param(3), X509_signature_dump(3)
β STANDARDS β
RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile β yes, the full name, we respect the classics π
π HISTORY π
the lore goes deep, ngl:
X509_ALGOR_new()andX509_ALGOR_free()appeared inSSLeay 0.4or earlier and have been available sinceOpenBSD 2.4.X509_ALGOR_dup()first appeared inSSLeay 0.9.1and has been available sinceOpenBSD 2.6.X509_ALGOR_set0()andX509_ALGOR_get0()first appeared inOpenSSL 0.9.8hand have been available sinceOpenBSD 4.5.X509_ALGOR_cmp()first appeared inOpenSSL 0.9.8zd,1.0.0p, and1.0.1kand has been available sinceOpenBSD 4.9.
and that's the page, bestie!! brought to you by the good people of Debian, dated June 8, 2025, filed under X509_ALGOR_DUP(3) in the Library Functions Manual πβ¨π go forth and identify those algorithms, slay π¦
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
- Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2002, 2015 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms