XBinder  Version 2.9.x
rtxBigInt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2022 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
28 #ifndef _RTXBIGINT_H_
29 #define _RTXBIGINT_H_
30 
31 #include "rtxsrc/rtxContext.h"
32 
33 /* Big Integer */
34 
35 typedef struct OSBigInt {
36  OSSIZE numocts; /* number of used octets in mag */
37  OSOCTET *mag; /* magnitude. Unsigned integer, big-endian
38  format. Must not have leading zero
39  bytes. */
40  int sign; /* sign, can be -1, 0, 1 */
41  OSSIZE allocated; /* number of allocated octets for mag */
42  OSBOOL dynamic; /* is buffer dynamic? */
43 } OSBigInt;
44 
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /* BigInt functions */
51 
58 EXTERNRT void rtxBigIntInit (OSBigInt* pInt);
59 
72 EXTERNRT int rtxBigIntEnsureCapacity(OSCTXT* pctxt, OSBigInt* pInt,
73  OSSIZE capacity);
74 
86 EXTERNRT int rtxBigIntSetStr
87 (OSCTXT* pctxt, OSBigInt* pInt, const char* value, int radix);
88 
102 EXTERNRT int rtxBigIntSetStrn
103 (OSCTXT* pctxt, OSBigInt* pInt, const char* value, OSSIZE len, int radix);
104 
114 EXTERNRT int rtxBigIntSetInt64 (OSCTXT* pctxt, OSBigInt* pInt, OSINT64 value);
115 
125 EXTERNRT int rtxBigIntSetUInt64
126 (OSCTXT* pctxt, OSBigInt* pInt, OSUINT64 value);
127 
138 EXTERNRT int rtxBigIntSetBytesSigned
139 (OSCTXT* pctxt, OSBigInt* pInt, OSOCTET* value, OSSIZE vallen);
140 
141 #define rtxBigIntSetBytes rtxBigIntSetBytesSigned
142 
153 EXTERNRT int rtxBigIntSetBytesUnsigned
154 (OSCTXT* pctxt, OSBigInt* pInt, OSOCTET* value, OSSIZE vallen);
155 
163 EXTERNRT OSSIZE rtxBigIntGetDataLen (const OSBigInt* pInt);
164 
176 EXTERNRT int rtxBigIntGetData
177 (OSCTXT* pctxt, const OSBigInt* pInt, OSOCTET* buffer, OSSIZE bufSize);
178 
187 EXTERNRT OSSIZE rtxBigIntDigitsNum (const OSBigInt* pInt, int radix);
188 
198 EXTERNRT int rtxBigIntCopy
199 (OSCTXT* pctxt, const OSBigInt* pSrc, OSBigInt* pDst);
200 
212 EXTERNRT int rtxBigIntFastCopy
213 (OSCTXT* pctxt, const OSBigInt* pSrc, OSBigInt* pDst);
214 
223 EXTERNRT OSBOOL rtxBigIntToReal(const OSBigInt* pSrc, OSREAL* pvalue);
224 
225 
236 EXTERNRT int rtxBigIntToString
237 (OSCTXT* pctxt, const OSBigInt* pInt, int radix, char* str, OSSIZE strSize);
238 
250 EXTERNRT char* rtxBigIntToDynStr
251 (OSCTXT* pctxt, const OSBigInt* pInt, int radix);
252 
261 EXTERNRT int rtxBigIntPrint
262 (const OSUTF8CHAR* name, const OSBigInt* bigint, int radix);
263 
274 EXTERNRT int rtxBigIntCompare (const OSBigInt* arg1, const OSBigInt* arg2);
275 
287 EXTERNRT int rtxBigIntStrCompare
288 (OSCTXT* pctxt, const char* arg1, const char* arg2);
289 
297 EXTERNRT void rtxBigIntFree (OSCTXT* pctxt, OSBigInt* pInt);
298 
299 /* Arithmetic */
310 EXTERNRT int rtxBigIntAdd
311  (OSCTXT* pctxt,
312  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
313 
323 EXTERNRT int rtxBigIntSubtract
324  (OSCTXT* pctxt,
325  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
326 
336 EXTERNRT int rtxBigIntMultiply
337  (OSCTXT* pctxt,
338  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
339 
340 /* Common */
341 
349 EXTERN OSSIZE rtxBase2DigitsToRadix(OSUINT8 radix, OSSIZE n);
350 
351 
358 EXTERN OSSIZE rtxRadixDigitsToBase2(OSUINT8 radix, OSSIZE n);
359 
365 EXTERNRT unsigned short rtxBigIntBitsPerDigit (int halfRadix);
366 EXTERNRT short rtxBigIntByteRadix (int halfRadix);
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 #endif /* RTXBIGINT */
373 
EXTERNRT int rtxBigIntAdd(OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
This function is used to add two big integer values.
EXTERN OSSIZE rtxRadixDigitsToBase2(OSUINT8 radix, OSSIZE n)
Return the number of base 2 digits that may be required to represent an integer having n radix digits...
EXTERNRT 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.
EXTERNRT int rtxBigIntMultiply(OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
This function is used to multiply two big integer values.
EXTERNRT char * rtxBigIntToDynStr(OSCTXT *pctxt, const OSBigInt *pInt, int radix)
This function is used to convert a binary big integer value to a dynamic string.
EXTERNRT OSSIZE rtxBigIntGetDataLen(const OSBigInt *pInt)
This function is used to get the size in bytes of the binary big integer data value.
EXTERNRT void rtxBigIntInit(OSBigInt *pInt)
This function initializes a big integer structure.
EXTERNRT int rtxBigIntSetUInt64(OSCTXT *pctxt, OSBigInt *pInt, OSUINT64 value)
This function sets a big integer binary value from an unsigned 64-bit integer value.
EXTERNRT int rtxBigIntSetBytesUnsigned(OSCTXT *pctxt, OSBigInt *pInt, OSOCTET *value, OSSIZE vallen)
This function sets a big integer binary value from a byte array.
EXTERNRT 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.
EXTERNRT 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...
Common run-time context definitions.
EXTERNRT int rtxBigIntSetBytesSigned(OSCTXT *pctxt, OSBigInt *pInt, OSOCTET *value, OSSIZE vallen)
This function sets a big integer binary value from a byte array.
EXTERNRT int rtxBigIntPrint(const OSUTF8CHAR *name, const OSBigInt *bigint, int radix)
This function is used to print a big integer value to standard output.
EXTERNRT int rtxBigIntStrCompare(OSCTXT *pctxt, const char *arg1, const char *arg2)
This function is used to compare two big integer numeric strings.
EXTERNRT unsigned short rtxBigIntBitsPerDigit(int halfRadix)
For internal use only.
EXTERNRT int rtxBigIntCompare(const OSBigInt *arg1, const OSBigInt *arg2)
This function is used to compare two big integer values.
EXTERNRT int rtxBigIntSetStr(OSCTXT *pctxt, OSBigInt *pInt, const char *value, int radix)
This function sets a big integer binary value from a null-terminated string.
EXTERNRT void rtxBigIntFree(OSCTXT *pctxt, OSBigInt *pInt)
This function frees internal memory within the big integer structure.
EXTERNRT int rtxBigIntSetInt64(OSCTXT *pctxt, OSBigInt *pInt, OSINT64 value)
This function sets a big integer binary value from a signed 64-bit integer value. ...
EXTERNRT int rtxBigIntSubtract(OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
This function is used to subtract one big integer value from another.
EXTERNRT 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.
Run-time context structure.
Definition: rtxContext.h:198
EXTERNRT 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 chara...
EXTERNRT 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...
EXTERNRT int rtxBigIntFastCopy(OSCTXT *pctxt, const OSBigInt *pSrc, OSBigInt *pDst)
This function is used to copy one BigInt to another.
EXTERNRT 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...
EXTERN OSSIZE rtxBase2DigitsToRadix(OSUINT8 radix, OSSIZE n)
Return the number of radix digits that may be required to represent an integer having n base 2 digits...