diff --git a/src/openbsd.h b/src/openbsd.h index b1f412f..0e8863d 100644 --- a/src/openbsd.h +++ b/src/openbsd.h @@ -5,11 +5,13 @@ #include #include #include +#include +#include +#include inline void arc4random_buf(void *buf, size_t nbytes) { - for( size_t n = 0; n < nbytes; ++ n) ((char*)(buf))[n] = rand() %256; } @@ -17,7 +19,10 @@ void arc4random_buf(void *buf, size_t nbytes) inline void arc4random_init(void) { - srand( (unsigned int) time(NULL)); + struct timeval tv; + gettimeofday(&tv, 0); + // this is not very good, but we lack a portable non-blocking API + srand( ((unsigned int) tv.tv_usec) ^ (unsigned int)getpid()); } diff --git a/test/main.cpp b/test/main.cpp index 0c64bec..73e289d 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -9,7 +9,9 @@ int main() std::string password = "top_secret"; std::string hash = bcrypt::generateHash(password); + std::cout << "Hash: " << hash << std::endl; + hash=bcrypt::generateHash(password); std::cout << "Hash: " << hash << std::endl; std::cout << "\"" << password << "\" : " << bcrypt::validatePassword(password,hash) << std::endl;