summaryrefslogtreecommitdiffhomepage
path: root/libtomcrypt/src/pk/dsa/dsa_sign_hash.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2007-02-03 08:20:30 +0000
committerMatt Johnston <matt@ucc.asn.au>2007-02-03 08:20:30 +0000
commitc5fd7dd5548f28e32d846e39d17e5c4de4e769af (patch)
tree81b522e272facfb27ff614936b4988bf6569ef2d /libtomcrypt/src/pk/dsa/dsa_sign_hash.c
parent5092e30605dfc5c45990d91cf606990e5c768255 (diff)
parent4a5208512ba02f735acbf7e948ed02353583581e (diff)
merge of '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
and '7f8670ac3bb975f40967f3979d09d2199b7e90c8' --HG-- extra : convert_revision : 6b61c50f4cf888bea302ac8fcf5dbb573b443251
Diffstat (limited to 'libtomcrypt/src/pk/dsa/dsa_sign_hash.c')
-rw-r--r--libtomcrypt/src/pk/dsa/dsa_sign_hash.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/libtomcrypt/src/pk/dsa/dsa_sign_hash.c b/libtomcrypt/src/pk/dsa/dsa_sign_hash.c
index 48d29a2..f84dd28 100644
--- a/libtomcrypt/src/pk/dsa/dsa_sign_hash.c
+++ b/libtomcrypt/src/pk/dsa/dsa_sign_hash.c
@@ -6,7 +6,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
- * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, 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 @@ int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen,
}
/* 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 @@ retry:
/* 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 @@ int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
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 @@ int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
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 $ */