From 7fca230be81bb52a33b48826e5072f9db35f7119 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 2 Aug 2015 13:53:22 +0200 Subject: [PATCH] Nits after pnacl merge --- .gitignore | 2 + configure.ac | 2 + src/libsodium/Makefile.am | 2 + src/libsodium/include/Makefile.am | 6 ++- src/libsodium/include/sodium.h | 4 +- .../include/sodium/randombytes_nativeclient.h | 10 ++--- .../nativeclient/randombytes_nativeclient.c | 41 ++++++++----------- src/libsodium/randombytes/randombytes.c | 5 ++- test/default/nacl-test-wrapper.sh | 2 +- 9 files changed, 40 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 9adea7ab..9e1388ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ *.cmake *.dSYM *.exp +*.final *.gcda *.gcno *.la *.lo *.log *.mem +*.nexe *.o *.plist *.scan diff --git a/configure.ac b/configure.ac index 72a85f9f..79c7dbb2 100644 --- a/configure.ac +++ b/configure.ac @@ -143,6 +143,8 @@ AC_PROG_CC_C99 AM_PROG_AS AC_USE_SYSTEM_EXTENSIONS +AC_CHECK_DEFINE([__native_client__], [NATIVECLIENT="yes"], []) + AC_CHECK_DEFINE([_FORTIFY_SOURCE], [], [ AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=2], [CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"]) diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index ec265f81..55c0dffd 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -158,6 +158,7 @@ libsodium_la_SOURCES = \ if !EMSCRIPTEN libsodium_la_SOURCES += \ randombytes/salsa20/randombytes_salsa20_random.c + if NATIVECLIENT libsodium_la_SOURCES += \ randombytes/nativeclient/randombytes_nativeclient.c @@ -165,6 +166,7 @@ else libsodium_la_SOURCES += \ randombytes/sysrandom/randombytes_sysrandom.c endif + endif if HAVE_TI_MODE diff --git a/src/libsodium/include/Makefile.am b/src/libsodium/include/Makefile.am index a86b5817..77e01eac 100644 --- a/src/libsodium/include/Makefile.am +++ b/src/libsodium/include/Makefile.am @@ -50,10 +50,14 @@ SODIUM_EXPORT = \ sodium/randombytes.h \ sodium/randombytes_salsa20_random.h \ sodium/randombytes_sysrandom.h \ - sodium/randombytes_nativeclient.h \ sodium/runtime.h \ sodium/utils.h +if NATIVECLIENT +SODIUM_EXPORT += \ + sodium/randombytes_nativeclient.h +endif + EXTRA_SRC = $(SODIUM_EXPORT) \ sodium/version.h.in diff --git a/src/libsodium/include/sodium.h b/src/libsodium/include/sodium.h index 7e9e13e8..97280f93 100644 --- a/src/libsodium/include/sodium.h +++ b/src/libsodium/include/sodium.h @@ -41,9 +41,11 @@ #include "sodium/crypto_verify_32.h" #include "sodium/crypto_verify_64.h" #include "sodium/randombytes.h" +#ifdef __native_client__ +# include "sodium/randombytes_nativeclient.h" +#endif #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" diff --git a/src/libsodium/include/sodium/randombytes_nativeclient.h b/src/libsodium/include/sodium/randombytes_nativeclient.h index 134349cb..07666cb6 100644 --- a/src/libsodium/include/sodium/randombytes_nativeclient.h +++ b/src/libsodium/include/sodium/randombytes_nativeclient.h @@ -2,6 +2,8 @@ #ifndef randombytes_nativeclient_H #define randombytes_nativeclient_H +#ifdef __native_client__ + #include #include @@ -20,20 +22,16 @@ 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 + +#endif diff --git a/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c b/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c index f0a997e7..034304ce 100644 --- a/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +++ b/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c @@ -1,21 +1,24 @@ + #include #include #include -#include "nacl/nacl_random.h" -#include "utils.h" -#include "randombytes.h" -#include "randombytes_nativeclient.h" +#ifdef __native_client__ +# include + +# include "utils.h" +# include "randombytes.h" +# include "randombytes_nativeclient.h" void -randombytes_nativeclient_random_stir(void) +randombytes_nativeclient_buf(void * const buf, const size_t size) { -} + size_t readnb; -int -randombytes_nativeclient_random_close(void) -{ - return 0; + if (nacl_secure_random(buf, size, &readnb) != 0) { + abort(); + } + assert(readnb == size); } uint32_t @@ -28,18 +31,6 @@ randombytes_nativeclient_random(void) 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) { @@ -49,8 +40,10 @@ randombytes_nativeclient_implementation_name(void) 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(.stir =) NULL, SODIUM_C99(.uniform =) NULL, SODIUM_C99(.buf =) randombytes_nativeclient_buf, - SODIUM_C99(.close =) randombytes_nativeclient_random_close + SODIUM_C99(.close =) NULL }; + +#endif diff --git a/src/libsodium/randombytes/randombytes.c b/src/libsodium/randombytes/randombytes.c index 29becfc0..e9e0e513 100644 --- a/src/libsodium/randombytes/randombytes.c +++ b/src/libsodium/randombytes/randombytes.c @@ -11,7 +11,10 @@ #include "randombytes.h" #include "randombytes_sysrandom.h" -#include "randombytes_nativeclient.h" + +#ifdef __native_client__ +# include "randombytes_nativeclient.h" +#endif #ifndef __EMSCRIPTEN__ #ifdef __native_client__ diff --git a/test/default/nacl-test-wrapper.sh b/test/default/nacl-test-wrapper.sh index 85053515..5b5468af 100755 --- a/test/default/nacl-test-wrapper.sh +++ b/test/default/nacl-test-wrapper.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#! /usr/bin/env bash if [ -z "$NACL_SDK_ROOT" -o -z "$PNACL_TRANSLATE" -o -z "$PNACL_FINALIZE" ] then