sodium.his the only header that has to be included.
-lsodiumto link it), and proper compilation/linker flags can be obtained using
pkg-configon systems where it is available:
SODIUM_EXPORT=. This is not required on other platforms.
sodium_init()initializes the library and should be called before any other function provided by Sodium. It is safe to call this function more than once and from different threads -- subsequent calls won't have any effects.
sodium_init()doesn't perform any memory allocations. However, on Unix systems, it may open
/dev/urandomand keep the descriptor open so that the device remains accessible after a
sodium_init()do not cause additional descriptors to be opened.
-1on failure, and
1if the library had already been initialized.
0or a very low number (<
160), and you are not running an obsolete kernel, this is very likely to be the case.
virtio-rnginterface is available. If this is a cloud service and the hypervisor settings are out of your reach, consider switching to a different service.
/proc/sys/kernel/random/entropy_availagain. If the value didn't go any higher, install
sodium_init(), and occasionally afterwards.
RDSEEDCPU instruction to seed the kernel RNG (not recommended as a unique entropy source).
random.trust_cpu=onin the kernel command line (requires Linux kernel > 4.19).
sodium_init()using code similar to the following: