tommath.h File Reference#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#include <tommath_class.h>
Go to the source code of this file.
|
Data Structures |
struct | mp_int |
Defines |
#define | MIN(x, y) ((x)<(y)?(x):(y)) |
#define | MAX(x, y) ((x)>(y)?(x):(y)) |
#define | OPT_CAST(x) |
#define | DIGIT_BIT 28 |
#define | MP_28BIT |
#define | XMALLOC malloc |
#define | XFREE free |
#define | XREALLOC realloc |
#define | XCALLOC calloc |
#define | MP_DIGIT_BIT DIGIT_BIT |
#define | MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1)) |
#define | MP_DIGIT_MAX MP_MASK |
#define | MP_LT -1 |
#define | MP_EQ 0 |
#define | MP_GT 1 |
#define | MP_ZPOS 0 |
#define | MP_NEG 1 |
#define | MP_OKAY 0 |
#define | MP_MEM -2 |
#define | MP_VAL -3 |
#define | MP_RANGE MP_VAL |
#define | MP_YES 1 |
#define | MP_NO 0 |
#define | LTM_PRIME_BBS 0x0001 |
#define | LTM_PRIME_SAFE 0x0002 |
#define | LTM_PRIME_2MSB_ON 0x0008 |
#define | MP_PREC 32 |
#define | MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1)) |
#define | USED(m) ((m)->used) |
#define | DIGIT(m, k) ((m)->dp[(k)]) |
#define | SIGN(m) ((m)->sign) |
#define | mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) |
#define | mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO) |
#define | mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO) |
#define | PRIME_SIZE 256 |
#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) |
#define | mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len)) |
#define | mp_raw_size(mp) mp_signed_bin_size(mp) |
#define | mp_toraw(mp, str) mp_to_signed_bin((mp), (str)) |
#define | mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len)) |
#define | mp_mag_size(mp) mp_unsigned_bin_size(mp) |
#define | mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str)) |
#define | mp_tobinary(M, S) mp_toradix((M), (S), 2) |
#define | mp_tooctal(M, S) mp_toradix((M), (S), 8) |
#define | mp_todecimal(M, S) mp_toradix((M), (S), 10) |
#define | mp_tohex(M, S) mp_toradix((M), (S), 16) |
#define | s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) |
Typedefs |
typedef unsigned long long | ulong64 |
typedef signed long long | long64 |
typedef unsigned long | mp_digit |
typedef ulong64 | mp_word |
typedef int | mp_err |
typedef int | ltm_prime_callback (unsigned char *dst, int len, void *dat) |
Functions |
char * | mp_error_to_string (int code) |
int | mp_init (mp_int *a) |
void | mp_clear (mp_int *a) |
int | mp_init_multi (mp_int *mp,...) |
void | mp_clear_multi (mp_int *mp,...) |
void | mp_exch (mp_int *a, mp_int *b) |
int | mp_shrink (mp_int *a) |
int | mp_grow (mp_int *a, int size) |
int | mp_init_size (mp_int *a, int size) |
void | mp_zero (mp_int *a) |
void | mp_set (mp_int *a, mp_digit b) |
int | mp_set_int (mp_int *a, unsigned long b) |
unsigned long | mp_get_int (mp_int *a) |
int | mp_init_set (mp_int *a, mp_digit b) |
int | mp_init_set_int (mp_int *a, unsigned long b) |
int | mp_copy (mp_int *a, mp_int *b) |
int | mp_init_copy (mp_int *a, mp_int *b) |
void | mp_clamp (mp_int *a) |
void | mp_rshd (mp_int *a, int b) |
int | mp_lshd (mp_int *a, int b) |
int | mp_div_2d (mp_int *a, int b, mp_int *c, mp_int *d) |
int | mp_div_2 (mp_int *a, mp_int *b) |
int | mp_mul_2d (mp_int *a, int b, mp_int *c) |
int | mp_mul_2 (mp_int *a, mp_int *b) |
int | mp_mod_2d (mp_int *a, int b, mp_int *c) |
int | mp_2expt (mp_int *a, int b) |
int | mp_cnt_lsb (mp_int *a) |
int | mp_rand (mp_int *a, int digits) |
int | mp_xor (mp_int *a, mp_int *b, mp_int *c) |
int | mp_or (mp_int *a, mp_int *b, mp_int *c) |
int | mp_and (mp_int *a, mp_int *b, mp_int *c) |
int | mp_neg (mp_int *a, mp_int *b) |
int | mp_abs (mp_int *a, mp_int *b) |
int | mp_cmp (mp_int *a, mp_int *b) |
int | mp_cmp_mag (mp_int *a, mp_int *b) |
int | mp_add (mp_int *a, mp_int *b, mp_int *c) |
int | mp_sub (mp_int *a, mp_int *b, mp_int *c) |
int | mp_mul (mp_int *a, mp_int *b, mp_int *c) |
int | mp_sqr (mp_int *a, mp_int *b) |
int | mp_div (mp_int *a, mp_int *b, mp_int *c, mp_int *d) |
int | mp_mod (mp_int *a, mp_int *b, mp_int *c) |
int | mp_cmp_d (mp_int *a, mp_digit b) |
int | mp_add_d (mp_int *a, mp_digit b, mp_int *c) |
int | mp_sub_d (mp_int *a, mp_digit b, mp_int *c) |
int | mp_mul_d (mp_int *a, mp_digit b, mp_int *c) |
int | mp_div_d (mp_int *a, mp_digit b, mp_int *c, mp_digit *d) |
int | mp_div_3 (mp_int *a, mp_int *c, mp_digit *d) |
int | mp_expt_d (mp_int *a, mp_digit b, mp_int *c) |
int | mp_mod_d (mp_int *a, mp_digit b, mp_digit *c) |
int | mp_addmod (mp_int *a, mp_int *b, mp_int *c, mp_int *d) |
int | mp_submod (mp_int *a, mp_int *b, mp_int *c, mp_int *d) |
int | mp_mulmod (mp_int *a, mp_int *b, mp_int *c, mp_int *d) |
int | mp_sqrmod (mp_int *a, mp_int *b, mp_int *c) |
int | mp_invmod (mp_int *a, mp_int *b, mp_int *c) |
int | mp_gcd (mp_int *a, mp_int *b, mp_int *c) |
int | mp_exteuclid (mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3) |
int | mp_lcm (mp_int *a, mp_int *b, mp_int *c) |
int | mp_n_root (mp_int *a, mp_digit b, mp_int *c) |
int | mp_sqrt (mp_int *arg, mp_int *ret) |
int | mp_is_square (mp_int *arg, int *ret) |
int | mp_jacobi (mp_int *a, mp_int *n, int *c) |
int | mp_reduce_setup (mp_int *a, mp_int *b) |
int | mp_reduce (mp_int *a, mp_int *b, mp_int *c) |
int | mp_montgomery_setup (mp_int *a, mp_digit *mp) |
int | mp_montgomery_calc_normalization (mp_int *a, mp_int *b) |
int | mp_montgomery_reduce (mp_int *a, mp_int *m, mp_digit mp) |
int | mp_dr_is_modulus (mp_int *a) |
void | mp_dr_setup (mp_int *a, mp_digit *d) |
int | mp_dr_reduce (mp_int *a, mp_int *b, mp_digit mp) |
int | mp_reduce_is_2k (mp_int *a) |
int | mp_reduce_2k_setup (mp_int *a, mp_digit *d) |
int | mp_reduce_2k (mp_int *a, mp_int *n, mp_digit d) |
int | mp_reduce_is_2k_l (mp_int *a) |
int | mp_reduce_2k_setup_l (mp_int *a, mp_int *d) |
int | mp_reduce_2k_l (mp_int *a, mp_int *n, mp_int *d) |
int | mp_exptmod (mp_int *a, mp_int *b, mp_int *c, mp_int *d) |
int | mp_prime_is_divisible (mp_int *a, int *result) |
int | mp_prime_fermat (mp_int *a, mp_int *b, int *result) |
int | mp_prime_miller_rabin (mp_int *a, mp_int *b, int *result) |
int | mp_prime_rabin_miller_trials (int size) |
int | mp_prime_is_prime (mp_int *a, int t, int *result) |
int | mp_prime_next_prime (mp_int *a, int t, int bbs_style) |
int | mp_prime_random_ex (mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat) |
int | mp_count_bits (mp_int *a) |
int | mp_unsigned_bin_size (mp_int *a) |
int | mp_read_unsigned_bin (mp_int *a, const unsigned char *b, int c) |
int | mp_to_unsigned_bin (mp_int *a, unsigned char *b) |
int | mp_to_unsigned_bin_n (mp_int *a, unsigned char *b, unsigned long *outlen) |
int | mp_signed_bin_size (mp_int *a) |
int | mp_read_signed_bin (mp_int *a, const unsigned char *b, int c) |
int | mp_to_signed_bin (mp_int *a, unsigned char *b) |
int | mp_to_signed_bin_n (mp_int *a, unsigned char *b, unsigned long *outlen) |
int | mp_read_radix (mp_int *a, const char *str, int radix) |
int | mp_toradix (mp_int *a, char *str, int radix) |
int | mp_toradix_n (mp_int *a, char *str, int radix, int maxlen) |
int | mp_radix_size (mp_int *a, int radix, int *size) |
int | mp_fread (mp_int *a, int radix, FILE *stream) |
int | mp_fwrite (mp_int *a, int radix, FILE *stream) |
int | s_mp_add (mp_int *a, mp_int *b, mp_int *c) |
int | s_mp_sub (mp_int *a, mp_int *b, mp_int *c) |
int | fast_s_mp_mul_digs (mp_int *a, mp_int *b, mp_int *c, int digs) |
int | s_mp_mul_digs (mp_int *a, mp_int *b, mp_int *c, int digs) |
int | fast_s_mp_mul_high_digs (mp_int *a, mp_int *b, mp_int *c, int digs) |
int | s_mp_mul_high_digs (mp_int *a, mp_int *b, mp_int *c, int digs) |
int | fast_s_mp_sqr (mp_int *a, mp_int *b) |
int | s_mp_sqr (mp_int *a, mp_int *b) |
int | mp_karatsuba_mul (mp_int *a, mp_int *b, mp_int *c) |
int | mp_toom_mul (mp_int *a, mp_int *b, mp_int *c) |
int | mp_karatsuba_sqr (mp_int *a, mp_int *b) |
int | mp_toom_sqr (mp_int *a, mp_int *b) |
int | fast_mp_invmod (mp_int *a, mp_int *b, mp_int *c) |
int | mp_invmod_slow (mp_int *a, mp_int *b, mp_int *c) |
int | fast_mp_montgomery_reduce (mp_int *a, mp_int *m, mp_digit mp) |
int | mp_exptmod_fast (mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode) |
int | s_mp_exptmod (mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode) |
void | bn_reverse (unsigned char *s, int len) |
Variables |
int | KARATSUBA_MUL_CUTOFF |
int | KARATSUBA_SQR_CUTOFF |
int | TOOM_MUL_CUTOFF |
int | TOOM_SQR_CUTOFF |
const mp_digit | ltm_prime_tab [] |
const char * | mp_s_rmap |
Define Documentation
#define DIGIT |
( |
m, |
|
|
k |
|
) |
((m)->dp[(k)]) |
#define LTM_PRIME_2MSB_ON 0x0008 |
#define LTM_PRIME_BBS 0x0001 |
#define LTM_PRIME_SAFE 0x0002 |
#define MAX |
( |
x, |
|
|
y |
|
) |
((x)>(y)?(x):(y)) |
#define MIN |
( |
x, |
|
|
y |
|
) |
((x)<(y)?(x):(y)) |
#define MP_DIGIT_BIT DIGIT_BIT |
#define MP_DIGIT_MAX MP_MASK |
#define mp_iseven |
( |
a |
|
) |
(((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO) |
#define mp_isodd |
( |
a |
|
) |
(((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO) |
#define mp_iszero |
( |
a |
|
) |
(((a)->used == 0) ? MP_YES : MP_NO) |
#define mp_mag_size |
( |
mp |
|
) |
mp_unsigned_bin_size(mp) |
#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) |
#define mp_raw_size |
( |
mp |
|
) |
mp_signed_bin_size(mp) |
#define mp_read_mag |
( |
mp, |
|
|
str, |
|
|
len |
|
) |
mp_read_unsigned_bin((mp), (str), (len)) |
#define mp_read_raw |
( |
mp, |
|
|
str, |
|
|
len |
|
) |
mp_read_signed_bin((mp), (str), (len)) |
#define mp_tobinary |
( |
M, |
|
|
S |
|
) |
mp_toradix((M), (S), 2) |
#define mp_todecimal |
( |
M, |
|
|
S |
|
) |
mp_toradix((M), (S), 10) |
#define mp_tohex |
( |
M, |
|
|
S |
|
) |
mp_toradix((M), (S), 16) |
#define mp_tomag |
( |
mp, |
|
|
str |
|
) |
mp_to_unsigned_bin((mp), (str)) |
#define mp_tooctal |
( |
M, |
|
|
S |
|
) |
mp_toradix((M), (S), 8) |
#define mp_toraw |
( |
mp, |
|
|
str |
|
) |
mp_to_signed_bin((mp), (str)) |
#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1)) |
#define s_mp_mul |
( |
a, |
|
|
b, |
|
|
c |
|
) |
s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) |
#define SIGN |
( |
m |
|
) |
((m)->sign) |
#define USED |
( |
m |
|
) |
((m)->used) |
Typedef Documentation
typedef signed long long long64 |
Function Documentation
void bn_reverse |
( |
unsigned char * |
s, |
|
|
int |
len | |
|
) |
| | |
int mp_2expt |
( |
mp_int * |
a, |
|
|
int |
b | |
|
) |
| | |
void mp_clear_multi |
( |
mp_int * |
mp, |
|
|
|
... | |
|
) |
| | |
int mp_count_bits |
( |
mp_int * |
a |
) |
|
int mp_dr_is_modulus |
( |
mp_int * |
a |
) |
|
char* mp_error_to_string |
( |
int |
code |
) |
|
int mp_fread |
( |
mp_int * |
a, |
|
|
int |
radix, |
|
|
FILE * |
stream | |
|
) |
| | |
int mp_fwrite |
( |
mp_int * |
a, |
|
|
int |
radix, |
|
|
FILE * |
stream | |
|
) |
| | |
unsigned long mp_get_int |
( |
mp_int * |
a |
) |
|
int mp_grow |
( |
mp_int * |
a, |
|
|
int |
size | |
|
) |
| | |
int mp_init_multi |
( |
mp_int * |
mp, |
|
|
|
... | |
|
) |
| | |
int mp_init_set_int |
( |
mp_int * |
a, |
|
|
unsigned long |
b | |
|
) |
| | |
int mp_init_size |
( |
mp_int * |
a, |
|
|
int |
size | |
|
) |
| | |
int mp_is_square |
( |
mp_int * |
arg, |
|
|
int * |
ret | |
|
) |
| | |
int mp_lshd |
( |
mp_int * |
a, |
|
|
int |
b | |
|
) |
| | |
int mp_montgomery_calc_normalization |
( |
mp_int * |
a, |
|
|
mp_int * |
b | |
|
) |
| | |
int mp_prime_fermat |
( |
mp_int * |
a, |
|
|
mp_int * |
b, |
|
|
int * |
result | |
|
) |
| | |
int mp_prime_is_divisible |
( |
mp_int * |
a, |
|
|
int * |
result | |
|
) |
| | |
int mp_prime_is_prime |
( |
mp_int * |
a, |
|
|
int |
t, |
|
|
int * |
result | |
|
) |
| | |
int mp_prime_miller_rabin |
( |
mp_int * |
a, |
|
|
mp_int * |
b, |
|
|
int * |
result | |
|
) |
| | |
int mp_prime_next_prime |
( |
mp_int * |
a, |
|
|
int |
t, |
|
|
int |
bbs_style | |
|
) |
| | |
int mp_prime_rabin_miller_trials |
( |
int |
size |
) |
|
int mp_radix_size |
( |
mp_int * |
a, |
|
|
int |
radix, |
|
|
int * |
size | |
|
) |
| | |
int mp_rand |
( |
mp_int * |
a, |
|
|
int |
digits | |
|
) |
| | |
int mp_read_radix |
( |
mp_int * |
a, |
|
|
const char * |
str, |
|
|
int |
radix | |
|
) |
| | |
int mp_read_signed_bin |
( |
mp_int * |
a, |
|
|
const unsigned char * |
b, |
|
|
int |
c | |
|
) |
| | |
int mp_read_unsigned_bin |
( |
mp_int * |
a, |
|
|
const unsigned char * |
b, |
|
|
int |
c | |
|
) |
| | |
int mp_reduce_is_2k |
( |
mp_int * |
a |
) |
|
int mp_reduce_is_2k_l |
( |
mp_int * |
a |
) |
|
void mp_rshd |
( |
mp_int * |
a, |
|
|
int |
b | |
|
) |
| | |
int mp_set_int |
( |
mp_int * |
a, |
|
|
unsigned long |
b | |
|
) |
| | |
int mp_signed_bin_size |
( |
mp_int * |
a |
) |
|
int mp_to_signed_bin |
( |
mp_int * |
a, |
|
|
unsigned char * |
b | |
|
) |
| | |
int mp_to_signed_bin_n |
( |
mp_int * |
a, |
|
|
unsigned char * |
b, |
|
|
unsigned long * |
outlen | |
|
) |
| | |
int mp_to_unsigned_bin |
( |
mp_int * |
a, |
|
|
unsigned char * |
b | |
|
) |
| | |
int mp_to_unsigned_bin_n |
( |
mp_int * |
a, |
|
|
unsigned char * |
b, |
|
|
unsigned long * |
outlen | |
|
) |
| | |
int mp_toradix |
( |
mp_int * |
a, |
|
|
char * |
str, |
|
|
int |
radix | |
|
) |
| | |
int mp_toradix_n |
( |
mp_int * |
a, |
|
|
char * |
str, |
|
|
int |
radix, |
|
|
int |
maxlen | |
|
) |
| | |
int mp_unsigned_bin_size |
( |
mp_int * |
a |
) |
|
Variable Documentation
Generated on Wed Mar 12 12:18:34 2008 by
1.5.1
|