rbnacl-libsodium 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/ChangeLog +20 -0
- data/vendor/libsodium/LICENSE +1 -1
- data/vendor/libsodium/Makefile.in +8 -4
- data/vendor/libsodium/THANKS +3 -0
- data/vendor/libsodium/autom4te.cache/output.1 +96 -57
- data/vendor/libsodium/autom4te.cache/output.3 +96 -57
- data/vendor/libsodium/autom4te.cache/requests +544 -544
- data/vendor/libsodium/autom4te.cache/traces.1 +386 -367
- data/vendor/libsodium/autom4te.cache/traces.3 +222 -213
- data/vendor/libsodium/builds/msvc/version.h +2 -2
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.props +1 -1
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.props +1 -1
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.props +1 -1
- data/vendor/libsodium/configure +95 -56
- data/vendor/libsodium/configure.ac +26 -11
- data/vendor/libsodium/dist-build/Makefile.am +1 -0
- data/vendor/libsodium/dist-build/Makefile.in +2 -0
- data/vendor/libsodium/dist-build/emscripten.sh +48 -10
- data/vendor/libsodium/dist-build/ios.sh +59 -7
- data/vendor/libsodium/libsodium-uninstalled.pc.in +6 -0
- data/vendor/libsodium/msvc-scripts/Makefile.in +1 -0
- data/vendor/libsodium/msvc-scripts/process.bat +2 -2
- data/vendor/libsodium/msvc-scripts/sodium.props +2 -2
- data/vendor/libsodium/src/Makefile.in +1 -0
- data/vendor/libsodium/src/libsodium/Makefile.in +1 -0
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +46 -4
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/box_curve25519xsalsa20poly1305.c +13 -2
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +8 -2
- data/vendor/libsodium/src/libsodium/crypto_sign/crypto_sign.c +6 -6
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +3 -1
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +13 -6
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +8 -8
- data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/ref/sign_edwards25519sha512batch.c +10 -6
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c +11 -5
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c +11 -5
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c +11 -5
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c +11 -5
- data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c +5 -1
- data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c +5 -1
- data/vendor/libsodium/src/libsodium/include/Makefile.in +1 -0
- data/vendor/libsodium/src/libsodium/include/sodium.h +44 -44
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +61 -36
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +0 -10
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +20 -18
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +3 -3
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +3 -3
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +2 -2
- data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +1 -1
- data/vendor/libsodium/src/libsodium/include/sodium/utils.h +10 -3
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +9 -2
- data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +9 -2
- data/vendor/libsodium/src/libsodium/sodium/utils.c +97 -72
- data/vendor/libsodium/test/Makefile.in +1 -0
- data/vendor/libsodium/test/default/Makefile.am +9 -2
- data/vendor/libsodium/test/default/Makefile.in +38 -78
- data/vendor/libsodium/test/default/box_easy2.c +55 -10
- data/vendor/libsodium/test/default/box_easy2.exp +3 -0
- data/vendor/libsodium/test/default/cmptest.h +4 -0
- data/vendor/libsodium/test/default/{pre.js → pre.js.inc} +10 -4
- data/vendor/libsodium/test/default/pwhash.c +6 -4
- data/vendor/libsodium/test/default/scalarmult6.c +0 -2
- data/vendor/libsodium/test/default/sign.c +1 -1
- data/vendor/libsodium/test/default/sodium_utils2.c +5 -2
- data/vendor/libsodium/test/default/sodium_utils3.c +3 -1
- metadata +5 -4
@@ -190,6 +190,7 @@ SODIUM_LIBRARY_VERSION = @SODIUM_LIBRARY_VERSION@
|
|
190
190
|
SODIUM_LIBRARY_VERSION_MAJOR = @SODIUM_LIBRARY_VERSION_MAJOR@
|
191
191
|
SODIUM_LIBRARY_VERSION_MINOR = @SODIUM_LIBRARY_VERSION_MINOR@
|
192
192
|
STRIP = @STRIP@
|
193
|
+
TEST_LDFLAGS = @TEST_LDFLAGS@
|
193
194
|
VERSION = @VERSION@
|
194
195
|
abs_builddir = @abs_builddir@
|
195
196
|
abs_srcdir = @abs_srcdir@
|
@@ -246,6 +247,7 @@ top_srcdir = @top_srcdir@
|
|
246
247
|
EXTRA_DIST = \
|
247
248
|
android-build.sh \
|
248
249
|
android-arm.sh \
|
250
|
+
android-armv7.sh \
|
249
251
|
android-x86.sh \
|
250
252
|
android-mips.sh \
|
251
253
|
emscripten.sh \
|
@@ -1,14 +1,52 @@
|
|
1
1
|
#! /bin/sh
|
2
2
|
|
3
|
+
export MAKE_FLAGS='-j4'
|
3
4
|
export PREFIX="$(pwd)/libsodium-js"
|
4
|
-
export EXPORTED_FUNCTIONS='["_crypto_aead_chacha20poly1305_abytes","_crypto_aead_chacha20poly1305_decrypt","_crypto_aead_chacha20poly1305_encrypt","_crypto_aead_chacha20poly1305_keybytes","_crypto_aead_chacha20poly1305_npubbytes","_crypto_aead_chacha20poly1305_nsecbytes","_crypto_auth","_crypto_auth_bytes","_crypto_auth_keybytes","_crypto_auth_verify","
|
5
|
+
export EXPORTED_FUNCTIONS='["_crypto_aead_chacha20poly1305_abytes","_crypto_aead_chacha20poly1305_decrypt","_crypto_aead_chacha20poly1305_encrypt","_crypto_aead_chacha20poly1305_keybytes","_crypto_aead_chacha20poly1305_npubbytes","_crypto_aead_chacha20poly1305_nsecbytes","_crypto_auth","_crypto_auth_bytes","_crypto_auth_keybytes","_crypto_auth_verify","_crypto_box_beforenm","_crypto_box_beforenmbytes","_crypto_box_detached","_crypto_box_detached_afternm","_crypto_box_easy","_crypto_box_easy_afternm","_crypto_box_keypair","_crypto_box_macbytes","_crypto_box_noncebytes","_crypto_box_open_detached","_crypto_box_open_detached_afternm","_crypto_box_open_easy","_crypto_box_open_easy_afternm","_crypto_box_publickeybytes","_crypto_box_secretkeybytes","_crypto_box_seed_keypair","_crypto_box_seedbytes","_crypto_generichash","_crypto_generichash_bytes","_crypto_generichash_bytes_max","_crypto_generichash_bytes_min","_crypto_generichash_final","_crypto_generichash_init","_crypto_generichash_keybytes","_crypto_generichash_keybytes_max","_crypto_generichash_keybytes_min","_crypto_generichash_update","_crypto_hash","_crypto_hash_bytes","_crypto_pwhash_scryptsalsa208sha256","_crypto_pwhash_scryptsalsa208sha256_memlimit_interactive","_crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive","_crypto_pwhash_scryptsalsa208sha256_opslimit_interactive","_crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive","_crypto_pwhash_scryptsalsa208sha256_saltbytes","_crypto_pwhash_scryptsalsa208sha256_str","_crypto_pwhash_scryptsalsa208sha256_str_verify","_crypto_pwhash_scryptsalsa208sha256_strbytes","_crypto_pwhash_scryptsalsa208sha256_strprefix","_crypto_scalarmult","_crypto_scalarmult_base","_crypto_scalarmult_bytes","_crypto_scalarmult_scalarbytes","_crypto_secretbox_detached","_crypto_secretbox_easy","_crypto_secretbox_keybytes","_crypto_secretbox_macbytes","_crypto_secretbox_noncebytes","_crypto_secretbox_open_detached","_crypto_secretbox_open_easy","_crypto_shorthash","_crypto_shorthash_bytes","_crypto_shorthash_keybytes","_crypto_sign","_crypto_sign_bytes","_crypto_sign_detached","_crypto_sign_ed25519_pk_to_curve25519","_crypto_sign_ed25519_sk_to_curve25519","_crypto_sign_keypair","_crypto_sign_open","_crypto_sign_publickeybytes","_crypto_sign_secretkeybytes","_crypto_sign_seed_keypair","_crypto_sign_seedbytes","_crypto_sign_verify_detached","_randombytes_buf","_randombytes_close","_randombytes_random","_randombytes_set_implementation","_randombytes_stir","_randombytes_sysrandom","_randombytes_sysrandom_buf","_randombytes_sysrandom_close","_randombytes_sysrandom_stir","_randombytes_sysrandom_uniform","_randombytes_uniform","_sodium_bin2hex","_sodium_hex2bin","_sodium_init","_sodium_library_version_major","_sodium_library_version_minor","_sodium_memcmp","_sodium_memzero","_sodium_version_string"]'
|
5
6
|
export TOTAL_MEMORY=33554432
|
6
|
-
export
|
7
|
-
export
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
export JS_EXPORTS_FLAGS="-s EXPORTED_FUNCTIONS=${EXPORTED_FUNCTIONS}"
|
8
|
+
export LDFLAGS="-s TOTAL_MEMORY=${TOTAL_MEMORY}"
|
9
|
+
|
10
|
+
rm -f test/js.done
|
11
|
+
|
12
|
+
emconfigure ./configure --enable-minimal --disable-shared --prefix="$PREFIX" \
|
13
|
+
CFLAGS="-O3" && \
|
14
|
+
emmake make clean && \
|
15
|
+
emmake make $MAKE_FLAGS install V=1 && \
|
16
|
+
emcc -O3 --closure 1 --llvm-lto 1 $LDFLAGS $JS_EXPORTS_FLAGS \
|
17
|
+
"${PREFIX}/lib/libsodium.a" -o "${PREFIX}/lib/libsodium.js" || exit 1
|
18
|
+
|
19
|
+
if test "x$NODE" = x; then
|
20
|
+
for candidate in iojs node nodejs; do
|
21
|
+
case $($candidate --version 2>&1) in #(
|
22
|
+
v*)
|
23
|
+
NODE=$candidate
|
24
|
+
break ;;
|
25
|
+
esac
|
26
|
+
done
|
27
|
+
fi
|
28
|
+
|
29
|
+
if test "x$NODE" = x; then
|
30
|
+
echo 'io.js / node.js not found - test suite skipped.' >&2
|
31
|
+
exit 1
|
32
|
+
fi
|
33
|
+
|
34
|
+
echo "Using [${NODE}] as a Javascript runtime."
|
35
|
+
|
36
|
+
echo 'Compiling the test suite...' && \
|
37
|
+
emmake make $MAKE_FLAGS check > /dev/null 2>&1
|
38
|
+
|
39
|
+
echo 'Running the test suite.'
|
40
|
+
echo 'sodium_utils2 and sodium_utils3 are expected to fail in Javascript.'
|
41
|
+
(
|
42
|
+
cd test/default && \
|
43
|
+
for file in *.js; do
|
44
|
+
echo "#! /usr/bin/env ${NODE}" > "${file}.tmp"
|
45
|
+
fgrep -v '#! /usr/bin/env node' "$file" >> "${file}.tmp"
|
46
|
+
chmod +x "${file}.tmp"
|
47
|
+
mv -f "${file}.tmp" "$file"
|
48
|
+
done
|
49
|
+
)
|
50
|
+
make $MAKE_FLAGS check || exit 1
|
51
|
+
echo 'Done.'
|
52
|
+
touch -r "${PREFIX}/lib/libsodium.js" test/js.done
|
@@ -1,18 +1,70 @@
|
|
1
1
|
#! /bin/sh
|
2
|
+
#
|
3
|
+
# Step 1.
|
4
|
+
# Configure for base system so simulator is covered
|
5
|
+
#
|
6
|
+
# Step 2.
|
7
|
+
# Make for iOS armv7, armv7s and arm64
|
8
|
+
#
|
9
|
+
# Step 3.
|
10
|
+
# Merge libs into final version for xcode import
|
2
11
|
|
12
|
+
export PREFIX="$(pwd)/libsodium-ios"
|
13
|
+
export IOS_PREFIX="$PREFIX/tmp/ios"
|
14
|
+
export OSX32_PREFIX="$PREFIX/tmp/osx32"
|
15
|
+
export OSX64_PREFIX="$PREFIX/tmp/osx64"
|
16
|
+
|
17
|
+
mkdir -p $IOS_PREFIX $OSX32_PREFIX $OSX64_PREFIX || exit 1
|
18
|
+
|
19
|
+
# Build for OSX32 First
|
20
|
+
export CFLAGS="-Oz -arch i386"
|
21
|
+
./configure --disable-shared \
|
22
|
+
--enable-minimal \
|
23
|
+
--prefix="$OSX32_PREFIX" || exit 1
|
24
|
+
|
25
|
+
make clean > /dev/null && make -j3 check && make -j3 install || exit 1
|
26
|
+
|
27
|
+
# Cleanup
|
28
|
+
make distclean > /dev/null
|
29
|
+
|
30
|
+
# Build for OSX64 Then
|
31
|
+
export CFLAGS="-Oz -arch x86_64"
|
32
|
+
./configure --disable-shared \
|
33
|
+
--enable-minimal \
|
34
|
+
--prefix="$OSX64_PREFIX"
|
35
|
+
|
36
|
+
make clean > /dev/null && make -j3 check && make -j3 install || exit 1
|
37
|
+
|
38
|
+
# Cleanup
|
39
|
+
make distclean > /dev/null || exit 1
|
40
|
+
|
41
|
+
# Build for iOS
|
3
42
|
export XCODEDIR=$(xcode-select -p)
|
4
43
|
export BASEDIR="${XCODEDIR}/Platforms/iPhoneOS.platform/Developer"
|
5
44
|
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
|
6
45
|
export SDK="${BASEDIR}/SDKs/iPhoneOS.sdk"
|
7
|
-
export IPHONEOS_VERSION_MIN
|
8
|
-
export CFLAGS="-Oz -mthumb -arch armv7 -isysroot ${SDK} -miphoneos-version-min=${IPHONEOS_VERSION_MIN}"
|
9
|
-
export LDFLAGS="-mthumb -arch armv7 -isysroot ${SDK} -miphoneos-version-min=${IPHONEOS_VERSION_MIN}"
|
10
|
-
export PREFIX="$(pwd)/libsodium-ios"
|
46
|
+
export IPHONEOS_VERSION_MIN=${IPHONEOS_VERSION_MIN-"5.1.1"}
|
47
|
+
export CFLAGS="-Oz -mthumb -arch armv7 -arch armv7s -arch arm64 -isysroot ${SDK} -miphoneos-version-min=${IPHONEOS_VERSION_MIN}"
|
48
|
+
export LDFLAGS="-mthumb -arch armv7 -arch armv7s -arch arm64 -isysroot ${SDK} -miphoneos-version-min=${IPHONEOS_VERSION_MIN}"
|
11
49
|
|
12
50
|
./configure --host=arm-apple-darwin10 \
|
13
51
|
--disable-shared \
|
14
52
|
--enable-minimal \
|
15
|
-
--prefix="$
|
16
|
-
|
17
|
-
make -j3 install
|
53
|
+
--prefix="$IOS_PREFIX" || exit 1
|
54
|
+
|
55
|
+
make clean > /dev/null && make -j3 install || exit 1
|
56
|
+
|
57
|
+
# Create universal binary and include folder
|
58
|
+
rm -fr -- "$PREFIX/include" "$PREFIX/libsodium.a" 2> /dev/null
|
59
|
+
mkdir -p -- "$PREFIX"
|
60
|
+
lipo -create "$IOS_PREFIX/lib/libsodium.a" "$OSX32_PREFIX/lib/libsodium.a" "$OSX64_PREFIX/lib/libsodium.a" -output "$PREFIX/libsodium.a"
|
61
|
+
mv -f -- "$IOS_PREFIX/include" "$PREFIX/"
|
62
|
+
|
63
|
+
echo
|
18
64
|
echo "libsodium has been installed into $PREFIX"
|
65
|
+
echo
|
66
|
+
file -- "$PREFIX/libsodium.a"
|
67
|
+
|
68
|
+
# Cleanup
|
69
|
+
rm -rf -- "$PREFIX/tmp"
|
70
|
+
make distclean > /dev/null
|
@@ -190,6 +190,7 @@ SODIUM_LIBRARY_VERSION = @SODIUM_LIBRARY_VERSION@
|
|
190
190
|
SODIUM_LIBRARY_VERSION_MAJOR = @SODIUM_LIBRARY_VERSION_MAJOR@
|
191
191
|
SODIUM_LIBRARY_VERSION_MINOR = @SODIUM_LIBRARY_VERSION_MINOR@
|
192
192
|
STRIP = @STRIP@
|
193
|
+
TEST_LDFLAGS = @TEST_LDFLAGS@
|
193
194
|
VERSION = @VERSION@
|
194
195
|
abs_builddir = @abs_builddir@
|
195
196
|
abs_srcdir = @abs_srcdir@
|
@@ -1,4 +1,4 @@
|
|
1
|
-
cscript msvc-scripts/rep.vbs //Nologo s/@VERSION@/1.0.
|
1
|
+
cscript msvc-scripts/rep.vbs //Nologo s/@VERSION@/1.0.2/ < src\libsodium\include\sodium\version.h.in > tmp
|
2
2
|
cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MAJOR@/7/ < tmp > tmp2
|
3
|
-
cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MINOR@/
|
3
|
+
cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MINOR@/4/ < tmp2 > src\libsodium\include\sodium\version.h
|
4
4
|
del tmp tmp2
|
@@ -12,13 +12,13 @@
|
|
12
12
|
<PreprocessorDefinitions>inline=__inline;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
13
13
|
</ClCompile>
|
14
14
|
<PreBuildEvent>
|
15
|
-
<Command
|
15
|
+
<Command>"$(SolutionDir)/msvc-scripts/process.bat"</Command>
|
16
16
|
</PreBuildEvent>
|
17
17
|
<PreBuildEvent>
|
18
18
|
<Message>Process .in files</Message>
|
19
19
|
</PreBuildEvent>
|
20
20
|
<PostBuildEvent>
|
21
|
-
<Command
|
21
|
+
<Command>"$(SolutionDir)/test/default/wintest.bat" $(Configuration) $(Platform)</Command>
|
22
22
|
</PostBuildEvent>
|
23
23
|
<PostBuildEvent>
|
24
24
|
<Message>Run the test suite</Message>
|
@@ -250,6 +250,7 @@ SODIUM_LIBRARY_VERSION = @SODIUM_LIBRARY_VERSION@
|
|
250
250
|
SODIUM_LIBRARY_VERSION_MAJOR = @SODIUM_LIBRARY_VERSION_MAJOR@
|
251
251
|
SODIUM_LIBRARY_VERSION_MINOR = @SODIUM_LIBRARY_VERSION_MINOR@
|
252
252
|
STRIP = @STRIP@
|
253
|
+
TEST_LDFLAGS = @TEST_LDFLAGS@
|
253
254
|
VERSION = @VERSION@
|
254
255
|
abs_builddir = @abs_builddir@
|
255
256
|
abs_srcdir = @abs_srcdir@
|
@@ -757,6 +757,7 @@ SODIUM_LIBRARY_VERSION = @SODIUM_LIBRARY_VERSION@
|
|
757
757
|
SODIUM_LIBRARY_VERSION_MAJOR = @SODIUM_LIBRARY_VERSION_MAJOR@
|
758
758
|
SODIUM_LIBRARY_VERSION_MINOR = @SODIUM_LIBRARY_VERSION_MINOR@
|
759
759
|
STRIP = @STRIP@
|
760
|
+
TEST_LDFLAGS = @TEST_LDFLAGS@
|
760
761
|
VERSION = @VERSION@
|
761
762
|
abs_builddir = @abs_builddir@
|
762
763
|
abs_srcdir = @abs_srcdir@
|
@@ -7,6 +7,14 @@
|
|
7
7
|
#include "crypto_secretbox.h"
|
8
8
|
#include "utils.h"
|
9
9
|
|
10
|
+
int
|
11
|
+
crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,
|
12
|
+
const unsigned char *m, unsigned long long mlen,
|
13
|
+
const unsigned char *n, const unsigned char *k)
|
14
|
+
{
|
15
|
+
return crypto_secretbox_detached(c, mac, m, mlen, n, k);
|
16
|
+
}
|
17
|
+
|
10
18
|
int
|
11
19
|
crypto_box_detached(unsigned char *c, unsigned char *mac,
|
12
20
|
const unsigned char *m, unsigned long long mlen,
|
@@ -19,12 +27,24 @@ crypto_box_detached(unsigned char *c, unsigned char *mac,
|
|
19
27
|
(void) sizeof(int[crypto_box_BEFORENMBYTES >=
|
20
28
|
crypto_secretbox_KEYBYTES ? 1 : -1]);
|
21
29
|
crypto_box_beforenm(k, pk, sk);
|
22
|
-
ret =
|
30
|
+
ret = crypto_box_detached_afternm(c, mac, m, mlen, n, k);
|
23
31
|
sodium_memzero(k, sizeof k);
|
24
32
|
|
25
33
|
return ret;
|
26
34
|
}
|
27
35
|
|
36
|
+
int
|
37
|
+
crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
|
38
|
+
unsigned long long mlen, const unsigned char *n,
|
39
|
+
const unsigned char *k)
|
40
|
+
{
|
41
|
+
if (mlen > SIZE_MAX - crypto_box_MACBYTES) {
|
42
|
+
return -1;
|
43
|
+
}
|
44
|
+
return crypto_box_detached_afternm(c + crypto_box_MACBYTES, c, m, mlen, n,
|
45
|
+
k);
|
46
|
+
}
|
47
|
+
|
28
48
|
int
|
29
49
|
crypto_box_easy(unsigned char *c, const unsigned char *m,
|
30
50
|
unsigned long long mlen, const unsigned char *n,
|
@@ -37,22 +57,44 @@ crypto_box_easy(unsigned char *c, const unsigned char *m,
|
|
37
57
|
pk, sk);
|
38
58
|
}
|
39
59
|
|
60
|
+
int
|
61
|
+
crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c,
|
62
|
+
const unsigned char *mac,
|
63
|
+
unsigned long long clen, const unsigned char *n,
|
64
|
+
const unsigned char *k)
|
65
|
+
{
|
66
|
+
return crypto_secretbox_open_detached(m, c, mac, clen, n, k);
|
67
|
+
}
|
68
|
+
|
40
69
|
int
|
41
70
|
crypto_box_open_detached(unsigned char *m, const unsigned char *c,
|
42
71
|
const unsigned char *mac,
|
43
|
-
|
44
|
-
|
72
|
+
unsigned long long clen, const unsigned char *n,
|
73
|
+
const unsigned char *pk, const unsigned char *sk)
|
45
74
|
{
|
46
75
|
unsigned char k[crypto_box_BEFORENMBYTES];
|
47
76
|
int ret;
|
48
77
|
|
49
78
|
crypto_box_beforenm(k, pk, sk);
|
50
|
-
ret =
|
79
|
+
ret = crypto_box_open_detached_afternm(m, c, mac, clen, n, k);
|
51
80
|
sodium_memzero(k, sizeof k);
|
52
81
|
|
53
82
|
return ret;
|
54
83
|
}
|
55
84
|
|
85
|
+
int
|
86
|
+
crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
|
87
|
+
unsigned long long clen, const unsigned char *n,
|
88
|
+
const unsigned char *k)
|
89
|
+
{
|
90
|
+
if (clen < crypto_box_MACBYTES) {
|
91
|
+
return -1;
|
92
|
+
}
|
93
|
+
return crypto_box_open_detached_afternm(m, c + crypto_box_MACBYTES, c,
|
94
|
+
clen - crypto_box_MACBYTES,
|
95
|
+
n, k);
|
96
|
+
}
|
97
|
+
|
56
98
|
int
|
57
99
|
crypto_box_open_easy(unsigned char *m, const unsigned char *c,
|
58
100
|
unsigned long long clen, const unsigned char *n,
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#include "api.h"
|
2
|
+
#include "utils.h"
|
2
3
|
|
3
4
|
int crypto_box(
|
4
5
|
unsigned char *c,
|
@@ -9,8 +10,13 @@ int crypto_box(
|
|
9
10
|
)
|
10
11
|
{
|
11
12
|
unsigned char k[crypto_box_BEFORENMBYTES];
|
13
|
+
int ret;
|
14
|
+
|
12
15
|
crypto_box_beforenm(k,pk,sk);
|
13
|
-
|
16
|
+
ret = crypto_box_afternm(c,m,mlen,n,k);
|
17
|
+
sodium_memzero(k, sizeof k);
|
18
|
+
|
19
|
+
return ret;
|
14
20
|
}
|
15
21
|
|
16
22
|
int crypto_box_open(
|
@@ -22,6 +28,11 @@ int crypto_box_open(
|
|
22
28
|
)
|
23
29
|
{
|
24
30
|
unsigned char k[crypto_box_BEFORENMBYTES];
|
31
|
+
int ret;
|
32
|
+
|
25
33
|
crypto_box_beforenm(k,pk,sk);
|
26
|
-
|
34
|
+
ret = crypto_box_open_afternm(m,c,clen,n,k);
|
35
|
+
sodium_memzero(k, sizeof k);
|
36
|
+
|
37
|
+
return ret;
|
27
38
|
}
|
@@ -35,7 +35,7 @@ void *
|
|
35
35
|
alloc_region(escrypt_region_t * region, size_t size)
|
36
36
|
{
|
37
37
|
uint8_t * base, * aligned;
|
38
|
-
#
|
38
|
+
#if defined(MAP_ANON) && defined(HAVE_MMAP)
|
39
39
|
if ((base = (uint8_t *) mmap(NULL, size, PROT_READ | PROT_WRITE,
|
40
40
|
#ifdef MAP_NOCORE
|
41
41
|
MAP_ANON | MAP_PRIVATE | MAP_NOCORE,
|
@@ -75,7 +75,7 @@ int
|
|
75
75
|
free_region(escrypt_region_t * region)
|
76
76
|
{
|
77
77
|
if (region->base) {
|
78
|
-
#
|
78
|
+
#if defined(MAP_ANON) && defined(HAVE_MMAP)
|
79
79
|
if (munmap(region->base, region->size))
|
80
80
|
return -1; /* LCOV_EXCL_LINE */
|
81
81
|
#else
|
@@ -29,7 +29,10 @@ crypto_secretbox_detached(unsigned char *c, unsigned char *mac,
|
|
29
29
|
|
30
30
|
crypto_core_hsalsa20(subkey, n, k, sigma);
|
31
31
|
|
32
|
-
if (c
|
32
|
+
if (((uintptr_t) c >= (uintptr_t) m &&
|
33
|
+
(uintptr_t) c - (uintptr_t) m < mlen) ||
|
34
|
+
((uintptr_t) m >= (uintptr_t) c &&
|
35
|
+
(uintptr_t) m - (uintptr_t) c < mlen)) {
|
33
36
|
memmove(c, m, mlen);
|
34
37
|
m = c;
|
35
38
|
}
|
@@ -95,7 +98,10 @@ crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c,
|
|
95
98
|
sodium_memzero(subkey, sizeof subkey);
|
96
99
|
return -1;
|
97
100
|
}
|
98
|
-
if (
|
101
|
+
if (((uintptr_t) c >= (uintptr_t) m &&
|
102
|
+
(uintptr_t) c - (uintptr_t) m < clen) ||
|
103
|
+
((uintptr_t) m >= (uintptr_t) c &&
|
104
|
+
(uintptr_t) m - (uintptr_t) c < clen)) {
|
99
105
|
memmove(m, c, clen);
|
100
106
|
c = m;
|
101
107
|
}
|
@@ -45,27 +45,27 @@ crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
|
|
45
45
|
}
|
46
46
|
|
47
47
|
int
|
48
|
-
crypto_sign(unsigned char *sm, unsigned long long *
|
48
|
+
crypto_sign(unsigned char *sm, unsigned long long *smlen_p,
|
49
49
|
const unsigned char *m, unsigned long long mlen,
|
50
50
|
const unsigned char *sk)
|
51
51
|
{
|
52
|
-
return crypto_sign_ed25519(sm,
|
52
|
+
return crypto_sign_ed25519(sm, smlen_p, m, mlen, sk);
|
53
53
|
}
|
54
54
|
|
55
55
|
int
|
56
|
-
crypto_sign_open(unsigned char *m, unsigned long long *
|
56
|
+
crypto_sign_open(unsigned char *m, unsigned long long *mlen_p,
|
57
57
|
const unsigned char *sm, unsigned long long smlen,
|
58
58
|
const unsigned char *pk)
|
59
59
|
{
|
60
|
-
return crypto_sign_ed25519_open(m,
|
60
|
+
return crypto_sign_ed25519_open(m, mlen_p, sm, smlen, pk);
|
61
61
|
}
|
62
62
|
|
63
63
|
int
|
64
|
-
crypto_sign_detached(unsigned char *sig, unsigned long long *
|
64
|
+
crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,
|
65
65
|
const unsigned char *m, unsigned long long mlen,
|
66
66
|
const unsigned char *sk)
|
67
67
|
{
|
68
|
-
return crypto_sign_ed25519_detached(sig,
|
68
|
+
return crypto_sign_ed25519_detached(sig, siglen_p, m, mlen, sk);
|
69
69
|
}
|
70
70
|
|
71
71
|
int
|
@@ -46,7 +46,9 @@ int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
|
|
46
46
|
fe x;
|
47
47
|
fe one_minus_y;
|
48
48
|
|
49
|
-
ge_frombytes_negate_vartime(&A, ed25519_pk)
|
49
|
+
if (ge_frombytes_negate_vartime(&A, ed25519_pk) != 0) {
|
50
|
+
return -1;
|
51
|
+
}
|
50
52
|
fe_1(one_minus_y);
|
51
53
|
fe_sub(one_minus_y, one_minus_y, A.Y);
|
52
54
|
fe_invert(one_minus_y, one_minus_y);
|
@@ -48,23 +48,30 @@ crypto_sign_verify_detached(const unsigned char *sig, const unsigned char *m,
|
|
48
48
|
}
|
49
49
|
|
50
50
|
int
|
51
|
-
crypto_sign_open(unsigned char *m, unsigned long long *
|
51
|
+
crypto_sign_open(unsigned char *m, unsigned long long *mlen_p,
|
52
52
|
const unsigned char *sm, unsigned long long smlen,
|
53
53
|
const unsigned char *pk)
|
54
54
|
{
|
55
|
+
unsigned long long mlen;
|
56
|
+
|
55
57
|
if (smlen < 64 || smlen > SIZE_MAX) {
|
56
58
|
goto badsig;
|
57
59
|
}
|
58
|
-
|
59
|
-
|
60
|
+
mlen = smlen - 64;
|
61
|
+
if (crypto_sign_verify_detached(sm, sm + 64, mlen, pk) != 0) {
|
62
|
+
memset(m, 0, mlen);
|
60
63
|
goto badsig;
|
61
64
|
}
|
62
|
-
|
63
|
-
|
65
|
+
if (mlen_p != NULL) {
|
66
|
+
*mlen_p = mlen;
|
67
|
+
}
|
68
|
+
memmove(m, sm + 64, mlen);
|
64
69
|
|
65
70
|
return 0;
|
66
71
|
|
67
72
|
badsig:
|
68
|
-
|
73
|
+
if (mlen_p != NULL) {
|
74
|
+
*mlen_p = 0;
|
75
|
+
}
|
69
76
|
return -1;
|
70
77
|
}
|