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

Update dsa benchmarking to use new DSA interface.

parent 38edca97
Branches
Tags
No related merge requests found
2014-03-26 Niels Möller <nisse@lysator.liu.se> 2014-03-26 Niels Möller <nisse@lysator.liu.se>
* examples/hogweed-benchmark.c: Update dsa benchmarking to use new
DSA interface.
* dsa.c (dsa_params_init, dsa_params_clear): New functions. * dsa.c (dsa_params_init, dsa_params_clear): New functions.
(dsa_public_key_init): Use dsa_params_init. (dsa_public_key_init): Use dsa_params_init.
(dsa_public_key_clear): Use dsa_params_clear. (dsa_public_key_clear): Use dsa_params_clear.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* nettle, low-level cryptographics library /* nettle, low-level cryptographics library
* *
* Copyright (C) 2013 Niels Möller * Copyright (C) 2013, 2014 Niels Möller
* *
* The nettle library is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU Lesser General Public License as published by
...@@ -265,8 +265,9 @@ bench_rsa_clear (void *p) ...@@ -265,8 +265,9 @@ bench_rsa_clear (void *p)
struct dsa_ctx struct dsa_ctx
{ {
struct dsa_public_key pub; struct dsa_params params;
struct dsa_private_key key; mpz_t pub;
mpz_t key;
struct knuth_lfib_ctx lfib; struct knuth_lfib_ctx lfib;
struct dsa_signature s; struct dsa_signature s;
uint8_t *digest; uint8_t *digest;
...@@ -292,8 +293,9 @@ bench_dsa_init (unsigned size) ...@@ -292,8 +293,9 @@ bench_dsa_init (unsigned size)
ctx = xalloc(sizeof(*ctx)); ctx = xalloc(sizeof(*ctx));
dsa_public_key_init (&ctx->pub); dsa_params_init (&ctx->params);
dsa_private_key_init (&ctx->key); mpz_init (ctx->pub);
mpz_init (ctx->key);
dsa_signature_init (&ctx->s); dsa_signature_init (&ctx->s);
knuth_lfib_init (&ctx->lfib, 1); knuth_lfib_init (&ctx->lfib, 1);
...@@ -303,16 +305,15 @@ bench_dsa_init (unsigned size) ...@@ -303,16 +305,15 @@ bench_dsa_init (unsigned size)
if (! (sexp_transport_iterator_first (&i, sizeof(dsa1024) - 1, dsa1024) if (! (sexp_transport_iterator_first (&i, sizeof(dsa1024) - 1, dsa1024)
&& sexp_iterator_check_type (&i, "private-key") && sexp_iterator_check_type (&i, "private-key")
&& sexp_iterator_check_type (&i, "dsa") && sexp_iterator_check_type (&i, "dsa")
&& dsa_keypair_from_sexp_alist ((struct dsa_params *) &ctx->pub, && dsa_keypair_from_sexp_alist (&ctx->params, ctx->pub, ctx->key,
ctx->pub.y, ctx->key.x,
0, DSA_SHA1_Q_BITS, &i)) ) 0, DSA_SHA1_Q_BITS, &i)) )
die ("Internal error.\n"); die ("Internal error.\n");
ctx->digest = hash_string (&nettle_sha1, 3, "foo"); ctx->digest = hash_string (&nettle_sha1, 3, "foo");
dsa_sha1_sign_digest (&ctx->pub, &ctx->key, dsa_sign (&ctx->params, ctx->key,
&ctx->lfib, (nettle_random_func *)knuth_lfib_random, &ctx->lfib, (nettle_random_func *)knuth_lfib_random,
ctx->digest, &ctx->s); SHA1_DIGEST_SIZE, ctx->digest, &ctx->s);
return ctx; return ctx;
} }
...@@ -324,9 +325,9 @@ bench_dsa_sign (void *p) ...@@ -324,9 +325,9 @@ bench_dsa_sign (void *p)
struct dsa_signature s; struct dsa_signature s;
dsa_signature_init (&s); dsa_signature_init (&s);
dsa_sha1_sign_digest (&ctx->pub, &ctx->key, dsa_sign (&ctx->params, ctx->key,
&ctx->lfib, (nettle_random_func *)knuth_lfib_random, &ctx->lfib, (nettle_random_func *)knuth_lfib_random,
ctx->digest, &s); SHA1_DIGEST_SIZE, ctx->digest, &s);
dsa_signature_clear (&s); dsa_signature_clear (&s);
} }
...@@ -334,7 +335,7 @@ static void ...@@ -334,7 +335,7 @@ static void
bench_dsa_verify (void *p) bench_dsa_verify (void *p)
{ {
struct dsa_ctx *ctx = p; struct dsa_ctx *ctx = p;
if (! dsa_sha1_verify_digest (&ctx->pub, ctx->digest, &ctx->s)) if (! dsa_verify (&ctx->params, ctx->pub, SHA1_DIGEST_SIZE, ctx->digest, &ctx->s))
die ("Internal error, dsa_sha1_verify_digest failed.\n"); die ("Internal error, dsa_sha1_verify_digest failed.\n");
} }
...@@ -342,8 +343,9 @@ static void ...@@ -342,8 +343,9 @@ static void
bench_dsa_clear (void *p) bench_dsa_clear (void *p)
{ {
struct dsa_ctx *ctx = p; struct dsa_ctx *ctx = p;
dsa_public_key_clear (&ctx->pub); dsa_params_clear (&ctx->params);
dsa_private_key_clear (&ctx->key); mpz_clear (ctx->pub);
mpz_clear (ctx->key);
dsa_signature_clear (&ctx->s); dsa_signature_clear (&ctx->s);
free (ctx->digest); free (ctx->digest);
free (ctx); free (ctx);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment