Debian Codegraph @

upstream/debian-unstable/man3/OPENSSL_secure_malloc.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "OPENSSL_SECURE_MALLOC 3SSL"
58 .TH OPENSSL_SECURE_MALLOC 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_initialized,
65 CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, CRYPTO_secure_malloc,
66 OPENSSL_secure_zalloc, CRYPTO_secure_zalloc, OPENSSL_secure_malloc_array,
67 CRYPTO_secure_malloc_array, OPENSSL_secure_calloc, CRYPTO_secure_calloc,
68 OPENSSL_secure_free, CRYPTO_secure_free, OPENSSL_secure_clear_free,
69 CRYPTO_secure_clear_free, OPENSSL_secure_actual_size,
70 CRYPTO_secure_allocated,
71 CRYPTO_secure_used \- secure heap storage
72 .SH SYNOPSIS
73 .IX Header "SYNOPSIS"
74 .Vb 1
75 \& #include <openssl/crypto.h>
76 \&
77 \& int CRYPTO_secure_malloc_init(size_t size, size_t minsize);
78 \&
79 \& int CRYPTO_secure_malloc_initialized();
80 \&
81 \& int CRYPTO_secure_malloc_done();
82 \&
83 \& void *OPENSSL_secure_malloc(size_t num);
84 \& void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
85 \&
86 \& void *OPENSSL_secure_zalloc(size_t num);
87 \& void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
88 \&
89 \& void *OPENSSL_secure_malloc_array(size_t num, size_t size);
90 \& void *CRYPTO_secure_malloc_array(size_t num, size_t size,
91 \& const char *file, int line);
92 \&
93 \& void *OPENSSL_secure_calloc(size_t num, size_t size);
94 \& void *CRYPTO_secure_calloc(size_t num, size_t size,
95 \& const char *file, int line);
96 \&
97 \& void OPENSSL_secure_free(void* ptr);
98 \& void CRYPTO_secure_free(void *ptr, const char *, int);
99 \&
100 \& void OPENSSL_secure_clear_free(void* ptr, size_t num);
101 \& void CRYPTO_secure_clear_free(void *ptr, size_t num, const char *, int);
102 \&
103 \& size_t OPENSSL_secure_actual_size(const void *ptr);
104 \&
105 \& int CRYPTO_secure_allocated(const void *ptr);
106 \& size_t CRYPTO_secure_used();
107 .Ve
108 .SH DESCRIPTION
109 .IX Header "DESCRIPTION"
110 In order to help protect applications (particularly long-running servers)
111 from pointer overruns or underruns that could return arbitrary data from
112 the program's dynamic memory area, where keys and other sensitive
113 information might be stored, OpenSSL supports the concept of a "secure heap."
114 The level and type of security guarantees depend on the operating system.
115 It is a good idea to review the code and see if it addresses your
116 threat model and concerns. It should be noted that the secure heap
117 uses a single read/write lock, and therefore any operations
118 that involve allocation or freeing of secure heap memory are serialised,
119 blocking other threads. With that in mind, highly concurrent applications
120 should enable the secure heap with caution and be aware of the performance
121 implications for multi-threaded code.
122 .PP
123 If a secure heap is used, then private key \fBBIGNUM\fR values are stored there.
124 This protects long-term storage of private keys, but will not necessarily
125 put all intermediate values and computations there.
126 .PP
127 \&\fBCRYPTO_secure_malloc_init()\fR creates the secure heap, with the specified
128 \&\f(CW\*(C`size\*(C'\fR in bytes. The \f(CW\*(C`minsize\*(C'\fR parameter is the minimum size to
129 allocate from the heap or zero to use a reasonable default value.
130 Both \f(CW\*(C`size\*(C'\fR and, if specified, \f(CW\*(C`minsize\*(C'\fR must be a power of two and
131 \&\f(CW\*(C`minsize\*(C'\fR should generally be small, for example 16 or 32.
132 \&\f(CW\*(C`minsize\*(C'\fR must be less than a quarter of \f(CW\*(C`size\*(C'\fR in any case.
133 .PP
134 \&\fBCRYPTO_secure_malloc_initialized()\fR indicates whether or not the secure
135 heap as been initialized and is available.
136 .PP
137 \&\fBCRYPTO_secure_malloc_done()\fR releases the heap and makes the memory unavailable
138 to the process if all secure memory has been freed.
139 It can take noticeably long to complete.
140 .PP
141 \&\fBOPENSSL_secure_malloc()\fR allocates \f(CW\*(C`num\*(C'\fR bytes from the heap.
142 If \fBCRYPTO_secure_malloc_init()\fR is not called, this is equivalent to
143 calling \fBOPENSSL_malloc()\fR.
144 It is a macro that expands to
145 \&\fBCRYPTO_secure_malloc()\fR and adds the \f(CW\*(C`_\|_FILE_\|_\*(C'\fR and \f(CW\*(C`_\|_LINE_\|_\*(C'\fR parameters.
146 .PP
147 \&\fBOPENSSL_secure_zalloc()\fR and \fBCRYPTO_secure_zalloc()\fR are like
148 \&\fBOPENSSL_secure_malloc()\fR and \fBCRYPTO_secure_malloc()\fR, respectively,
149 except that they call \fBmemset()\fR to zero the memory before returning.
150 .PP
151 \&\fBOPENSSL_secure_malloc_array()\fR, \fBCRYPTO_secure_malloc_array()\fR,
152 \&\fBOPENSSL_secure_calloc()\fR, and \fBCRYPTO_secure_calloc()\fR are variants
153 of \fBOPENSSL_secure_malloc()\fR, \fBCRYPTO_secure_malloc()\fR,
154 \&\fBOPENSSL_secure_zalloc()\fR, and \fBCRYPTO_secure_zalloc()\fR, respectively, that accept
155 an additional parameter, \fBsize\fR, which enables memory allocation
156 operations for an array of \fBnum\fR members \fBsize\fR bytes each;
157 these functions return an error if multiplication of \fBnum\fR and \fBsize\fR
158 leads to an integer overflow, thus preventing allocations of an incorrect size.
159 .PP
160 \&\fBOPENSSL_secure_free()\fR releases the memory at \f(CW\*(C`ptr\*(C'\fR back to the heap.
161 It must be called with a value previously obtained from
162 \&\fBOPENSSL_secure_malloc()\fR.
163 If \fBCRYPTO_secure_malloc_init()\fR is not called, this is equivalent to
164 calling \fBOPENSSL_free()\fR.
165 It exists for consistency with \fBOPENSSL_secure_malloc()\fR , and
166 is a macro that expands to \fBCRYPTO_secure_free()\fR and adds the \f(CW\*(C`_\|_FILE_\|_\*(C'\fR
167 and \f(CW\*(C`_\|_LINE_\|_\*(C'\fR parameters.. If the argument to \fBOPENSSL_secure_free()\fR
168 is NULL, nothing is done.
169 .PP
170 \&\fBOPENSSL_secure_clear_free()\fR is similar to \fBOPENSSL_secure_free()\fR except
171 that it has an additional \f(CW\*(C`num\*(C'\fR parameter which is used to clear
172 the memory if it was not allocated from the secure heap.
173 If \fBCRYPTO_secure_malloc_init()\fR is not called, this is equivalent to
174 calling \fBOPENSSL_clear_free()\fR. If the argument to \fBOPENSSL_secure_clear_free()\fR
175 is NULL, nothing is done.
176 .PP
177 \&\fBOPENSSL_secure_actual_size()\fR tells the actual size allocated to the
178 pointer; implementations may allocate more space than initially
179 requested, in order to "round up" and reduce secure heap fragmentation.
180 .PP
181 \&\fBOPENSSL_secure_allocated()\fR tells if a pointer is allocated in the secure heap.
182 .PP
183 \&\fBCRYPTO_secure_used()\fR returns the number of bytes allocated in the
184 secure heap.
185 .SH "RETURN VALUES"
186 .IX Header "RETURN VALUES"
187 \&\fBCRYPTO_secure_malloc_init()\fR returns 0 on failure, 1 if successful,
188 and 2 if successful but the heap could not be protected by memory
189 mapping.
190 .PP
191 \&\fBCRYPTO_secure_malloc_initialized()\fR returns 1 if the secure heap is
192 available (that is, if \fBCRYPTO_secure_malloc_init()\fR has been called,
193 but \fBCRYPTO_secure_malloc_done()\fR has not been called or failed) or 0 if not.
194 .PP
195 \&\fBOPENSSL_secure_malloc()\fR, \fBCRYPTO_secure_malloc()\fR, \fBOPENSSL_secure_zalloc()\fR,
196 \&\fBCRYPTO_secure_zalloc()\fR, \fBOPENSSL_secure_malloc_array()\fR,
197 \&\fBCRYPTO_secure_malloc_array()\fR, \fBOPENSSL_secure_calloc()\fR, and \fBCRYPTO_secure_calloc()\fR
198 return a pointer into the secure heap of the requested size, if it is
199 initialised, a pointer returned by the underlying \fBOPENSSL_malloc()\fR call,
200 if it is not, or \f(CW\*(C`NULL\*(C'\fR on error.
201 .PP
202 \&\fBCRYPTO_secure_allocated()\fR returns 1 if the pointer is in the secure heap, or 0 if not.
203 .PP
204 \&\fBCRYPTO_secure_malloc_done()\fR returns 1 if the secure memory area is released, or 0 if not.
205 .PP
206 \&\fBOPENSSL_secure_free()\fR and \fBOPENSSL_secure_clear_free()\fR return no values.
207 .SH "SEE ALSO"
208 .IX Header "SEE ALSO"
209 \&\fBOPENSSL_malloc\fR\|(3),
210 \&\fBBN_new\fR\|(3)
211 .SH HISTORY
212 .IX Header "HISTORY"
213 The \fBOPENSSL_secure_clear_free()\fR function was added in OpenSSL 1.1.0g.
214 .PP
215 The second argument to \fBCRYPTO_secure_malloc_init()\fR was changed from an \fBint\fR to
216 a \fBsize_t\fR in OpenSSL 3.0.
217 .PP
218 The \fBOPENSSL_secure_malloc_array()\fR, \fBCRYPTO_secure_malloc_array()\fR,
219 \&\fBOPENSSL_secure_calloc()\fR, and \fBCRYPTO_secure_calloc()\fR functions were added
220 in OpenSSL 3.6.
221 .SH COPYRIGHT
222 .IX Header "COPYRIGHT"
223 Copyright 2015\-2025 The OpenSSL Project Authors. All Rights Reserved.
224 .PP
225 Licensed under the Apache License 2.0 (the "License"). You may not use
226 this file except in compliance with the License. You can obtain a copy
227 in the file LICENSE in the source distribution or at
228 <https://www.openssl.org/source/license.html>.