Moved mp_mul_si() into bn_mp_prime_strong_lucas_selfridge.c as a local function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
diff --git a/bn_mp_mul_si.c b/bn_mp_mul_si.c
deleted file mode 100644
index 4fc17be..0000000
--- a/bn_mp_mul_si.c
+++ /dev/null
@@ -1,50 +0,0 @@
-#include "tommath_private.h"
-#ifdef BN_MP_MUL_SI_C
-
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * 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.
- */
-
-// multiply bigint a with int d and put the result in c
-// Like mp_mul_d() but with a signed long as the small input
-int mp_mul_si(const mp_int *a, long d, mp_int *c)
-{
- mp_int t;
- int err, neg = 0;
-
- if ((err = mp_init(&t)) != MP_OKAY) {
- return err;
- }
- if (d < 0) {
- neg = 1;
- d = -d;
- }
-
- // mp_digit might be smaller than a long, which excludes
- // the use of mp_mul_d() here.
- if ((err = mp_set_long(&t, (unsigned long) d)) != MP_OKAY) {
- goto LBL_MPMULSI_ERR;
- }
- if ((err = mp_mul(a, &t, c)) != MP_OKAY) {
- goto LBL_MPMULSI_ERR;
- }
- if (neg == 1) {
- c->sign = (a->sign == MP_NEG) ? MP_ZPOS: MP_NEG;
- }
-LBL_MPMULSI_ERR:
- mp_clear(&t);
- return err;
-}
-
-
-
-#endif
diff --git a/bn_mp_prime_frobenius_underwood.c b/bn_mp_prime_frobenius_underwood.c
index 28b5269..5be9d0d 100644
--- a/bn_mp_prime_frobenius_underwood.c
+++ b/bn_mp_prime_frobenius_underwood.c
@@ -14,7 +14,6 @@
* guarantee it works.
*/
-
#ifdef MP_8BIT
/*
* floor of positive solution of
diff --git a/bn_mp_prime_strong_lucas_selfridge.c b/bn_mp_prime_strong_lucas_selfridge.c
index 6d0e3fe..1fcbbd5 100644
--- a/bn_mp_prime_strong_lucas_selfridge.c
+++ b/bn_mp_prime_strong_lucas_selfridge.c
@@ -14,9 +14,50 @@
* guarantee it works.
*/
+/*
+ * 8-bit is just too small. You can try the Frobenius test
+ * but that frobenius test can fail, too, for the same reason.
+ */
#ifndef MP_8BIT
/*
+ * multiply bigint a with int d and put the result in c
+ * Like mp_mul_d() but with a signed long as the small input
+ */
+static int mp_mul_si(const mp_int *a, long d, mp_int *c)
+{
+ mp_int t;
+ int err, neg = 0;
+
+ if ((err = mp_init(&t)) != MP_OKAY) {
+ return err;
+ }
+ if (d < 0) {
+ neg = 1;
+ d = -d;
+ }
+
+ /*
+ * mp_digit might be smaller than a long, which excludes
+ * the use of mp_mul_d() here.
+ */
+ if ((err = mp_set_long(&t, (unsigned long) d)) != MP_OKAY) {
+ goto LBL_MPMULSI_ERR;
+ }
+ if ((err = mp_mul(a, &t, c)) != MP_OKAY) {
+ goto LBL_MPMULSI_ERR;
+ }
+ if (neg == 1) {
+ c->sign = (a->sign == MP_NEG) ? MP_ZPOS: MP_NEG;
+ }
+LBL_MPMULSI_ERR:
+ mp_clear(&t);
+ return err;
+}
+
+
+
+/*
Strong Lucas-Selfridge test.
returns MP_YES if it is a strong L-S prime, MP_NO if it is composite
diff --git a/tommath.h b/tommath.h
index f9132a2..80ab7b9 100644
--- a/tommath.h
+++ b/tommath.h
@@ -364,10 +364,6 @@ int mp_sub_d(const mp_int *a, mp_digit b, mp_int *c);
/* c = a * b */
int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c);
-/* multiply bigint a with int d and put the result in c
- Like mp_mul_d() but with a signed long as the small input */
-int mp_mul_si(const mp_int *a, long d, mp_int *c);
-
/* a/b => cb + d == a */
int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d);