Mercurial > dropbear
comparison libtommath/bn_mp_prime_miller_rabin.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_MILLER_RABIN_C | 2 #ifdef BN_MP_PRIME_MILLER_RABIN_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 /* Miller-Rabin test of "a" to the base of "b" as described in | 6 /* Miller-Rabin test of "a" to the base of "b" as described in |
16 * HAC pp. 139 Algorithm 4.24 | 7 * HAC pp. 139 Algorithm 4.24 |
17 * | 8 * |
18 * Sets result to 0 if definitely composite or 1 if probably prime. | 9 * Sets result to 0 if definitely composite or 1 if probably prime. |
19 * Randomly the chance of error is no more than 1/4 and often | 10 * Randomly the chance of error is no more than 1/4 and often |
20 * very much lower. | 11 * very much lower. |
21 */ | 12 */ |
22 int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result) | 13 mp_err mp_prime_miller_rabin(const mp_int *a, const mp_int *b, mp_bool *result) |
23 { | 14 { |
24 mp_int n1, y, r; | 15 mp_int n1, y, r; |
25 int s, j, err; | 16 mp_err err; |
17 int s, j; | |
26 | 18 |
27 /* default */ | 19 /* default */ |
28 *result = MP_NO; | 20 *result = MP_NO; |
29 | 21 |
30 /* ensure b > 1 */ | 22 /* ensure b > 1 */ |
95 LBL_N1: | 87 LBL_N1: |
96 mp_clear(&n1); | 88 mp_clear(&n1); |
97 return err; | 89 return err; |
98 } | 90 } |
99 #endif | 91 #endif |
100 | |
101 /* ref: HEAD -> master, tag: v1.1.0 */ | |
102 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ | |
103 /* commit time: 2019-01-28 20:32:32 +0100 */ |