Skip to content
Snippets Groups Projects
Commit a3399cff authored by Niels Möller's avatar Niels Möller
Browse files

* 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
parent ed7977cb
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......@@ -5,7 +5,7 @@
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Mller
* Copyright (C) 2002, 2003 Niels Mller
*
* 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 */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment