Now, is it possible to change this initial threshold for the non-blocking pool (if you don't want to learn all the nitty-gritty, skip to the end of this answer)? I suspected it was not, but I wasn't sure, so I went to consult to the most authoritative documentation available,: the source. The syscall getrandom(2) is defined in the kernel randomness driver. Note that this is specific to Linux kernel 4.14 (major changes to the randomness driver were made in 4.8).
static int crng_fast_load(const char *cp, size_t len) { unsigned long flags; char *p; // Enter the critical section (acquiringacquire athe spinlock). if (!spin_trylock_irqsave(&primary_crng.lock, flags)) return 0; // If crng_ready() is already true, leave the critical section and return. if (crng_ready()) { spin_unlock_irqrestore(&primary_crng.lock, flags); return 0; } // Mix in the values at cp with the CRNG state. Increment crng_init_cnt // for each byte from cp that gets mixed in (up to len times). p = (unsigned char *) &primary_crng.state[4]; while (len > 0 && crng_init_cnt < CRNG_INIT_CNT_THRESH) { p[crng_init_cnt % CHACHA20_KEY_SIZE] ^= *cp; cp++; crng_init_cnt++; len--; } // Leave the critical section (release the spinlock). spin_unlock_irqrestore(&primary_crng.lock, flags); // If crng_init_cnt is >= CRNG_INIT_CNT_THRESH, set crng_init to 1. if (crng_init_cnt >= CRNG_INIT_CNT_THRESH) { invalidate_batched_entropy(); crng_init = 1; wake_up_interruptible(&crng_init_wait); pr_notice("random: fast init done\n"); } return 1; } From this, we see that crng_init_cnt is incremented for each byte which crng_fast_load() takes in. The function is called early at boot in various entropy-gathering functions to add as much possible data to the pool early on. We're almost there! Last thing to do is finefind out what the value of CRNG_INIT_CNT_THRESH, defined here:
CHACHA20_KEY_SIZEis hardcoded atas 32.CRNG_INIT_CNT_THRESHis doubleCHACHA20_KEY_SIZE, making it is 64.crng_init_cntis incremented for every byte of early randomness gathered.- When at least 64 bytes of randomness are gathered,
crng_initis set to 1. - When
crng_initis 1,crng_ready()evaluates true. - When
crng_ready()evaluates true,getrandom()resumes and returns.
The amount of early entropy required before getrandom() resumes and returns is not in fact 128 bits. It is already hardcoded atas 64 bytes (512 bits), twice the amount you wanted.