What is the best replacement for windows rand_s on Linux / POSIX?

The problem is not in chance itself (we have rand), but in cryptographically secure PRNG. What can be used on Linux or ideally POSIX? Does NSS have anything useful?

Clarification . I know about / dev / random, but may end in an entropy pool. And I'm not sure if the cryptographic security of / dev / urandom is guaranteed.

+3
source share
3 answers

Use /dev/random(requires user input, such as mouse movement) or /dev/urandom. The latter has an entropy pool and does not require any user input if the pool is empty.

You can read from the pool as follows:

char buf[100];
FILE *fp;
if (fp = fopen("/dev/urandom", "r")) {
    fread(&buf, sizeof(char), 100, fp);
    fclose(fp);
}

Or something like that.

+5
source

Wikipedia ( ):

/dev/random /dev/urandom ( "" ), . , , , /dev/random. , . .

+5

The device /dev/randommust be a source of cryptographically secure bits.

+3
source

Source: https://habr.com/ru/post/1697373/


All Articles