cybersecurity · beginner · ~10 min
Match entropy source to the use case.
For each use case below, return the recommended source as an int:
0 = rand() — fast, deterministic with srand seed (NOT for security)1 = /dev/urandom — cryptographic, always-available, blocks only on very early boot2 = getrandom(2) syscall — Linux 3.17+, preferred, no fd neededImplement int recommend_entropy_source(int use_case):
Return:
0 for cases 0 and 3 (non-security).2 for cases 1, 2, 4 (security — prefer getrandom).-1 for unknown use_case.rand()/srand(time(NULL)) is the entropy source used in too many security CVEs. Choosing the right call matters.
Use-case integer.
0 / 2 / -1.
No real syscalls.
int recommend_entropy_source(int use_case) { /* TODO */ (void)use_case; return -1; }
Using rand() for security. Using /dev/urandom when getrandom is available.
Unknown use_case.
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.