---
name: "libressl-ASN1_INTEGER_get"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-ASN1_INTEGER_get"
---

# libressl-ASN1\_INTEGER\_get(3)

ASN.1 INTEGER and ENUMERATED utilities

## NAME

**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** – ASN.1 INTEGER and ENUMERATED utilities

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/asn1.h\>**

*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*);

## DESCRIPTION

These functions convert to and from *ASN1\_INTEGER* and *ASN1\_ENUMERATED* objects.

**ASN1\_INTEGER\_get\_uint64**() and **ASN1\_INTEGER\_get\_int64**() store the value of *a* in \**out\_val* if successful.

The deprecated function **ASN1\_INTEGER\_get**() converts *a* to the *long* type.

**ASN1\_INTEGER\_set\_uint64**(), **ASN1\_INTEGER\_set\_int64**(), and **ASN1\_INTEGER\_set**() set the type of *a* to V\_ASN1\_INTEGER or V\_ASN1\_NEG\_INTEGER depending on the sign of *v* and set the value of *a* to *v*.

**ASN1\_INTEGER\_cmp**() compares the signed integer numbers represented by *a1* and *a2*.

**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.

**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.

**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.

**ASN1\_ENUMERATED\_get\_int64**(), **ASN1\_ENUMERATED\_get**(), **ASN1\_ENUMERATED\_set\_int64**(), **ASN1\_ENUMERATED\_set**(), **BN\_to\_ASN1\_ENUMERATED**(), and **ASN1\_ENUMERATED\_to\_BN**() behave like their *ASN1\_INTEGER* counterparts except that they operate on an *ASN1\_ENUMERATED* object.

## RETURN VALUES

**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*.

**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. They only fail if a memory allocation error occurs.

**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.

**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.

**ASN1\_INTEGER\_to\_BN**() and **ASN1\_ENUMERATED\_to\_BN**() return a *BIGNUM* object of NULL if an error occurs. They can fail if the passed type is incorrect (due to a programming error) or due to memory allocation failures.

## SEE ALSO

ASN1\_INTEGER\_new(3), ASN1\_STRING\_length(3)

## HISTORY

**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.

**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.

**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.

## CAVEATS

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. The ambiguous return values of **ASN1\_INTEGER\_get**() and **ASN1\_ENUMERATED\_get**() imply that these functions should be avoided if possible.

## BUGS

**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.

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.
