Seed the pseudo-random number generator to auto generate salt

This commit is contained in:
hilch
2022-09-29 14:10:36 +02:00
parent c4d62a4010
commit 2c2980063e
2 changed files with 4 additions and 0 deletions

View File

@@ -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);

View File

@@ -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;
}