summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_prime_fermat.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 15:13:40 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 15:13:40 (GMT)
commitdb596f769f7d0d74193f88b121b949bce6853ebf (patch)
treefeb67968040c4869b021497e6e8859e0e90e41be /libtommath/bn_mp_prime_fermat.c
parent36098aafd9bbd015808f0607f94acc590d192e0d (diff)
parent7a4fe54c26332c21cd95b01cc07bd74714d060ae (diff)
downloadtcl-z_modifier.zip
tcl-z_modifier.tar.gz
tcl-z_modifier.tar.bz2
Merge trunkz_modifier
Diffstat (limited to 'libtommath/bn_mp_prime_fermat.c')
-rw-r--r--libtommath/bn_mp_prime_fermat.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/libtommath/bn_mp_prime_fermat.c b/libtommath/bn_mp_prime_fermat.c
index d99feeb..9c15435 100644
--- a/libtommath/bn_mp_prime_fermat.c
+++ b/libtommath/bn_mp_prime_fermat.c
@@ -16,44 +16,45 @@
*/
/* performs one Fermat test.
- *
+ *
* If "a" were prime then b**a == b (mod a) since the order of
* the multiplicative sub-group would be phi(a) = a-1. That means
* it would be the same as b**(a mod (a-1)) == b**1 == b (mod a).
*
* Sets result to 1 if the congruence holds, or zero otherwise.
*/
-int mp_prime_fermat (mp_int * a, mp_int * b, int *result)
+int mp_prime_fermat(const mp_int *a, const mp_int *b, int *result)
{
- mp_int t;
- int err;
-
- /* default to composite */
- *result = MP_NO;
-
- /* ensure b > 1 */
- if (mp_cmp_d(b, 1) != MP_GT) {
- return MP_VAL;
- }
-
- /* init t */
- if ((err = mp_init (&t)) != MP_OKAY) {
- return err;
- }
-
- /* compute t = b**a mod a */
- if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) {
- goto LBL_T;
- }
-
- /* is it equal to b? */
- if (mp_cmp (&t, b) == MP_EQ) {
- *result = MP_YES;
- }
-
- err = MP_OKAY;
-LBL_T:mp_clear (&t);
- return err;
+ mp_int t;
+ int err;
+
+ /* default to composite */
+ *result = MP_NO;
+
+ /* ensure b > 1 */
+ if (mp_cmp_d(b, 1) != MP_GT) {
+ return MP_VAL;
+ }
+
+ /* init t */
+ if ((err = mp_init(&t)) != MP_OKAY) {
+ return err;
+ }
+
+ /* compute t = b**a mod a */
+ if ((err = mp_exptmod(b, a, a, &t)) != MP_OKAY) {
+ goto LBL_T;
+ }
+
+ /* is it equal to b? */
+ if (mp_cmp(&t, b) == MP_EQ) {
+ *result = MP_YES;
+ }
+
+ err = MP_OKAY;
+LBL_T:
+ mp_clear(&t);
+ return err;
}
#endif