ASN1C C/C++ Common Runtime  ASN1C v7.3.x
Classes | Macros | Typedefs | Functions
rtxBigInt.h File Reference
#include "rtxsrc/rtxContext.h"

Go to the source code of this file.

Classes

struct  OSBigInt
 

Macros

#define rtxBigIntSetBytes   rtxBigIntSetBytesSigned
 

Typedefs

typedef struct OSBigInt OSBigInt
 

Functions

void rtxBigIntInit (OSBigInt *pInt)
 
int rtxBigIntEnsureCapacity (OSCTXT *pctxt, OSBigInt *pInt, OSSIZE capacity)
 
int rtxBigIntSetStr (OSCTXT *pctxt, OSBigInt *pInt, const char *value, int radix)
 
int rtxBigIntSetStrn (OSCTXT *pctxt, OSBigInt *pInt, const char *value, OSSIZE len, int radix)
 
int rtxBigIntSetInt64 (OSCTXT *pctxt, OSBigInt *pInt, OSINT64 value)
 
int rtxBigIntSetUInt64 (OSCTXT *pctxt, OSBigInt *pInt, OSUINT64 value)
 
int rtxBigIntSetBytesSigned (OSCTXT *pctxt, OSBigInt *pInt, OSOCTET *value, OSSIZE vallen)
 
int rtxBigIntSetBytesUnsigned (OSCTXT *pctxt, OSBigInt *pInt, OSOCTET *value, OSSIZE vallen)
 
OSSIZE rtxBigIntGetDataLen (const OSBigInt *pInt)
 
int rtxBigIntGetData (OSCTXT *pctxt, const OSBigInt *pInt, OSOCTET *buffer, OSSIZE bufSize)
 
OSSIZE rtxBigIntDigitsNum (const OSBigInt *pInt, int radix)
 
int rtxBigIntCopy (OSCTXT *pctxt, const OSBigInt *pSrc, OSBigInt *pDst)
 
int rtxBigIntFastCopy (OSCTXT *pctxt, const OSBigInt *pSrc, OSBigInt *pDst)
 
OSBOOL rtxBigIntToReal (const OSBigInt *pSrc, OSREAL *pvalue)
 
int rtxBigIntToString (OSCTXT *pctxt, const OSBigInt *pInt, int radix, char *str, OSSIZE strSize)
 
int rtxBigIntPrint (const OSUTF8CHAR *name, const OSBigInt *bigint, int radix)
 
int rtxBigIntCompare (const OSBigInt *arg1, const OSBigInt *arg2)
 
int rtxBigIntStrCompare (OSCTXT *pctxt, const char *arg1, const char *arg2)
 
void rtxBigIntFree (OSCTXT *pctxt, OSBigInt *pInt)
 
int rtxBigIntAdd (OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
 
int rtxBigIntSubtract (OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
 
int rtxBigIntMultiply (OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
 
unsigned short rtxBigIntBitsPerDigit (int radix)
 
short rtxBigIntByteRadix (int halfRadix)
 

Function Documentation

◆ rtxBigIntAdd()

int rtxBigIntAdd ( OSCTXT pctxt,
OSBigInt result,
const OSBigInt arg1,
const OSBigInt arg2 
)

This function is used to add two big integer values.

Parameters
pctxtPointer to a context structure.
resultPointer to big integer structure to receive result.
arg1First big integer to add.
arg2Second big integer to add.
Returns
Result of operation: 0 = success, negative error code if error.

◆ rtxBigIntCompare()

int rtxBigIntCompare ( const OSBigInt arg1,
const OSBigInt arg2 
)

This function is used to compare two big integer values.

Parameters
arg1First big integer to compare.
arg2Second big integer to compare.
Returns
Result of comparison: -1 = arg1 < arg2, 0 = arg1 == arg2, +1 = arg1 > arg2

◆ rtxBigIntCopy()

int rtxBigIntCopy ( OSCTXT pctxt,
const OSBigInt pSrc,
OSBigInt pDst 
)

This function is used to copy a big integer data value from one structure to another.

Parameters
pctxtPointer to a context structure.
pSrcPointer to source big integer structure.
pDstPointer to destination big integer structure.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntDigitsNum()

OSSIZE rtxBigIntDigitsNum ( const OSBigInt pInt,
int  radix 
)

This function is used to get the number of digits in the binary big integer data value based on radix.

Parameters
pIntPointer to big integer structure.
radixRadix of the string value, Valid values are 2, 8, 10, or 16.
Returns
Number of digits in the binary data value.

◆ rtxBigIntEnsureCapacity()

int rtxBigIntEnsureCapacity ( OSCTXT pctxt,
OSBigInt pInt,
OSSIZE  capacity 
)

This function ensures that the big integer has capacity to hold at least the given number of bytes. This can be used prior to directly copying bytes into mag. POST: On a successful return, pInt->allocated <= capacity; pInt->dynamic might now be TRUE. The value of the big integer is unchanged.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure.
capacityRequired capacity.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntFastCopy()

int rtxBigIntFastCopy ( OSCTXT pctxt,
const OSBigInt pSrc,
OSBigInt pDst 
)

This function is used to copy one BigInt to another. This function will not allocate memory for the byte buffer if the destination BigInt already has a large enough allocated array to hold the data. The destination BigInt must have been initialized using the rtxBigIntInit function.

Parameters
pctxtPointer to a context structure.
pSrcPointer to source big integer structure.
pDstPointer to destination big integer structure.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntFree()

void rtxBigIntFree ( OSCTXT pctxt,
OSBigInt pInt 
)

This function frees internal memory within the big integer structure.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure in which memory is to be freed.

◆ rtxBigIntGetData()

int rtxBigIntGetData ( OSCTXT pctxt,
const OSBigInt pInt,
OSOCTET *  buffer,
OSSIZE  bufSize 
)

This function is used to get the binary big integer data value in a byte array.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure.
bufferBuffer into which binary big integer value is to be copied.
bufSizeSize of the data buffer.
Returns
If success, number of bytes in byte array; if error, negative error code.

◆ rtxBigIntGetDataLen()

OSSIZE rtxBigIntGetDataLen ( const OSBigInt pInt)

This function is used to get the size in bytes of the binary big integer data value.

Parameters
pIntPointer to big integer structure.
Returns
Length in bytes of the binary data value.

◆ rtxBigIntInit()

void rtxBigIntInit ( OSBigInt pInt)

This function initializes a big integer structure. It must be called prior to working with the structure.

Parameters
pIntPointer to big integer data structure.

◆ rtxBigIntMultiply()

int rtxBigIntMultiply ( OSCTXT pctxt,
OSBigInt result,
const OSBigInt arg1,
const OSBigInt arg2 
)

This function is used to multiply two big integer values.

Parameters
pctxtPointer to a context structure.
resultPointer to big integer structure to receive result.
arg1First big integer to be multiplied.
arg2Second big integer to be multiplied.
Returns
Result of operation: 0 = success, negative error code if error.

◆ rtxBigIntPrint()

int rtxBigIntPrint ( const OSUTF8CHAR *  name,
const OSBigInt bigint,
int  radix 
)

This function is used to print a big integer value to standard output.

Parameters
nameName to print in "name=value" format.
bigintPointer to big integer value to be printed.
radixRadix of the string value, Valid values are 2, 8, 10, or 16.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntSetBytesSigned()

int rtxBigIntSetBytesSigned ( OSCTXT pctxt,
OSBigInt pInt,
OSOCTET *  value,
OSSIZE  vallen 
)

This function sets a big integer binary value from a byte array. The array is assumed to hold the value in 2's complement form.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure to receive converted value.
valueBuffer containing binary integer value in 2's complement form.
vallenNumber of byte in the value buffer.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntSetBytesUnsigned()

int rtxBigIntSetBytesUnsigned ( OSCTXT pctxt,
OSBigInt pInt,
OSOCTET *  value,
OSSIZE  vallen 
)

This function sets a big integer binary value from a byte array. The array is assumed to hold the value in unsigned form.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure to receive converted value.
valueBuffer containing binary unsigned integer value.
vallenNumber of byte in the value buffer.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntSetInt64()

int rtxBigIntSetInt64 ( OSCTXT pctxt,
OSBigInt pInt,
OSINT64  value 
)

This function sets a big integer binary value from a signed 64-bit integer value.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure to receive converted value.
value64-bit integer value to convert.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntSetStr()

int rtxBigIntSetStr ( OSCTXT pctxt,
OSBigInt pInt,
const char *  value,
int  radix 
)

This function sets a big integer binary value from a null-terminated string.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure to receive converted value.
valueNumeric string to convert.
radixRadix of the string value, Valid values are 0, 2, 8, 10, or 16. Zero must be used if string contains a prefix that identifies the radix (for example, 0x).
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntSetStrn()

int rtxBigIntSetStrn ( OSCTXT pctxt,
OSBigInt pInt,
const char *  value,
OSSIZE  len,
int  radix 
)

This function sets a big integer binary value from a character string using the given number of characters.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure to receive converted value.
valueNumeric string to convert.
lenNumber of bytes from character string to use.
radixRadix of the string value, Valid values are 0, 2, 8, 10, or 16. Zero must be used if string contains a prefix that identifies the radix (for example, 0x).
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntSetUInt64()

int rtxBigIntSetUInt64 ( OSCTXT pctxt,
OSBigInt pInt,
OSUINT64  value 
)

This function sets a big integer binary value from an unsigned 64-bit integer value.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure to receive converted value.
value64-bit integer value to convert.
Returns
Status of the operation, 0 = success, negative code if error.

◆ rtxBigIntStrCompare()

int rtxBigIntStrCompare ( OSCTXT pctxt,
const char *  arg1,
const char *  arg2 
)

This function is used to compare two big integer numeric strings.

Parameters
pctxtPointer to a context structure.
arg1First big integer string to compare.
arg2Second big integer string to compare.
Returns
Result of comparison: -1 = arg1 < arg2, 0 = arg1 == arg2, +1 = arg1 > arg2

◆ rtxBigIntSubtract()

int rtxBigIntSubtract ( OSCTXT pctxt,
OSBigInt result,
const OSBigInt arg1,
const OSBigInt arg2 
)

This function is used to subtract one big integer value from another.

Parameters
pctxtPointer to a context structure.
resultPointer to big integer structure to receive result.
arg1Big integer value that arg2 is subtracted from (minuend).
arg2Big integer to be subtracted from arg1 (subtrahend).
Returns
Result of operation: 0 = success, negative error code if error.

◆ rtxBigIntToReal()

OSBOOL rtxBigIntToReal ( const OSBigInt pSrc,
OSREAL *  pvalue 
)

This function converts the given big integer to a real, if it will fit without requiring rounding (i.e. loss of precision).

Parameters
pvalueReceives the OSREAL value. If null, this function only tests whether the conversion can be done.
Returns
TRUE/FALSE indicating whether the value can fit in a OSREAL without rounding.

◆ rtxBigIntToString()

int rtxBigIntToString ( OSCTXT pctxt,
const OSBigInt pInt,
int  radix,
char *  str,
OSSIZE  strSize 
)

This function is used to convert a binary big integer value to a string.

Parameters
pctxtPointer to a context structure.
pIntPointer to big integer structure to convert.
radixRadix of the string value, Valid values are 2, 8, 10, or 16.
strCharacter string buffer to receive converted value.
strSizeSize, in bytes, of the character string buffer.
Returns
Status of the operation, 0 = success, negative code if error.