Merge remote-tracking branch 'arbinger/pnacl' into nacl

* arbinger/pnacl:
  removed comment
  Added .final and .nexe output files to CLEANFILES
  revert original hack
  Initial patch for Chrome NaCl implementation
  Added patch to obtain random bytes for Chrome NaCl via IRT -- allows build with NaCl SDK toolchain
This commit is contained in:
Frank Denis 2015-08-02 12:54:05 +02:00
commit f610f781f2
10 changed files with 264 additions and 2 deletions

View File

@ -430,6 +430,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])

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1,39 @@
#ifndef randombytes_nativeclient_H
#define randombytes_nativeclient_H
#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

View File

@ -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
};

View File

@ -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

View File

@ -122,6 +122,122 @@ DISTCLEANFILES = \
stream4.res \
verify1.res
if NATIVECLIENT
CLEANFILES = \
aead_chacha20poly1305.final \
auth.final \
auth2.final \
auth3.final \
auth5.final \
auth6.final \
auth7.final \
box.final \
box2.final \
box7.final \
box8.final \
box_easy.final \
box_easy2.final \
box_seal.final \
box_seed.final \
chacha20.final \
core1.final \
core2.final \
core3.final \
core4.final \
core5.final \
core6.final \
ed25519_convert.final \
generichash.final \
generichash2.final \
generichash3.final \
hash.final \
hash2.final \
hash3.final \
onetimeauth.final \
onetimeauth2.final \
onetimeauth7.final \
pwhash.final \
pwhash_scrypt_ll.final \
randombytes.final \
scalarmult.final \
scalarmult2.final \
scalarmult5.final \
scalarmult6.final \
scalarmult7.final \
secretbox.final \
secretbox2.final \
secretbox7.final \
secretbox8.final \
secretbox_easy.final \
secretbox_easy2.final \
shorthash.final \
sign.final \
sodium_core.final \
sodium_utils.final \
sodium_version.final \
stream.final \
stream2.final \
stream3.final \
stream4.final \
verify1.final \
aead_chacha20poly1305.nexe \
auth.nexe \
auth2.nexe \
auth3.nexe \
auth5.nexe \
auth6.nexe \
auth7.nexe \
box.nexe \
box2.nexe \
box7.nexe \
box8.nexe \
box_easy.nexe \
box_easy2.nexe \
box_seal.nexe \
box_seed.nexe \
chacha20.nexe \
core1.nexe \
core2.nexe \
core3.nexe \
core4.nexe \
core5.nexe \
core6.nexe \
ed25519_convert.nexe \
generichash.nexe \
generichash2.nexe \
generichash3.nexe \
hash.nexe \
hash2.nexe \
hash3.nexe \
onetimeauth.nexe \
onetimeauth2.nexe \
onetimeauth7.nexe \
pwhash.nexe \
pwhash_scrypt_ll.nexe \
randombytes.nexe \
scalarmult.nexe \
scalarmult2.nexe \
scalarmult5.nexe \
scalarmult6.nexe \
scalarmult7.nexe \
secretbox.nexe \
secretbox2.nexe \
secretbox7.nexe \
secretbox8.nexe \
secretbox_easy.nexe \
secretbox_easy2.nexe \
shorthash.nexe \
sign.nexe \
sodium_core.nexe \
sodium_utils.nexe \
sodium_version.nexe \
stream.nexe \
stream2.nexe \
stream3.nexe \
stream4.nexe \
verify1.nexe
endif
AM_CPPFLAGS = \
-DTEST_SRCDIR=\"@srcdir@\" \
-I$(top_srcdir)/src/libsodium/include \
@ -190,10 +306,12 @@ TESTS_TARGETS = \
verify1
if !EMSCRIPTEN
if !NATIVECLIENT
TESTS_TARGETS += \
sodium_utils2 \
sodium_utils3
endif
endif
check_PROGRAMS = $(TESTS_TARGETS)
@ -373,4 +491,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

View 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"

View File

@ -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;