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,40 @@
|
|
1
|
+
/*
|
2
|
+
BLAKE2 reference source code package - reference C implementations
|
3
|
+
|
4
|
+
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
5
|
+
|
6
|
+
To the extent possible under law, the author(s) have dedicated all copyright
|
7
|
+
and related and neighboring rights to this software to the public domain
|
8
|
+
worldwide. This software is distributed without any warranty.
|
9
|
+
|
10
|
+
You should have received a copy of the CC0 Public Domain Dedication along with
|
11
|
+
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
12
|
+
*/
|
13
|
+
|
14
|
+
#ifndef argon2_impl_H
|
15
|
+
#define argon2_impl_H
|
16
|
+
|
17
|
+
#include <stdint.h>
|
18
|
+
#include <string.h>
|
19
|
+
|
20
|
+
static inline uint32_t rotl32( const uint32_t w, const unsigned c )
|
21
|
+
{
|
22
|
+
return ( w << c ) | ( w >> ( 32 - c ) );
|
23
|
+
}
|
24
|
+
|
25
|
+
static inline uint64_t rotl64( const uint64_t w, const unsigned c )
|
26
|
+
{
|
27
|
+
return ( w << c ) | ( w >> ( 64 - c ) );
|
28
|
+
}
|
29
|
+
|
30
|
+
static inline uint32_t rotr32( const uint32_t w, const unsigned c )
|
31
|
+
{
|
32
|
+
return ( w >> c ) | ( w << ( 32 - c ) );
|
33
|
+
}
|
34
|
+
|
35
|
+
static inline uint64_t rotr64( const uint64_t w, const unsigned c )
|
36
|
+
{
|
37
|
+
return ( w >> c ) | ( w << ( 64 - c ) );
|
38
|
+
}
|
39
|
+
|
40
|
+
#endif
|
@@ -0,0 +1,238 @@
|
|
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 <string.h>
|
16
|
+
#include <stdlib.h>
|
17
|
+
#include <stdio.h>
|
18
|
+
#include <limits.h>
|
19
|
+
|
20
|
+
|
21
|
+
#include "utils.h"
|
22
|
+
|
23
|
+
#include "argon2.h"
|
24
|
+
#include "argon2-encoding.h"
|
25
|
+
#include "argon2-core.h"
|
26
|
+
|
27
|
+
int argon2_ctx(argon2_context *context, argon2_type type) {
|
28
|
+
/* 1. Validate all inputs */
|
29
|
+
int result = validate_inputs(context);
|
30
|
+
uint32_t memory_blocks, segment_length;
|
31
|
+
argon2_instance_t instance;
|
32
|
+
|
33
|
+
if (ARGON2_OK != result) {
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
|
37
|
+
if (Argon2_i != type) {
|
38
|
+
return ARGON2_INCORRECT_TYPE;
|
39
|
+
}
|
40
|
+
|
41
|
+
/* 2. Align memory size */
|
42
|
+
/* Minimum memory_blocks = 8L blocks, where L is the number of lanes */
|
43
|
+
memory_blocks = context->m_cost;
|
44
|
+
|
45
|
+
if (memory_blocks < 2 * ARGON2_SYNC_POINTS * context->lanes) {
|
46
|
+
memory_blocks = 2 * ARGON2_SYNC_POINTS * context->lanes;
|
47
|
+
}
|
48
|
+
|
49
|
+
segment_length = memory_blocks / (context->lanes * ARGON2_SYNC_POINTS);
|
50
|
+
/* Ensure that all segments have equal length */
|
51
|
+
memory_blocks = segment_length * (context->lanes * ARGON2_SYNC_POINTS);
|
52
|
+
|
53
|
+
instance.region = NULL;
|
54
|
+
instance.passes = context->t_cost;
|
55
|
+
instance.memory_blocks = memory_blocks;
|
56
|
+
instance.segment_length = segment_length;
|
57
|
+
instance.lane_length = segment_length * ARGON2_SYNC_POINTS;
|
58
|
+
instance.lanes = context->lanes;
|
59
|
+
instance.threads = context->threads;
|
60
|
+
instance.type = type;
|
61
|
+
|
62
|
+
/* 3. Initialization: Hashing inputs, allocating memory, filling first
|
63
|
+
* blocks
|
64
|
+
*/
|
65
|
+
result = initialize(&instance, context);
|
66
|
+
|
67
|
+
if (ARGON2_OK != result) {
|
68
|
+
return result;
|
69
|
+
}
|
70
|
+
|
71
|
+
/* 4. Filling memory */
|
72
|
+
result = fill_memory_blocks(&instance);
|
73
|
+
|
74
|
+
if (ARGON2_OK != result) {
|
75
|
+
return result;
|
76
|
+
}
|
77
|
+
|
78
|
+
/* 5. Finalization */
|
79
|
+
finalize(context, &instance);
|
80
|
+
|
81
|
+
return ARGON2_OK;
|
82
|
+
}
|
83
|
+
|
84
|
+
int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
85
|
+
const uint32_t parallelism, const void *pwd,
|
86
|
+
const size_t pwdlen, const void *salt, const size_t saltlen,
|
87
|
+
void *hash, const size_t hashlen, char *encoded,
|
88
|
+
const size_t encodedlen, argon2_type type) {
|
89
|
+
|
90
|
+
argon2_context context;
|
91
|
+
int result;
|
92
|
+
uint8_t *out;
|
93
|
+
|
94
|
+
if (pwdlen > ARGON2_MAX_PWD_LENGTH) {
|
95
|
+
return ARGON2_PWD_TOO_LONG;
|
96
|
+
}
|
97
|
+
|
98
|
+
if (hashlen > ARGON2_MAX_OUTLEN) {
|
99
|
+
return ARGON2_OUTPUT_TOO_LONG;
|
100
|
+
}
|
101
|
+
|
102
|
+
if (saltlen > ARGON2_MAX_SALT_LENGTH) {
|
103
|
+
return ARGON2_SALT_TOO_LONG;
|
104
|
+
}
|
105
|
+
|
106
|
+
out = (uint8_t *) malloc(hashlen);
|
107
|
+
if (!out) {
|
108
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
109
|
+
}
|
110
|
+
|
111
|
+
context.out = (uint8_t *)out;
|
112
|
+
context.outlen = (uint32_t)hashlen;
|
113
|
+
context.pwd = (uint8_t *)pwd;
|
114
|
+
context.pwdlen = (uint32_t)pwdlen;
|
115
|
+
context.salt = (uint8_t *)salt;
|
116
|
+
context.saltlen = (uint32_t)saltlen;
|
117
|
+
context.secret = NULL;
|
118
|
+
context.secretlen = 0;
|
119
|
+
context.ad = NULL;
|
120
|
+
context.adlen = 0;
|
121
|
+
context.t_cost = t_cost;
|
122
|
+
context.m_cost = m_cost;
|
123
|
+
context.lanes = parallelism;
|
124
|
+
context.threads = parallelism;
|
125
|
+
context.flags = ARGON2_DEFAULT_FLAGS;
|
126
|
+
|
127
|
+
result = argon2_ctx(&context, type);
|
128
|
+
|
129
|
+
if (result != ARGON2_OK) {
|
130
|
+
sodium_memzero(out, hashlen);
|
131
|
+
free(out);
|
132
|
+
return result;
|
133
|
+
}
|
134
|
+
|
135
|
+
/* if raw hash requested, write it */
|
136
|
+
if (hash) {
|
137
|
+
memcpy(hash, out, hashlen);
|
138
|
+
}
|
139
|
+
|
140
|
+
/* if encoding requested, write it */
|
141
|
+
if (encoded && encodedlen) {
|
142
|
+
if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) {
|
143
|
+
sodium_memzero(out, hashlen);
|
144
|
+
sodium_memzero(encoded, encodedlen);
|
145
|
+
free(out);
|
146
|
+
return ARGON2_ENCODING_FAIL;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
sodium_memzero(out, hashlen);
|
151
|
+
free(out);
|
152
|
+
|
153
|
+
return ARGON2_OK;
|
154
|
+
}
|
155
|
+
|
156
|
+
int argon2i_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
|
157
|
+
const uint32_t parallelism, const void *pwd,
|
158
|
+
const size_t pwdlen, const void *salt,
|
159
|
+
const size_t saltlen, const size_t hashlen,
|
160
|
+
char *encoded, const size_t encodedlen) {
|
161
|
+
|
162
|
+
return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
163
|
+
NULL, hashlen, encoded, encodedlen, Argon2_i);
|
164
|
+
}
|
165
|
+
|
166
|
+
int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
167
|
+
const uint32_t parallelism, const void *pwd,
|
168
|
+
const size_t pwdlen, const void *salt,
|
169
|
+
const size_t saltlen, void *hash, const size_t hashlen) {
|
170
|
+
|
171
|
+
return argon2_hash(t_cost, m_cost, parallelism, pwd, pwdlen, salt, saltlen,
|
172
|
+
hash, hashlen, NULL, 0, Argon2_i);
|
173
|
+
}
|
174
|
+
|
175
|
+
int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
176
|
+
argon2_type type) {
|
177
|
+
|
178
|
+
argon2_context ctx;
|
179
|
+
uint8_t *out;
|
180
|
+
int decode_result;
|
181
|
+
int ret;
|
182
|
+
uint32_t encoded_len;
|
183
|
+
|
184
|
+
memset(&ctx, 0, sizeof ctx);
|
185
|
+
|
186
|
+
ctx.secret = NULL;
|
187
|
+
ctx.secretlen = 0;
|
188
|
+
|
189
|
+
/* max values, to be updated in decode_string */
|
190
|
+
encoded_len = (uint32_t) strlen(encoded);
|
191
|
+
ctx.adlen = encoded_len;
|
192
|
+
ctx.saltlen = encoded_len;
|
193
|
+
ctx.outlen = encoded_len;
|
194
|
+
|
195
|
+
ctx.ad = (uint8_t *) malloc(ctx.adlen);
|
196
|
+
ctx.salt = (uint8_t *) malloc(ctx.saltlen);
|
197
|
+
ctx.out = (uint8_t *) malloc(ctx.outlen);
|
198
|
+
if (!ctx.out || !ctx.salt || !ctx.ad) {
|
199
|
+
free(ctx.ad);
|
200
|
+
free(ctx.salt);
|
201
|
+
free(ctx.out);
|
202
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
203
|
+
}
|
204
|
+
out = (uint8_t *) malloc(ctx.outlen);
|
205
|
+
if (!out) {
|
206
|
+
free(ctx.ad);
|
207
|
+
free(ctx.salt);
|
208
|
+
free(ctx.out);
|
209
|
+
return ARGON2_MEMORY_ALLOCATION_ERROR;
|
210
|
+
}
|
211
|
+
|
212
|
+
decode_result = decode_string(&ctx, encoded, type);
|
213
|
+
if (decode_result != ARGON2_OK) {
|
214
|
+
free(ctx.ad);
|
215
|
+
free(ctx.salt);
|
216
|
+
free(ctx.out);
|
217
|
+
free(out);
|
218
|
+
return decode_result;
|
219
|
+
}
|
220
|
+
|
221
|
+
ret = argon2_hash(ctx.t_cost, ctx.m_cost, ctx.threads, pwd, pwdlen, ctx.salt,
|
222
|
+
ctx.saltlen, out, ctx.outlen, NULL, 0, type);
|
223
|
+
|
224
|
+
free(ctx.ad);
|
225
|
+
free(ctx.salt);
|
226
|
+
|
227
|
+
if (ret != ARGON2_OK || sodium_memcmp(out, ctx.out, ctx.outlen) != 0) {
|
228
|
+
ret = ARGON2_VERIFY_MISMATCH;
|
229
|
+
}
|
230
|
+
free(out);
|
231
|
+
free(ctx.out);
|
232
|
+
|
233
|
+
return ret;
|
234
|
+
}
|
235
|
+
|
236
|
+
int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen) {
|
237
|
+
return argon2_verify(encoded, pwd, pwdlen, Argon2_i);
|
238
|
+
}
|
@@ -0,0 +1,251 @@
|
|
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 this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
10
|
+
*/
|
11
|
+
#ifndef argon2_H
|
12
|
+
#define argon2_H
|
13
|
+
|
14
|
+
#include <stdint.h>
|
15
|
+
#include <stddef.h>
|
16
|
+
#include <limits.h>
|
17
|
+
|
18
|
+
/*
|
19
|
+
* Argon2 input parameter restrictions
|
20
|
+
*/
|
21
|
+
|
22
|
+
/* Minimum and maximum number of lanes (degree of parallelism) */
|
23
|
+
#define ARGON2_MIN_LANES UINT32_C(1)
|
24
|
+
#define ARGON2_MAX_LANES UINT32_C(0xFFFFFF)
|
25
|
+
|
26
|
+
/* Minimum and maximum number of threads */
|
27
|
+
#define ARGON2_MIN_THREADS UINT32_C(1)
|
28
|
+
#define ARGON2_MAX_THREADS UINT32_C(0xFFFFFF)
|
29
|
+
|
30
|
+
/* Number of synchronization points between lanes per pass */
|
31
|
+
#define ARGON2_SYNC_POINTS UINT32_C(4)
|
32
|
+
|
33
|
+
/* Minimum and maximum digest size in bytes */
|
34
|
+
#define ARGON2_MIN_OUTLEN UINT32_C(16)
|
35
|
+
#define ARGON2_MAX_OUTLEN UINT32_C(0xFFFFFFFF)
|
36
|
+
|
37
|
+
/* Minimum and maximum number of memory blocks (each of BLOCK_SIZE bytes) */
|
38
|
+
#define ARGON2_MIN_MEMORY (2 * ARGON2_SYNC_POINTS) /* 2 blocks per slice */
|
39
|
+
|
40
|
+
#define ARGON2_MIN(a, b) ((a) < (b) ? (a) : (b))
|
41
|
+
/* Max memory size is half the addressing space, topping at 2^32 blocks (4 TB) */
|
42
|
+
#define ARGON2_MAX_MEMORY_BITS \
|
43
|
+
ARGON2_MIN(UINT32_C(32), (sizeof(void *) * CHAR_BIT - 10 - 1))
|
44
|
+
#define ARGON2_MAX_MEMORY \
|
45
|
+
ARGON2_MIN(UINT32_C(0xFFFFFFFF), UINT64_C(1) << ARGON2_MAX_MEMORY_BITS)
|
46
|
+
|
47
|
+
/* Minimum and maximum number of passes */
|
48
|
+
#define ARGON2_MIN_TIME UINT32_C(3)
|
49
|
+
#define ARGON2_MAX_TIME UINT32_C(0xFFFFFFFF)
|
50
|
+
|
51
|
+
/* Minimum and maximum password length in bytes */
|
52
|
+
#define ARGON2_MIN_PWD_LENGTH UINT32_C(0)
|
53
|
+
#define ARGON2_MAX_PWD_LENGTH UINT32_C(0xFFFFFFFF)
|
54
|
+
|
55
|
+
/* Minimum and maximum associated data length in bytes */
|
56
|
+
#define ARGON2_MIN_AD_LENGTH UINT32_C(0)
|
57
|
+
#define ARGON2_MAX_AD_LENGTH UINT32_C(0xFFFFFFFF)
|
58
|
+
|
59
|
+
/* Minimum and maximum salt length in bytes */
|
60
|
+
#define ARGON2_MIN_SALT_LENGTH UINT32_C(8)
|
61
|
+
#define ARGON2_MAX_SALT_LENGTH UINT32_C(0xFFFFFFFF)
|
62
|
+
|
63
|
+
/* Minimum and maximum key length in bytes */
|
64
|
+
#define ARGON2_MIN_SECRET UINT32_C(0)
|
65
|
+
#define ARGON2_MAX_SECRET UINT32_C(0xFFFFFFFF)
|
66
|
+
|
67
|
+
#define ARGON2_FLAG_CLEAR_PASSWORD (UINT32_C(1) << 0)
|
68
|
+
#define ARGON2_FLAG_CLEAR_SECRET (UINT32_C(1) << 1)
|
69
|
+
#define ARGON2_FLAG_CLEAR_MEMORY (UINT32_C(1) << 2)
|
70
|
+
#define ARGON2_DEFAULT_FLAGS (ARGON2_FLAG_CLEAR_MEMORY)
|
71
|
+
|
72
|
+
/* Error codes */
|
73
|
+
typedef enum Argon2_ErrorCodes {
|
74
|
+
ARGON2_OK = 0,
|
75
|
+
|
76
|
+
ARGON2_OUTPUT_PTR_NULL = -1,
|
77
|
+
|
78
|
+
ARGON2_OUTPUT_TOO_SHORT = -2,
|
79
|
+
ARGON2_OUTPUT_TOO_LONG = -3,
|
80
|
+
|
81
|
+
ARGON2_PWD_TOO_SHORT = -4,
|
82
|
+
ARGON2_PWD_TOO_LONG = -5,
|
83
|
+
|
84
|
+
ARGON2_SALT_TOO_SHORT = -6,
|
85
|
+
ARGON2_SALT_TOO_LONG = -7,
|
86
|
+
|
87
|
+
ARGON2_AD_TOO_SHORT = -8,
|
88
|
+
ARGON2_AD_TOO_LONG = -9,
|
89
|
+
|
90
|
+
ARGON2_SECRET_TOO_SHORT = -10,
|
91
|
+
ARGON2_SECRET_TOO_LONG = -11,
|
92
|
+
|
93
|
+
ARGON2_TIME_TOO_SMALL = -12,
|
94
|
+
ARGON2_TIME_TOO_LARGE = -13,
|
95
|
+
|
96
|
+
ARGON2_MEMORY_TOO_LITTLE = -14,
|
97
|
+
ARGON2_MEMORY_TOO_MUCH = -15,
|
98
|
+
|
99
|
+
ARGON2_LANES_TOO_FEW = -16,
|
100
|
+
ARGON2_LANES_TOO_MANY = -17,
|
101
|
+
|
102
|
+
ARGON2_PWD_PTR_MISMATCH = -18, /* NULL ptr with non-zero length */
|
103
|
+
ARGON2_SALT_PTR_MISMATCH = -19, /* NULL ptr with non-zero length */
|
104
|
+
ARGON2_SECRET_PTR_MISMATCH = -20, /* NULL ptr with non-zero length */
|
105
|
+
ARGON2_AD_PTR_MISMATCH = -21, /* NULL ptr with non-zero length */
|
106
|
+
|
107
|
+
ARGON2_MEMORY_ALLOCATION_ERROR = -22,
|
108
|
+
|
109
|
+
ARGON2_FREE_MEMORY_CBK_NULL = -23,
|
110
|
+
ARGON2_ALLOCATE_MEMORY_CBK_NULL = -24,
|
111
|
+
|
112
|
+
ARGON2_INCORRECT_PARAMETER = -25,
|
113
|
+
ARGON2_INCORRECT_TYPE = -26,
|
114
|
+
|
115
|
+
ARGON2_OUT_PTR_MISMATCH = -27,
|
116
|
+
|
117
|
+
ARGON2_THREADS_TOO_FEW = -28,
|
118
|
+
ARGON2_THREADS_TOO_MANY = -29,
|
119
|
+
|
120
|
+
ARGON2_MISSING_ARGS = -30,
|
121
|
+
|
122
|
+
ARGON2_ENCODING_FAIL = -31,
|
123
|
+
|
124
|
+
ARGON2_DECODING_FAIL = -32,
|
125
|
+
|
126
|
+
ARGON2_THREAD_FAIL = -33,
|
127
|
+
|
128
|
+
ARGON2_DECODING_LENGTH_FAIL = -34,
|
129
|
+
|
130
|
+
ARGON2_VERIFY_MISMATCH = -35
|
131
|
+
} argon2_error_codes;
|
132
|
+
|
133
|
+
/* Argon2 external data structures */
|
134
|
+
|
135
|
+
/*
|
136
|
+
* Context: structure to hold Argon2 inputs:
|
137
|
+
* output array and its length,
|
138
|
+
* password and its length,
|
139
|
+
* salt and its length,
|
140
|
+
* secret and its length,
|
141
|
+
* associated data and its length,
|
142
|
+
* number of passes, amount of used memory (in KBytes, can be rounded up a bit)
|
143
|
+
* number of parallel threads that will be run.
|
144
|
+
* All the parameters above affect the output hash value.
|
145
|
+
* Additionally, two function pointers can be provided to allocate and
|
146
|
+
* deallocate the memory (if NULL, memory will be allocated internally).
|
147
|
+
* Also, three flags indicate whether to erase password, secret as soon as they
|
148
|
+
* are pre-hashed (and thus not needed anymore), and the entire memory
|
149
|
+
*****
|
150
|
+
* Simplest situation: you have output array out[8], password is stored in
|
151
|
+
* pwd[32], salt is stored in salt[16], you do not have keys nor associated data.
|
152
|
+
* You need to spend 1 GB of RAM and you run 5 passes of Argon2 with 4 parallel lanes.
|
153
|
+
* You want to erase the password, but you're OK with last pass not being erased.
|
154
|
+
* You want to use the default memory allocator.
|
155
|
+
* Then you initialize:
|
156
|
+
* Argon2_Context(out,8,pwd,32,salt,16,NULL,0,NULL,0,5,1<<20,4,4,NULL,NULL,true,false,false,false).
|
157
|
+
*/
|
158
|
+
typedef struct Argon2_Context {
|
159
|
+
uint8_t *out; /* output array */
|
160
|
+
uint32_t outlen; /* digest length */
|
161
|
+
|
162
|
+
uint8_t *pwd; /* password array */
|
163
|
+
uint32_t pwdlen; /* password length */
|
164
|
+
|
165
|
+
uint8_t *salt; /* salt array */
|
166
|
+
uint32_t saltlen; /* salt length */
|
167
|
+
|
168
|
+
uint8_t *secret; /* key array */
|
169
|
+
uint32_t secretlen; /* key length */
|
170
|
+
|
171
|
+
uint8_t *ad; /* associated data array */
|
172
|
+
uint32_t adlen; /* associated data length */
|
173
|
+
|
174
|
+
uint32_t t_cost; /* number of passes */
|
175
|
+
uint32_t m_cost; /* amount of memory requested (KB) */
|
176
|
+
uint32_t lanes; /* number of lanes */
|
177
|
+
uint32_t threads; /* maximum number of threads */
|
178
|
+
|
179
|
+
uint32_t flags; /* array of bool options */
|
180
|
+
} argon2_context;
|
181
|
+
|
182
|
+
/* Argon2 primitive type */
|
183
|
+
typedef enum Argon2_type { Argon2_i = 1 } argon2_type;
|
184
|
+
|
185
|
+
/*
|
186
|
+
* Function that performs memory-hard hashing with certain degree of parallelism
|
187
|
+
* @param context Pointer to the Argon2 internal structure
|
188
|
+
* @return Error code if smth is wrong, ARGON2_OK otherwise
|
189
|
+
*/
|
190
|
+
int argon2_ctx(argon2_context *context, argon2_type type);
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Hashes a password with Argon2i, producing an encoded hash
|
194
|
+
* @param t_cost Number of iterations
|
195
|
+
* @param m_cost Sets memory usage to m_cost kibibytes
|
196
|
+
* @param parallelism Number of threads and compute lanes
|
197
|
+
* @param pwd Pointer to password
|
198
|
+
* @param pwdlen Password size in bytes
|
199
|
+
* @param salt Pointer to salt
|
200
|
+
* @param saltlen Salt size in bytes
|
201
|
+
* @param hashlen Desired length of the hash in bytes
|
202
|
+
* @param encoded Buffer where to write the encoded hash
|
203
|
+
* @param encodedlen Size of the buffer (thus max size of the encoded hash)
|
204
|
+
* @pre Different parallelism levels will give different results
|
205
|
+
* @pre Returns ARGON2_OK if successful
|
206
|
+
*/
|
207
|
+
int argon2i_hash_encoded(const uint32_t t_cost, const uint32_t m_cost,
|
208
|
+
const uint32_t parallelism, const void *pwd,
|
209
|
+
const size_t pwdlen, const void *salt,
|
210
|
+
const size_t saltlen, const size_t hashlen,
|
211
|
+
char *encoded, const size_t encodedlen);
|
212
|
+
|
213
|
+
/**
|
214
|
+
* Hashes a password with Argon2i, producing a raw hash
|
215
|
+
* @param t_cost Number of iterations
|
216
|
+
* @param m_cost Sets memory usage to m_cost kibibytes
|
217
|
+
* @param parallelism Number of threads and compute lanes
|
218
|
+
* @param pwd Pointer to password
|
219
|
+
* @param pwdlen Password size in bytes
|
220
|
+
* @param salt Pointer to salt
|
221
|
+
* @param saltlen Salt size in bytes
|
222
|
+
* @param hash Buffer where to write the raw hash
|
223
|
+
* @param hashlen Desired length of the hash in bytes
|
224
|
+
* @pre Different parallelism levels will give different results
|
225
|
+
* @pre Returns ARGON2_OK if successful
|
226
|
+
*/
|
227
|
+
int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost,
|
228
|
+
const uint32_t parallelism, const void *pwd,
|
229
|
+
const size_t pwdlen, const void *salt,
|
230
|
+
const size_t saltlen, void *hash, const size_t hashlen);
|
231
|
+
|
232
|
+
/* generic function underlying the above ones */
|
233
|
+
int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
234
|
+
const uint32_t parallelism, const void *pwd,
|
235
|
+
const size_t pwdlen, const void *salt, const size_t saltlen,
|
236
|
+
void *hash, const size_t hashlen, char *encoded,
|
237
|
+
const size_t encodedlen, argon2_type type);
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Verifies a password against an encoded string
|
241
|
+
* Encoded string is restricted as in validate_inputs()
|
242
|
+
* @param encoded String encoding parameters, salt, hash
|
243
|
+
* @param pwd Pointer to password
|
244
|
+
* @pre Returns ARGON2_OK if successful
|
245
|
+
*/
|
246
|
+
int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen);
|
247
|
+
|
248
|
+
/* generic function underlying the above ones */
|
249
|
+
int argon2_verify(const char *encoded, const void *pwd, const size_t pwdlen,
|
250
|
+
argon2_type type);
|
251
|
+
#endif
|