aboutsummaryrefslogtreecommitdiff
path: root/src/serialize.h
diff options
context:
space:
mode:
authorPhilip Kaufmann <[email protected]>2012-11-08 19:38:49 +0100
committerLuke Dashjr <[email protected]>2012-11-12 23:55:22 +0000
commitff31f1fa10e2062465520ad8a3ff846c23b7a96f (patch)
tree2e74096d2185209048cf1523409d3d7a03ac5ca6 /src/serialize.h
parentFixed 100% CPU utilization problem on FreeBSD 9 (diff)
downloaddiscoin-ff31f1fa10e2062465520ad8a3ff846c23b7a96f.tar.xz
discoin-ff31f1fa10e2062465520ad8a3ff846c23b7a96f.zip
don't use memset() in privacy/security relevant code parts
As memset() can be optimized out by a compiler it should not be used in privacy/security relevant code parts. OpenSSL provides the safe OPENSSL_cleanse() function in crypto.h, which perfectly does the job of clean and overwrite data. For details see: http://www.viva64.com/en/b/0178/ - change memset() to OPENSSL_cleanse() where appropriate - change a hard-coded number from netbase.cpp into a sizeof()
Diffstat (limited to 'src/serialize.h')
-rw-r--r--src/serialize.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/serialize.h b/src/serialize.h
index 8b75cf8b8..73c1139db 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -14,6 +14,8 @@
#include <cstring>
#include <cstdio>
+#include <openssl/crypto.h> // for OPENSSL_cleanse()
+
#include <boost/type_traits/is_fundamental.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
@@ -813,7 +815,7 @@ struct secure_allocator : public std::allocator<T>
{
if (p != NULL)
{
- memset(p, 0, sizeof(T) * n);
+ OPENSSL_cleanse(p, sizeof(T) * n);
munlock(p, sizeof(T) * n);
}
std::allocator<T>::deallocate(p, n);
@@ -847,7 +849,7 @@ struct zero_after_free_allocator : public std::allocator<T>
void deallocate(T* p, std::size_t n)
{
if (p != NULL)
- memset(p, 0, sizeof(T) * n);
+ OPENSSL_cleanse(p, sizeof(T) * n);
std::allocator<T>::deallocate(p, n);
}
};