Add documentation for the SSL_export_keying_material() function
[openssl.git] / doc / man3 / OPENSSL_secure_malloc.pod
1 =pod
2
3 =head1 NAME
4
5 CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_initialized,
6 CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, CRYPTO_secure_malloc,
7 OPENSSL_secure_zalloc, CRYPTO_secure_zalloc, OPENSSL_secure_free,
8 CRYPTO_secure_free, OPENSSL_secure_actual_size,
9 CRYPTO_secure_used - secure heap storage
10
11 =head1 SYNOPSIS
12
13  #include <openssl/crypto.h>
14
15  int CRYPTO_secure_malloc_init(size_t size, int minsize);
16
17  int CRYPTO_secure_malloc_initialized();
18
19  int CRYPTO_secure_malloc_done();
20
21  void *OPENSSL_secure_malloc(size_t num);
22  void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
23
24  void *OPENSSL_secure_zalloc(size_t num);
25  void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
26
27  void OPENSSL_secure_free(void* ptr);
28  void CRYPTO_secure_free(void *ptr, const char *, int);
29
30  size_t OPENSSL_secure_actual_size(const void *ptr);
31
32  size_t CRYPTO_secure_used();
33
34 =head1 DESCRIPTION
35
36 In order to help protect applications (particularly long-running servers)
37 from pointer overruns or underruns that could return arbitrary data from
38 the program's dynamic memory area, where keys and other sensitive
39 information might be stored, OpenSSL supports the concept of a "secure heap."
40 The level and type of security guarantees depend on the operating system.
41 It is a good idea to review the code and see if it addresses your
42 threat model and concerns.
43
44 If a secure heap is used, then private key B<BIGNUM> values are stored there.
45 This protects long-term storage of private keys, but will not necessarily
46 put all intermediate values and computations there.
47
48 CRYPTO_secure_malloc_init() creates the secure heap, with the specified
49 C<size> in bytes. The C<minsize> parameter is the minimum size to
50 allocate from the heap. Both C<size> and C<minsize> must be a power
51 of two.
52
53 CRYPTO_secure_malloc_initialized() indicates whether or not the secure
54 heap as been initialized and is available.
55
56 CRYPTO_secure_malloc_done() releases the heap and makes the memory unavailable
57 to the process if all secure memory has been freed.
58 It can take noticeably long to complete.
59
60 OPENSSL_secure_malloc() allocates C<num> bytes from the heap.
61 If CRYPTO_secure_malloc_init() is not called, this is equivalent to
62 calling OPENSSL_malloc().
63 It is a macro that expands to
64 CRYPTO_secure_malloc() and adds the C<__FILE__> and C<__LINE__> parameters.
65
66 OPENSSL_secure_zalloc() and CRYPTO_secure_zalloc() are like
67 OPENSSL_secure_malloc() and CRYPTO_secure_malloc(), respectively,
68 except that they call memset() to zero the memory before returning.
69
70 OPENSSL_secure_free() releases the memory at C<ptr> back to the heap.
71 It must be called with a value previously obtained from
72 OPENSSL_secure_malloc().
73 If CRYPTO_secure_malloc_init() is not called, this is equivalent to
74 calling OPENSSL_free().
75 It exists for consistency with OPENSSL_secure_malloc() , and
76 is a macro that expands to CRYPTO_secure_free() and adds the C<__FILE__>
77 and C<__LINE__> parameters..
78
79 OPENSSL_secure_actual_size() tells the actual size allocated to the
80 pointer; implementations may allocate more space than initially
81 requested, in order to "round up" and reduce secure heap fragmentation.
82
83 CRYPTO_secure_used() returns the number of bytes allocated in the
84 secure heap.
85
86 =head1 RETURN VALUES
87
88 CRYPTO_secure_malloc_init() returns 0 on failure, 1 if successful,
89 and 2 if successful but the heap could not be protected by memory
90 mapping.
91
92 CRYPTO_secure_malloc_initialized() returns 1 if the secure heap is
93 available (that is, if CRYPTO_secure_malloc_init() has been called,
94 but CRYPTO_secure_malloc_done() has not been called or failed) or 0 if not.
95
96 OPENSSL_secure_malloc() and OPENSSL_secure_zalloc() return a pointer into
97 the secure heap of the requested size, or C<NULL> if memory could not be
98 allocated.
99
100 CRYPTO_secure_allocated() returns 1 if the pointer is in the secure heap, or 0 if not.
101
102 CRYPTO_secure_malloc_done() returns 1 if the secure memory area is released, or 0 if not.
103
104 OPENSSL_secure_free() returns no values.
105
106 =head1 SEE ALSO
107
108 L<OPENSSL_malloc(3)>,
109 L<BN_new(3)>
110
111 =head1 COPYRIGHT
112
113 Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
114
115 Licensed under the OpenSSL license (the "License").  You may not use
116 this file except in compliance with the License.  You can obtain a copy
117 in the file LICENSE in the source distribution or at
118 L<https://www.openssl.org/source/license.html>.
119
120 =cut