diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-01-22 16:29:54 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-01-22 16:29:54 (GMT) |
| commit | d6f67fed9485d427ed9150806ca7fabfb3b6e65f (patch) | |
| tree | 0cd3383cc9b3e3edf920ed788e83ee24c6783ccb /libtommath/tommath.h | |
| parent | 7e67cf48ebc00a5378ef2ef349aa3ba613d127d9 (diff) | |
| parent | 3cf1eb2c2370405ae05a7740dfdfdb206883b522 (diff) | |
| download | tcl-d6f67fed9485d427ed9150806ca7fabfb3b6e65f.zip tcl-d6f67fed9485d427ed9150806ca7fabfb3b6e65f.tar.gz tcl-d6f67fed9485d427ed9150806ca7fabfb3b6e65f.tar.bz2 | |
Merge libtommath v1.1.0-rc4
Diffstat (limited to 'libtommath/tommath.h')
| -rw-r--r-- | libtommath/tommath.h | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 5c90b90..b859679 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -7,8 +7,7 @@ * Michael Fromberger but has been written from scratch with * additional optimizations in place. * - * The library is free for all purposes without any express - * guarantee it works. + * SPDX-License-Identifier: Unlicense */ #ifndef BN_H_ #define BN_H_ @@ -17,7 +16,7 @@ #include <stdlib.h> #include <limits.h> -#include <tommath_class.h> +#include "tommath_class.h" #ifdef __cplusplus extern "C" { @@ -114,6 +113,7 @@ typedef mp_digit mp_min_u32; #define MP_MEM -2 /* out of mem */ #define MP_VAL -3 /* invalid input */ #define MP_RANGE MP_VAL +#define MP_ITER -4 /* Max. iterations reached */ #define MP_YES 1 /* yes response */ #define MP_NO 0 /* no response */ @@ -200,6 +200,9 @@ void mp_zero(mp_int *a); /* set to a digit */ void mp_set(mp_int *a, mp_digit b); +/* set a double */ +int mp_set_double(mp_int *a, double b); + /* set a 32-bit const */ int mp_set_int(mp_int *a, unsigned long b); @@ -209,6 +212,9 @@ int mp_set_long(mp_int *a, unsigned long b); /* set a platform dependent unsigned long long value */ int mp_set_long_long(mp_int *a, unsigned long long b); +/* get a double */ +double mp_get_double(const mp_int *a); + /* get a 32-bit value */ unsigned long mp_get_int(const mp_int *a); @@ -270,8 +276,10 @@ int mp_cnt_lsb(const mp_int *a); /* I Love Earth! */ -/* makes a pseudo-random int of a given size */ +/* makes a pseudo-random mp_int of a given size */ int mp_rand(mp_int *a, int digits); +/* makes a pseudo-random small int of a given size */ +int mp_rand_digit(mp_digit *r); #ifdef MP_PRNG_ENABLE_LTM_RNG /* as last resort we will fall back to libtomcrypt's rng_get_bytes() @@ -291,6 +299,11 @@ int mp_or(const mp_int *a, const mp_int *b, mp_int *c); /* c = a AND b */ int mp_and(const mp_int *a, const mp_int *b, mp_int *c); +/* Checks the bit at position b and returns MP_YES + if the bit is 1, MP_NO if it is 0 and MP_VAL + in case of error */ +int mp_get_bit(const mp_int *a, int b); + /* c = a XOR b (two complement) */ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c); @@ -410,6 +423,9 @@ int mp_is_square(const mp_int *arg, int *ret); /* computes the jacobi c = (a | n) (or Legendre if b is prime) */ int mp_jacobi(const mp_int *a, const mp_int *n, int *c); +/* computes the Kronecker symbol c = (a | p) (like jacobi() but with {a,p} in Z */ +int mp_kronecker(const mp_int *a, const mp_int *p, int *c); + /* used to setup the Barrett reduction for a given modulus b */ int mp_reduce_setup(mp_int *a, const mp_int *b); @@ -491,10 +507,27 @@ int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result); */ int mp_prime_rabin_miller_trials(int size); -/* performs t rounds of Miller-Rabin on "a" using the first - * t prime bases. Also performs an initial sieve of trial +/* performs one strong Lucas-Selfridge test of "a". + * Sets result to 0 if composite or 1 if probable prime + */ +int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result); + +/* performs one Frobenius test of "a" as described by Paul Underwood. + * Sets result to 0 if composite or 1 if probable prime + */ +int mp_prime_frobenius_underwood(const mp_int *N, int *result); + +/* performs t random rounds of Miller-Rabin on "a" additional to + * bases 2 and 3. Also performs an initial sieve of trial * division. Determines if "a" is prime with probability * of error no more than (1/4)**t. + * Both a strong Lucas-Selfridge to complete the BPSW test + * and a separate Frobenius test are available at compile time. + * With t<0 a deterministic test is run for primes up to + * 318665857834031151167461. With t<13 (abs(t)-13) additional + * tests with sequential small primes are run starting at 43. + * Is Fips 186.4 compliant if called with t as computed by + * mp_prime_rabin_miller_trials(); * * Sets result to 1 if probably prime, 0 otherwise */ |
