diff options
author | Rich Salz <rsalz@akamai.com> | 2020-02-05 14:28:37 -0500 |
---|---|---|
committer | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2020-02-14 15:18:27 +0100 |
commit | 6943335e3e3889fd7a1c7b027ccdcd4f3955b5ec (patch) | |
tree | 9979b8473e1a1d6d7ad0899f9a3a194804a0ae10 /crypto | |
parent | cdb16632636c4a1a439449d110f94cad15d2e9fe (diff) |
Make secure-memory be a config option
Adding support for "no-secure-memory" was simple, a one-liner.
Fixing all the "ifdef OPENSSL_SECURE_MEMORY" to be "ifndef NO_xxx"
was a bit more work. My original goof, for not following the OpenSSL
pattern "ifndef NO_" used everywhere else.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/11023)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/mem_sec.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/crypto/mem_sec.c b/crypto/mem_sec.c index 6aca27370e..00546166dd 100644 --- a/crypto/mem_sec.c +++ b/crypto/mem_sec.c @@ -20,8 +20,7 @@ #include <string.h> -/* e_os.h defines OPENSSL_SECURE_MEMORY if secure memory can be implemented */ -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY # include <stdlib.h> # include <assert.h> # include <unistd.h> @@ -47,7 +46,7 @@ # define MAP_ANON MAP_ANONYMOUS #endif -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY static size_t secure_mem_used; static int secure_mem_initialized; @@ -67,7 +66,7 @@ static int sh_allocated(const char *ptr); int CRYPTO_secure_malloc_init(size_t size, size_t minsize) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY int ret = 0; if (!secure_mem_initialized) { @@ -85,12 +84,12 @@ int CRYPTO_secure_malloc_init(size_t size, size_t minsize) return ret; #else return 0; -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ } int CRYPTO_secure_malloc_done(void) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY if (secure_mem_used == 0) { sh_done(); secure_mem_initialized = 0; @@ -98,22 +97,22 @@ int CRYPTO_secure_malloc_done(void) sec_malloc_lock = NULL; return 1; } -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ return 0; } int CRYPTO_secure_malloc_initialized(void) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY return secure_mem_initialized; #else return 0; -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ } void *CRYPTO_secure_malloc(size_t num, const char *file, int line) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY void *ret; size_t actual_size; @@ -128,12 +127,12 @@ void *CRYPTO_secure_malloc(size_t num, const char *file, int line) return ret; #else return CRYPTO_malloc(num, file, line); -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ } void *CRYPTO_secure_zalloc(size_t num, const char *file, int line) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY if (secure_mem_initialized) /* CRYPTO_secure_malloc() zeroes allocations when it is implemented */ return CRYPTO_secure_malloc(num, file, line); @@ -143,7 +142,7 @@ void *CRYPTO_secure_zalloc(size_t num, const char *file, int line) void CRYPTO_secure_free(void *ptr, const char *file, int line) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY size_t actual_size; if (ptr == NULL) @@ -160,13 +159,13 @@ void CRYPTO_secure_free(void *ptr, const char *file, int line) CRYPTO_THREAD_unlock(sec_malloc_lock); #else CRYPTO_free(ptr, file, line); -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ } void CRYPTO_secure_clear_free(void *ptr, size_t num, const char *file, int line) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY size_t actual_size; if (ptr == NULL) @@ -187,12 +186,12 @@ void CRYPTO_secure_clear_free(void *ptr, size_t num, return; OPENSSL_cleanse(ptr, num); CRYPTO_free(ptr, file, line); -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ } int CRYPTO_secure_allocated(const void *ptr) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY int ret; if (!secure_mem_initialized) @@ -203,21 +202,21 @@ int CRYPTO_secure_allocated(const void *ptr) return ret; #else return 0; -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ } size_t CRYPTO_secure_used(void) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY return secure_mem_used; #else return 0; -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ } size_t CRYPTO_secure_actual_size(void *ptr) { -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY size_t actual_size; CRYPTO_THREAD_write_lock(sec_malloc_lock); @@ -235,7 +234,7 @@ size_t CRYPTO_secure_actual_size(void *ptr) /* * SECURE HEAP IMPLEMENTATION */ -#ifdef OPENSSL_SECURE_MEMORY +#ifndef OPENSSL_NO_SECURE_MEMORY /* @@ -642,4 +641,4 @@ static size_t sh_actual_size(char *ptr) OPENSSL_assert(sh_testbit(ptr, list, sh.bittable)); return sh.arena_size / (ONE << list); } -#endif /* OPENSSL_SECURE_MEMORY */ +#endif /* OPENSSL_NO_SECURE_MEMORY */ |