From e7b7bbf21dcd6bdc3a58fe0b04af16b864823319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Tue, 5 Dec 2023 20:25:22 +0100 Subject: [PATCH] Delete nettle_openssl_init. --- ChangeLog | 7 +++++++ examples/nettle-benchmark.c | 4 ---- examples/nettle-openssl.c | 31 ++++++------------------------- non-nettle.h | 1 - 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 075ab197..8e79d487 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-12-05 Niels Möller <nisse@lysator.liu.se> + + * examples/nettle-openssl.c: Trim openssl includes and defines, + and use Nettle's definition of sha1 and md5 constants. + (nettle_openssl_init): Deleted. + * examples/nettle-benchmark.c (main): Delete call to nettle_openssl_init. + 2023-12-04 Niels Möller <nisse@lysator.liu.se> * examples/nettle-openssl.c (nettle_openssl_blowfish128) diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index 37073a67..2a11a694 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -908,10 +908,6 @@ main(int argc, char **argv) int c; const char *alg; -#if WITH_OPENSSL - nettle_openssl_init(); -#endif - const struct nettle_hash *hashes[] = { &nettle_md2, &nettle_md4, &nettle_md5, diff --git a/examples/nettle-openssl.c b/examples/nettle-openssl.c index 0d798617..cb179416 100644 --- a/examples/nettle-openssl.c +++ b/examples/nettle-openssl.c @@ -40,20 +40,13 @@ #if WITH_OPENSSL -/* No ancient ssleay compatibility */ -#define NCOMPAT -#define OPENSSL_DISABLE_OLD_DES_SUPPORT - #include <assert.h> -#include <openssl/conf.h> #include <openssl/evp.h> -#include <openssl/err.h> - -#include <openssl/md5.h> -#include <openssl/sha.h> #include "non-nettle.h" +#include "md5.h" +#include "sha1.h" /* We use Openssl's EVP api for all openssl ciphers. This API selects platform-specific implementations if appropriate, e.g., using x86 @@ -69,18 +62,6 @@ struct openssl_hash_ctx { EVP_MD_CTX *evp; }; -void -nettle_openssl_init(void) -{ - ERR_load_crypto_strings(); - OpenSSL_add_all_algorithms(); -#if OPENSSL_VERSION_NUMBER >= 0x1010000 - CONF_modules_load_file(NULL, NULL, 0); -#else - OPENSSL_config(NULL); -#endif -} - static void openssl_evp_set_encrypt_key(void *p, const uint8_t *key, const EVP_CIPHER *cipher) @@ -315,7 +296,7 @@ static void \ openssl_##name##_init(void *p) \ { \ struct openssl_hash_ctx *ctx = p; \ - if ((ctx->evp = EVP_MD_CTX_new()) == NULL) \ + if ((ctx->evp = EVP_MD_CTX_new()) == NULL) \ return; \ \ EVP_DigestInit(ctx->evp, EVP_##name()); \ @@ -326,7 +307,7 @@ openssl_##name##_digest(void *p, \ size_t length, uint8_t *dst) \ { \ struct openssl_hash_ctx *ctx = p; \ - assert(length == NAME##_DIGEST_LENGTH); \ + assert(length == NAME##_DIGEST_SIZE); \ \ EVP_DigestFinal(ctx->evp, dst, NULL); \ EVP_DigestInit(ctx->evp, EVP_##name()); \ @@ -335,13 +316,13 @@ openssl_##name##_digest(void *p, \ const struct nettle_hash \ nettle_openssl_##name = { \ "openssl " #name, sizeof(struct openssl_hash_ctx), \ - NAME##_DIGEST_LENGTH, NAME##_CBLOCK, \ + NAME##_DIGEST_SIZE, NAME##_BLOCK_SIZE, \ openssl_##name##_init, \ openssl_hash_update, \ openssl_##name##_digest \ }; OPENSSL_HASH(MD5, md5) -OPENSSL_HASH(SHA, sha1) +OPENSSL_HASH(SHA1, sha1) #endif /* WITH_OPENSSL */ diff --git a/non-nettle.h b/non-nettle.h index 7075540a..4da0cdde 100644 --- a/non-nettle.h +++ b/non-nettle.h @@ -71,7 +71,6 @@ extern const struct nettle_aead nettle_openssl_gcm_aes256; /* Glue to openssl, for comparative benchmarking. Code in * examples/nettle-openssl.c. */ -extern void nettle_openssl_init(void); extern const struct nettle_cipher nettle_openssl_aes128; extern const struct nettle_cipher nettle_openssl_aes192; extern const struct nettle_cipher nettle_openssl_aes256; -- GitLab