ASN1_INTEGER_GET(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… 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_uint64
  • ASN1_INTEGER_get_int64
  • ASN1_INTEGER_get
  • ASN1_INTEGER_set_uint64
  • ASN1_INTEGER_set_int64
  • ASN1_INTEGER_set
  • ASN1_INTEGER_cmp
  • ASN1_INTEGER_dup
  • BN_to_ASN1_INTEGER
  • ASN1_INTEGER_to_BN
  • ASN1_ENUMERATED_get_int64
  • ASN1_ENUMERATED_get
  • ASN1_ENUMERATED_set_int64
  • ASN1_ENUMERATED_set
  • BN_to_ASN1_ENUMERATED
  • ASN1_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() and ASN1_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 the long type. yeah, deprecated, we'll get to that in the caveats.
  • ASN1_INTEGER_set_uint64(), ASN1_INTEGER_set_int64(), and ASN1_INTEGER_set() β€” these set the type of a to V_ASN1_INTEGER or V_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 as ASN1_STRING_dup(3) without providing any type safety, except that it fails if the ASN1_STRING_length(3) of a is 0. 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 an ASN1_INTEGER. if ai is NULL, a new ASN1_INTEGER object is returned. otherwise, the existing object ai is used instead. your choice, main character 🌟
  • ASN1_INTEGER_to_BN() β€” converts ai into a BIGNUM. if bn is NULL, a new BIGNUM object 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(), and ASN1_ENUMERATED_to_BN() β€” these all behave like their ASN1_INTEGER counterparts except that they operate on an ASN1_ENUMERATED object. 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() returns 1 in case of success, or 0 if a is not of the type V_ASN1_INTEGER or greater than UINT64_MAX.
  • ASN1_INTEGER_get_int64() returns 1 in case of success, or 0 if a is not of the type V_ASN1_INTEGER or V_ASN1_NEG_INTEGER, less than INT64_MIN, or greater than INT64_MAX.
  • ASN1_INTEGER_get() and ASN1_ENUMERATED_get() return the converted value, 0 if a is NULL, or -1 on error β€” which is ambiguous because -1 is a legitimate value for an ASN1_INTEGER. yeah. that's a real problem. see caveats πŸ’€
  • ASN1_INTEGER_set_uint64(), ASN1_INTEGER_set_int64(), ASN1_INTEGER_set(), ASN1_ENUMERATED_set_int64(), and ASN1_ENUMERATED_set() return 1 for success or 0 for 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 than 0 if 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 allocated ASN1_STRING structure or NULL if a is a NULL pointer, if the length of a is 0, or if memory allocation fails.
  • BN_to_ASN1_INTEGER() and BN_to_ASN1_ENUMERATED() return an ASN1_INTEGER or ASN1_ENUMERATED object, respectively, or NULL if an error occurs. they only fail due to memory allocation errors. blessed 😌
  • ASN1_INTEGER_to_BN() and ASN1_ENUMERATED_to_BN() return a BIGNUM object of NULL if an error occurs. and yes, the page literally says "of NULL" β€” 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(), and ASN1_INTEGER_to_BN() first appeared in SSLeay 0.6.0.
  • ASN1_INTEGER_cmp() and ASN1_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(), and ASN1_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(), and ASN1_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(), and ASN1_INTEGER_to_BN() do not check whether their arguments are really of the type V_ASN1_INTEGER or V_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 of ASN1_INTEGER_dup() is not guaranteed to be of the type V_ASN1_INTEGER or `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 type V_ASN1_ENUMERATED or V_ASN1_NEG_ENUMERATED and 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