TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tomcrypt_math.h
Go to the documentation of this file.
1 
3 #define LTC_MP_LT -1
4 #define LTC_MP_EQ 0
5 #define LTC_MP_GT 1
6 
7 #define LTC_MP_NO 0
8 #define LTC_MP_YES 1
9 
10 #ifndef LTC_MECC
11  typedef void ecc_point;
12 #endif
13 
14 #ifndef LTC_MRSA
15  typedef void rsa_key;
16 #endif
17 
19 typedef struct {
21  char *name;
22 
25 
26 /* ---- init/deinit functions ---- */
27 
32  int (*init)(void **a);
33 
39  int (*init_copy)(void **dst, void *src);
40 
45  void (*deinit)(void *a);
46 
47 /* ---- data movement ---- */
48 
54  int (*neg)(void *src, void *dst);
55 
61  int (*copy)(void *src, void *dst);
62 
63 /* ---- trivial low level functions ---- */
64 
70  int (*set_int)(void *a, unsigned long n);
71 
76  unsigned long (*get_int)(void *a);
77 
83  unsigned long (*get_digit)(void *a, int n);
84 
89  int (*get_digit_count)(void *a);
90 
96  int (*compare)(void *a, void *b);
97 
103  int (*compare_d)(void *a, unsigned long n);
104 
109  int (*count_bits)(void * a);
110 
115  int (*count_lsb_bits)(void *a);
116 
122  int (*twoexpt)(void *a , int n);
123 
124 /* ---- radix conversions ---- */
125 
132  int (*read_radix)(void *a, const char *str, int radix);
133 
140  int (*write_radix)(void *a, char *str, int radix);
141 
146  unsigned long (*unsigned_size)(void *a);
147 
153  int (*unsigned_write)(void *src, unsigned char *dst);
154 
161  int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len);
162 
163 /* ---- basic math ---- */
164 
171  int (*add)(void *a, void *b, void *c);
172 
173 
180  int (*addi)(void *a, unsigned long b, void *c);
181 
188  int (*sub)(void *a, void *b, void *c);
189 
196  int (*subi)(void *a, unsigned long b, void *c);
197 
204  int (*mul)(void *a, void *b, void *c);
205 
212  int (*muli)(void *a, unsigned long b, void *c);
213 
219  int (*sqr)(void *a, void *b);
220 
228  int (*mpdiv)(void *a, void *b, void *c, void *d);
229 
235  int (*div_2)(void *a, void *b);
236 
243  int (*modi)(void *a, unsigned long b, unsigned long *c);
244 
251  int (*gcd)(void *a, void *b, void *c);
252 
259  int (*lcm)(void *a, void *b, void *c);
260 
268  int (*mulmod)(void *a, void *b, void *c, void *d);
269 
276  int (*sqrmod)(void *a, void *b, void *c);
277 
284  int (*invmod)(void *, void *, void *);
285 
286 /* ---- reduction ---- */
287 
293  int (*montgomery_setup)(void *a, void **b);
294 
300  int (*montgomery_normalization)(void *a, void *b);
301 
308  int (*montgomery_reduce)(void *a, void *b, void *c);
309 
314  void (*montgomery_deinit)(void *a);
315 
316 /* ---- exponentiation ---- */
317 
325  int (*exptmod)(void *a, void *b, void *c, void *d);
326 
332  int (*isprime)(void *a, int *b);
333 
334 /* ---- (optional) ecc point math ---- */
335 
344  int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
345 
354  int (*ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
355 
363  int (*ecc_ptdbl)(ecc_point *P, ecc_point *R, void *modulus, void *mp);
364 
373  int (*ecc_map)(ecc_point *P, void *modulus, void *mp);
374 
384  int (*ecc_mul2add)(ecc_point *A, void *kA,
385  ecc_point *B, void *kB,
386  ecc_point *C,
387  void *modulus);
388 
389 /* ---- (optional) rsa optimized math (for internal CRT) ---- */
390 
399  int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key);
400 
401 
411  int (*rsa_me)(const unsigned char *in, unsigned long inlen,
412  unsigned char *out, unsigned long *outlen, int which,
413  rsa_key *key);
415 
417 
418 int ltc_init_multi(void **a, ...);
419 void ltc_deinit_multi(void *a, ...);
420 
421 #ifdef LTM_DESC
422 extern const ltc_math_descriptor ltm_desc;
423 #endif
424 
425 #ifdef TFM_DESC
426 extern const ltc_math_descriptor tfm_desc;
427 #endif
428 
429 #ifdef GMP_DESC
430 extern const ltc_math_descriptor gmp_desc;
431 #endif
432 
433 #if !defined(DESC_DEF_ONLY) && defined(LTC_SOURCE)
434 
435 #define MP_DIGIT_BIT ltc_mp.bits_per_digit
436 
437 /* some handy macros */
438 #define mp_init(a) ltc_mp.init(a)
439 #define mp_init_multi ltc_init_multi
440 #define mp_clear(a) ltc_mp.deinit(a)
441 #define mp_clear_multi ltc_deinit_multi
442 #define mp_init_copy(a, b) ltc_mp.init_copy(a, b)
443 
444 #define mp_neg(a, b) ltc_mp.neg(a, b)
445 #define mp_copy(a, b) ltc_mp.copy(a, b)
446 
447 #define mp_set(a, b) ltc_mp.set_int(a, b)
448 #define mp_set_int(a, b) ltc_mp.set_int(a, b)
449 #define mp_get_int(a) ltc_mp.get_int(a)
450 #define mp_get_digit(a, n) ltc_mp.get_digit(a, n)
451 #define mp_get_digit_count(a) ltc_mp.get_digit_count(a)
452 #define mp_cmp(a, b) ltc_mp.compare(a, b)
453 #define mp_cmp_d(a, b) ltc_mp.compare_d(a, b)
454 #define mp_count_bits(a) ltc_mp.count_bits(a)
455 #define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a)
456 #define mp_2expt(a, b) ltc_mp.twoexpt(a, b)
457 
458 #define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c)
459 #define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c)
460 #define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a)
461 #define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b)
462 #define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
463 
464 #define mp_add(a, b, c) ltc_mp.add(a, b, c)
465 #define mp_add_d(a, b, c) ltc_mp.addi(a, b, c)
466 #define mp_sub(a, b, c) ltc_mp.sub(a, b, c)
467 #define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c)
468 #define mp_mul(a, b, c) ltc_mp.mul(a, b, c)
469 #define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c)
470 #define mp_sqr(a, b) ltc_mp.sqr(a, b)
471 #define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d)
472 #define mp_div_2(a, b) ltc_mp.div_2(a, b)
473 #define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c)
474 #define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c)
475 #define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c)
476 #define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c)
477 
478 #define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d)
479 #define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c)
480 #define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c)
481 
482 #define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b)
483 #define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
484 #define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c)
485 #define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a)
486 
487 #define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d)
488 #define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, c)
489 
490 #define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
491 #define mp_isodd(a) (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
492 #define mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0);
493 
494 #define mp_tohex(a, b) mp_toradix(a, b, 16)
495 
496 #endif
497 
498 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_math.h,v $ */
499 /* $Revision: 1.44 $ */
500 /* $Date: 2007/05/12 14:32:35 $ */
int ltc_init_multi(void **a,...)
ltc_math_descriptor ltc_mp
int bits_per_digit
Definition: tomcrypt_math.h:24
void rsa_key
Definition: tomcrypt_math.h:15
float mul(float a, float b)
Definition: g3dmath.h:453
Definition: tomcrypt_math.h:19
char * name
Definition: tomcrypt_math.h:21
void ltc_deinit_multi(void *a,...)
#define G(x, y, z)
void ecc_point
Definition: tomcrypt_math.h:11
uint8 const P[]
Definition: AuthenticationPackets.cpp:225
Definition: tomcrypt_prng.h:50
uint8 const Q[]
Definition: AuthenticationPackets.cpp:237