Mercurial > dropbear
comparison libtommath/bn_mp_prime_fermat.c @ 1692:1051e4eea25a
Update LibTomMath to 1.2.0 (#84)
* update C files
* update other files
* update headers
* update makefiles
* remove mp_set/get_double()
* use ltm 1.2.0 API
* update ltm_desc
* use bundled tommath if system-tommath is too old
* XMALLOC etc. were changed to MP_MALLOC etc.
author | Steffen Jaeckel <s@jaeckel.eu> |
---|---|
date | Tue, 26 May 2020 17:36:47 +0200 |
parents | f52919ffd3b1 |
children |
comparison
equal
deleted
inserted
replaced
1691:2d3745d58843 | 1692:1051e4eea25a |
---|---|
1 #include "tommath_private.h" | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_PRIME_FERMAT_C | 2 #ifdef BN_MP_PRIME_FERMAT_C |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis | 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */ |
4 * | 4 /* SPDX-License-Identifier: Unlicense */ |
5 * LibTomMath is a library that provides multiple-precision | |
6 * integer arithmetic as well as number theoretic functionality. | |
7 * | |
8 * The library was designed directly after the MPI library by | |
9 * Michael Fromberger but has been written from scratch with | |
10 * additional optimizations in place. | |
11 * | |
12 * SPDX-License-Identifier: Unlicense | |
13 */ | |
14 | 5 |
15 /* performs one Fermat test. | 6 /* performs one Fermat test. |
16 * | 7 * |
17 * If "a" were prime then b**a == b (mod a) since the order of | 8 * If "a" were prime then b**a == b (mod a) since the order of |
18 * the multiplicative sub-group would be phi(a) = a-1. That means | 9 * the multiplicative sub-group would be phi(a) = a-1. That means |
19 * it would be the same as b**(a mod (a-1)) == b**1 == b (mod a). | 10 * it would be the same as b**(a mod (a-1)) == b**1 == b (mod a). |
20 * | 11 * |
21 * Sets result to 1 if the congruence holds, or zero otherwise. | 12 * Sets result to 1 if the congruence holds, or zero otherwise. |
22 */ | 13 */ |
23 int mp_prime_fermat(const mp_int *a, const mp_int *b, int *result) | 14 mp_err mp_prime_fermat(const mp_int *a, const mp_int *b, mp_bool *result) |
24 { | 15 { |
25 mp_int t; | 16 mp_int t; |
26 int err; | 17 mp_err err; |
27 | 18 |
28 /* default to composite */ | 19 /* default to composite */ |
29 *result = MP_NO; | 20 *result = MP_NO; |
30 | 21 |
31 /* ensure b > 1 */ | 22 /* ensure b > 1 */ |
52 LBL_T: | 43 LBL_T: |
53 mp_clear(&t); | 44 mp_clear(&t); |
54 return err; | 45 return err; |
55 } | 46 } |
56 #endif | 47 #endif |
57 | |
58 /* ref: HEAD -> master, tag: v1.1.0 */ | |
59 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ | |
60 /* commit time: 2019-01-28 20:32:32 +0100 */ |