OPENSSL_secure_malloc.pod 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. Both C<size> and C<minsize> must be a power
  40. of two.
  41. CRYPTO_secure_malloc_initialized() indicates whether or not the secure
  42. heap as been initialized and is available.
  43. CRYPTO_secure_malloc_done() releases the heap and makes the memory unavailable
  44. to the process if all secure memory has been freed.
  45. It can take noticeably long to complete.
  46. OPENSSL_secure_malloc() allocates C<num> bytes from the heap.
  47. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  48. calling OPENSSL_malloc().
  49. It is a macro that expands to
  50. CRYPTO_secure_malloc() and adds the C<__FILE__> and C<__LINE__> parameters.
  51. OPENSSL_secure_zalloc() and CRYPTO_secure_zalloc() are like
  52. OPENSSL_secure_malloc() and CRYPTO_secure_malloc(), respectively,
  53. except that they call memset() to zero the memory before returning.
  54. OPENSSL_secure_free() releases the memory at C<ptr> back to the heap.
  55. It must be called with a value previously obtained from
  56. OPENSSL_secure_malloc().
  57. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  58. calling OPENSSL_free().
  59. It exists for consistency with OPENSSL_secure_malloc() , and
  60. is a macro that expands to CRYPTO_secure_free() and adds the C<__FILE__>
  61. and C<__LINE__> parameters..
  62. OPENSSL_secure_clear_free() is similar to OPENSSL_secure_free() except
  63. that it has an additional C<num> parameter which is used to clear
  64. the memory if it was not allocated from the secure heap.
  65. If CRYPTO_secure_malloc_init() is not called, this is equivalent to
  66. calling OPENSSL_clear_free().
  67. OPENSSL_secure_actual_size() tells the actual size allocated to the
  68. pointer; implementations may allocate more space than initially
  69. requested, in order to "round up" and reduce secure heap fragmentation.
  70. OPENSSL_secure_allocated() tells if a pointer is allocated in the secure heap.
  71. CRYPTO_secure_used() returns the number of bytes allocated in the
  72. secure heap.
  73. =head1 RETURN VALUES
  74. CRYPTO_secure_malloc_init() returns 0 on failure, 1 if successful,
  75. and 2 if successful but the heap could not be protected by memory
  76. mapping.
  77. CRYPTO_secure_malloc_initialized() returns 1 if the secure heap is
  78. available (that is, if CRYPTO_secure_malloc_init() has been called,
  79. but CRYPTO_secure_malloc_done() has not been called or failed) or 0 if not.
  80. OPENSSL_secure_malloc() and OPENSSL_secure_zalloc() return a pointer into
  81. the secure heap of the requested size, or C<NULL> if memory could not be
  82. allocated.
  83. CRYPTO_secure_allocated() returns 1 if the pointer is in the secure heap, or 0 if not.
  84. CRYPTO_secure_malloc_done() returns 1 if the secure memory area is released, or 0 if not.
  85. OPENSSL_secure_free() and OPENSSL_secure_clear_free() return no values.
  86. =head1 SEE ALSO
  87. L<OPENSSL_malloc(3)>,
  88. L<BN_new(3)>
  89. =head1 HISTORY
  90. The OPENSSL_secure_clear_free() function was added in OpenSSL 1.1.0g.
  91. The second argument to CRYPTO_secure_malloc_init() was changed from an B<int> to
  92. a B<size_t> in OpenSSL 3.0.
  93. =head1 COPYRIGHT
  94. Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  95. Licensed under the Apache License 2.0 (the "License"). You may not use
  96. this file except in compliance with the License. You can obtain a copy
  97. in the file LICENSE in the source distribution or at
  98. L<https://www.openssl.org/source/license.html>.
  99. =cut