|
|
 |
 |
|
Detailed Description
Arbitrary-precision integer manipulating functions are used to maintain big integers used within the ASN.1 run-time functions. Big integer variables are passed in and out of ASN.1 C encode and decode functions as character strings. Internally, a special structure is used for performing an arbitrary-precision match.
|
Functions |
| void | rtBigIntInit (ASN1BigInt *pInt) |
| int | rtBigIntSetStr (ASN1CTXT *pCtxt, ASN1BigInt *pInt, ASN1ConstCharPtr value, int radix) |
| int | rtBigIntSetInt64 (ASN1CTXT *pCtxt, ASN1BigInt *pInt, ASN1INT64 value) |
| int | rtBigIntSetBytes (ASN1CTXT *pCtxt, ASN1BigInt *pInt, ASN1OCTET *value, size_t vallen) |
| size_t | rtBigIntGetDataLen (ASN1BigInt *pInt) |
| long | rtBigIntGetData (ASN1CTXT *pCtxt, ASN1BigInt *pInt, ASN1OCTET *buffer, size_t bufSize) |
| int | rtBigIntDigitsNum (ASN1BigInt *pInt, int radix) |
| int | rtBigIntCopy (ASN1CTXT *pCtxt, const ASN1BigInt *pSrc, ASN1BigInt *pDst) |
| int | rtBigIntFastCopy (ASN1CTXT *pCtxt, ASN1BigInt *pSrc, ASN1BigInt *pDst) |
| int | rtBigIntToString (ASN1CTXT *pCtxt, ASN1BigInt *pInt, int radix, char *str, size_t strSize) |
| int | rtBigIntPrint (ASN1ConstCharPtr name, ASN1BigInt *bigint, int radix) |
| int | rtBigIntCompare (const ASN1BigInt *arg1, const ASN1BigInt *arg2) |
| int | rtBigIntStrCompare (ASN1CTXT *pCtxt, ASN1ConstCharPtr arg1, ASN1ConstCharPtr arg2) |
| void | rtBigIntFree (ASN1CTXT *pCtxt, ASN1BigInt *pInt) |
Function Documentation
| int rtBigIntCompare |
( |
const ASN1BigInt * |
arg1, |
|
|
const ASN1BigInt * |
arg2 |
|
) |
|
|
|
|
This function compares two big integer values. The result of comparison can be -1 (first value less than the second one), 0 (both values are equal), and 1 (the first value is greater than the second one).
- Parameters:
-
| arg1 | The first big integer value to compare. |
| arg2 | The second big integer value to compare. |
- Returns:
- The result of the comparison (-1, 0, 1).
|
| int rtBigIntCopy |
( |
ASN1CTXT * |
pCtxt, |
|
|
const ASN1BigInt * |
pSrc, |
|
|
ASN1BigInt * |
pDst |
|
) |
|
|
|
|
This function copies one big integer structure into another one. The destination big integer structure should not be initialized yet.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pSrc | The source big integer value to copy. |
| pDst | The destination big integer value to receive the copied value. This should not be initialized. |
- Returns:
- The status value of the operation.
|
| int rtBigIntDigitsNum |
( |
ASN1BigInt * |
pInt, |
|
|
int |
radix |
|
) |
|
|
|
|
This function returns the approximate number of digits of the big integer value according to the specified radix. This function may be used to calculate the size of the buffer for the rtBigIntToString function. The number of digits might be slightly greater than really necessary, but never less.
- Parameters:
-
| pInt | A pointer to a big integer structure. |
| radix | The base of value. Must be 2, 8, 10, or 16. |
- Returns:
- The approximated number of digits of the big integer.
|
| int rtBigIntFastCopy |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1BigInt * |
pSrc, |
|
|
ASN1BigInt * |
pDst |
|
) |
|
|
|
|
This function copies one big structure into another one. The destination big integer structure should be initialized before use of this function. This function might be faster than rtBigIntCopy because if the destination big integer already has enough allocated memory then memory will be reused without allocation.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pSrc | The source big integer value to copy. |
| pDst | The destination big integer value to receive the copied value. This should be initialized. |
- Returns:
- The status value of the operation.
|
| void rtBigIntFree |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1BigInt * |
pInt |
|
) |
|
|
|
|
This function releases memory if it was called for the current big integer. If the memory was not allocated or static memory was used, this function does nothing. It is recommended to not use the big integer structure after the rtBigIntFree is invoked for it.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pInt | A pointer to a big integer structure that will be freed. |
|
| long rtBigIntGetData |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1BigInt * |
pInt, |
|
|
ASN1OCTET * |
buffer, |
|
|
size_t |
bufSize |
|
) |
|
|
|
|
This function copies the two's complement binary representation of a big integer into an octet string. The output will be in big-endian octet-order: the most significant octet will be in the zeroth element.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pInt | A pointer to the big integer structure. |
| buffer | A pointer to an octet array to receive the two's complement binary representation of a arbitrary-precision integer. |
| bufSize | The length of an octet array. |
- Returns:
- If positive, number of octets actually copied to the buffer. If negative - the status value of the operation.
|
| size_t rtBigIntGetDataLen |
( |
ASN1BigInt * |
pInt |
) |
|
|
|
|
This function returns the number of octets necessary for storing a big integer value in the octet array. This function may be used for calculating the necessary buffer size for the rtBigIntGetData.
- Parameters:
-
| pInt | A pointer to the big integer structure onto which the value is to be stored. |
- Returns:
- The number of octets, necessary for storing a big integer value in the octet string.
|
| void rtBigIntInit |
( |
ASN1BigInt * |
pInt |
) |
|
|
|
|
This function initializes a big integer structure. This function should be called before the first use of the big integer.
- Parameters:
-
| pInt | A pointer to the big integer structure to be initialized. |
|
| int rtBigIntPrint |
( |
ASN1ConstCharPtr |
name, |
|
|
ASN1BigInt * |
bigint, |
|
|
int |
radix |
|
) |
|
|
|
|
This function prints a big integer value to standard output (stdout), according to the specified radix. In general, this function is very similar to the rtBigIntToString function. It simply prints the output value to standard output in a "name = value" format.
- Parameters:
-
| name | The name of the variable to print. |
| bigint | The big integer value to print. |
| radix | The base value for conversion to print. It must be 2, 8, 10, or 16. |
|
| int rtBigIntSetBytes |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1BigInt * |
pInt, |
|
|
ASN1OCTET * |
value, |
|
|
size_t |
vallen |
|
) |
|
|
|
|
This function translates an octet array containing the two's complement binary representation of an arbitrary-precision integer into a bigger structure. The input array is assumed to be in big-endian octet-order: the most significant octet is in the zeroth element.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pInt | A pointer to the big integer structure onto which the value is to be stored. A pointer to an updated big integer structure. |
| vallen | The length of the array. |
| value | The pointer to an octet array with two's complement binary representation of an arbitrary-precision integer. |
- Returns:
- The status value of the operation.
|
| int rtBigIntSetInt64 |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1BigInt * |
pInt, |
|
|
ASN1INT64 |
value |
|
) |
|
|
|
|
This function converts the ASNINT64 value to a big integer structure. An ASN1INT64 type is a 64-bit integer if the platform supports 64-bit integers. In the other case, it will be a 32-bit integer.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pInt | A pointer to the big integer structure onto which the value is to be stored. A pointer to an updated big integer structure. |
| value | A pointer to a character string to be converted. |
- Returns:
- The status value of the operation.
|
| int rtBigIntSetStr |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1BigInt * |
pInt, |
|
|
ASN1ConstCharPtr |
value, |
|
|
int |
radix |
|
) |
|
|
|
|
This function converts the character string to a big integer structure. The string might contain the prefix to indicate the radix ('0x' - 16, '0o' - 8, '0b' - 2, otherwise 10). In this case the radix argument should be set to 0.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pInt | A pointer to the big integer structure onto which the value is to be stored. A pointer to an updated big integer structure. |
| value | A pointer to a character string to be converted. |
| radix | The base value of pString. Must be 0, 2, 8, 10 or 16. If radix is 0 then the radix will be set according to string prefix ('0x' - 16, '0o' - 8, '0b' - 2, otherwise 10). |
- Returns:
- The status value of the operation.
|
| int rtBigIntStrCompare |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1ConstCharPtr |
arg1, |
|
|
ASN1ConstCharPtr |
arg2 |
|
) |
|
|
|
|
This function compares two big integer values, which are represented as strings. The strings might contain prefixes to indicate the actual radix of the big integer value ('0x' - 16, '0o' - 8, '0b' - 2, otherwise 10). The result of comparison can be -1 (first value less than the second one), 0 (both values are equal), and 1 (the first value is greater than the second one).
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| arg1 | The first big integer value to compare. |
| arg2 | The second big integer value to compare. |
- Returns:
- The result of the comparison (-1, 0, 1).
|
| int rtBigIntToString |
( |
ASN1CTXT * |
pCtxt, |
|
|
ASN1BigInt * |
pInt, |
|
|
int |
radix, |
|
|
char * |
str, |
|
|
size_t |
strSize |
|
) |
|
|
|
|
This function converts a big integer to a string according to the specified radix.
- Parameters:
-
| pCtxt | A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls. |
| pInt | A pointer to a big integer structure to be converted into a string. |
| radix | A base value for conversion. It must be 2, 8, 10, or 16. |
| strSize | The size of str. |
| str | A pointer to the buffer to receive the converted character string. |
- Returns:
- The status value of the operation.
|
|
This document may be distributed in any form, electronic
or otherwise, provided that it is distributed in its entirety
and that the copyright and this notice are included.
|
This file was last modified on
1 Oct 2004. ASN1C C/C++ Common Runtime, ASN1C v5.7x |
|