mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-24 12:36:01 -07:00
Set randombytes_implementation to NULL by default, to cope with Visual Studio 2008
This commit is contained in:
parent
a53a9c98d2
commit
80310ef56c
@ -20,18 +20,27 @@
|
|||||||
/* C++Builder defines a "random" macro */
|
/* C++Builder defines a "random" macro */
|
||||||
#undef random
|
#undef random
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
static const randombytes_implementation *implementation;
|
||||||
#ifdef __native_client__
|
|
||||||
static const randombytes_implementation *implementation =
|
#ifdef __EMSCRIPTEN__
|
||||||
&randombytes_nativeclient_implementation;
|
# define RANDOMBYTES_DEFAULT_IMPLEMENTATION NULL
|
||||||
#else
|
#else
|
||||||
static const randombytes_implementation *implementation =
|
# ifdef __native_client__
|
||||||
&randombytes_sysrandom_implementation;
|
# define RANDOMBYTES_DEFAULT_IMPLEMENTATION &randombytes_nativeclient_implementation;
|
||||||
#endif
|
# else
|
||||||
#else
|
# define RANDOMBYTES_DEFAULT_IMPLEMENTATION &randombytes_sysrandom_implementation;
|
||||||
static const randombytes_implementation *implementation = NULL;
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
randombytes_init_if_needed(void)
|
||||||
|
{
|
||||||
|
if (implementation == NULL) {
|
||||||
|
implementation = RANDOMBYTES_DEFAULT_IMPLEMENTATION;
|
||||||
|
implementation->stir();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
randombytes_set_implementation(randombytes_implementation *impl)
|
randombytes_set_implementation(randombytes_implementation *impl)
|
||||||
{
|
{
|
||||||
@ -44,6 +53,7 @@ const char *
|
|||||||
randombytes_implementation_name(void)
|
randombytes_implementation_name(void)
|
||||||
{
|
{
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
|
randombytes_init_if_needed();
|
||||||
return implementation->implementation_name();
|
return implementation->implementation_name();
|
||||||
#else
|
#else
|
||||||
return "js";
|
return "js";
|
||||||
@ -54,6 +64,7 @@ uint32_t
|
|||||||
randombytes_random(void)
|
randombytes_random(void)
|
||||||
{
|
{
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
|
randombytes_init_if_needed();
|
||||||
return implementation->random();
|
return implementation->random();
|
||||||
#else
|
#else
|
||||||
return EM_ASM_INT_V({
|
return EM_ASM_INT_V({
|
||||||
@ -66,9 +77,7 @@ void
|
|||||||
randombytes_stir(void)
|
randombytes_stir(void)
|
||||||
{
|
{
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
if (implementation != NULL && implementation->stir != NULL) {
|
randombytes_init_if_needed();
|
||||||
implementation->stir();
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
EM_ASM({
|
EM_ASM({
|
||||||
if (Module.getRandomValue === undefined) {
|
if (Module.getRandomValue === undefined) {
|
||||||
@ -110,11 +119,8 @@ randombytes_uniform(const uint32_t upper_bound)
|
|||||||
uint32_t min;
|
uint32_t min;
|
||||||
uint32_t r;
|
uint32_t r;
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
if (implementation != NULL && implementation->uniform != NULL) {
|
randombytes_init_if_needed();
|
||||||
return implementation->uniform(upper_bound);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (implementation->uniform != NULL) {
|
if (implementation->uniform != NULL) {
|
||||||
return implementation->uniform(upper_bound);
|
return implementation->uniform(upper_bound);
|
||||||
}
|
}
|
||||||
@ -134,6 +140,7 @@ void
|
|||||||
randombytes_buf(void * const buf, const size_t size)
|
randombytes_buf(void * const buf, const size_t size)
|
||||||
{
|
{
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
|
randombytes_init_if_needed();
|
||||||
if (size > (size_t) 0U) {
|
if (size > (size_t) 0U) {
|
||||||
implementation->buf(buf, size);
|
implementation->buf(buf, size);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user