Add automatic initializations support for EVP_MAC objects
authorRichard Levitte <levitte@openssl.org>
Wed, 24 Oct 2018 16:34:53 +0000 (18:34 +0200)
committerRichard Levitte <levitte@openssl.org>
Mon, 29 Oct 2018 12:35:19 +0000 (13:35 +0100)
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/7393)

crypto/evp/build.info
crypto/evp/c_allm.c [new file with mode: 0644]
crypto/include/internal/evp_int.h
crypto/init.c
include/openssl/crypto.h
ssl/ssl_init.c

index 6967fe9dc1774145347b240ea320944816965e48..e4fdedf3cc7e30d6ed30460bca1c48e6e57dcb2b 100644 (file)
@@ -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 (file)
index 0000000..d5eb858
--- /dev/null
@@ -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 <openssl/evp.h>
+#include "internal/evp_int.h"
+
+void openssl_add_all_macs_int(void)
+{
+}
index 5bc94086766c6041f142be204f9487d3554c3557..dadade33c965f5b4e925e19db890518826a82070 100644 (file)
@@ -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);
 
index 209d1a483daebee32c1407fb9cb1706923ee4501..fc6aade19197a444767b83827e38b5e08b76ff9f 100644 (file)
@@ -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;
index 7e50b1bf4694921b5da4845a04faf5674ae7ee7e..889b342ab2a36501be6c4806538510ae771c4096 100644 (file)
@@ -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 */
index c0ccb9304a636cea64f7d1430a43148e5a6dbcec..31dce9c79dc5ed39618e49223d5a69ad8a8a53ff 100644 (file)
@@ -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;