mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Mark randombytes_implementation functions static
This commit is contained in:
@@ -4,33 +4,19 @@
|
||||
|
||||
#ifdef __native_client__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
# include "export.h"
|
||||
# include "randombytes.h"
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_nativeclient_implementation;
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_nativeclient_implementation_name(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_nativeclient(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_nativeclient_uniform(const uint32_t upper_bound);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_nativeclient_buf(void * const buf, const size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,17 +2,8 @@
|
||||
#ifndef randombytes_salsa20_random_H
|
||||
#define randombytes_salsa20_random_H
|
||||
|
||||
/*
|
||||
* THREAD SAFETY: randombytes_salsa20_random*() functions are
|
||||
* not thread-safe.
|
||||
* Always wrap them in a mutex if you need thread safety,
|
||||
* and call randombytes_stir() after fork()ing.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "export.h"
|
||||
#include "randombytes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -21,24 +12,6 @@ extern "C" {
|
||||
SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_salsa20_implementation;
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_salsa20_implementation_name(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_salsa20_random(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_salsa20_random_stir(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_salsa20_random_uniform(const uint32_t upper_bound);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_salsa20_random_buf(void * const buf, const size_t size);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int randombytes_salsa20_random_close(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2,16 +2,8 @@
|
||||
#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 <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "export.h"
|
||||
#include "randombytes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -20,24 +12,6 @@ extern "C" {
|
||||
SODIUM_EXPORT
|
||||
extern struct randombytes_implementation randombytes_sysrandom_implementation;
|
||||
|
||||
SODIUM_EXPORT
|
||||
const char *randombytes_sysrandom_implementation_name(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_sysrandom(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_sysrandom_stir(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
uint32_t randombytes_sysrandom_uniform(const uint32_t upper_bound);
|
||||
|
||||
SODIUM_EXPORT
|
||||
void randombytes_sysrandom_buf(void * const buf, const size_t size);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int randombytes_sysrandom_close(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# include "randombytes.h"
|
||||
# include "randombytes_nativeclient.h"
|
||||
|
||||
void
|
||||
static void
|
||||
randombytes_nativeclient_buf(void * const buf, const size_t size)
|
||||
{
|
||||
size_t readnb;
|
||||
@@ -21,7 +21,7 @@ randombytes_nativeclient_buf(void * const buf, const size_t size)
|
||||
assert(readnb == size);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
static uint32_t
|
||||
randombytes_nativeclient_random(void)
|
||||
{
|
||||
uint32_t r;
|
||||
@@ -31,7 +31,7 @@ randombytes_nativeclient_random(void)
|
||||
return r;
|
||||
}
|
||||
|
||||
const char *
|
||||
static const char *
|
||||
randombytes_nativeclient_implementation_name(void)
|
||||
{
|
||||
return "nativeclient";
|
||||
|
||||
@@ -250,7 +250,7 @@ randombytes_salsa20_random_rekey(const unsigned char * const mix)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
randombytes_salsa20_random_stir(void)
|
||||
{
|
||||
/* constant to personalize the hash function */
|
||||
@@ -325,35 +325,7 @@ randombytes_salsa20_random_stir_if_needed(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
randombytes_salsa20_random_getword(void)
|
||||
{
|
||||
uint32_t val;
|
||||
int ret;
|
||||
|
||||
COMPILER_ASSERT(sizeof stream.rnd32 >= (sizeof stream.key) + (sizeof val));
|
||||
COMPILER_ASSERT(((sizeof stream.rnd32) - (sizeof stream.key))
|
||||
% sizeof val == (size_t) 0U);
|
||||
if (stream.rnd32_outleft <= (size_t) 0U) {
|
||||
randombytes_salsa20_random_stir_if_needed();
|
||||
COMPILER_ASSERT(sizeof stream.nonce == crypto_stream_salsa20_NONCEBYTES);
|
||||
ret = crypto_stream_salsa20((unsigned char *) stream.rnd32,
|
||||
(unsigned long long) sizeof stream.rnd32,
|
||||
(unsigned char *) &stream.nonce,
|
||||
stream.key);
|
||||
assert(ret == 0);
|
||||
stream.rnd32_outleft = (sizeof stream.rnd32) - (sizeof stream.key);
|
||||
randombytes_salsa20_random_rekey(&stream.rnd32[stream.rnd32_outleft]);
|
||||
stream.nonce++;
|
||||
}
|
||||
stream.rnd32_outleft -= sizeof val;
|
||||
memcpy(&val, &stream.rnd32[stream.rnd32_outleft], sizeof val);
|
||||
memset(&stream.rnd32[stream.rnd32_outleft], 0, sizeof val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
randombytes_salsa20_random_close(void)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -388,13 +360,7 @@ randombytes_salsa20_random_close(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
randombytes_salsa20_random(void)
|
||||
{
|
||||
return randombytes_salsa20_random_getword();
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
randombytes_salsa20_random_buf(void * const buf, const size_t size)
|
||||
{
|
||||
size_t i;
|
||||
@@ -417,7 +383,41 @@ randombytes_salsa20_random_buf(void * const buf, const size_t size)
|
||||
(unsigned char *) &stream.nonce, stream.key);
|
||||
}
|
||||
|
||||
const char *
|
||||
static uint32_t
|
||||
randombytes_salsa20_random_getword(void)
|
||||
{
|
||||
uint32_t val;
|
||||
int ret;
|
||||
|
||||
COMPILER_ASSERT(sizeof stream.rnd32 >= (sizeof stream.key) + (sizeof val));
|
||||
COMPILER_ASSERT(((sizeof stream.rnd32) - (sizeof stream.key))
|
||||
% sizeof val == (size_t) 0U);
|
||||
if (stream.rnd32_outleft <= (size_t) 0U) {
|
||||
randombytes_salsa20_random_stir_if_needed();
|
||||
COMPILER_ASSERT(sizeof stream.nonce == crypto_stream_salsa20_NONCEBYTES);
|
||||
ret = crypto_stream_salsa20((unsigned char *) stream.rnd32,
|
||||
(unsigned long long) sizeof stream.rnd32,
|
||||
(unsigned char *) &stream.nonce,
|
||||
stream.key);
|
||||
assert(ret == 0);
|
||||
stream.rnd32_outleft = (sizeof stream.rnd32) - (sizeof stream.key);
|
||||
randombytes_salsa20_random_rekey(&stream.rnd32[stream.rnd32_outleft]);
|
||||
stream.nonce++;
|
||||
}
|
||||
stream.rnd32_outleft -= sizeof val;
|
||||
memcpy(&val, &stream.rnd32[stream.rnd32_outleft], sizeof val);
|
||||
memset(&stream.rnd32[stream.rnd32_outleft], 0, sizeof val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
randombytes_salsa20_random(void)
|
||||
{
|
||||
return randombytes_salsa20_random_getword();
|
||||
}
|
||||
|
||||
static const char *
|
||||
randombytes_salsa20_implementation_name(void)
|
||||
{
|
||||
return "salsa20";
|
||||
|
||||
@@ -39,24 +39,24 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
|
||||
|
||||
#ifdef HAVE_SAFE_ARC4RANDOM
|
||||
|
||||
uint32_t
|
||||
static uint32_t
|
||||
randombytes_sysrandom(void)
|
||||
{
|
||||
return arc4random();
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
randombytes_sysrandom_stir(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
randombytes_sysrandom_buf(void * const buf, const size_t size)
|
||||
{
|
||||
return arc4random_buf(buf, size);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
randombytes_sysrandom_close(void)
|
||||
{
|
||||
return 0;
|
||||
@@ -214,7 +214,7 @@ randombytes_sysrandom_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
static void
|
||||
randombytes_sysrandom_stir(void)
|
||||
{
|
||||
if (stream.initialized == 0) {
|
||||
@@ -231,7 +231,7 @@ randombytes_sysrandom_stir_if_needed(void)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
randombytes_sysrandom_close(void)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -257,17 +257,7 @@ randombytes_sysrandom_close(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
randombytes_sysrandom(void)
|
||||
{
|
||||
uint32_t r;
|
||||
|
||||
randombytes_sysrandom_buf(&r, sizeof r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
randombytes_sysrandom_buf(void * const buf, const size_t size)
|
||||
{
|
||||
randombytes_sysrandom_stir_if_needed();
|
||||
@@ -298,9 +288,19 @@ randombytes_sysrandom_buf(void * const buf, const size_t size)
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
randombytes_sysrandom(void)
|
||||
{
|
||||
uint32_t r;
|
||||
|
||||
randombytes_sysrandom_buf(&r, sizeof r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* __OpenBSD__ */
|
||||
|
||||
const char *
|
||||
static const char *
|
||||
randombytes_sysrandom_implementation_name(void)
|
||||
{
|
||||
return "sysrandom";
|
||||
|
||||
Reference in New Issue
Block a user