diff libtomcrypt/src/pk/dsa/dsa_sign_hash.c @ 382:0cbe8f6dbf9e

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f) to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:41:05 +0000
parents 1b9e69c058d2
children f849a5ca2efc
line wrap: on
line diff
--- a/libtomcrypt/src/pk/dsa/dsa_sign_hash.c	Thu Jan 04 02:01:09 2007 +0000
+++ b/libtomcrypt/src/pk/dsa/dsa_sign_hash.c	Thu Jan 11 02:41:05 2007 +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"
 
@@ -29,10 +29,10 @@
   @return CRYPT_OK if successful
 */
 int dsa_sign_hash_raw(const unsigned char *in,  unsigned long inlen,
-                                   mp_int *r,   mp_int *s,
+                                   void   *r,   void *s,
                                prng_state *prng, int wprng, dsa_key *key)
 {
-   mp_int         k, kinv, tmp;
+   void         *k, *kinv, *tmp;
    unsigned char *buf;
    int            err;
 
@@ -59,7 +59,7 @@
    }
 
    /* Init our temps */
-   if ((err = mp_init_multi(&k, &kinv, &tmp, NULL)) != MP_OKAY)               { goto error; }
+   if ((err = mp_init_multi(&k, &kinv, &tmp, NULL)) != CRYPT_OK)                       { goto ERRBUF; }
 
 retry:
 
@@ -67,43 +67,40 @@
       /* gen random k */
       if (prng_descriptor[wprng].read(buf, key->qord, prng) != (unsigned long)key->qord) {
          err = CRYPT_ERROR_READPRNG;
-         goto LBL_ERR;
+         goto error;
       }
 
       /* read k */
-      if ((err = mp_read_unsigned_bin(&k, buf, key->qord)) != MP_OKAY)                { goto error; }
+      if ((err = mp_read_unsigned_bin(k, buf, key->qord)) != CRYPT_OK)                 { goto error; }
 
       /* k > 1 ? */
-      if (mp_cmp_d(&k, 1) != MP_GT)                                                   { goto retry; }
+      if (mp_cmp_d(k, 1) != LTC_MP_GT)                                                 { goto retry; }
 
       /* test gcd */
-      if ((err = mp_gcd(&k, &key->q, &tmp)) != MP_OKAY)                               { goto error; }
-   } while (mp_cmp_d(&tmp, 1) != MP_EQ);
+      if ((err = mp_gcd(k, key->q, tmp)) != CRYPT_OK)                                  { goto error; }
+   } while (mp_cmp_d(tmp, 1) != LTC_MP_EQ);
 
    /* now find 1/k mod q */
-   if ((err = mp_invmod(&k, &key->q, &kinv)) != MP_OKAY)                              { goto error; }
+   if ((err = mp_invmod(k, key->q, kinv)) != CRYPT_OK)                                 { goto error; }
 
    /* now find r = g^k mod p mod q */
-   if ((err = mp_exptmod(&key->g, &k, &key->p, r)) != MP_OKAY)                        { goto error; }
-   if ((err = mp_mod(r, &key->q, r)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_exptmod(key->g, k, key->p, r)) != CRYPT_OK)                           { goto error; }
+   if ((err = mp_mod(r, key->q, r)) != CRYPT_OK)                                       { goto error; }
 
-   if (mp_iszero(r) == MP_YES)                                                        { goto retry; }
+   if (mp_iszero(r) == LTC_MP_YES)                                                     { goto retry; }
 
    /* now find s = (in + xr)/k mod q */
-   if ((err = mp_read_unsigned_bin(&tmp, (unsigned char *)in, inlen)) != MP_OKAY)     { goto error; }
-   if ((err = mp_mul(&key->x, r, s)) != MP_OKAY)                                      { goto error; }
-   if ((err = mp_add(s, &tmp, s)) != MP_OKAY)                                         { goto error; }
-   if ((err = mp_mulmod(s, &kinv, &key->q, s)) != MP_OKAY)                            { goto error; }
+   if ((err = mp_read_unsigned_bin(tmp, (unsigned char *)in, inlen)) != CRYPT_OK)      { goto error; }
+   if ((err = mp_mul(key->x, r, s)) != CRYPT_OK)                                       { goto error; }
+   if ((err = mp_add(s, tmp, s)) != CRYPT_OK)                                          { goto error; }
+   if ((err = mp_mulmod(s, kinv, key->q, s)) != CRYPT_OK)                              { goto error; }
 
-   if (mp_iszero(s) == MP_YES)                                                        { goto retry; }
+   if (mp_iszero(s) == LTC_MP_YES)                                                     { goto retry; }
 
    err = CRYPT_OK;
-   goto LBL_ERR;
-
 error: 
-   err = mpi_to_ltc_error(err);
-LBL_ERR: 
-   mp_clear_multi(&k, &kinv, &tmp, NULL);
+   mp_clear_multi(k, kinv, tmp, NULL);
+ERRBUF:
 #ifdef LTC_CLEAN_STACK
    zeromem(buf, MDSA_MAX_GROUP);
 #endif
@@ -126,7 +123,7 @@
                         unsigned char *out, unsigned long *outlen,
                         prng_state *prng, int wprng, dsa_key *key)
 {
-   mp_int        r, s;
+   void         *r, *s;
    int           err;
 
    LTC_ARGCHK(in      != NULL);
@@ -134,26 +131,26 @@
    LTC_ARGCHK(outlen  != NULL);
    LTC_ARGCHK(key     != NULL);
 
-   if (mp_init_multi(&r, &s, NULL) != MP_OKAY) {
+   if (mp_init_multi(&r, &s, NULL) != CRYPT_OK) {
       return CRYPT_MEM;
    }
 
-   if ((err = dsa_sign_hash_raw(in, inlen, &r, &s, prng, wprng, key)) != CRYPT_OK) {
-      goto LBL_ERR;
+   if ((err = dsa_sign_hash_raw(in, inlen, r, s, prng, wprng, key)) != CRYPT_OK) {
+      goto error;
    }
 
    err = der_encode_sequence_multi(out, outlen, 
-                             LTC_ASN1_INTEGER, 1UL, &r, 
-                             LTC_ASN1_INTEGER, 1UL, &s, 
+                             LTC_ASN1_INTEGER, 1UL, r, 
+                             LTC_ASN1_INTEGER, 1UL, s, 
                              LTC_ASN1_EOL,     0UL, NULL);
 
-LBL_ERR:
-   mp_clear_multi(&r, &s, NULL);
+error:
+   mp_clear_multi(r, s, NULL);
    return err;
 }
 
 #endif
 
 /* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_sign_hash.c,v $ */
-/* $Revision: 1.6 $ */
-/* $Date: 2005/05/15 21:48:59 $ */
+/* $Revision: 1.12 $ */
+/* $Date: 2006/12/04 22:27:56 $ */