summaryrefslogtreecommitdiff
path: root/node/Utils.cpp
diff options
context:
space:
mode:
authorGrant Limberg <glimberg@gmail.com>2015-05-16 14:35:35 -0700
committerGrant Limberg <glimberg@gmail.com>2015-05-16 14:35:35 -0700
commitd0935f667fd809a32cb4184a2c422ff79dc6d933 (patch)
tree8dd92dfbe2fdd30375993a21619f701d48060340 /node/Utils.cpp
parent4a0280686c7a74b58a060375ffce385554d90040 (diff)
parent38243e5eff71b76d35904afffd2b21fe84ed958a (diff)
downloadinfinitytier-d0935f667fd809a32cb4184a2c422ff79dc6d933.tar.gz
infinitytier-d0935f667fd809a32cb4184a2c422ff79dc6d933.zip
Merge branch 'adamierymenko-dev' into android-jni
Diffstat (limited to 'node/Utils.cpp')
-rw-r--r--node/Utils.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/node/Utils.cpp b/node/Utils.cpp
index 3380b324..9630e6b3 100644
--- a/node/Utils.cpp
+++ b/node/Utils.cpp
@@ -49,6 +49,7 @@
#include "Utils.hpp"
#include "Mutex.hpp"
+#include "Salsa20.hpp"
namespace ZeroTier {
@@ -152,6 +153,7 @@ void Utils::getSecureRandom(void *buf,unsigned int bytes)
static HCRYPTPROV cryptProvider = NULL;
static Mutex globalLock;
+ static Salsa20 s20;
Mutex::Lock _l(globalLock);
@@ -161,12 +163,19 @@ void Utils::getSecureRandom(void *buf,unsigned int bytes)
exit(1);
return;
}
+ char s20key[32];
+ if (!CryptGenRandom(cryptProvider,(DWORD)sizeof(s20key),(BYTE *)s20key)) {
+ fprintf(stderr,"FATAL ERROR: Utils::getSecureRandom() CryptGenRandom failed!\r\n");
+ exit(1);
+ }
+ s20.init(s20key,256,s20key,8);
}
if (!CryptGenRandom(cryptProvider,(DWORD)bytes,(BYTE *)buf)) {
fprintf(stderr,"FATAL ERROR: Utils::getSecureRandom() CryptGenRandom failed!\r\n");
exit(1);
}
+ s20.encrypt(buf,buf,bytes);
#else // not __WINDOWS__