diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-05-14 17:41:05 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-05-14 17:41:05 -0700 |
| commit | e94518590de48e2718539f98b87e2f617fa02f75 (patch) | |
| tree | 8329028e4fc1e2e198f2e1e7ee275a47d02b9dc0 /node/Utils.cpp | |
| parent | a8835cd8b33903440f372ed66f4e3b49745ea68f (diff) | |
| download | infinitytier-e94518590de48e2718539f98b87e2f617fa02f75.tar.gz infinitytier-e94518590de48e2718539f98b87e2f617fa02f75.zip | |
First stab of PFS design work with PKC security -- may not implement in 1.0.3 but stubbing out.
Diffstat (limited to 'node/Utils.cpp')
| -rw-r--r-- | node/Utils.cpp | 9 |
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__ |
