From: Niels Möller Date: Wed, 9 Oct 2002 19:29:34 +0000 (+0200) Subject: * dsa-sign.c (dsa_sign): Needs the public key as argument, in X-Git-Tag: nettle_1.7_release_20030311~270 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03e759fc0701b581879524c84b9d78b9e857b3b1;p=thirdparty%2Fnettle.git * dsa-sign.c (dsa_sign): Needs the public key as argument, in addition to the private key. Use const. Rev: src/nettle/dsa-sign.c:1.3 --- diff --git a/dsa-sign.c b/dsa-sign.c index 3a69a216..cbf19ceb 100644 --- a/dsa-sign.c +++ b/dsa-sign.c @@ -72,7 +72,8 @@ nettle_mpz_random(mpz_t x, const mpz_t n, } void -dsa_sign(struct dsa_private_key *key, +dsa_sign(const struct dsa_public_key *pub, + const struct dsa_private_key *key, void *random_ctx, nettle_random_func random, struct sha1_ctx *hash, struct dsa_signature *signature) @@ -82,7 +83,7 @@ dsa_sign(struct dsa_private_key *key, mpz_t tmp; /* Select k, 0pub.q); + mpz_init_set(tmp, pub->q); mpz_sub_ui(tmp, tmp, 1); mpz_init(k); @@ -90,24 +91,24 @@ dsa_sign(struct dsa_private_key *key, mpz_add_ui(k, k, 1); /* Compute r = (g^k (mod p)) (mod q) */ - mpz_powm(tmp, key->pub.g, k, key->pub.p); - mpz_fdiv_r(signature->r, tmp, key->pub.q); + mpz_powm(tmp, pub->g, k, pub->p); + mpz_fdiv_r(signature->r, tmp, pub->q); /* Compute hash */ mpz_init(h); _dsa_hash(h, hash); /* Compute k^-1 (mod q) */ - if (!mpz_invert(k, k, key->pub.q)) + if (!mpz_invert(k, k, pub->q)) /* What do we do now? The key is invalid. */ abort(); /* Compute signature s = k^-1(h + xr) (mod q) */ mpz_mul(tmp, signature->r, key->x); - mpz_fdiv_r(tmp, tmp, key->pub.q); + mpz_fdiv_r(tmp, tmp, pub->q); mpz_add(tmp, tmp, h); mpz_mul(tmp, tmp, k); - mpz_fdiv_r(signature->s, tmp, key->pub.q); + mpz_fdiv_r(signature->s, tmp, pub->q); mpz_clear(k); mpz_clear(h);