]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
In openssl benchmarks, use RSA_generate_key_ex.
authorNiels Möller <nisse@lysator.liu.se>
Wed, 26 Dec 2018 16:49:31 +0000 (17:49 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Wed, 26 Dec 2018 16:49:31 +0000 (17:49 +0100)
ChangeLog
examples/hogweed-benchmark.c

index aa3daeb34d0dae8c11e1ebc3189a6c77854d7a10..980c697d4f728863ccbd2043caffae250b076731 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2018-12-26  Niels Möller  <nisse@lysator.liu.se>
 
+       * examples/hogweed-benchmark.c (make_openssl_rsa_ctx): New helper
+       function. Call openssl's RSA_generate_key_ex rather then the
+       deprecated RSA_generate_key.
+       (bench_openssl_rsa_init, bench_openssl_rsa_tr_init): Use it.
+
        * eccdata.c (ecc_pippenger_precompute): Check that table size is
        at least 2. Intended to silence warning from the clang static
        analyzer.
index a4a568820f84f3915b1823b1a06d71e581a07975..accdf87e64409df65056eacf24a49fbb9f0762b6 100644 (file)
@@ -59,6 +59,7 @@
 
 #if WITH_OPENSSL
 #include <openssl/rsa.h>
+#include <openssl/bn.h>
 #include <openssl/ec.h>
 #include <openssl/ecdsa.h>
 #include <openssl/objects.h>
@@ -532,41 +533,40 @@ struct openssl_rsa_ctx
   uint8_t *digest;
 };
 
-static void *
-bench_openssl_rsa_init (unsigned size)
+static struct openssl_rsa_ctx*
+make_openssl_rsa_ctx (unsigned size)
 {
   struct openssl_rsa_ctx *ctx = xalloc (sizeof (*ctx));
-
-  ctx->key = RSA_generate_key (size, 65537, NULL, NULL);
+  BIGNUM *e = BN_new();
+  BN_set_word(e, 65537);
+  ctx->key = RSA_new();
+  RSA_generate_key_ex (ctx->key, size, e, NULL);
   ctx->ref = xalloc (RSA_size (ctx->key));
   ctx->signature = xalloc (RSA_size (ctx->key));
   ctx->digest = hash_string (&nettle_sha1, "foo");
-  RSA_blinding_off(ctx->key);
 
   if (! RSA_sign (NID_sha1, ctx->digest, SHA1_DIGEST_SIZE,
                  ctx->ref, &ctx->siglen, ctx->key))
     die ("OpenSSL RSA_sign failed.\n");
 
+  BN_free(e);
   return ctx;
 }
 
 static void *
-bench_openssl_rsa_tr_init (unsigned size)
+bench_openssl_rsa_init (unsigned size)
 {
-  struct openssl_rsa_ctx *ctx = xalloc (sizeof (*ctx));
-
-  ctx->key = RSA_generate_key (size, 65537, NULL, NULL);
-  ctx->ref = xalloc (RSA_size (ctx->key));
-  ctx->signature = xalloc (RSA_size (ctx->key));
-  ctx->digest = hash_string (&nettle_sha1, "foo");
-
-  if (! RSA_sign (NID_sha1, ctx->digest, SHA1_DIGEST_SIZE,
-                 ctx->ref, &ctx->siglen, ctx->key))
-    die ("OpenSSL RSA_sign failed.\n");
-
+  struct openssl_rsa_ctx *ctx = make_openssl_rsa_ctx (size);
+  RSA_blinding_off(ctx->key);
   return ctx;
 }
 
+static void *
+bench_openssl_rsa_tr_init (unsigned size)
+{
+  return make_openssl_rsa_ctx (size);
+}
+
 static void
 bench_openssl_rsa_sign (void *p)
 {