mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-24 12:36:01 -07:00
Better document why sodium_init() should be used if thread safety is required
This commit is contained in:
parent
9927b7460e
commit
0331a0da97
@ -112,20 +112,19 @@ A convenience header includes everything you need to use the library:
|
|||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
|
||||||
This is not required, however, before any other libsodium function, you can
|
This is not required, however, before any other libsodium function, it
|
||||||
call:
|
is recommended to call:
|
||||||
|
|
||||||
sodium_init();
|
sodium_init();
|
||||||
|
|
||||||
This will pick optimized implementations of some primitives, if they
|
This will pick optimized implementations of some primitives, if they
|
||||||
appear to work as expected after running some tests, and these will be
|
appear to work as expected after running some tests, and these will be
|
||||||
used for subsequent operations. It only need to be called once.
|
used for subsequent operations.
|
||||||
|
It will also initialize the pseudorandom number generator.
|
||||||
This function is not thread-safe. No other Sodium functions should be
|
This function should only be called once, and before performing any other
|
||||||
called until it successfully returns. In a multithreading environment,
|
operations.
|
||||||
if, for some reason, you really need to call `sodium_init()` while some
|
Doing so is required to ensure thread safety of all the functions provided by
|
||||||
other Sodium functions may be running in different threads, add locks
|
the library.
|
||||||
accordingly (both around `sodium_init()` and around other functions).
|
|
||||||
|
|
||||||
Sodium also provides helper functions to generate random numbers,
|
Sodium also provides helper functions to generate random numbers,
|
||||||
leveraging `/dev/urandom` or `/dev/random` on *nix and the cryptographic
|
leveraging `/dev/urandom` or `/dev/random` on *nix and the cryptographic
|
||||||
|
Loading…
Reference in New Issue
Block a user