rbnacl-libsodium 1.0.13 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/lib/rbnacl/libsodium.rb +1 -0
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/AUTHORS +2 -2
- data/vendor/libsodium/ChangeLog +64 -0
- data/vendor/libsodium/Makefile.am +1 -0
- data/vendor/libsodium/README.markdown +1 -3
- data/vendor/libsodium/THANKS +13 -3
- data/vendor/libsodium/builds/Makefile.am +65 -0
- data/vendor/libsodium/builds/msvc/resource.rc +2 -2
- data/vendor/libsodium/builds/msvc/version.h +3 -3
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +168 -173
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +382 -394
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +168 -173
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +382 -394
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +168 -173
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +382 -394
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +168 -173
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +382 -394
- data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj +168 -173
- data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters +382 -394
- data/vendor/libsodium/configure.ac +59 -10
- data/vendor/libsodium/contrib/Findsodium.cmake +2 -0
- data/vendor/libsodium/dist-build/emscripten-symbols.def +72 -32
- data/vendor/libsodium/dist-build/emscripten.sh +33 -6
- data/vendor/libsodium/dist-build/generate-emscripten-symbols.sh +52 -38
- data/vendor/libsodium/dist-build/ios.sh +2 -2
- data/vendor/libsodium/libsodium.vcxproj +168 -173
- data/vendor/libsodium/libsodium.vcxproj.filters +220 -235
- data/vendor/libsodium/m4/ax_check_catchable_abrt.m4 +57 -0
- data/vendor/libsodium/m4/ax_check_gnu_make.m4 +2 -2
- data/vendor/libsodium/m4/ax_pthread.m4 +2 -2
- data/vendor/libsodium/msvc-scripts/process.bat +3 -3
- data/vendor/libsodium/packaging/dotnet-core/README.md +5 -5
- data/vendor/libsodium/packaging/dotnet-core/libsodium.props +5 -2
- data/vendor/libsodium/packaging/dotnet-core/prepare.py +13 -31
- data/vendor/libsodium/packaging/dotnet-core/recipes/linux-x64 +4 -0
- data/vendor/libsodium/packaging/nuget/package.config +1 -1
- data/vendor/libsodium/src/libsodium/Makefile.am +11 -12
- data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +11 -4
- data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +17 -4
- data/vendor/libsodium/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c +8 -1
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +5 -4
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c +11 -4
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +78 -17
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c +74 -64
- data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c +2 -0
- data/vendor/libsodium/src/libsodium/crypto_kx/crypto_kx.c +7 -0
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +17 -17
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +53 -48
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +37 -11
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +23 -179
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c +4 -12
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx512f.c +244 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c +3 -12
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +4 -12
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +1 -5
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-avx512f.h +145 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +91 -14
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c +35 -14
- data/vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c +41 -4
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +31 -17
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +4 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +5 -1
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +30 -1
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +8 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c +3 -3
- data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +5 -4
- data/vendor/libsodium/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c +11 -4
- data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_secretstream/xchacha20poly1305/secretstream_xchacha20poly1305.c +311 -0
- data/vendor/libsodium/src/libsodium/crypto_sign/crypto_sign.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ed25519_ref10.h +3 -0
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +9 -2
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +6 -5
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c +3 -2
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c +3 -2
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/u0.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c +3 -2
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c +12 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/crypto_stream.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.c +7 -1
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u0.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/xchacha20/stream_xchacha20.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_verify/sodium/verify.c +66 -29
- data/vendor/libsodium/src/libsodium/include/Makefile.am +1 -1
- data/vendor/libsodium/src/libsodium/include/sodium.h +2 -2
- data/vendor/libsodium/src/libsodium/include/sodium/core.h +9 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +26 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +16 -4
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h +10 -4
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h +6 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +24 -15
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_salsa208.h +8 -4
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +40 -18
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +8 -2
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2id.h +8 -2
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +11 -3
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h +6 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +17 -8
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h +102 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +1 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +10 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa2012.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa208.h +15 -5
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xchacha20.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xsalsa20.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/export.h +9 -0
- data/vendor/libsodium/src/libsodium/include/sodium/private/common.h +11 -0
- data/vendor/libsodium/src/libsodium/include/sodium/private/curve25519_ref10.h +2 -30
- data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +2 -0
- data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +12 -9
- data/vendor/libsodium/src/libsodium/include/sodium/utils.h +36 -0
- data/vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +3 -2
- data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +18 -14
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +11 -10
- data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +20 -8
- data/vendor/libsodium/src/libsodium/sodium/codecs.c +333 -0
- data/vendor/libsodium/src/libsodium/sodium/core.c +36 -4
- data/vendor/libsodium/src/libsodium/sodium/runtime.c +18 -0
- data/vendor/libsodium/src/libsodium/sodium/utils.c +87 -100
- data/vendor/libsodium/test/constcheck.sh +19 -0
- data/vendor/libsodium/test/default/Makefile.am +39 -7
- data/vendor/libsodium/test/default/aead_aes256gcm.c +6 -0
- data/vendor/libsodium/test/default/aead_chacha20poly1305.c +16 -0
- data/vendor/libsodium/test/default/aead_xchacha20poly1305.c +25 -15
- data/vendor/libsodium/test/default/auth.c +13 -0
- data/vendor/libsodium/test/default/auth.exp +8 -0
- data/vendor/libsodium/test/default/box.c +3 -0
- data/vendor/libsodium/test/default/box2.c +2 -0
- data/vendor/libsodium/test/default/box_easy.c +1 -4
- data/vendor/libsodium/test/default/box_easy2.c +7 -3
- data/vendor/libsodium/test/default/chacha20.c +9 -2
- data/vendor/libsodium/test/default/cmptest.h +47 -1
- data/vendor/libsodium/test/default/codecs.c +226 -0
- data/vendor/libsodium/test/default/codecs.exp +28 -0
- data/vendor/libsodium/test/default/core3.c +42 -15
- data/vendor/libsodium/test/default/ed25519_convert.c +17 -0
- data/vendor/libsodium/test/default/kdf.c +8 -4
- data/vendor/libsodium/test/default/keygen.c +5 -2
- data/vendor/libsodium/test/default/kx.c +30 -0
- data/vendor/libsodium/test/default/metamorphic.c +187 -0
- data/vendor/libsodium/test/default/metamorphic.exp +1 -0
- data/vendor/libsodium/test/default/misuse.c +145 -0
- data/vendor/libsodium/test/default/misuse.exp +0 -0
- data/vendor/libsodium/test/default/onetimeauth.c +2 -0
- data/vendor/libsodium/test/default/{pwhash.c → pwhash_argon2i.c} +133 -106
- data/vendor/libsodium/test/default/{pwhash.exp → pwhash_argon2i.exp} +0 -1
- data/vendor/libsodium/test/default/pwhash_argon2id.c +254 -144
- data/vendor/libsodium/test/default/pwhash_argon2id.exp +2 -3
- data/vendor/libsodium/test/default/pwhash_scrypt.c +61 -18
- data/vendor/libsodium/test/default/pwhash_scrypt.exp +6 -0
- data/vendor/libsodium/test/default/randombytes.c +8 -3
- data/vendor/libsodium/test/default/secretbox.c +8 -0
- data/vendor/libsodium/test/default/secretbox2.c +5 -0
- data/vendor/libsodium/test/default/secretbox_easy.c +19 -1
- data/vendor/libsodium/test/default/secretbox_easy.exp +2 -0
- data/vendor/libsodium/test/default/secretbox_easy2.c +4 -0
- data/vendor/libsodium/test/default/secretstream.c +280 -0
- data/vendor/libsodium/test/default/secretstream.exp +1 -0
- data/vendor/libsodium/test/default/sign.c +31 -0
- data/vendor/libsodium/test/default/sodium_core.c +23 -1
- data/vendor/libsodium/test/default/sodium_core.exp +1 -1
- data/vendor/libsodium/test/default/sodium_utils.c +45 -56
- data/vendor/libsodium/test/default/sodium_utils.exp +0 -8
- data/vendor/libsodium/test/default/stream.c +2 -0
- data/vendor/libsodium/test/default/stream2.c +1 -0
- data/vendor/libsodium/test/default/xchacha20.c +58 -7
- metadata +21 -18
- data/vendor/libsodium/dist-build/emscripten-wasm.sh +0 -132
- data/vendor/libsodium/m4/pkg.m4 +0 -214
- data/vendor/libsodium/packaging/dotnet-core/desktop.targets +0 -16
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/afternm_aes128ctr.c +0 -174
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/beforenm_aes128ctr.c +0 -66
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/common.h +0 -766
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts.h +0 -28
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts_aes128ctr.c +0 -28
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128.h +0 -50
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128_aes128ctr.c +0 -149
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/stream_aes128ctr_nacl.c +0 -31
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/xor_afternm_aes128ctr.c +0 -195
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/stream_aes128ctr.c +0 -19
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes128ctr.h +0 -65
@@ -1,5 +1,6 @@
|
|
1
1
|
#include "argon2-encoding.h"
|
2
2
|
#include "argon2-core.h"
|
3
|
+
#include "utils.h"
|
3
4
|
#include <limits.h>
|
4
5
|
#include <stdio.h>
|
5
6
|
#include <stdlib.h>
|
@@ -9,19 +10,6 @@
|
|
9
10
|
* Example code for a decoder and encoder of "hash strings", with Argon2
|
10
11
|
* parameters.
|
11
12
|
*
|
12
|
-
* This code comprises three sections:
|
13
|
-
*
|
14
|
-
* -- The first section contains generic Base64 encoding and decoding
|
15
|
-
* functions. It is conceptually applicable to any hash function
|
16
|
-
* implementation that uses Base64 to encode and decode parameters,
|
17
|
-
* salts and outputs. It could be made into a library, provided that
|
18
|
-
* the relevant functions are made public (non-static) and be given
|
19
|
-
* reasonable names to avoid collisions with other functions.
|
20
|
-
*
|
21
|
-
* -- The second section is specific to Argon2. It encodes and decodes
|
22
|
-
* the parameters, salts and outputs. It does not compute the hash
|
23
|
-
* itself.
|
24
|
-
*
|
25
13
|
* The code was originally written by Thomas Pornin <pornin@bolet.org>,
|
26
14
|
* to whom comments and remarks may be sent. It is released under what
|
27
15
|
* should amount to Public Domain or its closest equivalent; the
|
@@ -39,156 +27,6 @@
|
|
39
27
|
*/
|
40
28
|
|
41
29
|
/* ==================================================================== */
|
42
|
-
/*
|
43
|
-
* Common code; could be shared between different hash functions.
|
44
|
-
*
|
45
|
-
* Note: the Base64 functions below assume that uppercase letters (resp.
|
46
|
-
* lowercase letters) have consecutive numerical codes, that fit on 8
|
47
|
-
* bits. All modern systems use ASCII-compatible charsets, where these
|
48
|
-
* properties are true. If you are stuck with a dinosaur of a system
|
49
|
-
* that still defaults to EBCDIC then you already have much bigger
|
50
|
-
* interoperability issues to deal with.
|
51
|
-
*/
|
52
|
-
|
53
|
-
/*
|
54
|
-
* Some macros for constant-time comparisons. These work over values in
|
55
|
-
* the 0..255 range. Returned value is 0x00 on "false", 0xFF on "true".
|
56
|
-
*/
|
57
|
-
#define EQ(x, y) \
|
58
|
-
((((0U - ((unsigned) (x) ^ (unsigned) (y))) >> 8) & 0xFF) ^ 0xFF)
|
59
|
-
#define GT(x, y) ((((unsigned) (y) - (unsigned) (x)) >> 8) & 0xFF)
|
60
|
-
#define GE(x, y) (GT(y, x) ^ 0xFF)
|
61
|
-
#define LT(x, y) GT(y, x)
|
62
|
-
#define LE(x, y) GE(y, x)
|
63
|
-
|
64
|
-
/*
|
65
|
-
* Convert value x (0..63) to corresponding Base64 character.
|
66
|
-
*/
|
67
|
-
static int
|
68
|
-
b64_byte_to_char(unsigned x)
|
69
|
-
{
|
70
|
-
return (LT(x, 26) & (x + 'A')) |
|
71
|
-
(GE(x, 26) & LT(x, 52) & (x + ('a' - 26))) |
|
72
|
-
(GE(x, 52) & LT(x, 62) & (x + ('0' - 52))) | (EQ(x, 62) & '+') |
|
73
|
-
(EQ(x, 63) & '/');
|
74
|
-
}
|
75
|
-
|
76
|
-
/*
|
77
|
-
* Convert character c to the corresponding 6-bit value. If character c
|
78
|
-
* is not a Base64 character, then 0xFF (255) is returned.
|
79
|
-
*/
|
80
|
-
static unsigned
|
81
|
-
b64_char_to_byte(int c)
|
82
|
-
{
|
83
|
-
unsigned x;
|
84
|
-
|
85
|
-
x = (GE(c, 'A') & LE(c, 'Z') & (c - 'A')) |
|
86
|
-
(GE(c, 'a') & LE(c, 'z') & (c - ('a' - 26))) |
|
87
|
-
(GE(c, '0') & LE(c, '9') & (c - ('0' - 52))) | (EQ(c, '+') & 62) |
|
88
|
-
(EQ(c, '/') & 63);
|
89
|
-
return x | (EQ(x, 0) & (EQ(c, 'A') ^ 0xFF));
|
90
|
-
}
|
91
|
-
|
92
|
-
/*
|
93
|
-
* Convert some bytes to Base64. 'dst_len' is the length (in characters)
|
94
|
-
* of the output buffer 'dst'; if that buffer is not large enough to
|
95
|
-
* receive the result (including the terminating 0), then (size_t)-1
|
96
|
-
* is returned. Otherwise, the zero-terminated Base64 string is written
|
97
|
-
* in the buffer, and the output length (counted WITHOUT the terminating
|
98
|
-
* zero) is returned.
|
99
|
-
*/
|
100
|
-
static size_t
|
101
|
-
to_base64(char *dst, size_t dst_len, const void *src, size_t src_len)
|
102
|
-
{
|
103
|
-
size_t olen;
|
104
|
-
const unsigned char *buf;
|
105
|
-
unsigned acc, acc_len;
|
106
|
-
|
107
|
-
olen = (src_len / 3) << 2;
|
108
|
-
switch (src_len % 3) {
|
109
|
-
case 2:
|
110
|
-
olen++;
|
111
|
-
/* fall through */
|
112
|
-
case 1:
|
113
|
-
olen += 2;
|
114
|
-
break;
|
115
|
-
}
|
116
|
-
if (dst_len <= olen) {
|
117
|
-
return (size_t) -1;
|
118
|
-
}
|
119
|
-
acc = 0;
|
120
|
-
acc_len = 0;
|
121
|
-
buf = (const unsigned char *) src;
|
122
|
-
while (src_len-- > 0) {
|
123
|
-
acc = (acc << 8) + (*buf++);
|
124
|
-
acc_len += 8;
|
125
|
-
while (acc_len >= 6) {
|
126
|
-
acc_len -= 6;
|
127
|
-
*dst++ = (char) b64_byte_to_char((acc >> acc_len) & 0x3F);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
if (acc_len > 0) {
|
131
|
-
*dst++ = (char) b64_byte_to_char((acc << (6 - acc_len)) & 0x3F);
|
132
|
-
}
|
133
|
-
*dst++ = 0;
|
134
|
-
return olen;
|
135
|
-
}
|
136
|
-
|
137
|
-
/*
|
138
|
-
* Decode Base64 chars into bytes. The '*dst_len' value must initially
|
139
|
-
* contain the length of the output buffer '*dst'; when the decoding
|
140
|
-
* ends, the actual number of decoded bytes is written back in
|
141
|
-
* '*dst_len'.
|
142
|
-
*
|
143
|
-
* Decoding stops when a non-Base64 character is encountered, or when
|
144
|
-
* the output buffer capacity is exceeded. If an error occurred (output
|
145
|
-
* buffer is too small, invalid last characters leading to unprocessed
|
146
|
-
* buffered bits), then NULL is returned; otherwise, the returned value
|
147
|
-
* points to the first non-Base64 character in the source stream, which
|
148
|
-
* may be the terminating zero.
|
149
|
-
*/
|
150
|
-
static const char *
|
151
|
-
from_base64(void *dst, size_t *dst_len, const char *src)
|
152
|
-
{
|
153
|
-
size_t len;
|
154
|
-
unsigned char *buf;
|
155
|
-
unsigned acc, acc_len;
|
156
|
-
|
157
|
-
buf = (unsigned char *) dst;
|
158
|
-
len = 0;
|
159
|
-
acc = 0;
|
160
|
-
acc_len = 0;
|
161
|
-
for (;;) {
|
162
|
-
unsigned d;
|
163
|
-
|
164
|
-
d = b64_char_to_byte(*src);
|
165
|
-
if (d == 0xFF) {
|
166
|
-
break;
|
167
|
-
}
|
168
|
-
src++;
|
169
|
-
acc = (acc << 6) + d;
|
170
|
-
acc_len += 6;
|
171
|
-
if (acc_len >= 8) {
|
172
|
-
acc_len -= 8;
|
173
|
-
if ((len++) >= *dst_len) {
|
174
|
-
return NULL;
|
175
|
-
}
|
176
|
-
*buf++ = (acc >> acc_len) & 0xFF;
|
177
|
-
}
|
178
|
-
}
|
179
|
-
|
180
|
-
/*
|
181
|
-
* If the input length is equal to 1 modulo 4 (which is
|
182
|
-
* invalid), then there will remain 6 unprocessed bits;
|
183
|
-
* otherwise, only 0, 2 or 4 bits are buffered. The buffered
|
184
|
-
* bits must also all be zero.
|
185
|
-
*/
|
186
|
-
if (acc_len > 4 || (acc & ((1U << acc_len) - 1)) != 0) {
|
187
|
-
return NULL;
|
188
|
-
}
|
189
|
-
*dst_len = len;
|
190
|
-
return src;
|
191
|
-
}
|
192
30
|
|
193
31
|
/*
|
194
32
|
* Decode decimal integer from 'str'; the value is written in '*v'.
|
@@ -300,14 +138,18 @@ decode_string(argon2_context *ctx, const char *str, argon2_type type)
|
|
300
138
|
} while ((void)0, 0)
|
301
139
|
|
302
140
|
/* Decoding base64 into a binary buffer */
|
303
|
-
#define BIN(buf, max_len, len)
|
304
|
-
do {
|
305
|
-
size_t bin_len = (max_len);
|
306
|
-
|
307
|
-
if (
|
308
|
-
|
309
|
-
|
310
|
-
|
141
|
+
#define BIN(buf, max_len, len) \
|
142
|
+
do { \
|
143
|
+
size_t bin_len = (max_len); \
|
144
|
+
const char *str_end; \
|
145
|
+
if (sodium_base642bin((buf), (max_len), str, strlen(str), NULL, \
|
146
|
+
&bin_len, &str_end, \
|
147
|
+
sodium_base64_VARIANT_ORIGINAL_NO_PADDING) != 0 || \
|
148
|
+
bin_len > UINT32_MAX) { \
|
149
|
+
return ARGON2_DECODING_FAIL; \
|
150
|
+
} \
|
151
|
+
(len) = (uint32_t) bin_len; \
|
152
|
+
str = str_end; \
|
311
153
|
} while ((void) 0, 0)
|
312
154
|
|
313
155
|
size_t maxsaltlen = ctx->saltlen;
|
@@ -416,14 +258,16 @@ encode_string(char *dst, size_t dst_len, argon2_context *ctx, argon2_type type)
|
|
416
258
|
SS(tmp); \
|
417
259
|
} while ((void) 0, 0)
|
418
260
|
|
419
|
-
#define SB(buf, len)
|
420
|
-
do {
|
421
|
-
size_t sb_len
|
422
|
-
if (
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
261
|
+
#define SB(buf, len) \
|
262
|
+
do { \
|
263
|
+
size_t sb_len; \
|
264
|
+
if (sodium_bin2base64(dst, dst_len, (buf), (len), \
|
265
|
+
sodium_base64_VARIANT_ORIGINAL_NO_PADDING) == NULL) { \
|
266
|
+
return ARGON2_ENCODING_FAIL; \
|
267
|
+
} \
|
268
|
+
sb_len = strlen(dst); \
|
269
|
+
dst += sb_len; \
|
270
|
+
dst_len -= sb_len; \
|
427
271
|
} while ((void) 0, 0)
|
428
272
|
|
429
273
|
int validation_result;
|
@@ -140,7 +140,7 @@ generate_addresses(const argon2_instance_t *instance,
|
|
140
140
|
}
|
141
141
|
}
|
142
142
|
|
143
|
-
|
143
|
+
void
|
144
144
|
fill_segment_avx2(const argon2_instance_t *instance,
|
145
145
|
argon2_position_t position)
|
146
146
|
{
|
@@ -148,14 +148,14 @@ fill_segment_avx2(const argon2_instance_t *instance,
|
|
148
148
|
uint64_t pseudo_rand, ref_index, ref_lane;
|
149
149
|
uint32_t prev_offset, curr_offset;
|
150
150
|
uint32_t starting_index, i;
|
151
|
-
__m256i state[
|
151
|
+
__m256i state[ARGON2_HWORDS_IN_BLOCK];
|
152
152
|
int data_independent_addressing = 1;
|
153
153
|
|
154
154
|
/* Pseudo-random values that determine the reference block position */
|
155
155
|
uint64_t *pseudo_rands = NULL;
|
156
156
|
|
157
157
|
if (instance == NULL) {
|
158
|
-
return
|
158
|
+
return;
|
159
159
|
}
|
160
160
|
|
161
161
|
if (instance->type == Argon2_id &&
|
@@ -163,11 +163,7 @@ fill_segment_avx2(const argon2_instance_t *instance,
|
|
163
163
|
data_independent_addressing = 0;
|
164
164
|
}
|
165
165
|
|
166
|
-
pseudo_rands =
|
167
|
-
(uint64_t *) malloc(sizeof(uint64_t) * instance->segment_length);
|
168
|
-
if (pseudo_rands == NULL) {
|
169
|
-
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
170
|
-
}
|
166
|
+
pseudo_rands = instance->pseudo_rands;
|
171
167
|
|
172
168
|
if (data_independent_addressing) {
|
173
169
|
generate_addresses(instance, &position, pseudo_rands);
|
@@ -239,9 +235,5 @@ fill_segment_avx2(const argon2_instance_t *instance,
|
|
239
235
|
(uint8_t *) curr_block->v);
|
240
236
|
}
|
241
237
|
}
|
242
|
-
|
243
|
-
free(pseudo_rands);
|
244
|
-
|
245
|
-
return ARGON2_OK;
|
246
238
|
}
|
247
239
|
#endif
|
@@ -0,0 +1,244 @@
|
|
1
|
+
/*
|
2
|
+
* Argon2 source code package
|
3
|
+
*
|
4
|
+
* Written by Daniel Dinu and Dmitry Khovratovich, 2015
|
5
|
+
*
|
6
|
+
* This work is licensed under a Creative Commons CC0 1.0 License/Waiver.
|
7
|
+
*
|
8
|
+
* You should have received a copy of the CC0 Public Domain Dedication along
|
9
|
+
* with
|
10
|
+
* this software. If not, see
|
11
|
+
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
12
|
+
*/
|
13
|
+
|
14
|
+
#include <stdint.h>
|
15
|
+
#include <stdlib.h>
|
16
|
+
#include <string.h>
|
17
|
+
|
18
|
+
#include "argon2-core.h"
|
19
|
+
#include "argon2.h"
|
20
|
+
#include "private/common.h"
|
21
|
+
#include "private/sse2_64_32.h"
|
22
|
+
|
23
|
+
#if defined(HAVE_AVX512FINTRIN_H) && defined(HAVE_AVX2INTRIN_H) && \
|
24
|
+
defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)
|
25
|
+
|
26
|
+
# ifdef __GNUC__
|
27
|
+
# pragma GCC target("sse2")
|
28
|
+
# pragma GCC target("ssse3")
|
29
|
+
# pragma GCC target("sse4.1")
|
30
|
+
# pragma GCC target("avx2")
|
31
|
+
# pragma GCC target("avx512f")
|
32
|
+
# endif
|
33
|
+
|
34
|
+
# ifdef _MSC_VER
|
35
|
+
# include <intrin.h> /* for _mm_set_epi64x */
|
36
|
+
# endif
|
37
|
+
#include <emmintrin.h>
|
38
|
+
#include <immintrin.h>
|
39
|
+
#include <smmintrin.h>
|
40
|
+
#include <tmmintrin.h>
|
41
|
+
|
42
|
+
# include "blamka-round-avx512f.h"
|
43
|
+
|
44
|
+
static void
|
45
|
+
fill_block(__m512i *state, const uint8_t *ref_block, uint8_t *next_block)
|
46
|
+
{
|
47
|
+
__m512i block_XY[ARGON2_512BIT_WORDS_IN_BLOCK];
|
48
|
+
uint32_t i;
|
49
|
+
|
50
|
+
for (i = 0; i < ARGON2_512BIT_WORDS_IN_BLOCK; i++) {
|
51
|
+
block_XY[i] = state[i] = _mm512_xor_si512(
|
52
|
+
state[i], _mm512_loadu_si512((__m512i const *) (&ref_block[64 * i])));
|
53
|
+
}
|
54
|
+
|
55
|
+
for (i = 0; i < 2; ++i) {
|
56
|
+
BLAKE2_ROUND_1(
|
57
|
+
state[8 * i + 0], state[8 * i + 1], state[8 * i + 2], state[8 * i + 3],
|
58
|
+
state[8 * i + 4], state[8 * i + 5], state[8 * i + 6], state[8 * i + 7]);
|
59
|
+
}
|
60
|
+
|
61
|
+
for (i = 0; i < 2; ++i) {
|
62
|
+
BLAKE2_ROUND_2(
|
63
|
+
state[2 * 0 + i], state[2 * 1 + i], state[2 * 2 + i], state[2 * 3 + i],
|
64
|
+
state[2 * 4 + i], state[2 * 5 + i], state[2 * 6 + i], state[2 * 7 + i]);
|
65
|
+
}
|
66
|
+
|
67
|
+
for (i = 0; i < ARGON2_512BIT_WORDS_IN_BLOCK; i++) {
|
68
|
+
state[i] = _mm512_xor_si512(state[i], block_XY[i]);
|
69
|
+
_mm512_storeu_si512((__m512i *) (&next_block[64 * i]), state[i]);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
static void
|
74
|
+
fill_block_with_xor(__m512i *state, const uint8_t *ref_block,
|
75
|
+
uint8_t *next_block)
|
76
|
+
{
|
77
|
+
__m512i block_XY[ARGON2_512BIT_WORDS_IN_BLOCK];
|
78
|
+
uint32_t i;
|
79
|
+
|
80
|
+
for (i = 0; i < ARGON2_512BIT_WORDS_IN_BLOCK; i++) {
|
81
|
+
state[i] = _mm512_xor_si512(
|
82
|
+
state[i], _mm512_loadu_si512((__m512i const *) (&ref_block[64 * i])));
|
83
|
+
block_XY[i] = _mm512_xor_si512(
|
84
|
+
state[i], _mm512_loadu_si512((__m512i const *) (&next_block[64 * i])));
|
85
|
+
}
|
86
|
+
|
87
|
+
for (i = 0; i < 2; ++i) {
|
88
|
+
BLAKE2_ROUND_1(
|
89
|
+
state[8 * i + 0], state[8 * i + 1], state[8 * i + 2], state[8 * i + 3],
|
90
|
+
state[8 * i + 4], state[8 * i + 5], state[8 * i + 6], state[8 * i + 7]);
|
91
|
+
}
|
92
|
+
|
93
|
+
for (i = 0; i < 2; ++i) {
|
94
|
+
BLAKE2_ROUND_2(
|
95
|
+
state[2 * 0 + i], state[2 * 1 + i], state[2 * 2 + i], state[2 * 3 + i],
|
96
|
+
state[2 * 4 + i], state[2 * 5 + i], state[2 * 6 + i], state[2 * 7 + i]);
|
97
|
+
}
|
98
|
+
|
99
|
+
for (i = 0; i < ARGON2_512BIT_WORDS_IN_BLOCK; i++) {
|
100
|
+
state[i] = _mm512_xor_si512(state[i], block_XY[i]);
|
101
|
+
_mm512_storeu_si512((__m512i *) (&next_block[64 * i]), state[i]);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
static void
|
106
|
+
generate_addresses(const argon2_instance_t *instance,
|
107
|
+
const argon2_position_t *position, uint64_t *pseudo_rands)
|
108
|
+
{
|
109
|
+
block address_block, input_block, tmp_block;
|
110
|
+
uint32_t i;
|
111
|
+
|
112
|
+
init_block_value(&address_block, 0);
|
113
|
+
init_block_value(&input_block, 0);
|
114
|
+
|
115
|
+
if (instance != NULL && position != NULL) {
|
116
|
+
input_block.v[0] = position->pass;
|
117
|
+
input_block.v[1] = position->lane;
|
118
|
+
input_block.v[2] = position->slice;
|
119
|
+
input_block.v[3] = instance->memory_blocks;
|
120
|
+
input_block.v[4] = instance->passes;
|
121
|
+
input_block.v[5] = instance->type;
|
122
|
+
|
123
|
+
for (i = 0; i < instance->segment_length; ++i) {
|
124
|
+
if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) {
|
125
|
+
/* Temporary zero-initialized blocks */
|
126
|
+
__m512i zero_block[ARGON2_512BIT_WORDS_IN_BLOCK];
|
127
|
+
__m512i zero2_block[ARGON2_512BIT_WORDS_IN_BLOCK];
|
128
|
+
|
129
|
+
memset(zero_block, 0, sizeof(zero_block));
|
130
|
+
memset(zero2_block, 0, sizeof(zero2_block));
|
131
|
+
init_block_value(&address_block, 0);
|
132
|
+
init_block_value(&tmp_block, 0);
|
133
|
+
/* Increasing index counter */
|
134
|
+
input_block.v[6]++;
|
135
|
+
/* First iteration of G */
|
136
|
+
fill_block_with_xor(zero_block, (uint8_t *) &input_block.v,
|
137
|
+
(uint8_t *) &tmp_block.v);
|
138
|
+
/* Second iteration of G */
|
139
|
+
fill_block_with_xor(zero2_block, (uint8_t *) &tmp_block.v,
|
140
|
+
(uint8_t *) &address_block.v);
|
141
|
+
}
|
142
|
+
|
143
|
+
pseudo_rands[i] = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK];
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
void
|
149
|
+
fill_segment_avx512f(const argon2_instance_t *instance,
|
150
|
+
argon2_position_t position)
|
151
|
+
{
|
152
|
+
block *ref_block = NULL, *curr_block = NULL;
|
153
|
+
uint64_t pseudo_rand, ref_index, ref_lane;
|
154
|
+
uint32_t prev_offset, curr_offset;
|
155
|
+
uint32_t starting_index, i;
|
156
|
+
__m512i state[ARGON2_512BIT_WORDS_IN_BLOCK];
|
157
|
+
int data_independent_addressing = 1;
|
158
|
+
|
159
|
+
/* Pseudo-random values that determine the reference block position */
|
160
|
+
uint64_t *pseudo_rands = NULL;
|
161
|
+
|
162
|
+
if (instance == NULL) {
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
|
166
|
+
if (instance->type == Argon2_id &&
|
167
|
+
(position.pass != 0 || position.slice >= ARGON2_SYNC_POINTS / 2)) {
|
168
|
+
data_independent_addressing = 0;
|
169
|
+
}
|
170
|
+
|
171
|
+
pseudo_rands = instance->pseudo_rands;
|
172
|
+
|
173
|
+
if (data_independent_addressing) {
|
174
|
+
generate_addresses(instance, &position, pseudo_rands);
|
175
|
+
}
|
176
|
+
|
177
|
+
starting_index = 0;
|
178
|
+
|
179
|
+
if ((0 == position.pass) && (0 == position.slice)) {
|
180
|
+
starting_index = 2; /* we have already generated the first two blocks */
|
181
|
+
}
|
182
|
+
|
183
|
+
/* Offset of the current block */
|
184
|
+
curr_offset = position.lane * instance->lane_length +
|
185
|
+
position.slice * instance->segment_length + starting_index;
|
186
|
+
|
187
|
+
if (0 == curr_offset % instance->lane_length) {
|
188
|
+
/* Last block in this lane */
|
189
|
+
prev_offset = curr_offset + instance->lane_length - 1;
|
190
|
+
} else {
|
191
|
+
/* Previous block */
|
192
|
+
prev_offset = curr_offset - 1;
|
193
|
+
}
|
194
|
+
|
195
|
+
memcpy(state, ((instance->region->memory + prev_offset)->v),
|
196
|
+
ARGON2_BLOCK_SIZE);
|
197
|
+
|
198
|
+
for (i = starting_index; i < instance->segment_length;
|
199
|
+
++i, ++curr_offset, ++prev_offset) {
|
200
|
+
/*1.1 Rotating prev_offset if needed */
|
201
|
+
if (curr_offset % instance->lane_length == 1) {
|
202
|
+
prev_offset = curr_offset - 1;
|
203
|
+
}
|
204
|
+
|
205
|
+
/* 1.2 Computing the index of the reference block */
|
206
|
+
/* 1.2.1 Taking pseudo-random value from the previous block */
|
207
|
+
if (data_independent_addressing) {
|
208
|
+
#pragma warning(push)
|
209
|
+
#pragma warning(disable : 6385)
|
210
|
+
pseudo_rand = pseudo_rands[i];
|
211
|
+
#pragma warning(pop)
|
212
|
+
} else {
|
213
|
+
pseudo_rand = instance->region->memory[prev_offset].v[0];
|
214
|
+
}
|
215
|
+
|
216
|
+
/* 1.2.2 Computing the lane of the reference block */
|
217
|
+
ref_lane = ((pseudo_rand >> 32)) % instance->lanes;
|
218
|
+
|
219
|
+
if ((position.pass == 0) && (position.slice == 0)) {
|
220
|
+
/* Can not reference other lanes yet */
|
221
|
+
ref_lane = position.lane;
|
222
|
+
}
|
223
|
+
|
224
|
+
/* 1.2.3 Computing the number of possible reference block within the
|
225
|
+
* lane.
|
226
|
+
*/
|
227
|
+
position.index = i;
|
228
|
+
ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF,
|
229
|
+
ref_lane == position.lane);
|
230
|
+
|
231
|
+
/* 2 Creating a new block */
|
232
|
+
ref_block = instance->region->memory +
|
233
|
+
instance->lane_length * ref_lane + ref_index;
|
234
|
+
curr_block = instance->region->memory + curr_offset;
|
235
|
+
if (position.pass != 0) {
|
236
|
+
fill_block_with_xor(state, (uint8_t *) ref_block->v,
|
237
|
+
(uint8_t *) curr_block->v);
|
238
|
+
} else {
|
239
|
+
fill_block(state, (uint8_t *) ref_block->v,
|
240
|
+
(uint8_t *) curr_block->v);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
}
|
244
|
+
#endif
|