Browse Source

math descriptor: add parameter "b" to isprime()

Steffen Jaeckel 11 years ago
parent
commit
ca42862d52
4 changed files with 21 additions and 13 deletions
  1. 4 3
      src/headers/tomcrypt_math.h
  2. 6 3
      src/math/gmp_desc.c
  3. 7 4
      src/math/ltm_desc.c
  4. 4 3
      src/math/tfm_desc.c

+ 4 - 3
src/headers/tomcrypt_math.h

@@ -326,10 +326,11 @@ typedef struct {
 
    /** Primality testing
        @param a     The integer to test
-       @param b     The destination of the result (FP_YES if prime)
+       @param b     The number of tests that shall be executed
+       @param c     The destination of the result (FP_YES if prime)
        @return CRYPT_OK on success
    */
-   int (*isprime)(void *a, int *b);
+   int (*isprime)(void *a, int b, int *c);
 
 /* ----  (optional) ecc point math ---- */
 
@@ -516,7 +517,7 @@ extern const ltc_math_descriptor gmp_desc;
 #define mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
 
 #define mp_exptmod(a,b,c,d)          ltc_mp.exptmod(a,b,c,d)
-#define mp_prime_is_prime(a, b, c)   ltc_mp.isprime(a, c)
+#define mp_prime_is_prime(a, b, c)   ltc_mp.isprime(a, b, c)
 
 #define mp_iszero(a)                 (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
 #define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)

+ 6 - 3
src/math/gmp_desc.c

@@ -442,11 +442,14 @@ static int exptmod(void *a, void *b, void *c, void *d)
    return CRYPT_OK;
 }
 
-static int isprime(void *a, int *b)
+static int isprime(void *a, int b, int *c)
 {
    LTC_ARGCHK(a != NULL);
-   LTC_ARGCHK(b != NULL);
-   *b = mpz_probab_prime_p(a, 8) > 0 ? LTC_MP_YES : LTC_MP_NO;
+   LTC_ARGCHK(c != NULL);
+   if (b == 0) {
+       b = 8;
+   } /* if */
+   *c = mpz_probab_prime_p(a, b) > 0 ? LTC_MP_YES : LTC_MP_NO;
    return CRYPT_OK;
 }
 

+ 7 - 4
src/math/ltm_desc.c

@@ -400,13 +400,16 @@ static int exptmod(void *a, void *b, void *c, void *d)
    return mpi_to_ltc_error(mp_exptmod(a,b,c,d));
 }
 
-static int isprime(void *a, int *b)
+static int isprime(void *a, int b, int *c)
 {
    int err;
    LTC_ARGCHK(a != NULL);
-   LTC_ARGCHK(b != NULL);
-   err = mpi_to_ltc_error(mp_prime_is_prime(a, 8, b));
-   *b = (*b == MP_YES) ? LTC_MP_YES : LTC_MP_NO;
+   LTC_ARGCHK(c != NULL);
+   if (b == 0) {
+       b = 8;
+   } /* if */
+   err = mpi_to_ltc_error(mp_prime_is_prime(a, b, c));
+   *c = (*c == MP_YES) ? LTC_MP_YES : LTC_MP_NO;
    return err;
 }
 

+ 4 - 3
src/math/tfm_desc.c

@@ -413,11 +413,12 @@ static int exptmod(void *a, void *b, void *c, void *d)
    return tfm_to_ltc_error(fp_exptmod(a,b,c,d));
 }
 
-static int isprime(void *a, int *b)
+static int isprime(void *a, int b, int *c)
 {
    LTC_ARGCHK(a != NULL);
-   LTC_ARGCHK(b != NULL);
-   *b = (fp_isprime(a) == FP_YES) ? LTC_MP_YES : LTC_MP_NO;
+   LTC_ARGCHK(c != NULL);
+   (void)b;
+   *c = (fp_isprime(a) == FP_YES) ? LTC_MP_YES : LTC_MP_NO;
    return CRYPT_OK;
 }