diff libtomcrypt/src/pk/dsa/dsa_verify_key.c @ 478:d4f32c3443ac dbclient-netcat-alike

propagate from branch 'au.asn.ucc.matt.dropbear' (head f21045c791002d81fc6b8dde6537ea481e513eb2) to branch 'au.asn.ucc.matt.dropbear.dbclient-netcat-alike' (head d1f69334581dc4c35f9ca16aa5355074c9dd315d)
author Matt Johnston <matt@ucc.asn.au>
date Sun, 14 Sep 2008 06:47:51 +0000
parents 0cbe8f6dbf9e
children f849a5ca2efc
line wrap: on
line diff
--- a/libtomcrypt/src/pk/dsa/dsa_verify_key.c	Tue Mar 21 16:16:41 2006 +0000
+++ b/libtomcrypt/src/pk/dsa/dsa_verify_key.c	Sun Sep 14 06:47:51 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 $ */