int getentropy(void* buffer, size_t buffer_size) { if (buffer_size > GETENTROPY_MAX) {
errno = EINVAL; return -1;
}
int saved_errno = errno;
size_t collected = 0; while (collected < buffer_size) { long count = TEMP_FAILURE_RETRY(getrandom(static_cast<char*>(buffer) + collected,
buffer_size - collected, GRND_NONBLOCK)); if (count == -1) { // One of several things could have gone wrong: // EAGAIN: there isn't enough entropy right now. // ENOSYS/EINVAL: getrandom(2) or GRND_NONBLOCK isn't supported. // EFAULT: `buffer` is invalid. // Realistically we're here because of EAGAIN, // for which /dev/urandom is the solution --- // it'll return low entropy randomness where getrandom() won't, // but we fall back /dev/urandom for all cases because it can't hurt, // and we don't need to optimize the EFAULT case. // See https://man7.org/linux/man-pages/man7/random.7.html for getrandom() // vs /dev/random vs /dev/urandom. // See http://b/33059407 and http://b/67015565. return getentropy_urandom(buffer, buffer_size, saved_errno);
}
collected += count;
}
errno = saved_errno; return0;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.