2
0

OPENSSL_secure_malloc.pod 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_used - secure heap storage
  9. =head1 SYNOPSIS
  10. #include <openssl/crypto.h>
  11. int CRYPTO_secure_malloc_init(size_t size, int minsize);
  12. int CRYPTO_secure_malloc_initialized();
  13. int CRYPTO_secure_malloc_done();
  14. void *OPENSSL_secure_malloc(size_t num);
  15. void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
  16. void *OPENSSL_secure_zalloc(size_t num);
  17. void *CRYPTO_secure_zalloc(size_t num, const char *file, int line);
  18. void OPENSSL_secure_free(void* ptr);
  19. void CRYPTO_secure_free(void *ptr, const char *, int);
  20. void OPENSSL_secure_clear_free(void* ptr, size_t num);
  21. void CRYPTO_secure_clear_free(void *ptr, size_t num, const char *, int);
  22. size_t OPENSSL_secure_actual_size(const void *ptr);
  23. size_t CRYPTO_secure_used();
  24. =head1 DESCRIPTION
  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. If a secure heap is used, then private key B<BIGNUM> values are stored there.
  33. This protects long-term storage of private keys, but will not necessarily
  34. put all intermediate values and computations there.
  35. CRYPTO_secure_malloc_init() creates the secure heap, with the specified
  36. C<size> in bytes. The C<minsize> parameter is the minimum size to
  37. allocate from the heap. Both C<size> and C<minsize> must be a power
  38. of two.
  39. CRYPTO_secure_malloc_initialized() indicates whether or not the secure
  40. heap as been initialized and is available.
  41. CRYPTO_secure_malloc_done() releases the heap and makes the memory unavailable
  42. to the process if all secure memory has been freed.
  43. It can take noticeably long to complete.
  44. OPENSSL_secure_malloc() allocates C<num> bytes from the heap.
  45. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  46. calling OPENSSL_malloc().
  47. It is a macro that expands to
  48. CRYPTO_secure_malloc() and adds the C<__FILE__> and C<__LINE__> parameters.
  49. OPENSSL_secure_zalloc() and CRYPTO_secure_zalloc() are like
  50. OPENSSL_secure_malloc() and CRYPTO_secure_malloc(), respectively,
  51. except that they call memset() to zero the memory before returning.
  52. OPENSSL_secure_free() releases the memory at C<ptr> back to the heap.
  53. It must be called with a value previously obtained from
  54. OPENSSL_secure_malloc().
  55. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  56. calling OPENSSL_free().
  57. It exists for consistency with OPENSSL_secure_malloc() , and
  58. is a macro that expands to CRYPTO_secure_free() and adds the C<__FILE__>
  59. and C<__LINE__> parameters..
  60. OPENSSL_secure_clear_free() is similar to OPENSSL_secure_free() except
  61. that it has an additional C<num> parameter which is used to clear
  62. the memory if it was not allocated from the secure heap.
  63. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  64. calling OPENSSL_clear_free().
  65. OPENSSL_secure_actual_size() tells the actual size allocated to the
  66. pointer; implementations may allocate more space than initially
  67. requested, in order to "round up" and reduce secure heap fragmentation.
  68. CRYPTO_secure_used() returns the number of bytes allocated in the
  69. secure heap.
  70. =head1 RETURN VALUES
  71. CRYPTO_secure_malloc_init() returns 0 on failure, 1 if successful,
  72. and 2 if successful but the heap could not be protected by memory
  73. mapping.
  74. CRYPTO_secure_malloc_initialized() returns 1 if the secure heap is
  75. available (that is, if CRYPTO_secure_malloc_init() has been called,
  76. but CRYPTO_secure_malloc_done() has not been called or failed) or 0 if not.
  77. OPENSSL_secure_malloc() and OPENSSL_secure_zalloc() return a pointer into
  78. the secure heap of the requested size, or C<NULL> if memory could not be
  79. allocated.
  80. CRYPTO_secure_allocated() returns 1 if the pointer is in the secure heap, or 0 if not.
  81. CRYPTO_secure_malloc_done() returns 1 if the secure memory area is released, or 0 if not.
  82. OPENSSL_secure_free() and OPENSSL_secure_clear_free() return no values.
  83. =head1 SEE ALSO
  84. L<OPENSSL_malloc(3)>,
  85. L<BN_new(3)>
  86. =head1 HISTORY
  87. OPENSSL_secure_clear_free() was added in OpenSSL 1.1.0g.
  88. =head1 COPYRIGHT
  89. Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  90. Licensed under the OpenSSL license (the "License"). You may not use
  91. this file except in compliance with the License. You can obtain a copy
  92. in the file LICENSE in the source distribution or at
  93. L<https://www.openssl.org/source/license.html>.
  94. =cut