From a3399cff809345becc0f2b4f72268ce32aa84b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Thu, 23 Jan 2003 23:43:22 +0100 Subject: [PATCH] * dsa-verify.c (dsa_verify_digest): New function. (dsa_verify): Most of the code moved to dsa_verify_digest, which is used here. * dsa-sign.c (dsa_sign_digest): New function. (dsa_sign): Most of the code moved to dsa_sign_digest, which is used here. * dsa.c (_dsa_hash): Deleted function. Rev: src/nettle/dsa-sign.c:1.5 Rev: src/nettle/dsa-verify.c:1.3 --- dsa-sign.c | 26 ++++++++++++++++++++------ dsa-verify.c | 28 ++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/dsa-sign.c b/dsa-sign.c index b87226fb..ab5adb0b 100644 --- a/dsa-sign.c +++ b/dsa-sign.c @@ -37,11 +37,11 @@ void -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) +dsa_sign_digest(const struct dsa_public_key *pub, + const struct dsa_private_key *key, + void *random_ctx, nettle_random_func random, + const uint8_t *digest, + struct dsa_signature *signature) { mpz_t k; mpz_t h; @@ -61,7 +61,7 @@ dsa_sign(const struct dsa_public_key *pub, /* Compute hash */ mpz_init(h); - _dsa_hash(h, hash); + nettle_mpz_set_str_256_u(h, SHA1_DIGEST_SIZE, digest); /* Compute k^-1 (mod q) */ if (!mpz_invert(k, k, pub->q)) @@ -80,4 +80,18 @@ dsa_sign(const struct dsa_public_key *pub, mpz_clear(tmp); } +void +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) +{ + uint8_t digest[SHA1_DIGEST_SIZE]; + sha1_digest(hash, sizeof(digest), digest); + + dsa_sign_digest(pub, key, random_ctx, random, + digest, signature); +} + #endif /* WITH_PUBLIC_KEY */ diff --git a/dsa-verify.c b/dsa-verify.c index 43d76c77..87c2a48a 100644 --- a/dsa-verify.c +++ b/dsa-verify.c @@ -5,7 +5,7 @@ /* nettle, low-level cryptographics library * - * Copyright (C) 2002 Niels M�ller + * Copyright (C) 2002, 2003 Niels M�ller * * The nettle library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -31,12 +31,14 @@ #include "dsa.h" +#include "bignum.h" + #include <stdlib.h> int -dsa_verify(const struct dsa_public_key *key, - struct sha1_ctx *hash, - const struct dsa_signature *signature) +dsa_verify_digest(const struct dsa_public_key *key, + const uint8_t *digest, + const struct dsa_signature *signature) { mpz_t w; mpz_t tmp; @@ -65,12 +67,11 @@ dsa_verify(const struct dsa_public_key *key, mpz_init(tmp); mpz_init(v); - - /* Compute hash */ - _dsa_hash(tmp, hash); + + /* The message digest */ + nettle_mpz_set_str_256_u(tmp, SHA1_DIGEST_SIZE, digest); /* v = g^{w * h (mod q)} (mod p) */ - mpz_mul(tmp, tmp, w); mpz_fdiv_r(tmp, tmp, key->q); @@ -97,4 +98,15 @@ dsa_verify(const struct dsa_public_key *key, return res; } +int +dsa_verify(const struct dsa_public_key *key, + struct sha1_ctx *hash, + const struct dsa_signature *signature) +{ + uint8_t digest[SHA1_DIGEST_SIZE]; + sha1_digest(hash, sizeof(digest), digest); + + return dsa_verify_digest(key, digest, signature); +} + #endif /* WITH_PUBLIC_KEY */ -- GitLab