rbnacl-libsodium 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +23 -0
- data/CHANGES.md +5 -0
- data/Gemfile +5 -2
- data/Rakefile +5 -0
- data/ext/rbnacl/extconf.rb +2 -1
- data/lib/rbnacl/libsodium.rb +8 -2
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/AUTHORS +14 -0
- data/vendor/libsodium/ChangeLog +26 -0
- data/vendor/libsodium/LICENSE +1 -1
- data/vendor/libsodium/Makefile.am +1 -0
- data/vendor/libsodium/Makefile.in +9 -0
- data/vendor/libsodium/README.markdown +7 -0
- data/vendor/libsodium/aclocal.m4 +1 -0
- data/vendor/libsodium/appveyor.yml +25 -0
- data/vendor/libsodium/autom4te.cache/output.1 +640 -126
- data/vendor/libsodium/autom4te.cache/output.6 +19049 -0
- data/vendor/libsodium/autom4te.cache/requests +1151 -914
- data/vendor/libsodium/autom4te.cache/traces.1 +472 -426
- data/vendor/libsodium/autom4te.cache/traces.6 +3193 -0
- data/vendor/libsodium/builds/msvc/version.h +2 -2
- data/vendor/libsodium/builds/msvc/vs2010/libsodium.sln +50 -79
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +208 -166
- data/vendor/libsodium/builds/msvc/vs2012/libsodium.sln +50 -79
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +206 -164
- data/vendor/libsodium/builds/msvc/vs2013/libsodium.sln +52 -81
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +206 -164
- data/vendor/libsodium/builds/msvc/vs2015/libsodium.sln +52 -81
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +206 -164
- data/vendor/libsodium/configure +639 -125
- data/vendor/libsodium/configure.ac +94 -16
- data/vendor/libsodium/dist-build/Makefile.in +9 -0
- data/vendor/libsodium/dist-build/emscripten-symbols.def +370 -0
- data/vendor/libsodium/dist-build/emscripten.sh +9 -3
- data/vendor/libsodium/dist-build/generate-emscripten-symbols.sh +43 -0
- data/vendor/libsodium/libsodium-uninstalled.pc.in +1 -1
- data/vendor/libsodium/libsodium.pc.in +1 -1
- data/vendor/libsodium/libsodium.vcxproj +70 -66
- data/vendor/libsodium/libsodium.vcxproj.filters +204 -192
- data/vendor/libsodium/m4/ax_valgrind_check.m4 +190 -0
- data/vendor/libsodium/msvc-scripts/Makefile.in +9 -0
- data/vendor/libsodium/msvc-scripts/process.bat +2 -2
- data/vendor/libsodium/src/Makefile.in +9 -0
- data/vendor/libsodium/src/libsodium/Makefile.am +31 -6
- data/vendor/libsodium/src/libsodium/Makefile.in +238 -42
- data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +234 -38
- data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +208 -118
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_seal.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/before_curve25519xsalsa20poly1305.c +1 -4
- data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +1799 -1790
- data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.h +39 -39
- data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.c +86 -0
- data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.h +28 -0
- data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20.c +38 -46
- data/vendor/libsodium/src/libsodium/crypto_core/salsa20/ref/core_salsa20.c +47 -55
- data/vendor/libsodium/src/libsodium/crypto_core/salsa2012/ref/core_salsa2012.c +47 -55
- data/vendor/libsodium/src/libsodium/crypto_core/salsa208/ref/core_salsa208.c +47 -55
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/generichash_blake2_api.c +7 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2-impl.h +0 -89
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2.h +50 -141
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.c +45 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.h +123 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ref.c +3 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/{blake2b-round.h → blake2b-compress-sse41.h} +2 -28
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.c +2 -4
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.h +97 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-avx2.h +339 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse2.h +0 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse41.h +0 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +29 -18
- data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +4 -43
- data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +3 -32
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +1 -20
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +22 -41
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +12 -39
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +2 -4
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h +1 -20
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +570 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +198 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +444 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h +32 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c +229 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +222 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-impl.h +40 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +238 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +251 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.c +80 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.h +8 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ref.h +38 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h +117 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +164 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c +106 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +4 -4
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +186 -186
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +3 -2
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +33 -33
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +253 -254
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +16 -17
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +11 -11
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/consts_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe.h +3 -2
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51.h +5 -3
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c +41 -41
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_mul.S +10 -2
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_nsquare.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_pack.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c +31 -32
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +2 -6
- data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash24.c +8 -28
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +75 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/afternm_aes128ctr.c +6 -6
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/common.h +1 -18
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128_aes128ctr.c +20 -20
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/types.h +4 -4
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/xor_afternm_aes128ctr.c +6 -6
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +56 -77
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c +1 -5
- data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c +1 -5
- data/vendor/libsodium/src/libsodium/include/Makefile.am +3 -0
- data/vendor/libsodium/src/libsodium/include/Makefile.in +19 -8
- data/vendor/libsodium/src/libsodium/include/sodium.h +3 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +50 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +94 -22
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +6 -6
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_hchacha20.h +35 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +3 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +89 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +86 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +6 -6
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +0 -11
- data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +3 -0
- data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +3 -0
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +5 -1
- data/vendor/libsodium/src/libsodium/sodium/common.h +150 -0
- data/vendor/libsodium/src/libsodium/sodium/core.c +3 -1
- data/vendor/libsodium/src/libsodium/sodium/runtime.c +37 -19
- data/vendor/libsodium/src/libsodium/sodium/utils.c +18 -9
- data/vendor/libsodium/test/Makefile.in +9 -0
- data/vendor/libsodium/test/default/Makefile.am +10 -0
- data/vendor/libsodium/test/default/Makefile.in +53 -20
- data/vendor/libsodium/test/default/aead_aes256gcm.c +43 -17
- data/vendor/libsodium/test/default/aead_chacha20poly1305.c +179 -86
- data/vendor/libsodium/test/default/auth7.c +5 -5
- data/vendor/libsodium/test/default/box.c +4 -4
- data/vendor/libsodium/test/default/box2.c +1 -1
- data/vendor/libsodium/test/default/core6.c +1 -1
- data/vendor/libsodium/test/default/generichash.c +12 -1
- data/vendor/libsodium/test/default/generichash2.c +2 -2
- data/vendor/libsodium/test/default/generichash3.c +21 -0
- data/vendor/libsodium/test/default/pwhash.c +186 -168
- data/vendor/libsodium/test/default/pwhash.exp +11 -30
- data/vendor/libsodium/test/default/pwhash_scrypt.c +349 -0
- data/vendor/libsodium/test/default/pwhash_scrypt.exp +31 -0
- data/vendor/libsodium/test/default/secretbox.c +1 -1
- data/vendor/libsodium/test/default/secretbox2.c +1 -1
- data/vendor/libsodium/test/default/sign.c +15 -0
- data/vendor/libsodium/test/default/sodium_utils2.c +8 -3
- data/vendor/libsodium/test/default/sodium_utils3.c +4 -2
- data/vendor/libsodium/test/default/verify1.c +0 -4
- data/vendor/libsodium/test/quirks/quirks.h +3 -0
- metadata +37 -22
- data/vendor/libsodium/builds/msvc/vs2010/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2010/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/builds/msvc/vs2012/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2012/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/builds/msvc/vs2013/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2013/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/builds/msvc/vs2015/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2015/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sysendian.h +0 -146
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/common_aes128ctr.c +0 -64
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef argon2_encoding_H
|
2
|
+
#define argon2_encoding_H
|
3
|
+
|
4
|
+
#include "argon2.h"
|
5
|
+
|
6
|
+
/*
|
7
|
+
* encode an Argon2 hash string into the provided buffer. 'dst_len'
|
8
|
+
* contains the size, in characters, of the 'dst' buffer; if 'dst_len'
|
9
|
+
* is less than the number of required characters (including the
|
10
|
+
* terminating 0), then this function returns 0.
|
11
|
+
*
|
12
|
+
* if ctx->outlen is 0, then the hash string will be a salt string
|
13
|
+
* (no output). if ctx->saltlen is also 0, then the string will be a
|
14
|
+
* parameter-only string (no salt and no output).
|
15
|
+
*
|
16
|
+
* On success, ARGON2_OK is returned.
|
17
|
+
*
|
18
|
+
* No other parameters are checked
|
19
|
+
*/
|
20
|
+
int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
|
21
|
+
argon2_type type);
|
22
|
+
|
23
|
+
/*
|
24
|
+
* Decodes an Argon2 hash string into the provided structure 'ctx'.
|
25
|
+
* The fields ctx.saltlen, ctx.adlen, ctx.outlen set the maximal salt, ad, out length values
|
26
|
+
* that are allowed; invalid input string causes an error
|
27
|
+
*
|
28
|
+
* Returned value is ARGON2_OK on success.
|
29
|
+
*/
|
30
|
+
int decode_string(argon2_context *ctx, const char *str, argon2_type type);
|
31
|
+
|
32
|
+
#endif
|
@@ -0,0 +1,229 @@
|
|
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.h"
|
19
|
+
#include "argon2-core.h"
|
20
|
+
#include "argon2-impl.h"
|
21
|
+
#include "blamka-round-ref.h"
|
22
|
+
|
23
|
+
static void fill_block(const block *prev_block, const block *ref_block,
|
24
|
+
block *next_block) {
|
25
|
+
block blockR, block_tmp;
|
26
|
+
unsigned i;
|
27
|
+
|
28
|
+
copy_block(&blockR, ref_block);
|
29
|
+
xor_block(&blockR, prev_block);
|
30
|
+
copy_block(&block_tmp, &blockR);
|
31
|
+
/* Now blockR = ref_block + prev_block and bloc_tmp = ref_block + prev_block
|
32
|
+
Apply Blake2 on columns of 64-bit words: (0,1,...,15), then
|
33
|
+
(16,17,..31)... finally (112,113,...127) */
|
34
|
+
for (i = 0; i < 8; ++i) {
|
35
|
+
BLAKE2_ROUND_NOMSG(
|
36
|
+
blockR.v[16 * i], blockR.v[16 * i + 1], blockR.v[16 * i + 2],
|
37
|
+
blockR.v[16 * i + 3], blockR.v[16 * i + 4], blockR.v[16 * i + 5],
|
38
|
+
blockR.v[16 * i + 6], blockR.v[16 * i + 7], blockR.v[16 * i + 8],
|
39
|
+
blockR.v[16 * i + 9], blockR.v[16 * i + 10], blockR.v[16 * i + 11],
|
40
|
+
blockR.v[16 * i + 12], blockR.v[16 * i + 13], blockR.v[16 * i + 14],
|
41
|
+
blockR.v[16 * i + 15]);
|
42
|
+
}
|
43
|
+
|
44
|
+
/* Apply Blake2 on rows of 64-bit words: (0,1,16,17,...112,113), then
|
45
|
+
(2,3,18,19,...,114,115).. finally (14,15,30,31,...,126,127) */
|
46
|
+
for (i = 0; i < 8; i++) {
|
47
|
+
BLAKE2_ROUND_NOMSG(
|
48
|
+
blockR.v[2 * i], blockR.v[2 * i + 1], blockR.v[2 * i + 16],
|
49
|
+
blockR.v[2 * i + 17], blockR.v[2 * i + 32], blockR.v[2 * i + 33],
|
50
|
+
blockR.v[2 * i + 48], blockR.v[2 * i + 49], blockR.v[2 * i + 64],
|
51
|
+
blockR.v[2 * i + 65], blockR.v[2 * i + 80], blockR.v[2 * i + 81],
|
52
|
+
blockR.v[2 * i + 96], blockR.v[2 * i + 97], blockR.v[2 * i + 112],
|
53
|
+
blockR.v[2 * i + 113]);
|
54
|
+
}
|
55
|
+
|
56
|
+
copy_block(next_block, &block_tmp);
|
57
|
+
xor_block(next_block, &blockR);
|
58
|
+
}
|
59
|
+
|
60
|
+
static void fill_block_with_xor(const block *prev_block, const block *ref_block,
|
61
|
+
block *next_block) {
|
62
|
+
block blockR, block_tmp;
|
63
|
+
unsigned i;
|
64
|
+
|
65
|
+
copy_block(&blockR, ref_block);
|
66
|
+
xor_block(&blockR, prev_block);
|
67
|
+
copy_block(&block_tmp, &blockR);
|
68
|
+
xor_block(&block_tmp, next_block); /* Saving the next block contents for XOR over */
|
69
|
+
/* Now blockR = ref_block + prev_block and bloc_tmp = ref_block + prev_block + next_block */
|
70
|
+
/* Apply Blake2 on columns of 64-bit words: (0,1,...,15) , then
|
71
|
+
(16,17,..31)... finally (112,113,...127) */
|
72
|
+
for (i = 0; i < 8; ++i) {
|
73
|
+
BLAKE2_ROUND_NOMSG(
|
74
|
+
blockR.v[16 * i], blockR.v[16 * i + 1], blockR.v[16 * i + 2],
|
75
|
+
blockR.v[16 * i + 3], blockR.v[16 * i + 4], blockR.v[16 * i + 5],
|
76
|
+
blockR.v[16 * i + 6], blockR.v[16 * i + 7], blockR.v[16 * i + 8],
|
77
|
+
blockR.v[16 * i + 9], blockR.v[16 * i + 10], blockR.v[16 * i + 11],
|
78
|
+
blockR.v[16 * i + 12], blockR.v[16 * i + 13], blockR.v[16 * i + 14],
|
79
|
+
blockR.v[16 * i + 15]);
|
80
|
+
}
|
81
|
+
|
82
|
+
/* Apply Blake2 on rows of 64-bit words: (0,1,16,17,...112,113), then
|
83
|
+
(2,3,18,19,...,114,115).. finally (14,15,30,31,...,126,127) */
|
84
|
+
for (i = 0; i < 8; i++) {
|
85
|
+
BLAKE2_ROUND_NOMSG(
|
86
|
+
blockR.v[2 * i], blockR.v[2 * i + 1], blockR.v[2 * i + 16],
|
87
|
+
blockR.v[2 * i + 17], blockR.v[2 * i + 32], blockR.v[2 * i + 33],
|
88
|
+
blockR.v[2 * i + 48], blockR.v[2 * i + 49], blockR.v[2 * i + 64],
|
89
|
+
blockR.v[2 * i + 65], blockR.v[2 * i + 80], blockR.v[2 * i + 81],
|
90
|
+
blockR.v[2 * i + 96], blockR.v[2 * i + 97], blockR.v[2 * i + 112],
|
91
|
+
blockR.v[2 * i + 113]);
|
92
|
+
}
|
93
|
+
|
94
|
+
copy_block(next_block, &block_tmp);
|
95
|
+
xor_block(next_block, &blockR);
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* Generate pseudo-random values to reference blocks in the segment and puts
|
100
|
+
* them into the array
|
101
|
+
* @param instance Pointer to the current instance
|
102
|
+
* @param position Pointer to the current position
|
103
|
+
* @param pseudo_rands Pointer to the array of 64-bit values
|
104
|
+
* @pre pseudo_rands must point to @a instance->segment_length allocated values
|
105
|
+
*/
|
106
|
+
static void generate_addresses(const argon2_instance_t *instance,
|
107
|
+
const argon2_position_t *position,
|
108
|
+
uint64_t *pseudo_rands) {
|
109
|
+
block zero_block, input_block, address_block, tmp_block;
|
110
|
+
uint32_t i;
|
111
|
+
|
112
|
+
init_block_value(&zero_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
|
+
input_block.v[6]++;
|
126
|
+
init_block_value(&tmp_block, 0);
|
127
|
+
init_block_value(&address_block, 0);
|
128
|
+
fill_block_with_xor(&zero_block, &input_block, &tmp_block);
|
129
|
+
fill_block_with_xor(&zero_block, &tmp_block, &address_block);
|
130
|
+
}
|
131
|
+
|
132
|
+
pseudo_rands[i] = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK];
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
int fill_segment_ref(const argon2_instance_t *instance,
|
138
|
+
argon2_position_t position) {
|
139
|
+
block *ref_block = NULL, *curr_block = NULL;
|
140
|
+
uint64_t pseudo_rand, ref_index, ref_lane;
|
141
|
+
uint32_t prev_offset, curr_offset;
|
142
|
+
uint32_t starting_index;
|
143
|
+
uint32_t i;
|
144
|
+
const int data_independent_addressing = 1; /* instance->type == Argon2_i */
|
145
|
+
/* Pseudo-random values that determine the reference block position */
|
146
|
+
uint64_t *pseudo_rands = NULL;
|
147
|
+
|
148
|
+
if (instance == NULL) {
|
149
|
+
return ARGON2_OK;
|
150
|
+
}
|
151
|
+
|
152
|
+
pseudo_rands =
|
153
|
+
(uint64_t *)malloc(sizeof(uint64_t) * (instance->segment_length));
|
154
|
+
|
155
|
+
if (pseudo_rands == NULL) {
|
156
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
157
|
+
}
|
158
|
+
|
159
|
+
if (data_independent_addressing) {
|
160
|
+
generate_addresses(instance, &position, pseudo_rands);
|
161
|
+
}
|
162
|
+
|
163
|
+
starting_index = 0;
|
164
|
+
|
165
|
+
if ((0 == position.pass) && (0 == position.slice)) {
|
166
|
+
starting_index = 2; /* we have already generated the first two blocks */
|
167
|
+
}
|
168
|
+
|
169
|
+
/* Offset of the current block */
|
170
|
+
curr_offset = position.lane * instance->lane_length +
|
171
|
+
position.slice * instance->segment_length + starting_index;
|
172
|
+
|
173
|
+
if (0 == curr_offset % instance->lane_length) {
|
174
|
+
/* Last block in this lane */
|
175
|
+
prev_offset = curr_offset + instance->lane_length - 1;
|
176
|
+
} else {
|
177
|
+
/* Previous block */
|
178
|
+
prev_offset = curr_offset - 1;
|
179
|
+
}
|
180
|
+
|
181
|
+
for (i = starting_index; i < instance->segment_length;
|
182
|
+
++i, ++curr_offset, ++prev_offset) {
|
183
|
+
/*1.1 Rotating prev_offset if needed */
|
184
|
+
if (curr_offset % instance->lane_length == 1) {
|
185
|
+
prev_offset = curr_offset - 1;
|
186
|
+
}
|
187
|
+
|
188
|
+
/* 1.2 Computing the index of the reference block */
|
189
|
+
/* 1.2.1 Taking pseudo-random value from the previous block */
|
190
|
+
if (data_independent_addressing) {
|
191
|
+
#pragma warning(push)
|
192
|
+
#pragma warning(disable: 6385)
|
193
|
+
pseudo_rand = pseudo_rands[i];
|
194
|
+
#pragma warning(pop)
|
195
|
+
} else {
|
196
|
+
pseudo_rand = instance->region->memory[prev_offset].v[0];
|
197
|
+
}
|
198
|
+
|
199
|
+
/* 1.2.2 Computing the lane of the reference block */
|
200
|
+
ref_lane = ((pseudo_rand >> 32)) % instance->lanes;
|
201
|
+
|
202
|
+
if ((position.pass == 0) && (position.slice == 0)) {
|
203
|
+
/* Can not reference other lanes yet */
|
204
|
+
ref_lane = position.lane;
|
205
|
+
}
|
206
|
+
|
207
|
+
/* 1.2.3 Computing the number of possible reference block within the
|
208
|
+
* lane.
|
209
|
+
*/
|
210
|
+
position.index = i;
|
211
|
+
ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF,
|
212
|
+
ref_lane == position.lane);
|
213
|
+
|
214
|
+
/* 2 Creating a new block */
|
215
|
+
ref_block =
|
216
|
+
instance->region->memory + instance->lane_length * ref_lane + ref_index;
|
217
|
+
curr_block = instance->region->memory + curr_offset;
|
218
|
+
if (position.pass != 0) {
|
219
|
+
fill_block_with_xor(instance->region->memory + prev_offset, ref_block, curr_block);
|
220
|
+
} else {
|
221
|
+
fill_block(instance->region->memory + prev_offset, ref_block, curr_block);
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
free(pseudo_rands);
|
226
|
+
|
227
|
+
return ARGON2_OK;
|
228
|
+
}
|
229
|
+
|
@@ -0,0 +1,222 @@
|
|
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
|
+
#if (defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)) || \
|
19
|
+
(defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)))
|
20
|
+
|
21
|
+
#pragma GCC target("sse2")
|
22
|
+
#pragma GCC target("ssse3")
|
23
|
+
|
24
|
+
#ifdef _MSC_VER
|
25
|
+
# include <intrin.h> /* for _mm_set_epi64x */
|
26
|
+
#endif
|
27
|
+
#include <emmintrin.h>
|
28
|
+
#include <tmmintrin.h>
|
29
|
+
|
30
|
+
#include "argon2.h"
|
31
|
+
#include "argon2-core.h"
|
32
|
+
#include "argon2-impl.h"
|
33
|
+
#include "blamka-round-ssse3.h"
|
34
|
+
|
35
|
+
static void fill_block(__m128i *state, const uint8_t *ref_block, uint8_t *next_block) {
|
36
|
+
__m128i block_XY[ARGON2_OWORDS_IN_BLOCK];
|
37
|
+
uint32_t i;
|
38
|
+
|
39
|
+
for (i = 0; i < ARGON2_OWORDS_IN_BLOCK; i++) {
|
40
|
+
block_XY[i] = state[i] = _mm_xor_si128(
|
41
|
+
state[i], _mm_loadu_si128((__m128i const *)(&ref_block[16 * i])));
|
42
|
+
}
|
43
|
+
|
44
|
+
for (i = 0; i < 8; ++i) {
|
45
|
+
BLAKE2_ROUND(state[8 * i + 0], state[8 * i + 1], state[8 * i + 2],
|
46
|
+
state[8 * i + 3], state[8 * i + 4], state[8 * i + 5],
|
47
|
+
state[8 * i + 6], state[8 * i + 7]);
|
48
|
+
}
|
49
|
+
|
50
|
+
for (i = 0; i < 8; ++i) {
|
51
|
+
BLAKE2_ROUND(state[8 * 0 + i], state[8 * 1 + i], state[8 * 2 + i],
|
52
|
+
state[8 * 3 + i], state[8 * 4 + i], state[8 * 5 + i],
|
53
|
+
state[8 * 6 + i], state[8 * 7 + i]);
|
54
|
+
}
|
55
|
+
|
56
|
+
for (i = 0; i < ARGON2_OWORDS_IN_BLOCK; i++) {
|
57
|
+
state[i] = _mm_xor_si128(state[i], block_XY[i]);
|
58
|
+
_mm_storeu_si128((__m128i *)(&next_block[16 * i]), state[i]);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
static void fill_block_with_xor(__m128i *state, const uint8_t *ref_block, uint8_t *next_block) {
|
63
|
+
__m128i block_XY[ARGON2_OWORDS_IN_BLOCK];
|
64
|
+
uint32_t i;
|
65
|
+
|
66
|
+
for (i = 0; i < ARGON2_OWORDS_IN_BLOCK; i++) {
|
67
|
+
state[i] = _mm_xor_si128(state[i], _mm_loadu_si128((__m128i const *)(&ref_block[16 * i])));
|
68
|
+
block_XY[i] = _mm_xor_si128(state[i], _mm_loadu_si128((__m128i const *)(&next_block[16 * i])));
|
69
|
+
}
|
70
|
+
|
71
|
+
for (i = 0; i < 8; ++i) {
|
72
|
+
BLAKE2_ROUND(state[8 * i + 0], state[8 * i + 1], state[8 * i + 2],
|
73
|
+
state[8 * i + 3], state[8 * i + 4], state[8 * i + 5],
|
74
|
+
state[8 * i + 6], state[8 * i + 7]);
|
75
|
+
}
|
76
|
+
|
77
|
+
for (i = 0; i < 8; ++i) {
|
78
|
+
BLAKE2_ROUND(state[8 * 0 + i], state[8 * 1 + i], state[8 * 2 + i],
|
79
|
+
state[8 * 3 + i], state[8 * 4 + i], state[8 * 5 + i],
|
80
|
+
state[8 * 6 + i], state[8 * 7 + i]);
|
81
|
+
}
|
82
|
+
|
83
|
+
for (i = 0; i < ARGON2_OWORDS_IN_BLOCK; i++) {
|
84
|
+
state[i] = _mm_xor_si128(state[i], block_XY[i]);
|
85
|
+
_mm_storeu_si128((__m128i *)(&next_block[16 * i]), state[i]);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
static void generate_addresses(const argon2_instance_t *instance,
|
90
|
+
const argon2_position_t *position,
|
91
|
+
uint64_t *pseudo_rands) {
|
92
|
+
block address_block, input_block, tmp_block;
|
93
|
+
uint32_t i;
|
94
|
+
|
95
|
+
init_block_value(&address_block, 0);
|
96
|
+
init_block_value(&input_block, 0);
|
97
|
+
|
98
|
+
if (instance != NULL && position != NULL) {
|
99
|
+
input_block.v[0] = position->pass;
|
100
|
+
input_block.v[1] = position->lane;
|
101
|
+
input_block.v[2] = position->slice;
|
102
|
+
input_block.v[3] = instance->memory_blocks;
|
103
|
+
input_block.v[4] = instance->passes;
|
104
|
+
input_block.v[5] = instance->type;
|
105
|
+
|
106
|
+
for (i = 0; i < instance->segment_length; ++i) {
|
107
|
+
if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) {
|
108
|
+
/* Temporary zero-initialized blocks */
|
109
|
+
__m128i zero_block[ARGON2_OWORDS_IN_BLOCK];
|
110
|
+
__m128i zero2_block[ARGON2_OWORDS_IN_BLOCK];
|
111
|
+
memset(zero_block, 0, sizeof(zero_block));
|
112
|
+
memset(zero2_block, 0, sizeof(zero2_block));
|
113
|
+
init_block_value(&address_block, 0);
|
114
|
+
init_block_value(&tmp_block, 0);
|
115
|
+
/* Increasing index counter */
|
116
|
+
input_block.v[6]++;
|
117
|
+
/* First iteration of G */
|
118
|
+
fill_block_with_xor(zero_block, (uint8_t *)&input_block.v, (uint8_t *)&tmp_block.v);
|
119
|
+
/* Second iteration of G */
|
120
|
+
fill_block_with_xor(zero2_block, (uint8_t *)&tmp_block.v, (uint8_t *)&address_block.v);
|
121
|
+
}
|
122
|
+
|
123
|
+
pseudo_rands[i] = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK];
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
int fill_segment_ssse3(const argon2_instance_t *instance,
|
129
|
+
argon2_position_t position) {
|
130
|
+
block *ref_block = NULL, *curr_block = NULL;
|
131
|
+
uint64_t pseudo_rand, ref_index, ref_lane;
|
132
|
+
uint32_t prev_offset, curr_offset;
|
133
|
+
uint32_t starting_index, i;
|
134
|
+
__m128i state[64];
|
135
|
+
const int data_independent_addressing = 1; /* instance->type == Argon2_i */
|
136
|
+
|
137
|
+
/* Pseudo-random values that determine the reference block position */
|
138
|
+
uint64_t *pseudo_rands = NULL;
|
139
|
+
|
140
|
+
if (instance == NULL) {
|
141
|
+
return ARGON2_OK;
|
142
|
+
}
|
143
|
+
|
144
|
+
pseudo_rands =
|
145
|
+
(uint64_t *)malloc(sizeof(uint64_t) * instance->segment_length);
|
146
|
+
if (pseudo_rands == NULL) {
|
147
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
148
|
+
}
|
149
|
+
|
150
|
+
if (data_independent_addressing) {
|
151
|
+
generate_addresses(instance, &position, pseudo_rands);
|
152
|
+
}
|
153
|
+
|
154
|
+
starting_index = 0;
|
155
|
+
|
156
|
+
if ((0 == position.pass) && (0 == position.slice)) {
|
157
|
+
starting_index = 2; /* we have already generated the first two blocks */
|
158
|
+
}
|
159
|
+
|
160
|
+
/* Offset of the current block */
|
161
|
+
curr_offset = position.lane * instance->lane_length +
|
162
|
+
position.slice * instance->segment_length + starting_index;
|
163
|
+
|
164
|
+
if (0 == curr_offset % instance->lane_length) {
|
165
|
+
/* Last block in this lane */
|
166
|
+
prev_offset = curr_offset + instance->lane_length - 1;
|
167
|
+
} else {
|
168
|
+
/* Previous block */
|
169
|
+
prev_offset = curr_offset - 1;
|
170
|
+
}
|
171
|
+
|
172
|
+
memcpy(state, ((instance->region->memory + prev_offset)->v), ARGON2_BLOCK_SIZE);
|
173
|
+
|
174
|
+
for (i = starting_index; i < instance->segment_length;
|
175
|
+
++i, ++curr_offset, ++prev_offset) {
|
176
|
+
/*1.1 Rotating prev_offset if needed */
|
177
|
+
if (curr_offset % instance->lane_length == 1) {
|
178
|
+
prev_offset = curr_offset - 1;
|
179
|
+
}
|
180
|
+
|
181
|
+
/* 1.2 Computing the index of the reference block */
|
182
|
+
/* 1.2.1 Taking pseudo-random value from the previous block */
|
183
|
+
if (data_independent_addressing) {
|
184
|
+
#pragma warning(push)
|
185
|
+
#pragma warning(disable: 6385)
|
186
|
+
pseudo_rand = pseudo_rands[i];
|
187
|
+
#pragma warning(pop)
|
188
|
+
} else {
|
189
|
+
pseudo_rand = instance->region->memory[prev_offset].v[0];
|
190
|
+
}
|
191
|
+
|
192
|
+
/* 1.2.2 Computing the lane of the reference block */
|
193
|
+
ref_lane = ((pseudo_rand >> 32)) % instance->lanes;
|
194
|
+
|
195
|
+
if ((position.pass == 0) && (position.slice == 0)) {
|
196
|
+
/* Can not reference other lanes yet */
|
197
|
+
ref_lane = position.lane;
|
198
|
+
}
|
199
|
+
|
200
|
+
/* 1.2.3 Computing the number of possible reference block within the
|
201
|
+
* lane.
|
202
|
+
*/
|
203
|
+
position.index = i;
|
204
|
+
ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF,
|
205
|
+
ref_lane == position.lane);
|
206
|
+
|
207
|
+
/* 2 Creating a new block */
|
208
|
+
ref_block =
|
209
|
+
instance->region->memory + instance->lane_length * ref_lane + ref_index;
|
210
|
+
curr_block = instance->region->memory + curr_offset;
|
211
|
+
if (position.pass != 0) {
|
212
|
+
fill_block_with_xor(state, (uint8_t *)ref_block->v, (uint8_t *)curr_block->v);
|
213
|
+
} else {
|
214
|
+
fill_block(state, (uint8_t *)ref_block->v, (uint8_t *)curr_block->v);
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
free(pseudo_rands);
|
219
|
+
|
220
|
+
return ARGON2_OK;
|
221
|
+
}
|
222
|
+
#endif
|