ASN1C C/C++ Common Runtime  ASN1C v7.6.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 */
309 EXTERNRT int rtxBigIntAdd
310  (OSCTXT* pctxt,
311  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
312 
322 EXTERNRT int rtxBigIntSubtract
323  (OSCTXT* pctxt,
324  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
325 
335 EXTERNRT int rtxBigIntMultiply
336  (OSCTXT* pctxt,
337  OSBigInt* result, const OSBigInt* arg1, const OSBigInt* arg2);
338 
339 /* Common */
340 EXTERNRT unsigned short rtxBigIntBitsPerDigit (int radix);
341 EXTERNRT short rtxBigIntByteRadix (int halfRadix);
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 
347 #endif /* RTXBIGINT */
348 
int rtxBigIntCopy(OSCTXT *pctxt, const OSBigInt *pSrc, OSBigInt *pDst)
int rtxBigIntCompare(const OSBigInt *arg1, const OSBigInt *arg2)
int rtxBigIntFastCopy(OSCTXT *pctxt, const OSBigInt *pSrc, OSBigInt *pDst)
int rtxBigIntSetInt64(OSCTXT *pctxt, OSBigInt *pInt, OSINT64 value)
int rtxBigIntMultiply(OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
void rtxBigIntInit(OSBigInt *pInt)
int rtxBigIntStrCompare(OSCTXT *pctxt, const char *arg1, const char *arg2)
int rtxBigIntGetData(OSCTXT *pctxt, const OSBigInt *pInt, OSOCTET *buffer, OSSIZE bufSize)
int rtxBigIntAdd(OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
int rtxBigIntSubtract(OSCTXT *pctxt, OSBigInt *result, const OSBigInt *arg1, const OSBigInt *arg2)
OSSIZE rtxBigIntDigitsNum(const OSBigInt *pInt, int radix)
int rtxBigIntEnsureCapacity(OSCTXT *pctxt, OSBigInt *pInt, OSSIZE capacity)
int rtxBigIntPrint(const OSUTF8CHAR *name, const OSBigInt *bigint, int radix)
char * rtxBigIntToDynStr(OSCTXT *pctxt, const OSBigInt *pInt, int radix)
int rtxBigIntSetStrn(OSCTXT *pctxt, OSBigInt *pInt, const char *value, OSSIZE len, int radix)
void rtxBigIntFree(OSCTXT *pctxt, OSBigInt *pInt)
int rtxBigIntToString(OSCTXT *pctxt, const OSBigInt *pInt, int radix, char *str, OSSIZE strSize)
int rtxBigIntSetStr(OSCTXT *pctxt, OSBigInt *pInt, const char *value, int radix)
OSBOOL rtxBigIntToReal(const OSBigInt *pSrc, OSREAL *pvalue)
int rtxBigIntSetBytesUnsigned(OSCTXT *pctxt, OSBigInt *pInt, OSOCTET *value, OSSIZE vallen)
Definition: rtxContext.h:198
Definition: rtxBigInt.h:35
int rtxBigIntSetBytesSigned(OSCTXT *pctxt, OSBigInt *pInt, OSOCTET *value, OSSIZE vallen)
OSSIZE rtxBigIntGetDataLen(const OSBigInt *pInt)
int rtxBigIntSetUInt64(OSCTXT *pctxt, OSBigInt *pInt, OSUINT64 value)