OPENSSL_secure_malloc.pod 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. OPENSSL_secure_clear_free, CRYPTO_secure_free, CRYPTO_secure_clear_free,
  7. OPENSSL_secure_actual_size, OPENSSL_secure_allocated, CRYPTO_secure_used
  8. - 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. int OPENSSL_secure_allocated(const void *ptr);
  24. size_t CRYPTO_secure_used();
  25. =head1 DESCRIPTION
  26. In order to help protect applications (particularly long-running servers)
  27. from pointer overruns or underruns that could return arbitrary data from
  28. the program's dynamic memory area, where keys and other sensitive
  29. information might be stored, OpenSSL supports the concept of a "secure heap."
  30. The level and type of security guarantees depend on the operating system.
  31. It is a good idea to review the code and see if it addresses your
  32. threat model and concerns.
  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. CRYPTO_secure_malloc_init() creates the secure heap, with the specified
  37. C<size> in bytes. The C<minsize> parameter is the minimum size to
  38. allocate from the heap. Both C<size> and C<minsize> must be a power
  39. of two.
  40. CRYPTO_secure_malloc_initialized() indicates whether or not the secure
  41. heap as been initialized and is available.
  42. CRYPTO_secure_malloc_done() releases the heap and makes the memory unavailable
  43. to the process if all secure memory has been freed.
  44. It can take noticeably long to complete.
  45. OPENSSL_secure_malloc() allocates C<num> bytes from the heap.
  46. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  47. calling OPENSSL_malloc().
  48. It is a macro that expands to
  49. CRYPTO_secure_malloc() and adds the C<__FILE__> and C<__LINE__> parameters.
  50. OPENSSL_secure_zalloc() and CRYPTO_secure_zalloc() are like
  51. OPENSSL_secure_malloc() and CRYPTO_secure_malloc(), respectively,
  52. except that they call memset() to zero the memory before returning.
  53. 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. OPENSSL_secure_malloc().
  56. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  57. calling OPENSSL_free().
  58. It exists for consistency with OPENSSL_secure_malloc() , and
  59. is a macro that expands to CRYPTO_secure_free() and adds the C<__FILE__>
  60. and C<__LINE__> parameters..
  61. OPENSSL_secure_allocated() tells whether or not a pointer is within
  62. the secure heap.
  63. OPENSSL_secure_actual_size() tells the actual size allocated to the
  64. pointer; implementations may allocate more space than initially
  65. requested, in order to "round up" and reduce secure heap fragmentation.
  66. CRYPTO_secure_used() returns the number of bytes allocated in the
  67. secure heap.
  68. =head1 RETURN VALUES
  69. CRYPTO_secure_malloc_init() returns 0 on failure, 1 if successful,
  70. and 2 if successful but the heap could not be protected by memory
  71. mapping.
  72. CRYPTO_secure_malloc_initialized() returns 1 if the secure heap is
  73. available (that is, if CRYPTO_secure_malloc_init() has been called,
  74. but CRYPTO_secure_malloc_done() has not been called or failed) or 0 if not.
  75. OPENSSL_secure_malloc() and OPENSSL_secure_zalloc() return a pointer into
  76. the secure heap of the requested size, or C<NULL> if memory could not be
  77. allocated.
  78. CRYPTO_secure_allocated() returns 1 if the pointer is in the secure heap, or 0 if not.
  79. CRYPTO_secure_malloc_done() returns 1 if the secure memory area is released, or 0 if not.
  80. OPENSSL_secure_free() and OPENSSL_secure_clear_free() return no values.
  81. =head1 SEE ALSO
  82. L<OPENSSL_malloc(3)>,
  83. L<BN_new(3)>
  84. =head1 HISTORY
  85. OPENSSL_secure_clear_free() was added in OpenSSL 1.1.0g.
  86. =head1 COPYRIGHT
  87. Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  88. Licensed under the OpenSSL license (the "License"). You may not use
  89. this file except in compliance with the License. You can obtain a copy
  90. in the file LICENSE in the source distribution or at
  91. L<https://www.openssl.org/source/license.html>.
  92. =cut