XBinder  Version 2.6.x
rtxBigInt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2018 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 
247 EXTERNRT int rtxBigIntPrint
248 (const OSUTF8CHAR* name, const OSBigInt* bigint, int radix);
249 
260 EXTERNRT int rtxBigIntCompare (const OSBigInt* arg1, const OSBigInt* arg2);
261 
273 EXTERNRT int rtxBigIntStrCompare
274 (OSCTXT* pctxt, const char* arg1, const char* arg2);
275 
283 EXTERNRT void rtxBigIntFree (OSCTXT* pctxt, OSBigInt* pInt);
284 
285 /* Arithmetic */
295 EXTERNRT int rtxBigIntAdd
296  (OSCTXT* pctxt,
297  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
298 
308 EXTERNRT int rtxBigIntSubtract
309  (OSCTXT* pctxt,
310  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
311 
321 EXTERNRT int rtxBigIntMultiply
322  (OSCTXT* pctxt,
323  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
324 
325 /* Common */
326 EXTERNRT unsigned short rtxBigIntBitsPerDigit (int radix);
327 EXTERNRT short rtxBigIntByteRadix (int halfRadix);
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif /* RTXBIGINT */
334 
EXTERNRT int rtxBigIntAdd(OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
This function is used to add two big integer values.
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 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 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:185
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...