.\" -*- coding: UTF-8 -*- .\" Copyright 2014, Theodore Ts'o .\" Copyright 2015, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH getrandom 2 "8 février 2026" "Linux man\-pages 6.18" .SH NOM getrandom \- obtenir une série d'octets aléatoires .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP,\ \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .P \fBssize_t getrandom(\fPsize_t size; \fB void \fP\fIbuf\fP\fB[\fP\fIsize\fP\fB], size_t \fP\fIsize\fP\fB, unsigned int \fP\fIflags\fP\fB);\fP .fi .SH DESCRIPTION The \fBgetrandom\fP() system call fills the buffer pointed to by \fIbuf\fP with up to \fIsize\fP random bytes. These bytes can be used to seed user\-space random number generators or for cryptographic purposes. .P Par défaut, \fBgetrandom\fP() dessine une entropie à partir d'une source \fIurandom\fP (soit la même source que le périphérique \fI/dev/urandom\fP). Ce comportement peut être modifié avec le paramètre \fIflags\fP. .P Si la source \fIurandom\fP a été initialisée, les lectures jusqu'à 256 octets renverront toujours autant d'octets que demandé et ne seront pas interrompues par des signaux. Il n'y a pas une telle garantie pour les tampons plus gros. Par exemple, si l'appel est interrompu par un gestionnaire de signal, il peut renvoyer un tampon partiellement rempli ou échouer avec l'erreur \fBEINTR\fP. .P Si la source \fIurandom\fP n'a pas encore été initialisée, \fBgetrandom\fP() se bloquera, sauf si \fBGRND_NONBLOCK\fP est indiqué dans \fIflags\fP. .P Le paramètre \fIflags\fP est un masque de bit qui peut contenir aucune ou plusieurs des valeurs suivantes unies (OU logique) ensemble : .TP \fBGRND_RANDOM\fP If this bit is set, then random bytes are drawn from the \fIrandom\fP source (i.e., the same source as the \fI/dev/random\fP device) instead of the \fIurandom\fP source. The \fIrandom\fP source is limited based on the entropy that can be obtained from environmental noise. If the number of available bytes in the \fIrandom\fP source is less than requested in \fIsize\fP, the call returns just the available random bytes. If no random bytes are available, the behavior depends on the presence of \fBGRND_NONBLOCK\fP in the \fIflags\fP argument. .TP \fBGRND_NONBLOCK\fP Par défaut, pendant une lecture depuis la source \fIrandom\fP, \fBgetrandom\fP() se bloque si aucun octet aléatoire n'est disponible, tandis que pendant une lecture à partir de la source \fIurandom\fP, il se bloque si la réserve (pool) d'entropie n'a pas encore été initialisée. Si le paramètre \fBGRND_NONBLOCK\fP est positionné, \fBgetrandom\fP() ne se bloque pas dans ces cas, mais il renvoie immédiatement \fB\-1\fP et il positionne \fIerrno\fP sur \fBEAGAIN\fP. .SH "VALEUR RENVOYÉE" On success, \fBgetrandom\fP() returns the number of bytes that were copied to the buffer \fIbuf\fP. This may be less than the number of bytes requested via \fIsize\fP if either \fBGRND_RANDOM\fP was specified in \fIflags\fP and insufficient entropy was present in the \fIrandom\fP source or the system call was interrupted by a signal. .P En cas d'erreur, la valeur de retour est \fB\-1\fP et \fIerrno\fP est définie pour préciser l'erreur. .SH ERREURS .TP \fBEAGAIN\fP L'entropie demandée n'était pas disponible et \fBgetrandom\fP() se serait bloqué si le paramètre \fBGRND_NONBLOCK\fP n'avait pas été positionné. .TP \fBEFAULT\fP L'adresse à laquelle renvoie \fIbuf\fP est en dehors de l'espace d'adressage accessible. .TP \fBEINTR\fP L'appel a été interrompu par un gestionnaire de signal ; voir la description sur la manière dont sont gérés les appels \fBread\fP(2) interrompus sur des périphériques « lents » avec et sans l'attribut \fBSA_RESTART\fP dans la page de manuel de \fBsignal\fP(7). .TP \fBEINVAL\fP Un paramètre non valable a été indiqué dans \fIflags\fP. .TP \fBENOSYS\fP La fonction enveloppe de la glibc pour \fBgetrandom\fP() a déterminé que le noyau sous\-jacent n'implémente pas cet appel système. .SH NORMES Linux. .SH HISTORIQUE Linux 3.17, glibc 2.25. .SH NOTES Pour un aperçu et une comparaison des interfaces utilisables pour produire de l'aléatoire, voir \fBrandom\fP(7). .P .\" Contrairement à \fI/dev/random\fP et à \fI/dev/urandom\fP, \fBgetrandom\fP() n'implique pas d'utiliser des noms de chemin ou des descripteurs de fichier. Ainsi, \fBgetrandom\fP() peut être utile dans les cas où \fBchroot\fP(2) rend invisibles les noms de chemin \fI/dev\fP, et où une application (comme un démon qui démarre) ferme un descripteur de fichier pour un de ces fichiers ouverts par une bibliothèque. .SS "Nombre maximal d'octets renvoyés" À partir de Linux 3.19, les limites suivantes s'appliquent : .IP \- 3 Pendant une lecture à partir d'une source \fIurandom\fP, un maximum de 32Mi\-1 octets est renvoyé par un appel \fBgetrandom\fP() sur des systèmes où \fIint\fP a une taille de 32 bits. .IP \- Lors d'une lecture à partir d'une source \fIrandom\fP, un maximum de 512 octets est renvoyé. .SS "Interruption par un gestionnaire de signal" Lors de la lecture à partir d'une source \fIurandom\fP (\fBGRND_RANDOM\fP n'est pas positionné), \fBgetrandom\fP() se bloquera jusqu'à ce que la réserve (pool) d'entropie soit initialisée (sauf si l'attribut \fBGRND_NONBLOCK\fP a été indiqué). Si une demande est faite pour lire un grand nombre d'octets (plus de 256), \fBgetrandom\fP() se bloquera jusqu'à ce que ces octets soient générés et transférés de la mémoire du noyau vers \fIbuf\fP. Lors d'une lecture à partir d'une source \fIrandom\fP (\fBGRND_RANDOM\fP est positionné), \fBgetrandom\fP() se bloquera jusqu'à ce que des octets aléatoires soient disponibles (sauf si l'attribut \fBGRND_NONBLOCK\fP a été indiqué). .P The behavior when a call to \fBgetrandom\fP() that is blocked while reading from the \fIurandom\fP source is interrupted by a signal handler depends on the initialization state of the entropy buffer and on the request size, \fIsize\fP. If the entropy is not yet initialized, then the call fails with the \fBEINTR\fP error. If the entropy pool has been initialized and the request size is large (\fIsize\fP\ >\ 256), the call either succeeds, returning a partially filled buffer, or fails with the error \fBEINTR\fP. If the entropy pool has been initialized and the request size is small (\fIsize\fP\ <=\ 256), then \fBgetrandom\fP() will not fail with \fBEINTR\fP. Instead, it will return all of the bytes that have been requested. .P Pendant une lecture avec une source \fIrandom\fP, les requêtes bloquantes de n'importe quelle taille peuvent être interrompues par un gestionnaire de signal (l'appel échoue avec l'erreur \fBEINTR\fP). .P L'utilisation de \fBgetrandom\fP() pour lire de petits tampons (<=\ 256 octets) à partir d'une source \fIurandom\fP est le cas d'utilisation privilégié. .P The special treatment of small values of \fIsize\fP was designed for compatibility with OpenBSD's \fBgetentropy\fP(3), which is nowadays supported by glibc. .P The user of \fBgetrandom\fP() \fImust\fP always check the return value, to determine whether either an error occurred or fewer bytes than requested were returned. In the case where \fBGRND_RANDOM\fP is not specified and \fIsize\fP is less than or equal to 256, a return of fewer bytes than requested should never happen, but the careful programmer will check for this anyway! .SH BOGUES .\" FIXME patch proposed https://lkml.org/lkml/2014/11/29/16 À partir de Linux 3.19, le bogue suivant existe : .IP \- 3 Selon la charge du processeur, \fBgetrandom\fP() ne réagit pas aux interruptions avant de lire tous les octets demandés. .SH "VOIR AUSSI" \fBgetentropy\fP(3), \fBrandom\fP(4), \fBurandom\fP(4), \fBrandom\fP(7), \fBsignal\fP(7) .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot et Jean-Philippe MENGUAL . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .