588c4b15f9a665861c9478904d25683e8af95a40
[openssl.git] / doc / crypto / OPENSSL_secure_malloc.pod
1 =pod
2
3 =head1 NAME
4
5 CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, OPENSSL_secure_free, OPENSSL_secure_allocated - use secure heap storage
6
7 =head1 SYNOPSIS
8
9  #include <openssl/crypto.h>
10
11  int CRYPTO_secure_malloc_init(size_t size, int minsize);
12
13  int CRYPTO_secure_malloc_initialized();
14
15  void CRYPTO_secure_malloc_done();
16
17  void *OPENSSL_secure_malloc(int num);
18
19  void OPENSSL_secure_free(void* ptr);
20
21  int OPENSSL_secure_allocated(const void* ptr);
22
23 =head1 DESCRIPTION
24
25 In order to help protect applications (particularly long-running servers)
26 from pointer overruns or underruns that could return arbitrary data from
27 the program's dynamic memory area, where keys and other sensitive
28 information might be stored, OpenSSL supports the concept of a "secure heap."
29 The level and type of security guarantees depend on the operating system.
30 It is a good idea to review the code and see if it addresses your
31 threat model and concerns.
32
33 If a secure heap is used, then private key B<BIGNUM> values are stored there.
34 This protects long-term storage of private keys, but will not necessarily
35 put all intermediate values and computations there.
36
37 B<CRYPTO_secure_malloc_init> creates the secure heap, with the specified
38 C<size> in bytes. The C<minsize> parameter is the minimum size to
39 allocate from the heap. Both C<size> and C<minsize> must be a power
40 of two.  It is an error to call this after any B<OPENSSL_secure_malloc>
41 calls have been made.
42
43 B<CRYPTO_secure_malloc_initialized> indicates whether or not the secure
44 heap as been initialized and is available.
45
46 B<CRYPTO_secure_malloc_done> releases the heap and makes the memory unavailable
47 to the process. It can take noticeably long to complete.
48
49 B<OPENSSL_secure_malloc> allocates C<num> bytes from the heap.
50 If B<CRYPTO_secure_malloc_init> is not called, this is equivalent to
51 calling B<OPENSSL_malloc>.
52
53 B<OPENSSL_secure_free> releases the memory at C<ptr> back to the heap.
54 It must be called with a value previously obtained from
55 B<OPENSSL_secure_malloc>.
56 If B<CRYPTO_secure_malloc_init> is not called, this is equivalent to
57 calling B<OPENSSL_free>.
58
59 B<OPENSSL_secure_allocated> tells whether or not a pointer is within
60 the secure heap.
61
62 =head1 RETURN VALUES
63
64 B<CRYPTO_secure_malloc_init> returns 0 on failure, 1 if successful,
65 and 2 if successful but the heap could not be protected by memory
66 mapping.
67
68 B<CRYPTO_secure_malloc_initialized> returns 1 if the secure heap is
69 available (that is, if B<CRYPTO_secure_malloc_init> has been called,
70 but B<CRYPTO_secure_malloc_done> has not) or 0 if not.
71
72 B<OPENSSL_secure_malloc> returns a pointer into the secure heap of
73 the requested size, or C<NULL> if memory could not be allocated.
74
75 B<CRYPTO_secure_allocated> returns 1 if the pointer is in the
76 the secure heap, or 0 if not.
77
78 B<CRYPTO_secure_malloc_done> and B<OPENSSL_secure_free>
79 return no values.
80
81 =head1 SEE ALSO
82
83 L<BN_new(3)>,
84 L<bn_internal(3)>
85
86 =cut