]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
* dsa-verify.c (dsa_verify_digest): New function.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 23 Jan 2003 22:43:22 +0000 (23:43 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Thu, 23 Jan 2003 22:43:22 +0000 (23:43 +0100)
(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
dsa-verify.c

index b87226fbfef852c5715f03bfa56a96de5cc59b03..ab5adb0b4d0858382c8bd648e6f983a3034e4141 100644 (file)
 
 
 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 */
index 43d76c77c0db5fb8810aa2b43fde44605e9d986d..87c2a48a091f2f8a94453bdafd2c16a4bc979fe1 100644 (file)
@@ -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
 
 #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 */