OPENSSL_secure_malloc.pod 5.3 KB

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