diff libtomcrypt/src/pk/dsa/dsa_verify_key.c @ 511:582cb38e4eb5 insecure-nocrypto

propagate from branch 'au.asn.ucc.matt.dropbear' (head cdcc3c729e29544e8b98a408e2dc60e4483dfd2a) to branch 'au.asn.ucc.matt.dropbear.insecure-nocrypto' (head 0ca38a1cf349f7426ac9de34ebe4c3e3735effab)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 06 Nov 2008 13:16:55 +0000
parents 0cbe8f6dbf9e
children f849a5ca2efc
line wrap: on
line diff
--- a/libtomcrypt/src/pk/dsa/dsa_verify_key.c	Mon Oct 02 06:40:51 2006 +0000
+++ b/libtomcrypt/src/pk/dsa/dsa_verify_key.c	Thu Nov 06 13:16:55 2008 +0000
@@ -6,7 +6,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://libtomcrypt.org
+ * Tom St Denis, [email protected], http://libtomcrypt.com
  */
 #include "tomcrypt.h"
 
@@ -25,7 +25,7 @@
 */
 int dsa_verify_key(dsa_key *key, int *stat)
 {
-   mp_int tmp, tmp2;
+   void   *tmp, *tmp2;
    int    res, err;
 
    LTC_ARGCHK(key  != NULL);
@@ -35,15 +35,14 @@
    *stat = 0;
 
    /* first make sure key->q and key->p are prime */
-   if ((err = is_prime(&key->q, &res)) != CRYPT_OK) {
+   if ((err = mp_prime_is_prime(key->q, 8, &res)) != CRYPT_OK) {
       return err;
    }
    if (res == 0) {
       return CRYPT_OK;
    }
 
-
-   if ((err = is_prime(&key->p, &res)) != CRYPT_OK) {
+   if ((err = mp_prime_is_prime(key->p, 8, &res)) != CRYPT_OK) {
       return err;
    }
    if (res == 0) {
@@ -51,52 +50,51 @@
    }
 
    /* now make sure that g is not -1, 0 or 1 and <p */
-   if (mp_cmp_d(&key->g, 0) == MP_EQ || mp_cmp_d(&key->g, 1) == MP_EQ) {
+   if (mp_cmp_d(key->g, 0) == LTC_MP_EQ || mp_cmp_d(key->g, 1) == LTC_MP_EQ) {
       return CRYPT_OK;
    }
-   if ((err = mp_init_multi(&tmp, &tmp2, NULL)) != MP_OKAY)               { goto error; }
-   if ((err = mp_sub_d(&key->p, 1, &tmp)) != MP_OKAY)                     { goto error; }
-   if (mp_cmp(&tmp, &key->g) == MP_EQ || mp_cmp(&key->g, &key->p) != MP_LT) {
+   if ((err = mp_init_multi(&tmp, &tmp2, NULL)) != CRYPT_OK)               { return err; }
+   if ((err = mp_sub_d(key->p, 1, tmp)) != CRYPT_OK)                       { goto error; }
+   if (mp_cmp(tmp, key->g) == LTC_MP_EQ || mp_cmp(key->g, key->p) != LTC_MP_LT) {
       err = CRYPT_OK;
-      goto done;
+      goto error;
    }
 
    /* 1 < y < p-1 */
-   if (!(mp_cmp_d(&key->y, 1) == MP_GT && mp_cmp(&key->y, &tmp) == MP_LT)) {
+   if (!(mp_cmp_d(key->y, 1) == LTC_MP_GT && mp_cmp(key->y, tmp) == LTC_MP_LT)) {
       err = CRYPT_OK;
-      goto done;
+      goto error;
    }
 
    /* now we have to make sure that g^q = 1, and that p-1/q gives 0 remainder */
-   if ((err = mp_div(&tmp, &key->q, &tmp, &tmp2)) != MP_OKAY)             { goto error; }
-   if (mp_iszero(&tmp2) != MP_YES) {
+   if ((err = mp_div(tmp, key->q, tmp, tmp2)) != CRYPT_OK)             { goto error; }
+   if (mp_iszero(tmp2) != LTC_MP_YES) {
       err = CRYPT_OK;
-      goto done;
+      goto error;
    }
 
-   if ((err = mp_exptmod(&key->g, &key->q, &key->p, &tmp)) != MP_OKAY)    { goto error; }
-   if (mp_cmp_d(&tmp, 1) != MP_EQ) {
+   if ((err = mp_exptmod(key->g, key->q, key->p, tmp)) != CRYPT_OK)    { goto error; }
+   if (mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
       err = CRYPT_OK;
-      goto done;
+      goto error;
    }
 
    /* now we have to make sure that y^q = 1, this makes sure y \in g^x mod p */
-   if ((err = mp_exptmod(&key->y, &key->q, &key->p, &tmp)) != MP_OKAY)       { goto error; }
-   if (mp_cmp_d(&tmp, 1) != MP_EQ) {
+   if ((err = mp_exptmod(key->y, key->q, key->p, tmp)) != CRYPT_OK)       { goto error; }
+   if (mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
       err = CRYPT_OK;
-      goto done;
+      goto error;
    }
 
    /* at this point we are out of tests ;-( */
    err   = CRYPT_OK;
    *stat = 1;
-   goto done;
-error: err = mpi_to_ltc_error(err);
-done : mp_clear_multi(&tmp, &tmp2, NULL);
+error: 
+   mp_clear_multi(tmp, tmp2, NULL);
    return err;
 }
 #endif
 
 /* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_verify_key.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2005/05/05 14:35:59 $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2006/12/04 03:18:43 $ */