ASN1_INTEGER_GET(3)
π ASN1_INTEGER_GET π
okay so this is one of those Library Functions Manual pages, bestie β specifically the libcrypto one about ASN.1 INTEGER and ENUMERATED utilities. it's a lot of function names, but like, they're all variations on the same vibe, i promise. stay with me π«Ά
β¨ NAME β¨
girl, take a breath, here's the whole squad:
ASN1_INTEGER_get_uint64ASN1_INTEGER_get_int64ASN1_INTEGER_getASN1_INTEGER_set_uint64ASN1_INTEGER_set_int64ASN1_INTEGER_setASN1_INTEGER_cmpASN1_INTEGER_dupBN_to_ASN1_INTEGERASN1_INTEGER_to_BNASN1_ENUMERATED_get_int64ASN1_ENUMERATED_getASN1_ENUMERATED_set_int64ASN1_ENUMERATED_setBN_to_ASN1_ENUMERATEDASN1_ENUMERATED_to_BN
and collectively they're your ASN.1 INTEGER and ENUMERATED utilities. that's the whole personality β¨
π¦ SYNOPSIS π¦
okay so this pulls from the libcrypto library, and you're gonna need this:
#include <openssl/asn1.h>
then, like, all of these:
int
ASN1_INTEGER_get_uint64(uint64_t *out_val, const ASN1_INTEGER *a);
int
ASN1_INTEGER_get_int64(int64_t *out_val, const ASN1_INTEGER *a);
long
ASN1_INTEGER_get(const ASN1_INTEGER *a);
int
ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t v);
int
ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t v);
int
ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
int
ASN1_INTEGER_cmp(const ASN1_INTEGER *a1, const ASN1_INTEGER *a2);
ASN1_INTEGER *
ASN1_INTEGER_dup(const ASN1_INTEGER *a);
ASN1_INTEGER *
BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
BIGNUM *
ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
int
ASN1_ENUMERATED_get_int64(int64_t *out_val, const ASN1_ENUMERATED *a);
long
ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
int
ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t v);
int
ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
ASN1_ENUMERATED *
BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai);
BIGNUM *
ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn);
no cap, that's the whole list. slay π
πΈ DESCRIPTION πΈ
the core concept: these functions convert to and from ASN1_INTEGER and ASN1_ENUMERATED objects. it's giving translator energy π
ASN1_INTEGER_get_uint64()andASN1_INTEGER_get_int64()β these two store the value of a into*out_val, but only if it works out. if it succeeds, slay πASN1_INTEGER_get()β the deprecated one π converts a to thelongtype. yeah, deprecated, we'll get to that in the caveats.ASN1_INTEGER_set_uint64(),ASN1_INTEGER_set_int64(), andASN1_INTEGER_set()β these set the type of a toV_ASN1_INTEGERorV_ASN1_NEG_INTEGER, depending on the sign of v, and then set the value of a to v. the sign picks the vibe, basically β¨ASN1_INTEGER_cmp()β compares the signed integer numbers represented by a1 and a2. head-to-head, let them fight π«ΆASN1_INTEGER_dup()β does exactly the same asASN1_STRING_dup(3)without providing any type safety, except that it fails if theASN1_STRING_length(3)of a is0. so like... it's the dupe but with a little extra condition, and the "no type safety" part is genuinely not a flex, bestie πBN_to_ASN1_INTEGER()β converts bn to anASN1_INTEGER. if ai isNULL, a newASN1_INTEGERobject is returned. otherwise, the existing object ai is used instead. your choice, main character πASN1_INTEGER_to_BN()β converts ai into aBIGNUM. if bn isNULL, a newBIGNUMobject is returned. otherwise, the existing object bn is used instead. same deal, opposite direction πASN1_ENUMERATED_get_int64(),ASN1_ENUMERATED_get(),ASN1_ENUMERATED_set_int64(),ASN1_ENUMERATED_set(),BN_to_ASN1_ENUMERATED(), andASN1_ENUMERATED_to_BN()β these all behave like theirASN1_INTEGERcounterparts except that they operate on anASN1_ENUMERATEDobject. literally the same icon, different font π
π RETURN VALUES π
this is the part where you gotta pay attention, bestie, the numbers are doing the talking π£οΈ
ASN1_INTEGER_get_uint64()returns1in case of success, or0if a is not of the typeV_ASN1_INTEGERor greater thanUINT64_MAX.ASN1_INTEGER_get_int64()returns1in case of success, or0if a is not of the typeV_ASN1_INTEGERorV_ASN1_NEG_INTEGER, less thanINT64_MIN, or greater thanINT64_MAX.ASN1_INTEGER_get()andASN1_ENUMERATED_get()return the converted value,0if a isNULL, or-1on error β which is ambiguous because-1is a legitimate value for anASN1_INTEGER. yeah. that's a real problem. see caveats πASN1_INTEGER_set_uint64(),ASN1_INTEGER_set_int64(),ASN1_INTEGER_set(),ASN1_ENUMERATED_set_int64(), andASN1_ENUMERATED_set()return1for success or0for failure. and honestly? they only fail if a memory allocation error occurs. lowkey forgiving π«ΆASN1_INTEGER_cmp()returns a value greater than, equal to, or less than0if the signed integer number represented by a1 is greater than, equal to, or less than the signed integer number represented by a2, respectively. classic compare-core πASN1_INTEGER_dup()returns a pointer to a newly allocatedASN1_STRINGstructure orNULLif a is aNULLpointer, if the length of a is0, or if memory allocation fails.BN_to_ASN1_INTEGER()andBN_to_ASN1_ENUMERATED()return anASN1_INTEGERorASN1_ENUMERATEDobject, respectively, orNULLif an error occurs. they only fail due to memory allocation errors. blessed πASN1_INTEGER_to_BN()andASN1_ENUMERATED_to_BN()return aBIGNUMobject ofNULLif an error occurs. and yes, the page literally says "ofNULL" β im just relaying it exactly, don't come for me π they can fail if the passed type is incorrect (due to a programming error) or due to memory allocation failures.
π₯ SEE ALSO π₯
go read these next, bestie, they're the supporting cast:
π HISTORY π
storytime, because this lore goes back decades:
ASN1_INTEGER_set()first appeared in SSLeay 0.5.1.ASN1_INTEGER_get(),BN_to_ASN1_INTEGER(), andASN1_INTEGER_to_BN()first appeared in SSLeay 0.6.0.ASN1_INTEGER_cmp()andASN1_INTEGER_dup()first appeared in SSLeay 0.6.5.- these functions have been available since OpenBSD 2.3.
then a second wave:
ASN1_ENUMERATED_get(),ASN1_ENUMERATED_set(),BN_to_ASN1_ENUMERATED(), andASN1_ENUMERATED_to_BN()first appeared in OpenSSL 0.9.2b and have been available since OpenBSD 2.6.
and the actual babies of the group:
ASN1_INTEGER_get_uint64(),ASN1_INTEGER_get_int64(),ASN1_INTEGER_set_uint64(),ASN1_INTEGER_set_int64(),ASN1_ENUMERATED_get_int64(), andASN1_ENUMERATED_set_int64()first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 7.2.
generational icons, honestly π
β οΈ CAVEATS β οΈ
bestie. listen. this part matters.
in general an ASN1_INTEGER or ASN1_ENUMERATED type can contain an integer of almost arbitrary size and so cannot always be represented by a C long type. like, it simply does not fit, periodt.
and the ambiguous return values of ASN1_INTEGER_get() and ASN1_ENUMERATED_get() imply that these functions should be avoided if possible. avoided if possible. that's a direct quote, im not being dramatic for once π
π BUGS π
okay so the messy part. buckle up.
ASN1_INTEGER_cmp(),ASN1_INTEGER_dup(), andASN1_INTEGER_to_BN()do not check whether their arguments are really of the typeV_ASN1_INTEGERorV_ASN1_NEG_INTEGER. they may report success even if their arguments are of a wrong type. consequently, even in case of success, the return value ofASN1_INTEGER_dup()is not guaranteed to be of the typeV_ASN1_INTEGERor `V_ASN1_NEG_INTEGER either. so it can say "yeah it worked β¨" about something that isn't what you think it is. not the flex it thinks it is π«- similarly,
ASN1_ENUMERATED_to_BN()does not check whether its argument is really of the typeV_ASN1_ENUMERATEDorV_ASN1_NEG_ENUMERATEDand may report success even if the argument is of a wrong type. same disease, different function π
so yeah, that's the whole page. no skipped options, no skipped warnings, we went through all of it together π
mwah, this page came from Debian, dated June 8, 2025 β filed under Library Functions Manual as ASN1_INTEGER_GET(3) πβ¨ love that for us, bye bestie! π
π¦ 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) 2018, 2021, 2022 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 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