From edc5faffd625286e807f9f770db9dd523d24df38 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 26 Apr 2013 17:27:55 -0700 Subject: [PATCH] Add more information about thread safety until we provide a thread-safe API. --- README.markdown | 2 +- src/libsodium/include/sodium/crypto_box.h | 7 +++++++ src/libsodium/include/sodium/crypto_sign.h | 7 +++++++ src/libsodium/include/sodium/randombytes_salsa20_random.h | 6 ++++++ src/libsodium/include/sodium/randombytes_sysrandom.h | 6 ++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 0714325d..46029b2d 100644 --- a/README.markdown +++ b/README.markdown @@ -94,7 +94,7 @@ Sodium also provides helper functions to generate random numbers, leveraging `/dev/urandom` or `/dev/random` on *nix and the cryptographic service provider on Windows. The interface is similar to `arc4random(3)`. It is `fork(2)`-safe but not thread-safe. This holds -true for `crypto_sign_keypair()` as well. +true for `crypto_sign_keypair()` and `crypto_box_keypair()` as well. uint32_t randombytes_random(void); diff --git a/src/libsodium/include/sodium/crypto_box.h b/src/libsodium/include/sodium/crypto_box.h index 11cf4279..ec2c1f86 100644 --- a/src/libsodium/include/sodium/crypto_box.h +++ b/src/libsodium/include/sodium/crypto_box.h @@ -1,6 +1,13 @@ #ifndef crypto_box_H #define crypto_box_H +/* + * THREAD SAFETY: crypto_box_keypair() is thread-safe, + * provided that you called sodium_init() once before using any + * other libsodium function. + * Other functions are always thread-safe. + */ + #include #include "crypto_box_curve25519xsalsa20poly1305.h" diff --git a/src/libsodium/include/sodium/crypto_sign.h b/src/libsodium/include/sodium/crypto_sign.h index dd7d9e5a..d8de83c6 100644 --- a/src/libsodium/include/sodium/crypto_sign.h +++ b/src/libsodium/include/sodium/crypto_sign.h @@ -1,6 +1,13 @@ #ifndef crypto_sign_H #define crypto_sign_H +/* + * THREAD SAFETY: crypto_sign_keypair() is thread-safe, + * provided that you called sodium_init() once before using any + * other libsodium function. + * Other functions, including crypto_sign_seed_keypair() are always thread-safe. + */ + #include #include "crypto_sign_ed25519.h" diff --git a/src/libsodium/include/sodium/randombytes_salsa20_random.h b/src/libsodium/include/sodium/randombytes_salsa20_random.h index f6b66b7c..377c1440 100644 --- a/src/libsodium/include/sodium/randombytes_salsa20_random.h +++ b/src/libsodium/include/sodium/randombytes_salsa20_random.h @@ -2,6 +2,12 @@ #ifndef randombytes_salsa20_random_H #define randombytes_salsa20_random_H +/* + * THREAD SAFETY: randombytes_salsa20_random*() functions are + * fork()-safe but not thread-safe. + * Always wrap them in a mutex if you need thread safety. + */ + #include #include diff --git a/src/libsodium/include/sodium/randombytes_sysrandom.h b/src/libsodium/include/sodium/randombytes_sysrandom.h index 49ec967d..0ef09ea8 100644 --- a/src/libsodium/include/sodium/randombytes_sysrandom.h +++ b/src/libsodium/include/sodium/randombytes_sysrandom.h @@ -2,6 +2,12 @@ #ifndef randombytes_sysrandom_H #define randombytes_sysrandom_H +/* + * THREAD SAFETY: randombytes_sysrandom() functions are thread-safe, + * provided that you called sodium_init() once before using any + * other libsodium function. + */ + #include #include