From 1eb23ca50b6cc4f46abf44d48d6be816c34d566c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Wed, 26 Dec 2018 17:49:31 +0100 Subject: [PATCH] In openssl benchmarks, use RSA_generate_key_ex. --- ChangeLog | 5 +++++ examples/hogweed-benchmark.c | 34 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa3daeb3..980c697d 100644 --- 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. diff --git a/examples/hogweed-benchmark.c b/examples/hogweed-benchmark.c index a4a56882..accdf87e 100644 --- a/examples/hogweed-benchmark.c +++ b/examples/hogweed-benchmark.c @@ -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) { -- GitLab