Skip to content

Commit

Permalink
lib/openssl/UniqueBN: add "clear" template parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Oct 25, 2023
1 parent fb4a9e8 commit 49a8b8c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/openssl/UniqueBN.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@

#include <memory>

/**
* @param clear clear memory before freeing it; use this for sensitive
* values such as private keys
*/
template<bool clear>
struct BNDeleter {
void operator()(BIGNUM *bn) noexcept {
BN_free(bn);
if (clear)
BN_clear_free(bn);
else
BN_free(bn);
}
};

using UniqueBIGNUM = std::unique_ptr<BIGNUM, BNDeleter>;
template<bool clear>
using UniqueBIGNUM = std::unique_ptr<BIGNUM, BNDeleter<clear>>;

0 comments on commit 49a8b8c

Please sign in to comment.