Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tomcrypt/src/headers/tommath.h
5971 views
1
/* LibTomMath, multiple-precision integer library -- Tom St Denis
2
*
3
* LibTomMath is a library that provides multiple-precision
4
* integer arithmetic as well as number theoretic functionality.
5
*
6
* The library was designed directly after the MPI library by
7
* Michael Fromberger but has been written from scratch with
8
* additional optimizations in place.
9
*
10
* SPDX-License-Identifier: Unlicense
11
*/
12
#ifndef BN_H_
13
#define BN_H_
14
15
#include <stdlib.h>
16
#include <stdint.h>
17
#include <limits.h>
18
19
#define LTM_NO_FILE
20
21
#ifdef __cplusplus
22
extern "C" {
23
#endif
24
25
/* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */
26
#if defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)
27
# define MP_32BIT
28
#endif
29
30
/* detect 64-bit mode if possible */
31
#if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) || \
32
defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \
33
defined(__s390x__) || defined(__arch64__) || defined(__aarch64__) || \
34
defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
35
defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
36
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
37
# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
38
# if defined(__GNUC__)
39
/* we support 128bit integers only via: __attribute__((mode(TI))) */
40
# define MP_64BIT
41
# else
42
/* otherwise we fall back to MP_32BIT even on 64bit platforms */
43
# define MP_32BIT
44
# endif
45
# endif
46
#endif
47
48
/* some default configurations.
49
*
50
* A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
51
* A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
52
*
53
* At the very least a mp_digit must be able to hold 7 bits
54
* [any size beyond that is ok provided it doesn't overflow the data type]
55
*/
56
#ifdef MP_8BIT
57
typedef uint8_t mp_digit;
58
typedef uint16_t mp_word;
59
# define MP_SIZEOF_MP_DIGIT 1
60
# ifdef DIGIT_BIT
61
# error You must not define DIGIT_BIT when using MP_8BIT
62
# endif
63
#elif defined(MP_16BIT)
64
typedef uint16_t mp_digit;
65
typedef uint32_t mp_word;
66
# define MP_SIZEOF_MP_DIGIT 2
67
# ifdef DIGIT_BIT
68
# error You must not define DIGIT_BIT when using MP_16BIT
69
# endif
70
#elif defined(MP_64BIT)
71
/* for GCC only on supported platforms */
72
typedef uint64_t mp_digit;
73
typedef unsigned long mp_word __attribute__((mode(TI)));
74
# define DIGIT_BIT 60
75
#else
76
/* this is the default case, 28-bit digits */
77
78
/* this is to make porting into LibTomCrypt easier :-) */
79
typedef uint32_t mp_digit;
80
typedef uint64_t mp_word;
81
82
# ifdef MP_31BIT
83
/* this is an extension that uses 31-bit digits */
84
# define DIGIT_BIT 31
85
# else
86
/* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
87
# define DIGIT_BIT 28
88
# define MP_28BIT
89
# endif
90
#endif
91
92
/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
93
#ifndef DIGIT_BIT
94
# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
95
typedef uint_least32_t mp_min_u32;
96
#else
97
typedef mp_digit mp_min_u32;
98
#endif
99
100
#define MP_DIGIT_BIT DIGIT_BIT
101
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
102
#define MP_DIGIT_MAX MP_MASK
103
104
/* equalities */
105
#define MP_LT -1 /* less than */
106
#define MP_EQ 0 /* equal to */
107
#define MP_GT 1 /* greater than */
108
109
#define MP_ZPOS 0 /* positive integer */
110
#define MP_NEG 1 /* negative */
111
112
#define MP_OKAY 0 /* ok result */
113
#define MP_MEM -2 /* out of mem */
114
#define MP_VAL -3 /* invalid input */
115
#define MP_RANGE MP_VAL
116
#define MP_ITER -4 /* Max. iterations reached */
117
118
#define MP_YES 1 /* yes response */
119
#define MP_NO 0 /* no response */
120
121
/* Primality generation flags */
122
#define LTM_PRIME_BBS 0x0001 /* BBS style prime */
123
#define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
124
#define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
125
126
typedef int mp_err;
127
128
/* you'll have to tune these... */
129
extern int KARATSUBA_MUL_CUTOFF,
130
KARATSUBA_SQR_CUTOFF,
131
TOOM_MUL_CUTOFF,
132
TOOM_SQR_CUTOFF;
133
134
/* define this to use lower memory usage routines (exptmods mostly) */
135
/* #define MP_LOW_MEM */
136
137
/* default precision */
138
#ifndef MP_PREC
139
# ifndef MP_LOW_MEM
140
# define MP_PREC 32 /* default digits of precision */
141
# else
142
# define MP_PREC 8 /* default digits of precision */
143
# endif
144
#endif
145
146
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
147
#define MP_WARRAY (1u << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1))
148
149
/* the infamous mp_int structure */
150
typedef struct {
151
int used, alloc, sign;
152
mp_digit *dp;
153
} mp_int;
154
155
/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
156
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
157
158
159
#define USED(m) ((m)->used)
160
#define DIGIT(m, k) ((m)->dp[(k)])
161
#define SIGN(m) ((m)->sign)
162
163
/* error code to char* string */
164
const char *mp_error_to_string(int code);
165
166
/* ---> init and deinit bignum functions <--- */
167
/* init a bignum */
168
int mp_init(mp_int *a);
169
170
/* free a bignum */
171
void mp_clear(mp_int *a);
172
173
/* init a null terminated series of arguments */
174
int mp_init_multi(mp_int *mp, ...);
175
176
/* clear a null terminated series of arguments */
177
void mp_clear_multi(mp_int *mp, ...);
178
179
/* exchange two ints */
180
void mp_exch(mp_int *a, mp_int *b);
181
182
/* shrink ram required for a bignum */
183
int mp_shrink(mp_int *a);
184
185
/* grow an int to a given size */
186
int mp_grow(mp_int *a, int size);
187
188
/* init to a given number of digits */
189
int mp_init_size(mp_int *a, int size);
190
191
/* ---> Basic Manipulations <--- */
192
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
193
#define mp_iseven(a) ((((a)->used == 0) || (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO)
194
#define mp_isodd(a) ((((a)->used > 0) && (((a)->dp[0] & 1u) == 1u)) ? MP_YES : MP_NO)
195
#define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
196
197
/* set to zero */
198
void mp_zero(mp_int *a);
199
200
/* set to a digit */
201
void mp_set(mp_int *a, mp_digit b);
202
203
/* set a double */
204
int mp_set_double(mp_int *a, double b);
205
206
/* set a 32-bit const */
207
int mp_set_int(mp_int *a, unsigned long b);
208
209
/* set a platform dependent unsigned long value */
210
int mp_set_long(mp_int *a, unsigned long b);
211
212
/* set a platform dependent unsigned long long value */
213
int mp_set_long_long(mp_int *a, unsigned long long b);
214
215
/* get a double */
216
double mp_get_double(const mp_int *a);
217
218
/* get a 32-bit value */
219
unsigned long mp_get_int(const mp_int *a);
220
221
/* get a platform dependent unsigned long value */
222
unsigned long mp_get_long(const mp_int *a);
223
224
/* get a platform dependent unsigned long long value */
225
unsigned long long mp_get_long_long(const mp_int *a);
226
227
/* initialize and set a digit */
228
int mp_init_set(mp_int *a, mp_digit b);
229
230
/* initialize and set 32-bit value */
231
int mp_init_set_int(mp_int *a, unsigned long b);
232
233
/* copy, b = a */
234
int mp_copy(const mp_int *a, mp_int *b);
235
236
/* inits and copies, a = b */
237
int mp_init_copy(mp_int *a, const mp_int *b);
238
239
/* trim unused digits */
240
void mp_clamp(mp_int *a);
241
242
/* import binary data */
243
int mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op);
244
245
/* export binary data */
246
int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, const mp_int *op);
247
248
/* ---> digit manipulation <--- */
249
250
/* right shift by "b" digits */
251
void mp_rshd(mp_int *a, int b);
252
253
/* left shift by "b" digits */
254
int mp_lshd(mp_int *a, int b);
255
256
/* c = a / 2**b, implemented as c = a >> b */
257
int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d);
258
259
/* b = a/2 */
260
int mp_div_2(const mp_int *a, mp_int *b);
261
262
/* c = a * 2**b, implemented as c = a << b */
263
int mp_mul_2d(const mp_int *a, int b, mp_int *c);
264
265
/* b = a*2 */
266
int mp_mul_2(const mp_int *a, mp_int *b);
267
268
/* c = a mod 2**b */
269
int mp_mod_2d(const mp_int *a, int b, mp_int *c);
270
271
/* computes a = 2**b */
272
int mp_2expt(mp_int *a, int b);
273
274
/* Counts the number of lsbs which are zero before the first zero bit */
275
int mp_cnt_lsb(const mp_int *a);
276
277
/* I Love Earth! */
278
279
/* makes a pseudo-random mp_int of a given size */
280
int mp_rand(mp_int *a, int digits);
281
/* makes a pseudo-random small int of a given size */
282
int mp_rand_digit(mp_digit *r);
283
284
#ifdef MP_PRNG_ENABLE_LTM_RNG
285
/* A last resort to provide random data on systems without any of the other
286
* implemented ways to gather entropy.
287
* It is compatible with `rng_get_bytes()` from libtomcrypt so you could
288
* provide that one and then set `ltm_rng = rng_get_bytes;` */
289
extern unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
290
extern void (*ltm_rng_callback)(void);
291
#endif
292
293
/* ---> binary operations <--- */
294
/* c = a XOR b */
295
int mp_xor(const mp_int *a, const mp_int *b, mp_int *c);
296
297
/* c = a OR b */
298
int mp_or(const mp_int *a, const mp_int *b, mp_int *c);
299
300
/* c = a AND b */
301
int mp_and(const mp_int *a, const mp_int *b, mp_int *c);
302
303
/* Checks the bit at position b and returns MP_YES
304
if the bit is 1, MP_NO if it is 0 and MP_VAL
305
in case of error */
306
int mp_get_bit(const mp_int *a, int b);
307
308
/* c = a XOR b (two complement) */
309
int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c);
310
311
/* c = a OR b (two complement) */
312
int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c);
313
314
/* c = a AND b (two complement) */
315
int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c);
316
317
/* right shift (two complement) */
318
int mp_tc_div_2d(const mp_int *a, int b, mp_int *c);
319
320
/* ---> Basic arithmetic <--- */
321
322
/* b = ~a */
323
int mp_complement(const mp_int *a, mp_int *b);
324
325
/* b = -a */
326
int mp_neg(const mp_int *a, mp_int *b);
327
328
/* b = |a| */
329
int mp_abs(const mp_int *a, mp_int *b);
330
331
/* compare a to b */
332
int mp_cmp(const mp_int *a, const mp_int *b);
333
334
/* compare |a| to |b| */
335
int mp_cmp_mag(const mp_int *a, const mp_int *b);
336
337
/* c = a + b */
338
int mp_add(const mp_int *a, const mp_int *b, mp_int *c);
339
340
/* c = a - b */
341
int mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
342
343
/* c = a * b */
344
int mp_mul(const mp_int *a, const mp_int *b, mp_int *c);
345
346
/* b = a*a */
347
int mp_sqr(const mp_int *a, mp_int *b);
348
349
/* a/b => cb + d == a */
350
int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d);
351
352
/* c = a mod b, 0 <= c < b */
353
int mp_mod(const mp_int *a, const mp_int *b, mp_int *c);
354
355
/* ---> single digit functions <--- */
356
357
/* compare against a single digit */
358
int mp_cmp_d(const mp_int *a, mp_digit b);
359
360
/* c = a + b */
361
int mp_add_d(const mp_int *a, mp_digit b, mp_int *c);
362
363
/* c = a - b */
364
int mp_sub_d(const mp_int *a, mp_digit b, mp_int *c);
365
366
/* c = a * b */
367
int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c);
368
369
/* a/b => cb + d == a */
370
int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
371
372
/* a/3 => 3c + d == a */
373
int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d);
374
375
/* c = a**b */
376
int mp_expt_d(const mp_int *a, mp_digit b, mp_int *c);
377
int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast);
378
379
/* c = a mod b, 0 <= c < b */
380
int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c);
381
382
/* ---> number theory <--- */
383
384
/* d = a + b (mod c) */
385
int mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
386
387
/* d = a - b (mod c) */
388
int mp_submod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
389
390
/* d = a * b (mod c) */
391
int mp_mulmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
392
393
/* c = a * a (mod b) */
394
int mp_sqrmod(const mp_int *a, const mp_int *b, mp_int *c);
395
396
/* c = 1/a (mod b) */
397
int mp_invmod(const mp_int *a, const mp_int *b, mp_int *c);
398
399
/* c = (a, b) */
400
int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c);
401
402
/* produces value such that U1*a + U2*b = U3 */
403
int mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
404
405
/* c = [a, b] or (a*b)/(a, b) */
406
int mp_lcm(const mp_int *a, const mp_int *b, mp_int *c);
407
408
/* finds one of the b'th root of a, such that |c|**b <= |a|
409
*
410
* returns error if a < 0 and b is even
411
*/
412
int mp_n_root(const mp_int *a, mp_digit b, mp_int *c);
413
int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast);
414
415
/* special sqrt algo */
416
int mp_sqrt(const mp_int *arg, mp_int *ret);
417
418
/* special sqrt (mod prime) */
419
int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret);
420
421
/* is number a square? */
422
int mp_is_square(const mp_int *arg, int *ret);
423
424
/* computes the jacobi c = (a | n) (or Legendre if b is prime) */
425
int mp_jacobi(const mp_int *a, const mp_int *n, int *c);
426
427
/* computes the Kronecker symbol c = (a | p) (like jacobi() but with {a,p} in Z */
428
int mp_kronecker(const mp_int *a, const mp_int *p, int *c);
429
430
/* used to setup the Barrett reduction for a given modulus b */
431
int mp_reduce_setup(mp_int *a, const mp_int *b);
432
433
/* Barrett Reduction, computes a (mod b) with a precomputed value c
434
*
435
* Assumes that 0 < x <= m*m, note if 0 > x > -(m*m) then you can merely
436
* compute the reduction as -1 * mp_reduce(mp_abs(x)) [pseudo code].
437
*/
438
int mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu);
439
440
/* setups the montgomery reduction */
441
int mp_montgomery_setup(const mp_int *n, mp_digit *rho);
442
443
/* computes a = B**n mod b without division or multiplication useful for
444
* normalizing numbers in a Montgomery system.
445
*/
446
int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b);
447
448
/* computes x/R == x (mod N) via Montgomery Reduction */
449
int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho);
450
451
/* returns 1 if a is a valid DR modulus */
452
int mp_dr_is_modulus(const mp_int *a);
453
454
/* sets the value of "d" required for mp_dr_reduce */
455
void mp_dr_setup(const mp_int *a, mp_digit *d);
456
457
/* reduces a modulo n using the Diminished Radix method */
458
int mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k);
459
460
/* returns true if a can be reduced with mp_reduce_2k */
461
int mp_reduce_is_2k(const mp_int *a);
462
463
/* determines k value for 2k reduction */
464
int mp_reduce_2k_setup(const mp_int *a, mp_digit *d);
465
466
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
467
int mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d);
468
469
/* returns true if a can be reduced with mp_reduce_2k_l */
470
int mp_reduce_is_2k_l(const mp_int *a);
471
472
/* determines k value for 2k reduction */
473
int mp_reduce_2k_setup_l(const mp_int *a, mp_int *d);
474
475
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
476
int mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d);
477
478
/* Y = G**X (mod P) */
479
int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y);
480
481
/* ---> Primes <--- */
482
483
/* number of primes */
484
#ifdef MP_8BIT
485
# define PRIME_SIZE 31
486
#else
487
# define PRIME_SIZE 256
488
#endif
489
490
/* table of first PRIME_SIZE primes */
491
extern const mp_digit ltm_prime_tab[PRIME_SIZE];
492
493
/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
494
int mp_prime_is_divisible(const mp_int *a, int *result);
495
496
/* performs one Fermat test of "a" using base "b".
497
* Sets result to 0 if composite or 1 if probable prime
498
*/
499
int mp_prime_fermat(const mp_int *a, const mp_int *b, int *result);
500
501
/* performs one Miller-Rabin test of "a" using base "b".
502
* Sets result to 0 if composite or 1 if probable prime
503
*/
504
int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result);
505
506
/* This gives [for a given bit size] the number of trials required
507
* such that Miller-Rabin gives a prob of failure lower than 2^-96
508
*/
509
int mp_prime_rabin_miller_trials(int size);
510
511
/* performs one strong Lucas-Selfridge test of "a".
512
* Sets result to 0 if composite or 1 if probable prime
513
*/
514
int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result);
515
516
/* performs one Frobenius test of "a" as described by Paul Underwood.
517
* Sets result to 0 if composite or 1 if probable prime
518
*/
519
int mp_prime_frobenius_underwood(const mp_int *N, int *result);
520
521
/* performs t random rounds of Miller-Rabin on "a" additional to
522
* bases 2 and 3. Also performs an initial sieve of trial
523
* division. Determines if "a" is prime with probability
524
* of error no more than (1/4)**t.
525
* Both a strong Lucas-Selfridge to complete the BPSW test
526
* and a separate Frobenius test are available at compile time.
527
* With t<0 a deterministic test is run for primes up to
528
* 318665857834031151167461. With t<13 (abs(t)-13) additional
529
* tests with sequential small primes are run starting at 43.
530
* Is Fips 186.4 compliant if called with t as computed by
531
* mp_prime_rabin_miller_trials();
532
*
533
* Sets result to 1 if probably prime, 0 otherwise
534
*/
535
int mp_prime_is_prime(const mp_int *a, int t, int *result);
536
537
/* finds the next prime after the number "a" using "t" trials
538
* of Miller-Rabin.
539
*
540
* bbs_style = 1 means the prime must be congruent to 3 mod 4
541
*/
542
int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
543
544
/* makes a truly random prime of a given size (bytes),
545
* call with bbs = 1 if you want it to be congruent to 3 mod 4
546
*
547
* You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
548
* have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
549
* so it can be NULL
550
*
551
* The prime generated will be larger than 2^(8*size).
552
*/
553
#define mp_prime_random(a, t, size, bbs, cb, dat) mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
554
555
/* makes a truly random prime of a given size (bits),
556
*
557
* Flags are as follows:
558
*
559
* LTM_PRIME_BBS - make prime congruent to 3 mod 4
560
* LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
561
* LTM_PRIME_2MSB_ON - make the 2nd highest bit one
562
*
563
* You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
564
* have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
565
* so it can be NULL
566
*
567
*/
568
int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
569
570
/* ---> radix conversion <--- */
571
int mp_count_bits(const mp_int *a);
572
573
int mp_unsigned_bin_size(const mp_int *a);
574
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
575
int mp_to_unsigned_bin(const mp_int *a, unsigned char *b);
576
int mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen);
577
578
int mp_signed_bin_size(const mp_int *a);
579
int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
580
int mp_to_signed_bin(const mp_int *a, unsigned char *b);
581
int mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen);
582
583
int mp_read_radix(mp_int *a, const char *str, int radix);
584
int mp_toradix(const mp_int *a, char *str, int radix);
585
int mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen);
586
int mp_radix_size(const mp_int *a, int radix, int *size);
587
588
#ifndef LTM_NO_FILE
589
int mp_fread(mp_int *a, int radix, FILE *stream);
590
int mp_fwrite(const mp_int *a, int radix, FILE *stream);
591
#endif
592
593
#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
594
#define mp_raw_size(mp) mp_signed_bin_size(mp)
595
#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
596
#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
597
#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
598
#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
599
600
#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
601
#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
602
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
603
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
604
605
#ifdef __cplusplus
606
}
607
#endif
608
609
#endif
610
611