From 0145dd324e8fcfd2c0dfe296c12586101f0cf3b9 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 24 Oct 2018 18:34:53 +0200 Subject: [PATCH] Add automatic initializations support for EVP_MAC objects Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/7393) --- crypto/evp/build.info | 2 +- crypto/evp/c_allm.c | 15 +++++++++++++++ crypto/include/internal/evp_int.h | 1 + crypto/init.c | 25 +++++++++++++++++++++++++ include/openssl/crypto.h | 9 ++++++++- ssl/ssl_init.c | 3 ++- 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 crypto/evp/c_allm.c diff --git a/crypto/evp/build.info b/crypto/evp/build.info index 6967fe9dc1..e4fdedf3cc 100644 --- a/crypto/evp/build.info +++ b/crypto/evp/build.info @@ -13,7 +13,7 @@ SOURCE[../../libcrypto]=\ e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c \ e_aes_cbc_hmac_sha1.c e_aes_cbc_hmac_sha256.c e_rc4_hmac_md5.c \ e_chacha20_poly1305.c cmeth_lib.c \ - mac_lib.c + mac_lib.c c_allm.c INCLUDE[e_aes.o]=.. ../modes INCLUDE[e_aes_cbc_hmac_sha1.o]=../modes diff --git a/crypto/evp/c_allm.c b/crypto/evp/c_allm.c new file mode 100644 index 0000000000..d5eb858cc3 --- /dev/null +++ b/crypto/evp/c_allm.c @@ -0,0 +1,15 @@ +/* + * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include "internal/evp_int.h" + +void openssl_add_all_macs_int(void) +{ +} diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index 5bc9408676..dadade33c9 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h @@ -448,6 +448,7 @@ struct evp_pkey_st { void openssl_add_all_ciphers_int(void); void openssl_add_all_digests_int(void); +void openssl_add_all_macs_int(void); void evp_cleanup_int(void); void evp_app_cleanup_int(void); diff --git a/crypto/init.c b/crypto/init.c index 209d1a483d..fc6aade191 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -235,6 +235,23 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests) return 1; } +static CRYPTO_ONCE add_all_macs = CRYPTO_ONCE_STATIC_INIT; +DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_macs) +{ + /* + * OPENSSL_NO_AUTOALGINIT is provided here to prevent at compile time + * pulling in all the macs during static linking + */ +#ifndef OPENSSL_NO_AUTOALGINIT +# ifdef OPENSSL_INIT_DEBUG + fprintf(stderr, "OPENSSL_INIT: ossl_init_add_all_macs: " + "openssl_add_all_macs_int()\n"); +# endif + openssl_add_all_macs_int(); +#endif + return 1; +} + DEFINE_RUN_ONCE_STATIC(ossl_init_no_add_algs) { /* Do nothing */ @@ -619,6 +636,14 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) && !RUN_ONCE(&add_all_digests, ossl_init_add_all_digests)) return 0; + if ((opts & OPENSSL_INIT_NO_ADD_ALL_MACS) + && !RUN_ONCE(&add_all_macs, ossl_init_no_add_algs)) + return 0; + + if ((opts & OPENSSL_INIT_ADD_ALL_MACS) + && !RUN_ONCE(&add_all_macs, ossl_init_add_all_macs)) + return 0; + if ((opts & OPENSSL_INIT_ATFORK) && !openssl_init_fork_handlers()) return 0; diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h index 7e50b1bf46..889b342ab2 100644 --- a/include/openssl/crypto.h +++ b/include/openssl/crypto.h @@ -377,7 +377,14 @@ int CRYPTO_memcmp(const void * in_a, const void * in_b, size_t len); /* OPENSSL_INIT_ZLIB 0x00010000L */ # define OPENSSL_INIT_ATFORK 0x00020000L /* OPENSSL_INIT_BASE_ONLY 0x00040000L */ -/* OPENSSL_INIT flag range 0xfff00000 reserved for OPENSSL_init_ssl() */ +/* FREE: 0x00080000L */ +/* OPENSSL_INIT flag range 0x03f00000 reserved for OPENSSL_init_ssl() */ +# define OPENSSL_INIT_NO_ADD_ALL_MACS 0x04000000L +# define OPENSSL_INIT_ADD_ALL_MACS 0x08000000L +/* FREE: 0x10000000L */ +/* FREE: 0x20000000L */ +/* FREE: 0x40000000L */ +/* FREE: 0x80000000L */ /* Max OPENSSL_INIT flag value is 0x80000000 */ /* openssl and dasync not counted as builtin */ diff --git a/ssl/ssl_init.c b/ssl/ssl_init.c index c0ccb9304a..31dce9c79d 100644 --- a/ssl/ssl_init.c +++ b/ssl/ssl_init.c @@ -199,7 +199,8 @@ int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS * settings) | OPENSSL_INIT_LOAD_CONFIG #endif | OPENSSL_INIT_ADD_ALL_CIPHERS - | OPENSSL_INIT_ADD_ALL_DIGESTS, + | OPENSSL_INIT_ADD_ALL_DIGESTS + | OPENSSL_INIT_ADD_ALL_MACS, settings)) return 0; -- 2.34.1