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
@@ -2,9 +2,6 @@
|
|
2
2
|
#define TEST_NAME "aead_aes256gcm"
|
3
3
|
#include "cmptest.h"
|
4
4
|
|
5
|
-
#if defined(HAVE_WMMINTRIN_H) || \
|
6
|
-
(defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)))
|
7
|
-
|
8
5
|
static struct {
|
9
6
|
const char *key_hex;
|
10
7
|
const char *nonce_hex;
|
@@ -3079,26 +3076,31 @@ static struct {
|
|
3079
3076
|
}
|
3080
3077
|
};
|
3081
3078
|
|
3082
|
-
int
|
3079
|
+
static int
|
3083
3080
|
tv(void)
|
3084
3081
|
{
|
3085
3082
|
unsigned char *ad;
|
3086
3083
|
unsigned char *ciphertext;
|
3087
3084
|
unsigned char *decrypted;
|
3085
|
+
unsigned char *detached_ciphertext;
|
3088
3086
|
unsigned char *expected_ciphertext;
|
3089
3087
|
unsigned char *key;
|
3090
3088
|
unsigned char *message;
|
3089
|
+
unsigned char *mac;
|
3091
3090
|
unsigned char *nonce;
|
3092
3091
|
char *hex;
|
3093
3092
|
unsigned long long found_ciphertext_len;
|
3093
|
+
unsigned long long found_mac_len;
|
3094
3094
|
unsigned long long found_message_len;
|
3095
3095
|
size_t ad_len;
|
3096
3096
|
size_t ciphertext_len;
|
3097
|
+
size_t detached_ciphertext_len;
|
3097
3098
|
size_t i = 0U;
|
3098
3099
|
size_t message_len;
|
3099
3100
|
|
3100
3101
|
key = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_KEYBYTES);
|
3101
3102
|
nonce = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_NPUBBYTES);
|
3103
|
+
mac = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_ABYTES);
|
3102
3104
|
|
3103
3105
|
do {
|
3104
3106
|
assert(strlen(tests[i].key_hex) == 2 * crypto_aead_aes256gcm_KEYBYTES);
|
@@ -3120,6 +3122,7 @@ tv(void)
|
|
3120
3122
|
tests[i].ad_hex, strlen(tests[i].ad_hex),
|
3121
3123
|
NULL, NULL, NULL);
|
3122
3124
|
ciphertext_len = message_len + crypto_aead_aes256gcm_ABYTES;
|
3125
|
+
detached_ciphertext_len = message_len;
|
3123
3126
|
expected_ciphertext = (unsigned char *) sodium_malloc(ciphertext_len);
|
3124
3127
|
assert(strlen(tests[i].ciphertext_hex) == 2 * message_len);
|
3125
3128
|
sodium_hex2bin(expected_ciphertext, message_len,
|
@@ -3130,6 +3133,24 @@ tv(void)
|
|
3130
3133
|
tests[i].mac_hex, strlen(tests[i].mac_hex),
|
3131
3134
|
NULL, NULL, NULL);
|
3132
3135
|
ciphertext = (unsigned char *) sodium_malloc(ciphertext_len);
|
3136
|
+
detached_ciphertext = (unsigned char *) sodium_malloc(detached_ciphertext_len);
|
3137
|
+
|
3138
|
+
crypto_aead_aes256gcm_encrypt_detached(detached_ciphertext, mac,
|
3139
|
+
&found_mac_len,
|
3140
|
+
message, message_len,
|
3141
|
+
ad, ad_len, NULL, nonce, key);
|
3142
|
+
assert(found_mac_len == crypto_aead_aes256gcm_ABYTES);
|
3143
|
+
if (memcmp(detached_ciphertext, expected_ciphertext,
|
3144
|
+
detached_ciphertext_len) != 0 ||
|
3145
|
+
memcmp(mac, expected_ciphertext + message_len,
|
3146
|
+
crypto_aead_aes256gcm_ABYTES) != 0) {
|
3147
|
+
printf("Detached encryption of test vector #%u failed\n", (unsigned int) i);
|
3148
|
+
hex = (char *) sodium_malloc((size_t) found_ciphertext_len * 2 + 1);
|
3149
|
+
sodium_bin2hex(hex, (size_t) found_ciphertext_len * 2 + 1,
|
3150
|
+
ciphertext, ciphertext_len);
|
3151
|
+
printf("Computed: [%s]\n", hex);
|
3152
|
+
sodium_free(hex);
|
3153
|
+
}
|
3133
3154
|
|
3134
3155
|
crypto_aead_aes256gcm_encrypt(ciphertext, &found_ciphertext_len,
|
3135
3156
|
message, message_len,
|
@@ -3144,7 +3165,9 @@ tv(void)
|
|
3144
3165
|
printf("Computed: [%s]\n", hex);
|
3145
3166
|
sodium_free(hex);
|
3146
3167
|
}
|
3168
|
+
|
3147
3169
|
decrypted = (unsigned char *) sodium_malloc(message_len);
|
3170
|
+
found_message_len = 1;
|
3148
3171
|
if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len,
|
3149
3172
|
NULL, ciphertext,
|
3150
3173
|
randombytes_uniform(ciphertext_len),
|
@@ -3152,6 +3175,9 @@ tv(void)
|
|
3152
3175
|
printf("Verification of test vector #%u after truncation succeeded\n",
|
3153
3176
|
(unsigned int) i);
|
3154
3177
|
}
|
3178
|
+
if (found_message_len != 0) {
|
3179
|
+
printf("Message length should have been set to zero after a failure\n");
|
3180
|
+
}
|
3155
3181
|
if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len,
|
3156
3182
|
NULL, ciphertext,
|
3157
3183
|
randombytes_uniform(crypto_aead_aes256gcm_ABYTES),
|
@@ -3168,14 +3194,27 @@ tv(void)
|
|
3168
3194
|
if (memcmp(decrypted, message, message_len) != 0) {
|
3169
3195
|
printf("Incorrect decryption of test vector #%u\n", (unsigned int) i);
|
3170
3196
|
}
|
3197
|
+
memset(decrypted, 0xd0, message_len);
|
3198
|
+
if (crypto_aead_aes256gcm_decrypt_detached(decrypted,
|
3199
|
+
NULL, detached_ciphertext,
|
3200
|
+
detached_ciphertext_len,
|
3201
|
+
mac, ad, ad_len, nonce, key) != 0) {
|
3202
|
+
printf("Detached verification of test vector #%u failed\n", (unsigned int) i);
|
3203
|
+
}
|
3204
|
+
if (memcmp(decrypted, message, message_len) != 0) {
|
3205
|
+
printf("Incorrect decryption of test vector #%u\n", (unsigned int) i);
|
3206
|
+
}
|
3207
|
+
|
3171
3208
|
sodium_free(message);
|
3172
3209
|
sodium_free(ad);
|
3173
3210
|
sodium_free(expected_ciphertext);
|
3174
3211
|
sodium_free(ciphertext);
|
3175
3212
|
sodium_free(decrypted);
|
3213
|
+
sodium_free(detached_ciphertext);
|
3176
3214
|
} while (++i < (sizeof tests) / (sizeof tests[0]));
|
3177
3215
|
|
3178
3216
|
sodium_free(key);
|
3217
|
+
sodium_free(mac);
|
3179
3218
|
sodium_free(nonce);
|
3180
3219
|
|
3181
3220
|
return 0;
|
@@ -3196,16 +3235,3 @@ main(void)
|
|
3196
3235
|
|
3197
3236
|
return 0;
|
3198
3237
|
}
|
3199
|
-
|
3200
|
-
#else
|
3201
|
-
|
3202
|
-
int
|
3203
|
-
main(void)
|
3204
|
-
{
|
3205
|
-
assert(crypto_aead_aes256gcm_is_available() >= 0);
|
3206
|
-
printf("OK\n");
|
3207
|
-
|
3208
|
-
return 0;
|
3209
|
-
}
|
3210
|
-
|
3211
|
-
#endif
|
@@ -5,118 +5,160 @@
|
|
5
5
|
static int
|
6
6
|
tv(void)
|
7
7
|
{
|
8
|
-
|
8
|
+
#undef MLEN
|
9
|
+
#define MLEN 10U
|
10
|
+
#undef ADLEN
|
11
|
+
#define ADLEN 10U
|
12
|
+
#undef CLEN
|
13
|
+
#define CLEN (MLEN + crypto_aead_chacha20poly1305_ABYTES)
|
14
|
+
static const unsigned char firstkey[crypto_aead_chacha20poly1305_KEYBYTES]
|
9
15
|
= { 0x42, 0x90, 0xbc, 0xb1, 0x54, 0x17, 0x35, 0x31, 0xf3, 0x14, 0xaf,
|
10
16
|
0x57, 0xf3, 0xbe, 0x3b, 0x50, 0x06, 0xda, 0x37, 0x1e, 0xce, 0x27,
|
11
17
|
0x2a, 0xfa, 0x1b, 0x5d, 0xbd, 0xd1, 0x10, 0x0a, 0x10, 0x07 };
|
12
|
-
static unsigned char m[
|
18
|
+
static const unsigned char m[MLEN]
|
13
19
|
= { 0x86, 0xd0, 0x99, 0x74, 0x84, 0x0b, 0xde, 0xd2, 0xa5, 0xca };
|
14
|
-
static unsigned char nonce[crypto_aead_chacha20poly1305_NPUBBYTES]
|
20
|
+
static const unsigned char nonce[crypto_aead_chacha20poly1305_NPUBBYTES]
|
15
21
|
= { 0xcd, 0x7c, 0xf6, 0x7b, 0xe3, 0x9c, 0x79, 0x4a };
|
16
|
-
static unsigned char ad[
|
22
|
+
static const unsigned char ad[ADLEN]
|
17
23
|
= { 0x87, 0xe2, 0x29, 0xd4, 0x50, 0x08, 0x45, 0xa0, 0x79, 0xc0 };
|
18
|
-
|
19
|
-
|
20
|
-
unsigned char
|
21
|
-
unsigned
|
24
|
+
unsigned char *c = (unsigned char *) sodium_malloc(CLEN);
|
25
|
+
unsigned char *detached_c = (unsigned char *) sodium_malloc(MLEN);
|
26
|
+
unsigned char *mac = (unsigned char *) sodium_malloc(crypto_aead_chacha20poly1305_ABYTES);
|
27
|
+
unsigned char *m2 = (unsigned char *) sodium_malloc(MLEN);
|
28
|
+
unsigned long long found_clen;
|
29
|
+
unsigned long long found_maclen;
|
22
30
|
unsigned long long m2len;
|
23
31
|
size_t i;
|
24
32
|
|
25
|
-
crypto_aead_chacha20poly1305_encrypt(c, &
|
33
|
+
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, m, MLEN,
|
34
|
+
ad, ADLEN,
|
26
35
|
NULL, nonce, firstkey);
|
27
|
-
if (
|
28
|
-
printf("
|
36
|
+
if (found_clen != CLEN) {
|
37
|
+
printf("found_clen is not properly set\n");
|
29
38
|
}
|
30
|
-
for (i = 0U; i <
|
31
|
-
printf(",0x%02x", (unsigned int)c[i]);
|
39
|
+
for (i = 0U; i < CLEN; ++i) {
|
40
|
+
printf(",0x%02x", (unsigned int) c[i]);
|
32
41
|
if (i % 8 == 7) {
|
33
42
|
printf("\n");
|
34
43
|
}
|
35
44
|
}
|
36
45
|
printf("\n");
|
46
|
+
crypto_aead_chacha20poly1305_encrypt_detached(detached_c,
|
47
|
+
mac, &found_maclen,
|
48
|
+
m, MLEN, ad, ADLEN,
|
49
|
+
NULL, nonce, firstkey);
|
50
|
+
if (found_maclen != crypto_aead_chacha20poly1305_abytes()) {
|
51
|
+
printf("found_maclen is not properly set\n");
|
52
|
+
}
|
53
|
+
if (memcmp(detached_c, c, MLEN) != 0) {
|
54
|
+
printf("detached ciphertext is bogus\n");
|
55
|
+
}
|
37
56
|
|
38
|
-
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c,
|
39
|
-
|
57
|
+
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, CLEN,
|
58
|
+
ad, ADLEN,
|
59
|
+
nonce, firstkey) != 0) {
|
40
60
|
printf("crypto_aead_chacha20poly1305_decrypt() failed\n");
|
41
61
|
}
|
42
|
-
if (m2len !=
|
62
|
+
if (m2len != MLEN) {
|
43
63
|
printf("m2len is not properly set\n");
|
44
64
|
}
|
45
|
-
if (memcmp(m, m2,
|
65
|
+
if (memcmp(m, m2, MLEN) != 0) {
|
46
66
|
printf("m != m2\n");
|
47
67
|
}
|
68
|
+
memset(m2, 0, m2len);
|
69
|
+
if (crypto_aead_chacha20poly1305_decrypt_detached(m2, NULL,
|
70
|
+
c, MLEN, mac,
|
71
|
+
ad, ADLEN,
|
72
|
+
nonce, firstkey) != 0) {
|
73
|
+
printf("crypto_aead_chacha20poly1305_decrypt_detached() failed\n");
|
74
|
+
}
|
75
|
+
if (memcmp(m, m2, MLEN) != 0) {
|
76
|
+
printf("detached m != m2\n");
|
77
|
+
}
|
48
78
|
|
49
|
-
for (i = 0U; i <
|
79
|
+
for (i = 0U; i < CLEN; i++) {
|
50
80
|
c[i] ^= (i + 1U);
|
51
|
-
if (crypto_aead_chacha20poly1305_decrypt(m2, NULL, NULL, c,
|
52
|
-
ad,
|
53
|
-
== 0 || memcmp(m, m2,
|
81
|
+
if (crypto_aead_chacha20poly1305_decrypt(m2, NULL, NULL, c, CLEN,
|
82
|
+
ad, ADLEN, nonce, firstkey)
|
83
|
+
== 0 || memcmp(m, m2, MLEN) == 0) {
|
54
84
|
printf("message can be forged\n");
|
55
85
|
}
|
56
86
|
c[i] ^= (i + 1U);
|
57
87
|
}
|
58
88
|
|
59
|
-
crypto_aead_chacha20poly1305_encrypt(c, &
|
60
|
-
nonce, firstkey);
|
61
|
-
if (
|
62
|
-
printf("
|
89
|
+
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, m, MLEN,
|
90
|
+
NULL, 0U, NULL, nonce, firstkey);
|
91
|
+
if (found_clen != CLEN) {
|
92
|
+
printf("found_clen is not properly set (adlen=0)\n");
|
63
93
|
}
|
64
|
-
for (i = 0U; i <
|
65
|
-
printf(",0x%02x", (unsigned int)c[i]);
|
94
|
+
for (i = 0U; i < CLEN; ++i) {
|
95
|
+
printf(",0x%02x", (unsigned int) c[i]);
|
66
96
|
if (i % 8 == 7) {
|
67
97
|
printf("\n");
|
68
98
|
}
|
69
99
|
}
|
70
100
|
printf("\n");
|
71
101
|
|
72
|
-
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c,
|
102
|
+
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, CLEN,
|
73
103
|
NULL, 0U, nonce, firstkey) != 0) {
|
74
104
|
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
|
75
105
|
}
|
76
|
-
if (m2len !=
|
106
|
+
if (m2len != MLEN) {
|
77
107
|
printf("m2len is not properly set (adlen=0)\n");
|
78
108
|
}
|
79
|
-
if (memcmp(m, m2,
|
109
|
+
if (memcmp(m, m2, MLEN) != 0) {
|
80
110
|
printf("m != m2 (adlen=0)\n");
|
81
111
|
}
|
82
|
-
|
112
|
+
m2len = 1;
|
83
113
|
if (crypto_aead_chacha20poly1305_decrypt(
|
84
114
|
m2, &m2len, NULL, c, crypto_aead_chacha20poly1305_ABYTES / 2, NULL,
|
85
115
|
0U, nonce, firstkey) != -1) {
|
86
116
|
printf("crypto_aead_chacha20poly1305_decrypt() worked with a short "
|
87
117
|
"ciphertext\n");
|
88
118
|
}
|
119
|
+
if (m2len != 0) {
|
120
|
+
printf("Message length should have been set to zero after a failure\n");
|
121
|
+
}
|
122
|
+
m2len = 1;
|
89
123
|
if (crypto_aead_chacha20poly1305_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
|
90
124
|
nonce, firstkey) != -1) {
|
91
125
|
printf("crypto_aead_chacha20poly1305_decrypt() worked with an empty "
|
92
126
|
"ciphertext\n");
|
93
127
|
}
|
94
|
-
|
95
|
-
|
96
|
-
crypto_aead_chacha20poly1305_encrypt(c, &clen, c, sizeof m, NULL, 0U, NULL,
|
97
|
-
nonce, firstkey);
|
98
|
-
if (clen != sizeof m + crypto_aead_chacha20poly1305_abytes()) {
|
99
|
-
printf("clen is not properly set (adlen=0)\n");
|
128
|
+
if (m2len != 0) {
|
129
|
+
printf("Message length should have been set to zero after a failure\n");
|
100
130
|
}
|
101
|
-
|
102
|
-
|
131
|
+
|
132
|
+
memcpy(c, m, MLEN);
|
133
|
+
crypto_aead_chacha20poly1305_encrypt(c, &found_clen, c, MLEN,
|
134
|
+
NULL, 0U, NULL, nonce, firstkey);
|
135
|
+
if (found_clen != CLEN) {
|
136
|
+
printf("found_clen is not properly set (adlen=0)\n");
|
137
|
+
}
|
138
|
+
for (i = 0U; i < CLEN; ++i) {
|
139
|
+
printf(",0x%02x", (unsigned int) c[i]);
|
103
140
|
if (i % 8 == 7) {
|
104
141
|
printf("\n");
|
105
142
|
}
|
106
143
|
}
|
107
144
|
printf("\n");
|
108
145
|
|
109
|
-
if (crypto_aead_chacha20poly1305_decrypt(c, &m2len, NULL, c,
|
146
|
+
if (crypto_aead_chacha20poly1305_decrypt(c, &m2len, NULL, c, CLEN,
|
110
147
|
NULL, 0U, nonce, firstkey) != 0) {
|
111
148
|
printf("crypto_aead_chacha20poly1305_decrypt() failed (adlen=0)\n");
|
112
149
|
}
|
113
|
-
if (m2len !=
|
150
|
+
if (m2len != MLEN) {
|
114
151
|
printf("m2len is not properly set (adlen=0)\n");
|
115
152
|
}
|
116
|
-
if (memcmp(m, c,
|
153
|
+
if (memcmp(m, c, MLEN) != 0) {
|
117
154
|
printf("m != c (adlen=0)\n");
|
118
155
|
}
|
119
156
|
|
157
|
+
sodium_free(c);
|
158
|
+
sodium_free(detached_c);
|
159
|
+
sodium_free(mac);
|
160
|
+
sodium_free(m2);
|
161
|
+
|
120
162
|
assert(crypto_aead_chacha20poly1305_keybytes() > 0U);
|
121
163
|
assert(crypto_aead_chacha20poly1305_npubbytes() > 0U);
|
122
164
|
assert(crypto_aead_chacha20poly1305_nsecbytes() == 0U);
|
@@ -127,126 +169,177 @@ tv(void)
|
|
127
169
|
static int
|
128
170
|
tv_ietf(void)
|
129
171
|
{
|
130
|
-
|
172
|
+
#undef MLEN
|
173
|
+
#define MLEN 114U
|
174
|
+
#undef ADLEN
|
175
|
+
#define ADLEN 12U
|
176
|
+
#undef CLEN
|
177
|
+
#define CLEN (MLEN + crypto_aead_chacha20poly1305_ietf_ABYTES)
|
178
|
+
static const unsigned char firstkey[crypto_aead_chacha20poly1305_ietf_KEYBYTES]
|
131
179
|
= {
|
132
180
|
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
133
181
|
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
134
182
|
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
135
183
|
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
|
136
184
|
};
|
185
|
+
#undef MESSAGE
|
137
186
|
#define MESSAGE "Ladies and Gentlemen of the class of '99: If I could offer you " \
|
138
187
|
"only one tip for the future, sunscreen would be it."
|
139
|
-
|
140
|
-
static unsigned char nonce[
|
188
|
+
unsigned char *m = (unsigned char *) sodium_malloc(MLEN);
|
189
|
+
static const unsigned char nonce[crypto_aead_chacha20poly1305_ietf_NPUBBYTES]
|
141
190
|
= { 0x07, 0x00, 0x00, 0x00,
|
142
191
|
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 };
|
143
|
-
static unsigned char ad[
|
192
|
+
static const unsigned char ad[ADLEN]
|
144
193
|
= { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 };
|
145
|
-
|
146
|
-
|
147
|
-
unsigned char
|
148
|
-
unsigned
|
194
|
+
unsigned char *c = (unsigned char *) sodium_malloc(CLEN);
|
195
|
+
unsigned char *detached_c = (unsigned char *) sodium_malloc(MLEN);
|
196
|
+
unsigned char *mac = (unsigned char *) sodium_malloc(crypto_aead_chacha20poly1305_ietf_ABYTES);
|
197
|
+
unsigned char *m2 = (unsigned char *) sodium_malloc(MLEN);
|
198
|
+
unsigned long long found_clen;
|
199
|
+
unsigned long long found_maclen;
|
149
200
|
unsigned long long m2len;
|
150
201
|
size_t i;
|
151
202
|
|
152
|
-
assert(sizeof MESSAGE - 1U ==
|
153
|
-
memcpy(m, MESSAGE,
|
154
|
-
crypto_aead_chacha20poly1305_ietf_encrypt(c, &
|
203
|
+
assert(sizeof MESSAGE - 1U == MLEN);
|
204
|
+
memcpy(m, MESSAGE, MLEN);
|
205
|
+
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
|
206
|
+
ad, ADLEN,
|
155
207
|
NULL, nonce, firstkey);
|
156
|
-
if (
|
157
|
-
printf("
|
208
|
+
if (found_clen != MLEN + crypto_aead_chacha20poly1305_ietf_abytes()) {
|
209
|
+
printf("found_clen is not properly set\n");
|
158
210
|
}
|
159
|
-
for (i = 0U; i <
|
160
|
-
printf(",0x%02x", (unsigned int)c[i]);
|
211
|
+
for (i = 0U; i < CLEN; ++i) {
|
212
|
+
printf(",0x%02x", (unsigned int) c[i]);
|
161
213
|
if (i % 8 == 7) {
|
162
214
|
printf("\n");
|
163
215
|
}
|
164
216
|
}
|
165
217
|
printf("\n");
|
218
|
+
crypto_aead_chacha20poly1305_ietf_encrypt_detached(detached_c,
|
219
|
+
mac, &found_maclen,
|
220
|
+
m, MLEN,
|
221
|
+
ad, ADLEN,
|
222
|
+
NULL, nonce, firstkey);
|
223
|
+
if (found_maclen != crypto_aead_chacha20poly1305_ietf_abytes()) {
|
224
|
+
printf("found_maclen is not properly set\n");
|
225
|
+
}
|
226
|
+
if (memcmp(detached_c, c, MLEN) != 0) {
|
227
|
+
printf("detached ciphertext is bogus\n");
|
228
|
+
}
|
166
229
|
|
167
|
-
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c,
|
168
|
-
|
230
|
+
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN, ad,
|
231
|
+
ADLEN, nonce, firstkey) != 0) {
|
169
232
|
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed\n");
|
170
233
|
}
|
171
|
-
if (m2len !=
|
234
|
+
if (m2len != MLEN) {
|
172
235
|
printf("m2len is not properly set\n");
|
173
236
|
}
|
174
|
-
if (memcmp(m, m2,
|
237
|
+
if (memcmp(m, m2, MLEN) != 0) {
|
175
238
|
printf("m != m2\n");
|
176
239
|
}
|
240
|
+
memset(m2, 0, m2len);
|
241
|
+
if (crypto_aead_chacha20poly1305_ietf_decrypt_detached(m2, NULL,
|
242
|
+
c, MLEN, mac,
|
243
|
+
ad, ADLEN,
|
244
|
+
nonce, firstkey) != 0) {
|
245
|
+
printf("crypto_aead_chacha20poly1305_ietf_decrypt_detached() failed\n");
|
246
|
+
}
|
247
|
+
if (memcmp(m, m2, MLEN) != 0) {
|
248
|
+
printf("detached m != m2\n");
|
249
|
+
}
|
177
250
|
|
178
|
-
for (i = 0U; i <
|
251
|
+
for (i = 0U; i < CLEN; i++) {
|
179
252
|
c[i] ^= (i + 1U);
|
180
|
-
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, NULL, NULL, c,
|
181
|
-
ad,
|
182
|
-
== 0 || memcmp(m, m2,
|
253
|
+
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, NULL, NULL, c, CLEN,
|
254
|
+
ad, ADLEN, nonce, firstkey)
|
255
|
+
== 0 || memcmp(m, m2, MLEN) == 0) {
|
183
256
|
printf("message can be forged\n");
|
184
257
|
}
|
185
258
|
c[i] ^= (i + 1U);
|
186
259
|
}
|
187
|
-
crypto_aead_chacha20poly1305_ietf_encrypt(c, &
|
188
|
-
nonce, firstkey);
|
189
|
-
if (
|
260
|
+
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, m, MLEN,
|
261
|
+
NULL, 0U, NULL, nonce, firstkey);
|
262
|
+
if (found_clen != CLEN) {
|
190
263
|
printf("clen is not properly set (adlen=0)\n");
|
191
264
|
}
|
192
|
-
for (i = 0U; i <
|
193
|
-
printf(",0x%02x", (unsigned int)c[i]);
|
265
|
+
for (i = 0U; i < CLEN; ++i) {
|
266
|
+
printf(",0x%02x", (unsigned int) c[i]);
|
194
267
|
if (i % 8 == 7) {
|
195
268
|
printf("\n");
|
196
269
|
}
|
197
270
|
}
|
198
271
|
printf("\n");
|
199
|
-
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c,
|
272
|
+
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, CLEN,
|
200
273
|
NULL, 0U, nonce, firstkey) != 0) {
|
201
274
|
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
|
202
275
|
}
|
203
|
-
if (m2len !=
|
276
|
+
if (m2len != MLEN) {
|
204
277
|
printf("m2len is not properly set (adlen=0)\n");
|
205
278
|
}
|
206
|
-
if (memcmp(m, m2,
|
279
|
+
if (memcmp(m, m2, MLEN) != 0) {
|
207
280
|
printf("m != m2 (adlen=0)\n");
|
208
281
|
}
|
209
|
-
|
282
|
+
m2len = 1;
|
210
283
|
if (crypto_aead_chacha20poly1305_ietf_decrypt(
|
211
|
-
m2, &m2len, NULL, c,
|
284
|
+
m2, &m2len, NULL, c, crypto_aead_chacha20poly1305_ietf_ABYTES / 2, NULL,
|
212
285
|
0U, nonce, firstkey) != -1) {
|
213
286
|
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with a short "
|
214
287
|
"ciphertext\n");
|
215
288
|
}
|
289
|
+
if (m2len != 0) {
|
290
|
+
printf("Message length should have been set to zero after a failure\n");
|
291
|
+
}
|
292
|
+
m2len = 1;
|
216
293
|
if (crypto_aead_chacha20poly1305_ietf_decrypt(m2, &m2len, NULL, c, 0U, NULL, 0U,
|
217
294
|
nonce, firstkey) != -1) {
|
218
295
|
printf("crypto_aead_chacha20poly1305_ietf_decrypt() worked with an empty "
|
219
296
|
"ciphertext\n");
|
220
297
|
}
|
298
|
+
if (m2len != 0) {
|
299
|
+
printf("Message length should have been set to zero after a failure\n");
|
300
|
+
}
|
221
301
|
|
222
|
-
memcpy(c, m,
|
223
|
-
crypto_aead_chacha20poly1305_ietf_encrypt(c, &
|
224
|
-
nonce, firstkey);
|
225
|
-
if (
|
302
|
+
memcpy(c, m, MLEN);
|
303
|
+
crypto_aead_chacha20poly1305_ietf_encrypt(c, &found_clen, c, MLEN,
|
304
|
+
NULL, 0U, NULL, nonce, firstkey);
|
305
|
+
if (found_clen != CLEN) {
|
226
306
|
printf("clen is not properly set (adlen=0)\n");
|
227
307
|
}
|
228
|
-
for (i = 0U; i <
|
229
|
-
printf(",0x%02x", (unsigned int)c[i]);
|
308
|
+
for (i = 0U; i < CLEN; ++i) {
|
309
|
+
printf(",0x%02x", (unsigned int) c[i]);
|
230
310
|
if (i % 8 == 7) {
|
231
311
|
printf("\n");
|
232
312
|
}
|
233
313
|
}
|
234
314
|
printf("\n");
|
235
315
|
|
236
|
-
if (crypto_aead_chacha20poly1305_ietf_decrypt(c, &m2len, NULL, c,
|
316
|
+
if (crypto_aead_chacha20poly1305_ietf_decrypt(c, &m2len, NULL, c, CLEN,
|
237
317
|
NULL, 0U, nonce, firstkey) != 0) {
|
238
318
|
printf("crypto_aead_chacha20poly1305_ietf_decrypt() failed (adlen=0)\n");
|
239
319
|
}
|
240
|
-
if (m2len !=
|
320
|
+
if (m2len != MLEN) {
|
241
321
|
printf("m2len is not properly set (adlen=0)\n");
|
242
322
|
}
|
243
|
-
if (memcmp(m, c,
|
323
|
+
if (memcmp(m, c, MLEN) != 0) {
|
244
324
|
printf("m != c (adlen=0)\n");
|
245
325
|
}
|
246
326
|
|
247
|
-
|
327
|
+
sodium_free(c);
|
328
|
+
sodium_free(detached_c);
|
329
|
+
sodium_free(mac);
|
330
|
+
sodium_free(m2);
|
331
|
+
sodium_free(m);
|
332
|
+
|
333
|
+
assert(crypto_aead_chacha20poly1305_ietf_keybytes() > 0U);
|
334
|
+
assert(crypto_aead_chacha20poly1305_ietf_keybytes() == crypto_aead_chacha20poly1305_keybytes());
|
248
335
|
assert(crypto_aead_chacha20poly1305_ietf_npubbytes() > 0U);
|
249
|
-
assert(
|
336
|
+
assert(crypto_aead_chacha20poly1305_ietf_npubbytes() > crypto_aead_chacha20poly1305_npubbytes());
|
337
|
+
assert(crypto_aead_chacha20poly1305_ietf_nsecbytes() == 0U);
|
338
|
+
assert(crypto_aead_chacha20poly1305_ietf_nsecbytes() == crypto_aead_chacha20poly1305_nsecbytes());
|
339
|
+
assert(crypto_aead_chacha20poly1305_IETF_KEYBYTES == crypto_aead_chacha20poly1305_ietf_KEYBYTES);
|
340
|
+
assert(crypto_aead_chacha20poly1305_IETF_NSECBYTES == crypto_aead_chacha20poly1305_ietf_NSECBYTES);
|
341
|
+
assert(crypto_aead_chacha20poly1305_IETF_NPUBBYTES == crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
|
342
|
+
assert(crypto_aead_chacha20poly1305_IETF_ABYTES == crypto_aead_chacha20poly1305_ietf_ABYTES);
|
250
343
|
|
251
344
|
return 0;
|
252
345
|
}
|