diff libtomcrypt/src/math/ltm_desc.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children 1051e4eea25a
line wrap: on
line diff
--- a/libtomcrypt/src/math/ltm_desc.c	Thu Feb 08 23:11:40 2018 +0800
+++ b/libtomcrypt/src/math/ltm_desc.c	Fri Feb 09 21:44:05 2018 +0800
@@ -5,8 +5,6 @@
  *
  * The library is free for all purposes without any express
  * guarantee it works.
- *
- * Tom St Denis, [email protected], http://libtom.org
  */
 
 #define DESC_DEF_ONLY
@@ -25,7 +23,7 @@
 };
 
 /**
-   Convert a MPI error to a LTC error (Possibly the most powerful function ever!  Oh wait... no) 
+   Convert a MPI error to a LTC error (Possibly the most powerful function ever!  Oh wait... no)
    @param err    The error to convert
    @return The equivalent LTC error code or CRYPT_ERROR if none found
 */
@@ -34,7 +32,7 @@
    int x;
 
    for (x = 0; x < (int)(sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0])); x++) {
-       if (err == mpi_to_ltc_codes[x].mpi_code) { 
+       if (err == mpi_to_ltc_codes[x].mpi_code) {
           return mpi_to_ltc_codes[x].ltc_code;
        }
    }
@@ -51,7 +49,7 @@
    if (*a == NULL) {
       return CRYPT_MEM;
    }
-   
+
    if ((err = mpi_to_ltc_error(mp_init(*a))) != CRYPT_OK) {
       XFREE(*a);
    }
@@ -88,7 +86,7 @@
 }
 
 /* ---- trivial ---- */
-static int set_int(void *a, unsigned long b)
+static int set_int(void *a, ltc_mp_digit b)
 {
    LTC_ARGCHK(a != NULL);
    return mpi_to_ltc_error(mp_set_int(a, b));
@@ -100,7 +98,7 @@
    return mp_get_int(a);
 }
 
-static unsigned long get_digit(void *a, int n)
+static ltc_mp_digit get_digit(void *a, int n)
 {
    mp_int *A;
    LTC_ARGCHK(a != NULL);
@@ -115,7 +113,7 @@
    A = a;
    return A->used;
 }
-   
+
 static int compare(void *a, void *b)
 {
    int ret;
@@ -126,11 +124,11 @@
       case MP_LT: return LTC_MP_LT;
       case MP_EQ: return LTC_MP_EQ;
       case MP_GT: return LTC_MP_GT;
+      default:    return 0;
    }
-   return 0;
 }
 
-static int compare_d(void *a, unsigned long b)
+static int compare_d(void *a, ltc_mp_digit b)
 {
    int ret;
    LTC_ARGCHK(a != NULL);
@@ -139,8 +137,8 @@
       case MP_LT: return LTC_MP_LT;
       case MP_EQ: return LTC_MP_EQ;
       case MP_GT: return LTC_MP_GT;
+      default:    return 0;
    }
-   return 0;
 }
 
 static int count_bits(void *a)
@@ -211,8 +209,8 @@
    LTC_ARGCHK(c != NULL);
    return mpi_to_ltc_error(mp_add(a, b, c));
 }
-  
-static int addi(void *a, unsigned long b, void *c)
+
+static int addi(void *a, ltc_mp_digit b, void *c)
 {
    LTC_ARGCHK(a != NULL);
    LTC_ARGCHK(c != NULL);
@@ -228,7 +226,7 @@
    return mpi_to_ltc_error(mp_sub(a, b, c));
 }
 
-static int subi(void *a, unsigned long b, void *c)
+static int subi(void *a, ltc_mp_digit b, void *c)
 {
    LTC_ARGCHK(a != NULL);
    LTC_ARGCHK(c != NULL);
@@ -244,7 +242,7 @@
    return mpi_to_ltc_error(mp_mul(a, b, c));
 }
 
-static int muli(void *a, unsigned long b, void *c)
+static int muli(void *a, ltc_mp_digit b, void *c)
 {
    LTC_ARGCHK(a != NULL);
    LTC_ARGCHK(c != NULL);
@@ -275,7 +273,7 @@
 }
 
 /* modi */
-static int modi(void *a, unsigned long b, unsigned long *c)
+static int modi(void *a, ltc_mp_digit b, ltc_mp_digit *c)
 {
    mp_digit tmp;
    int      err;
@@ -288,7 +286,7 @@
    }
    *c = tmp;
    return CRYPT_OK;
-}  
+}
 
 /* gcd */
 static int gcd(void *a, void *b, void *c)
@@ -308,6 +306,24 @@
    return mpi_to_ltc_error(mp_lcm(a, b, c));
 }
 
+static int addmod(void *a, void *b, void *c, void *d)
+{
+   LTC_ARGCHK(a != NULL);
+   LTC_ARGCHK(b != NULL);
+   LTC_ARGCHK(c != NULL);
+   LTC_ARGCHK(d != NULL);
+   return mpi_to_ltc_error(mp_addmod(a,b,c,d));
+}
+
+static int submod(void *a, void *b, void *c, void *d)
+{
+   LTC_ARGCHK(a != NULL);
+   LTC_ARGCHK(b != NULL);
+   LTC_ARGCHK(c != NULL);
+   LTC_ARGCHK(d != NULL);
+   return mpi_to_ltc_error(mp_submod(a,b,c,d));
+}
+
 static int mulmod(void *a, void *b, void *c, void *d)
 {
    LTC_ARGCHK(a != NULL);
@@ -380,17 +396,26 @@
    LTC_ARGCHK(c != NULL);
    LTC_ARGCHK(d != NULL);
    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 = LTC_MILLER_RABIN_REPS;
+   } /* 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;
-}   
+}
+
+static int set_rand(void *a, int size)
+{
+   LTC_ARGCHK(a != NULL);
+   return mpi_to_ltc_error(mp_rand(a, size));
+}
 
 const ltc_math_descriptor ltm_desc = {
 
@@ -436,7 +461,7 @@
    &mulmod,
    &sqrmod,
    &invmod,
-   
+
    &montgomery_setup,
    &montgomery_normalization,
    &montgomery_reduce,
@@ -448,7 +473,7 @@
 #ifdef LTC_MECC
 #ifdef LTC_MECC_FP
    &ltc_ecc_fp_mulmod,
-#else   
+#else
    &ltc_ecc_mulmod,
 #endif
    &ltc_ecc_projective_add_point,
@@ -471,13 +496,18 @@
    &rsa_make_key,
    &rsa_exptmod,
 #else
-   NULL, NULL
+   NULL, NULL,
 #endif
+   &addmod,
+   &submod,
+
+   &set_rand,
+
 };
 
 
 #endif
 
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */