Debian Codegraph @

upstream/debian-trixie/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.5.6 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_free,
67 CRYPTO_secure_free, OPENSSL_secure_clear_free,
68 CRYPTO_secure_clear_free, OPENSSL_secure_actual_size,
69 CRYPTO_secure_allocated,
70 CRYPTO_secure_used \- secure heap storage
71 .SH SYNOPSIS
72 .IX Header "SYNOPSIS"
73 .Vb 1
74 \& #include <openssl/crypto.h>
75 \&
76 \& int CRYPTO_secure_malloc_init(size_t size, size_t minsize);
77 \&
78 \& int CRYPTO_secure_malloc_initialized();
79 \&
80 \& int CRYPTO_secure_malloc_done();
81 \&
82 \& void *OPENSSL_secure_malloc(size_t num);
83 \& void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
84 \&
85 \& void *OPENSSL_secure_zalloc(size_t num);
86 \& void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
87 \&
88 \& void OPENSSL_secure_free(void* ptr);
89 \& void CRYPTO_secure_free(void *ptr, const char *, int);
90 \&
91 \& void OPENSSL_secure_clear_free(void* ptr, size_t num);
92 \& void CRYPTO_secure_clear_free(void *ptr, size_t num, const char *, int);
93 \&
94 \& size_t OPENSSL_secure_actual_size(const void *ptr);
95 \&
96 \& int CRYPTO_secure_allocated(const void *ptr);
97 \& size_t CRYPTO_secure_used();
98 .Ve
99 .SH DESCRIPTION
100 .IX Header "DESCRIPTION"
101 In order to help protect applications (particularly long-running servers)
102 from pointer overruns or underruns that could return arbitrary data from
103 the program's dynamic memory area, where keys and other sensitive
104 information might be stored, OpenSSL supports the concept of a "secure heap."
105 The level and type of security guarantees depend on the operating system.
106 It is a good idea to review the code and see if it addresses your
107 threat model and concerns. It should be noted that the secure heap
108 uses a single read/write lock, and therefore any operations
109 that involve allocation or freeing of secure heap memory are serialised,
110 blocking other threads. With that in mind, highly concurrent applications
111 should enable the secure heap with caution and be aware of the performance
112 implications for multi-threaded code.
113 .PP
114 If a secure heap is used, then private key \fBBIGNUM\fR values are stored there.
115 This protects long-term storage of private keys, but will not necessarily
116 put all intermediate values and computations there.
117 .PP
118 \&\fBCRYPTO_secure_malloc_init()\fR creates the secure heap, with the specified
119 \&\f(CW\*(C`size\*(C'\fR in bytes. The \f(CW\*(C`minsize\*(C'\fR parameter is the minimum size to
120 allocate from the heap or zero to use a reasonable default value.
121 Both \f(CW\*(C`size\*(C'\fR and, if specified, \f(CW\*(C`minsize\*(C'\fR must be a power of two and
122 \&\f(CW\*(C`minsize\*(C'\fR should generally be small, for example 16 or 32.
123 \&\f(CW\*(C`minsize\*(C'\fR must be less than a quarter of \f(CW\*(C`size\*(C'\fR in any case.
124 .PP
125 \&\fBCRYPTO_secure_malloc_initialized()\fR indicates whether or not the secure
126 heap as been initialized and is available.
127 .PP
128 \&\fBCRYPTO_secure_malloc_done()\fR releases the heap and makes the memory unavailable
129 to the process if all secure memory has been freed.
130 It can take noticeably long to complete.
131 .PP
132 \&\fBOPENSSL_secure_malloc()\fR allocates \f(CW\*(C`num\*(C'\fR bytes from the heap.
133 If \fBCRYPTO_secure_malloc_init()\fR is not called, this is equivalent to
134 calling \fBOPENSSL_malloc()\fR.
135 It is a macro that expands to
136 \&\fBCRYPTO_secure_malloc()\fR and adds the \f(CW\*(C`_\|_FILE_\|_\*(C'\fR and \f(CW\*(C`_\|_LINE_\|_\*(C'\fR parameters.
137 .PP
138 \&\fBOPENSSL_secure_zalloc()\fR and \fBCRYPTO_secure_zalloc()\fR are like
139 \&\fBOPENSSL_secure_malloc()\fR and \fBCRYPTO_secure_malloc()\fR, respectively,
140 except that they call \fBmemset()\fR to zero the memory before returning.
141 .PP
142 \&\fBOPENSSL_secure_free()\fR releases the memory at \f(CW\*(C`ptr\*(C'\fR back to the heap.
143 It must be called with a value previously obtained from
144 \&\fBOPENSSL_secure_malloc()\fR.
145 If \fBCRYPTO_secure_malloc_init()\fR is not called, this is equivalent to
146 calling \fBOPENSSL_free()\fR.
147 It exists for consistency with \fBOPENSSL_secure_malloc()\fR , and
148 is a macro that expands to \fBCRYPTO_secure_free()\fR and adds the \f(CW\*(C`_\|_FILE_\|_\*(C'\fR
149 and \f(CW\*(C`_\|_LINE_\|_\*(C'\fR parameters.. If the argument to \fBOPENSSL_secure_free()\fR
150 is NULL, nothing is done.
151 .PP
152 \&\fBOPENSSL_secure_clear_free()\fR is similar to \fBOPENSSL_secure_free()\fR except
153 that it has an additional \f(CW\*(C`num\*(C'\fR parameter which is used to clear
154 the memory if it was not allocated from the secure heap.
155 If \fBCRYPTO_secure_malloc_init()\fR is not called, this is equivalent to
156 calling \fBOPENSSL_clear_free()\fR. If the argument to \fBOPENSSL_secure_clear_free()\fR
157 is NULL, nothing is done.
158 .PP
159 \&\fBOPENSSL_secure_actual_size()\fR tells the actual size allocated to the
160 pointer; implementations may allocate more space than initially
161 requested, in order to "round up" and reduce secure heap fragmentation.
162 .PP
163 \&\fBOPENSSL_secure_allocated()\fR tells if a pointer is allocated in the secure heap.
164 .PP
165 \&\fBCRYPTO_secure_used()\fR returns the number of bytes allocated in the
166 secure heap.
167 .SH "RETURN VALUES"
168 .IX Header "RETURN VALUES"
169 \&\fBCRYPTO_secure_malloc_init()\fR returns 0 on failure, 1 if successful,
170 and 2 if successful but the heap could not be protected by memory
171 mapping.
172 .PP
173 \&\fBCRYPTO_secure_malloc_initialized()\fR returns 1 if the secure heap is
174 available (that is, if \fBCRYPTO_secure_malloc_init()\fR has been called,
175 but \fBCRYPTO_secure_malloc_done()\fR has not been called or failed) or 0 if not.
176 .PP
177 \&\fBOPENSSL_secure_malloc()\fR and \fBOPENSSL_secure_zalloc()\fR return a pointer into
178 the secure heap of the requested size, or \f(CW\*(C`NULL\*(C'\fR if memory could not be
179 allocated.
180 .PP
181 \&\fBCRYPTO_secure_allocated()\fR returns 1 if the pointer is in the secure heap, or 0 if not.
182 .PP
183 \&\fBCRYPTO_secure_malloc_done()\fR returns 1 if the secure memory area is released, or 0 if not.
184 .PP
185 \&\fBOPENSSL_secure_free()\fR and \fBOPENSSL_secure_clear_free()\fR return no values.
186 .SH "SEE ALSO"
187 .IX Header "SEE ALSO"
188 \&\fBOPENSSL_malloc\fR\|(3),
189 \&\fBBN_new\fR\|(3)
190 .SH HISTORY
191 .IX Header "HISTORY"
192 The \fBOPENSSL_secure_clear_free()\fR function was added in OpenSSL 1.1.0g.
193 .PP
194 The second argument to \fBCRYPTO_secure_malloc_init()\fR was changed from an \fBint\fR to
195 a \fBsize_t\fR in OpenSSL 3.0.
196 .SH COPYRIGHT
197 .IX Header "COPYRIGHT"
198 Copyright 2015\-2025 The OpenSSL Project Authors. All Rights Reserved.
199 .PP
200 Licensed under the Apache License 2.0 (the "License"). You may not use
201 this file except in compliance with the License. You can obtain a copy
202 in the file LICENSE in the source distribution or at
203 <https://www.openssl.org/source/license.html>.