diff options
Diffstat (limited to 'powm.h')
| -rw-r--r-- | powm.h | 44 |
1 files changed, 44 insertions, 0 deletions
| @@ -0,0 +1,44 @@ | |||
| 1 | #ifndef __LIBGSMKBIGNUM_POWM_H__ | ||
| 2 | #define __LIBGSMKBIGNUM_POWM_H__ | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #ifdef USE32BITLIMB | ||
| 12 | typedef uint32_t limb_t; | ||
| 13 | typedef uint64_t dlimb_t; | ||
| 14 | #else | ||
| 15 | typedef uint64_t limb_t; | ||
| 16 | typedef unsigned int uint128_t __attribute__((mode(TI))); | ||
| 17 | typedef uint128_t dlimb_t; | ||
| 18 | #endif | ||
| 19 | |||
| 20 | |||
| 21 | /* import from serialized format, big endian byte representation | ||
| 22 | return amount of limbs */ | ||
| 23 | uint32_t mp_import( limb_t *dest, uint8_t const * src, uint32_t byte_size ); | ||
| 24 | void mp_export( uint8_t *dest, const limb_t *scr, uint32_t limb_size ); | ||
| 25 | |||
| 26 | /* This function works with precalculated parameters passed in r_square | ||
| 27 | and r_inverse. The latter being 1, if the bottom limb_t is -1. */ | ||
| 28 | void powm_internal( limb_t * result, | ||
| 29 | const limb_t * base, uint32_t base_limbs, | ||
| 30 | const limb_t * exponent, uint32_t exp_limbs, | ||
| 31 | const limb_t * modulus, uint32_t mod_limbs, | ||
| 32 | const limb_t * r_square, const limb_t r_inverse ); | ||
| 33 | |||
| 34 | /* Not yet implemented */ | ||
| 35 | void powm( limb_t * result, | ||
| 36 | const limb_t * base, uint32_t base_limbs, | ||
| 37 | const limb_t * exponent, int expbits, | ||
| 38 | const limb_t * modulus, uint32_t mod_limbs ); | ||
| 39 | |||
| 40 | #ifdef __cplusplus | ||
| 41 | } | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #endif | ||
