OPENSSL_secure_malloc.pod 4.4 KB
Newer Older
R
Rich Salz 已提交
1 2 3 4
=pod

=head1 NAME

R
Rich Salz 已提交
5 6 7 8
CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_initialized,
CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, CRYPTO_secure_malloc,
OPENSSL_secure_zalloc, CRYPTO_secure_zalloc, OPENSSL_secure_free,
CRYPTO_secure_free, OPENSSL_secure_actual_size, OPENSSL_secure_allocated,
9
CRYPTO_secure_used - secure heap storage
R
Rich Salz 已提交
10 11 12 13 14 15 16 17 18

=head1 SYNOPSIS

 #include <openssl/crypto.h>

 int CRYPTO_secure_malloc_init(size_t size, int minsize);

 int CRYPTO_secure_malloc_initialized();

T
Todd Short 已提交
19
 int CRYPTO_secure_malloc_done();
R
Rich Salz 已提交
20

T
Todd Short 已提交
21 22
 void *OPENSSL_secure_malloc(size_t num);
 void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
R
Rich Salz 已提交
23

T
Todd Short 已提交
24 25
 void *OPENSSL_secure_zalloc(size_t num);
 void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
R
Rich Salz 已提交
26

R
Rich Salz 已提交
27
 void OPENSSL_secure_free(void* ptr);
28
 void CRYPTO_secure_free(void *ptr, const char *, int);
R
Rich Salz 已提交
29

R
Rich Salz 已提交
30 31 32
 size_t OPENSSL_secure_actual_size(const void *ptr);
 int OPENSSL_secure_allocated(const void *ptr);

33
 size_t CRYPTO_secure_used();
R
Rich Salz 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

=head1 DESCRIPTION

In order to help protect applications (particularly long-running servers)
from pointer overruns or underruns that could return arbitrary data from
the program's dynamic memory area, where keys and other sensitive
information might be stored, OpenSSL supports the concept of a "secure heap."
The level and type of security guarantees depend on the operating system.
It is a good idea to review the code and see if it addresses your
threat model and concerns.

If a secure heap is used, then private key B<BIGNUM> values are stored there.
This protects long-term storage of private keys, but will not necessarily
put all intermediate values and computations there.

R
Rich Salz 已提交
49
CRYPTO_secure_malloc_init() creates the secure heap, with the specified
R
Rich Salz 已提交
50 51
C<size> in bytes. The C<minsize> parameter is the minimum size to
allocate from the heap. Both C<size> and C<minsize> must be a power
T
Todd Short 已提交
52
of two.
R
Rich Salz 已提交
53

R
Rich Salz 已提交
54
CRYPTO_secure_malloc_initialized() indicates whether or not the secure
R
Rich Salz 已提交
55 56
heap as been initialized and is available.

R
Rich Salz 已提交
57
CRYPTO_secure_malloc_done() releases the heap and makes the memory unavailable
T
Todd Short 已提交
58
to the process if all secure memory has been freed.
R
Rich Salz 已提交
59
It can take noticeably long to complete.
R
Rich Salz 已提交
60

R
Rich Salz 已提交
61 62 63
OPENSSL_secure_malloc() allocates C<num> bytes from the heap.
If CRYPTO_secure_malloc_init() is not called, this is equivalent to
calling OPENSSL_malloc().
R
Rich Salz 已提交
64
It is a macro that expands to
R
Rich Salz 已提交
65 66 67 68 69
CRYPTO_secure_malloc() and adds the C<__FILE__> and C<__LINE__> parameters.

OPENSSL_secure_zalloc() and CRYPTO_secure_zalloc() are like
OPENSSL_secure_malloc() and CRYPTO_secure_malloc(), respectively,
except that they call memset() to zero the memory before returning.
R
Rich Salz 已提交
70

R
Rich Salz 已提交
71
OPENSSL_secure_free() releases the memory at C<ptr> back to the heap.
R
Rich Salz 已提交
72
It must be called with a value previously obtained from
R
Rich Salz 已提交
73 74 75 76
OPENSSL_secure_malloc().
If CRYPTO_secure_malloc_init() is not called, this is equivalent to
calling OPENSSL_free().
It exists for consistency with OPENSSL_secure_malloc() , and
77 78
is a macro that expands to CRYPTO_secure_free() and adds the C<__FILE__>
and C<__LINE__> parameters..
R
Rich Salz 已提交
79

R
Rich Salz 已提交
80
OPENSSL_secure_allocated() tells whether or not a pointer is within
R
Rich Salz 已提交
81
the secure heap.
R
Rich Salz 已提交
82
OPENSSL_secure_actual_size() tells the actual size allocated to the
R
Rich Salz 已提交
83 84 85
pointer; implementations may allocate more space than initially
requested, in order to "round up" and reduce secure heap fragmentation.

T
Todd Short 已提交
86
CRYPTO_secure_used() returns the number of bytes allocated in the
R
Rich Salz 已提交
87
secure heap.
R
Rich Salz 已提交
88 89 90

=head1 RETURN VALUES

R
Rich Salz 已提交
91
CRYPTO_secure_malloc_init() returns 0 on failure, 1 if successful,
R
Rich Salz 已提交
92 93 94
and 2 if successful but the heap could not be protected by memory
mapping.

R
Rich Salz 已提交
95 96
CRYPTO_secure_malloc_initialized() returns 1 if the secure heap is
available (that is, if CRYPTO_secure_malloc_init() has been called,
T
Todd Short 已提交
97
but CRYPTO_secure_malloc_done() has not been called or failed) or 0 if not.
R
Rich Salz 已提交
98

R
Rich Salz 已提交
99 100 101
OPENSSL_secure_malloc() and OPENSSL_secure_zalloc() return a pointer into
the secure heap of the requested size, or C<NULL> if memory could not be
allocated.
R
Rich Salz 已提交
102

A
Alex Gaynor 已提交
103
CRYPTO_secure_allocated() returns 1 if the pointer is in the secure heap, or 0 if not.
R
Rich Salz 已提交
104

T
Todd Short 已提交
105
CRYPTO_secure_malloc_done() returns 1 if the secure memory area is released, or 0 if not.
R
Rich Salz 已提交
106

T
Todd Short 已提交
107
OPENSSL_secure_free() returns no values.
R
Rich Salz 已提交
108

R
Rich Salz 已提交
109 110
=head1 SEE ALSO

R
Rich Salz 已提交
111
L<OPENSSL_malloc(3)>,
112
L<BN_new(3)>
R
Rich Salz 已提交
113

R
Rich Salz 已提交
114 115 116 117 118 119 120 121 122 123
=head1 COPYRIGHT

Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the OpenSSL license (the "License").  You may not use
this file except in compliance with the License.  You can obtain a copy
in the file LICENSE in the source distribution or at
L<https://www.openssl.org/source/license.html>.

=cut