glibc/stdlib/Versions
Adhemerval Zanella Netto 6f4e0fcfa2 stdlib: Add arc4random, arc4random_buf, and arc4random_uniform (BZ #4417)
The implementation is based on scalar Chacha20 with per-thread cache.
It uses getrandom or /dev/urandom as fallback to get the initial entropy,
and reseeds the internal state on every 16MB of consumed buffer.

To improve performance and lower memory consumption the per-thread cache
is allocated lazily on first arc4random functions call, and if the
memory allocation fails getentropy or /dev/urandom is used as fallback.
The cache is also cleared on thread exit iff it was initialized (so if
arc4random is not called it is not touched).

Although it is lock-free, arc4random is still not async-signal-safe
(the per thread state is not updated atomically).

The ChaCha20 implementation is based on RFC8439 [1], omitting the final
XOR of the keystream with the plaintext because the plaintext is a
stream of zeros.  This strategy is similar to what OpenBSD arc4random
does.

The arc4random_uniform is based on previous work by Florian Weimer,
where the algorithm is based on Jérémie Lumbroso paper Optimal Discrete
Uniform Generation from Coin Flips, and Applications (2013) [2], who
credits Donald E. Knuth and Andrew C. Yao, The complexity of nonuniform
random number generation (1976), for solving the general case.

The main advantage of this method is the that the unit of randomness is not
the uniform random variable (uint32_t), but a random bit.  It optimizes the
internal buffer sampling by initially consuming a 32-bit random variable
and then sampling byte per byte.  Depending of the upper bound requested,
it might lead to better CPU utilization.

Checked on x86_64-linux-gnu, aarch64-linux, and powerpc64le-linux-gnu.

Co-authored-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Yann Droneaud <ydroneaud@opteya.com>

[1] https://datatracker.ietf.org/doc/html/rfc8439
[2] https://arxiv.org/pdf/1304.1916.pdf
2022-07-22 11:58:27 -03:00

156 lines
2.9 KiB
Plaintext

%include <float128-abi.h>
libc {
GLIBC_2.0 {
# functions with required interface outside normal name space
__xpg_basename;
# functions used in inline functions or macros
__strtod_internal; __strtof_internal; __strtold_internal;
__strtol_internal; __strtoll_internal;
__strtoul_internal; __strtoull_internal;
# functions formerly so used (compatibility symbols)
__strtoq_internal; __strtouq_internal;
# compatibility symbol
__secure_getenv;
# a*
a64l; abort; abs; atexit; atof; atoi; atol; atoll;
# b*
bsearch;
# c*
canonicalize_file_name; clearenv;
# d*
div; drand48; drand48_r;
# e*
erand48; erand48_r; exit;
# g*
getenv; getsubopt;
# i*
initstate; initstate_r;
# l*
l64a; labs; lcong48; lcong48_r; ldiv; llabs; lldiv; lrand48; lrand48_r;
# m*
mblen; mbrlen; mbrtowc; mbsinit; mbsnrtowcs; mbsrtowcs; mbstowcs;
mbtowc; mcount; mrand48; mrand48_r;
# n*
nrand48; nrand48_r;
# o*
on_exit;
# p*
putenv;
# q*
qsort;
# r*
rand; rand_r; random; random_r; realpath; rpmatch;
# s*
seed48; seed48_r; setcontext; setenv; setstate; setstate_r; srand; srand48;
srand48_r; srandom; srandom_r; step; strfmon; strtod; strtof; strtol;
strtold; strtoll; strtoq; strtoul; strtoull; strtouq; system;
# u*
unsetenv;
# w*
wcstombs; wctomb;
}
GLIBC_2.1 {
# a*
addseverity;
# f*
fmtmsg;
# g*
getcontext;
# m*
makecontext;
# s*
strtoimax; strtoumax; swapcontext;
}
GLIBC_2.1.1 {
# _*
_Exit;
# i*
imaxabs; imaxdiv;
}
GLIBC_2.1.3 {
# used by new G++ ABI
__cxa_atexit; __cxa_finalize;
}
GLIBC_2.3 {
# Silent change in SUS.
realpath;
}
GLIBC_2.8 {
qsort_r;
}
GLIBC_2.10 {
quick_exit; __cxa_at_quick_exit;
}
GLIBC_2.17 {
secure_getenv;
}
GLIBC_2.18 {
__cxa_thread_atexit_impl;
}
GLIBC_2.24 {
quick_exit;
}
GLIBC_2.25 {
# s*
strfromd; strfromf; strfroml;
getrandom; getentropy;
}
%ifdef FLOAT128_VERSION
FLOAT128_VERSION {
strfromf128;
strtof128;
strtof128_l;
}
%endif
GLIBC_2.27 {
# _Float64x functions, only present for some configurations.
strfromf64x;
strtof64x;
strtof64x_l;
# _Float32, _Float64 and _Float32x functions, for all configurations.
strfromf32; strfromf64; strfromf32x;
strtof32; strtof64; strtof32x;
strtof32_l; strtof64_l; strtof32x_l;
}
GLIBC_2.36 {
arc4random;
arc4random_buf;
arc4random_uniform;
}
GLIBC_PRIVATE {
# functions which have an additional interface since they are
# are cancelable.
__libc_system;
# Variable which needs a dynamic symbol table entry.
__abort_msg;
# Used from other libraries
__libc_secure_getenv;
__call_tls_dtors;
__strtof_nan; __strtod_nan; __strtold_nan;
}
}