mirror of
https://github.com/allankoechke/Bcrypt.cpp.git
synced 2026-12-03 01:02:22 +00:00
Seed the pseudo-random number generator to auto generate salt
This commit is contained in:
@@ -322,6 +322,8 @@ std::string bcrypt::generateHash(const std::string &password, unsigned int round
|
||||
char salt[_SALT_LEN];
|
||||
|
||||
unsigned char seed[17]{};
|
||||
arc4random_init();
|
||||
|
||||
arc4random_buf(seed, 16);
|
||||
|
||||
bcrypt_gensalt('b', rounds, seed, salt);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef ARC4RANDOM_H_INCLUDED
|
||||
#define ARC4RANDOM_H_INCLUDED
|
||||
|
||||
#include <cstdlib> /* srand, rand */
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
@@ -8,6 +9,7 @@
|
||||
inline
|
||||
void arc4random_buf(void *buf, size_t nbytes)
|
||||
{
|
||||
|
||||
for( size_t n = 0; n < nbytes; ++ n)
|
||||
((char*)(buf))[n] = rand() %256;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user