Initial patch for Chrome NaCl implementation
This commit is contained in:
parent
a678c09ea3
commit
34a4931d9a
@ -428,6 +428,8 @@ AS_IF([test "x$EMSCRIPTEN" != "x"],[
|
||||
AC_SUBST(TEST_LDFLAGS)
|
||||
AM_CONDITIONAL([EMSCRIPTEN], [test "x$EMSCRIPTEN" != "x"])
|
||||
|
||||
AM_CONDITIONAL([NATIVECLIENT], [test "x$NATIVECLIENT" != "x"])
|
||||
|
||||
dnl Libtool.
|
||||
|
||||
LT_INIT([dlopen])
|
||||
|
@ -157,8 +157,14 @@ libsodium_la_SOURCES = \
|
||||
|
||||
if !EMSCRIPTEN
|
||||
libsodium_la_SOURCES += \
|
||||
randombytes/salsa20/randombytes_salsa20_random.c \
|
||||
randombytes/sysrandom/randombytes_sysrandom.c
|
||||
randombytes/salsa20/randombytes_salsa20_random.c
|
||||
if NATIVECLIENT
|
||||
libsodium_la_SOURCES += \
|
||||
randombytes/nativeclient/randombytes_nativeclient.c
|
||||
else
|
||||
libsodium_la_SOURCES += \
|
||||
randombytes/sysrandom/randombytes_sysrandom.c
|
||||
endif
|
||||
endif
|
||||
|
||||
if HAVE_TI_MODE
|
||||
|
@ -50,6 +50,7 @@ SODIUM_EXPORT = \
|
||||
sodium/randombytes.h \
|
||||
sodium/randombytes_salsa20_random.h \
|
||||
sodium/randombytes_sysrandom.h \
|
||||
sodium/randombytes_nativeclient.h \
|
||||
sodium/runtime.h \
|
||||
sodium/utils.h
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "sodium/randombytes.h"
|
||||
#include "sodium/randombytes_salsa20_random.h"
|
||||
#include "sodium/randombytes_sysrandom.h"
|
||||
#include "sodium/randombytes_nativeclient.h"
|
||||
#include "sodium/runtime.h"
|
||||
#include "sodium/utils.h"
|
||||
#include "sodium/version.h"
|
||||
|
43
src/libsodium/include/sodium/randombytes_nativeclient.h
Normal file
43
src/libsodium/include/sodium/randombytes_nativeclient.h
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#ifndef randombytes_nativeclient_H
|
||||
#define randombytes_nativeclient_H
|
||||
|
||||
/*
|
||||
* THREAD SAFETY: TODO
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#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
|
||||
void randombytes_nativeclient_stir(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);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int randombytes_nativeclient_close(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,56 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nacl/nacl_random.h"
|
||||
#include "utils.h"
|
||||
#include "randombytes.h"
|
||||
#include "randombytes_nativeclient.h"
|
||||
|
||||
void
|
||||
randombytes_nativeclient_random_stir(void)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
randombytes_nativeclient_random_close(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
randombytes_nativeclient_random(void)
|
||||
{
|
||||
uint32_t r;
|
||||
|
||||
randombytes_nativeclient_buf(&r, sizeof r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
randombytes_nativeclient_buf(void * const buf, const size_t size)
|
||||
{
|
||||
size_t readnb;
|
||||
|
||||
if (nacl_secure_random(buf, size, &readnb) != 0) {
|
||||
abort();
|
||||
}
|
||||
|
||||
assert(readnb == size);
|
||||
}
|
||||
|
||||
const char *
|
||||
randombytes_nativeclient_implementation_name(void)
|
||||
{
|
||||
return "nativeclient";
|
||||
}
|
||||
|
||||
struct randombytes_implementation randombytes_nativeclient_implementation = {
|
||||
SODIUM_C99(.implementation_name =) randombytes_nativeclient_implementation_name,
|
||||
SODIUM_C99(.random =) randombytes_nativeclient_random,
|
||||
SODIUM_C99(.stir =) randombytes_nativeclient_random_stir,
|
||||
SODIUM_C99(.uniform =) NULL,
|
||||
SODIUM_C99(.buf =) randombytes_nativeclient_buf,
|
||||
SODIUM_C99(.close =) randombytes_nativeclient_random_close
|
||||
};
|
@ -11,10 +11,16 @@
|
||||
|
||||
#include "randombytes.h"
|
||||
#include "randombytes_sysrandom.h"
|
||||
#include "randombytes_nativeclient.h"
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#ifdef __native_client__
|
||||
static const randombytes_implementation *implementation =
|
||||
&randombytes_nativeclient_implementation;
|
||||
#else
|
||||
static const randombytes_implementation *implementation =
|
||||
&randombytes_sysrandom_implementation;
|
||||
#endif
|
||||
#else
|
||||
static const randombytes_implementation *implementation = NULL;
|
||||
#endif
|
||||
|
@ -190,10 +190,12 @@ TESTS_TARGETS = \
|
||||
verify1
|
||||
|
||||
if !EMSCRIPTEN
|
||||
if !NATIVECLIENT
|
||||
TESTS_TARGETS += \
|
||||
sodium_utils2 \
|
||||
sodium_utils3
|
||||
endif
|
||||
endif
|
||||
|
||||
check_PROGRAMS = $(TESTS_TARGETS)
|
||||
|
||||
@ -373,4 +375,8 @@ stream4_LDADD = $(TESTS_LDADD)
|
||||
verify1_SOURCE = cmptest.h verify1.c
|
||||
verify1_LDADD = $(TESTS_LDADD)
|
||||
|
||||
if NATIVECLIENT
|
||||
LOG_COMPILER = ./nacl-test-wrapper.sh
|
||||
endif
|
||||
|
||||
verify: check
|
||||
|
25
test/default/nacl-test-wrapper.sh
Executable file
25
test/default/nacl-test-wrapper.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$NACL_SDK_ROOT" -o -z "$PNACL_TRANSLATE" -o -z "$PNACL_FINALIZE" ]
|
||||
then
|
||||
echo "One or more variables need to be set:
|
||||
\$NACL_SDK_ROOT=$NACL_SDK_ROOT
|
||||
\$PNACL_TRANSLATE=$PNACL_TRANSLATE
|
||||
\$PNACL_FINALIZE=$PNACL_FINALIZE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$1.nexe" ]
|
||||
then
|
||||
$PNACL_FINALIZE "$1" -o "$1.final"
|
||||
$PNACL_TRANSLATE -arch `uname -m` "$1.final" -o "$1.nexe"
|
||||
fi
|
||||
|
||||
command -v python >/dev/null 2>&1 || { echo >&2 "I require python but it's not installed. Aborting."; exit 1; }
|
||||
ANY=(`find $NACL_SDK_ROOT -name sel_ldr.py`)
|
||||
if [ -z ${ANY[0]} ]
|
||||
then
|
||||
echo "Couldn't find a sel_ldr.py under $NACL_SDK_ROOT"
|
||||
exit 1
|
||||
fi
|
||||
python ${ANY[0]} "$1.nexe"
|
@ -105,7 +105,11 @@ static uint32_t randombytes_uniform_impl(const uint32_t upper_bound)
|
||||
|
||||
static int impl_tests(void)
|
||||
{
|
||||
#ifndef __native_client__
|
||||
randombytes_implementation impl = randombytes_sysrandom_implementation;
|
||||
#else
|
||||
randombytes_implementation impl = randombytes_nativeclient_implementation;
|
||||
#endif
|
||||
uint32_t v = randombytes_random();
|
||||
|
||||
impl.uniform = randombytes_uniform_impl;
|
||||
|
Loading…
Reference in New Issue
Block a user