1OPENSSL_SECURE_MALLOC(3ossl)        OpenSSL       OPENSSL_SECURE_MALLOC(3ossl)
2
3
4

NAME

6       CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_initialized,
7       CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, CRYPTO_secure_malloc,
8       OPENSSL_secure_zalloc, CRYPTO_secure_zalloc, OPENSSL_secure_free,
9       CRYPTO_secure_free, OPENSSL_secure_clear_free,
10       CRYPTO_secure_clear_free, OPENSSL_secure_actual_size,
11       CRYPTO_secure_allocated, CRYPTO_secure_used - secure heap storage
12

SYNOPSIS

14        #include <openssl/crypto.h>
15
16        int CRYPTO_secure_malloc_init(size_t size, size_t minsize);
17
18        int CRYPTO_secure_malloc_initialized();
19
20        int CRYPTO_secure_malloc_done();
21
22        void *OPENSSL_secure_malloc(size_t num);
23        void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
24
25        void *OPENSSL_secure_zalloc(size_t num);
26        void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
27
28        void OPENSSL_secure_free(void* ptr);
29        void CRYPTO_secure_free(void *ptr, const char *, int);
30
31        void OPENSSL_secure_clear_free(void* ptr, size_t num);
32        void CRYPTO_secure_clear_free(void *ptr, size_t num, const char *, int);
33
34        size_t OPENSSL_secure_actual_size(const void *ptr);
35
36        int CRYPTO_secure_allocated(const void *ptr);
37        size_t CRYPTO_secure_used();
38

DESCRIPTION

40       In order to help protect applications (particularly long-running
41       servers) from pointer overruns or underruns that could return arbitrary
42       data from the program's dynamic memory area, where keys and other
43       sensitive information might be stored, OpenSSL supports the concept of
44       a "secure heap."  The level and type of security guarantees depend on
45       the operating system.  It is a good idea to review the code and see if
46       it addresses your threat model and concerns.
47
48       If a secure heap is used, then private key BIGNUM values are stored
49       there.  This protects long-term storage of private keys, but will not
50       necessarily put all intermediate values and computations there.
51
52       CRYPTO_secure_malloc_init() creates the secure heap, with the specified
53       "size" in bytes. The "minsize" parameter is the minimum size to
54       allocate from the heap or zero to use a reasonable default value.  Both
55       "size" and, if specified, "minsize" must be a power of two and
56       "minsize" should generally be small, for example 16 or 32.  "minsize"
57       must be less than a quarter of "size" in any case.
58
59       CRYPTO_secure_malloc_initialized() indicates whether or not the secure
60       heap as been initialized and is available.
61
62       CRYPTO_secure_malloc_done() releases the heap and makes the memory
63       unavailable to the process if all secure memory has been freed.  It can
64       take noticeably long to complete.
65
66       OPENSSL_secure_malloc() allocates "num" bytes from the heap.  If
67       CRYPTO_secure_malloc_init() is not called, this is equivalent to
68       calling OPENSSL_malloc().  It is a macro that expands to
69       CRYPTO_secure_malloc() and adds the "__FILE__" and "__LINE__"
70       parameters.
71
72       OPENSSL_secure_zalloc() and CRYPTO_secure_zalloc() are like
73       OPENSSL_secure_malloc() and CRYPTO_secure_malloc(), respectively,
74       except that they call memset() to zero the memory before returning.
75
76       OPENSSL_secure_free() releases the memory at "ptr" back to the heap.
77       It must be called with a value previously obtained from
78       OPENSSL_secure_malloc().  If CRYPTO_secure_malloc_init() is not called,
79       this is equivalent to calling OPENSSL_free().  It exists for
80       consistency with OPENSSL_secure_malloc() , and is a macro that expands
81       to CRYPTO_secure_free() and adds the "__FILE__" and "__LINE__"
82       parameters..
83
84       OPENSSL_secure_clear_free() is similar to OPENSSL_secure_free() except
85       that it has an additional "num" parameter which is used to clear the
86       memory if it was not allocated from the secure heap.  If
87       CRYPTO_secure_malloc_init() is not called, this is equivalent to
88       calling OPENSSL_clear_free().
89
90       OPENSSL_secure_actual_size() tells the actual size allocated to the
91       pointer; implementations may allocate more space than initially
92       requested, in order to "round up" and reduce secure heap fragmentation.
93
94       OPENSSL_secure_allocated() tells if a pointer is allocated in the
95       secure heap.
96
97       CRYPTO_secure_used() returns the number of bytes allocated in the
98       secure heap.
99

RETURN VALUES

101       CRYPTO_secure_malloc_init() returns 0 on failure, 1 if successful, and
102       2 if successful but the heap could not be protected by memory mapping.
103
104       CRYPTO_secure_malloc_initialized() returns 1 if the secure heap is
105       available (that is, if CRYPTO_secure_malloc_init() has been called, but
106       CRYPTO_secure_malloc_done() has not been called or failed) or 0 if not.
107
108       OPENSSL_secure_malloc() and OPENSSL_secure_zalloc() return a pointer
109       into the secure heap of the requested size, or "NULL" if memory could
110       not be allocated.
111
112       CRYPTO_secure_allocated() returns 1 if the pointer is in the secure
113       heap, or 0 if not.
114
115       CRYPTO_secure_malloc_done() returns 1 if the secure memory area is
116       released, or 0 if not.
117
118       OPENSSL_secure_free() and OPENSSL_secure_clear_free() return no values.
119

SEE ALSO

121       OPENSSL_malloc(3), BN_new(3)
122

HISTORY

124       The OPENSSL_secure_clear_free() function was added in OpenSSL 1.1.0g.
125
126       The second argument to CRYPTO_secure_malloc_init() was changed from an
127       int to a size_t in OpenSSL 3.0.
128
130       Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
131
132       Licensed under the Apache License 2.0 (the "License").  You may not use
133       this file except in compliance with the License.  You can obtain a copy
134       in the file LICENSE in the source distribution or at
135       <https://www.openssl.org/source/license.html>.
136
137
138
1393.0.5                             2022-07-05      OPENSSL_SECURE_MALLOC(3ossl)
Impressum