mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Import ipcrypt
This commit is contained in:
@@ -43,6 +43,7 @@ EXTRA_DIST = \
|
||||
generichash3.exp \
|
||||
hash.exp \
|
||||
hash3.exp \
|
||||
ipcrypt.exp \
|
||||
kdf.exp \
|
||||
kdf_hkdf.exp \
|
||||
keygen.exp \
|
||||
@@ -131,6 +132,7 @@ DISTCLEANFILES = \
|
||||
hash.res \
|
||||
hash2.res \
|
||||
hash3.res \
|
||||
ipcrypt.res \
|
||||
kdf.res \
|
||||
kdf_hkdf.res \
|
||||
keygen.res \
|
||||
@@ -226,6 +228,7 @@ TESTS_TARGETS = \
|
||||
generichash3 \
|
||||
hash \
|
||||
hash3 \
|
||||
ipcrypt \
|
||||
kdf \
|
||||
keygen \
|
||||
kx \
|
||||
@@ -392,6 +395,9 @@ hash_LDADD = $(TESTS_LDADD)
|
||||
hash3_SOURCE = cmptest.h hash3.c
|
||||
hash3_LDADD = $(TESTS_LDADD)
|
||||
|
||||
ipcrypt_SOURCE = cmptest.h ipcrypt.c
|
||||
ipcrypt_LDADD = $(TESTS_LDADD)
|
||||
|
||||
kdf_SOURCE = cmptest.h kdf.c
|
||||
kdf_LDADD = $(TESTS_LDADD)
|
||||
|
||||
|
||||
+60
-37
@@ -148,15 +148,16 @@ am__EXEEXT_3 = aead_aegis128l$(EXEEXT) aead_aegis256$(EXEEXT) \
|
||||
core3$(EXEEXT) core4$(EXEEXT) core5$(EXEEXT) core6$(EXEEXT) \
|
||||
ed25519_convert$(EXEEXT) generichash$(EXEEXT) \
|
||||
generichash2$(EXEEXT) generichash3$(EXEEXT) hash$(EXEEXT) \
|
||||
hash3$(EXEEXT) kdf$(EXEEXT) keygen$(EXEEXT) kx$(EXEEXT) \
|
||||
metamorphic$(EXEEXT) misuse$(EXEEXT) onetimeauth$(EXEEXT) \
|
||||
onetimeauth2$(EXEEXT) onetimeauth7$(EXEEXT) \
|
||||
pwhash_argon2i$(EXEEXT) pwhash_argon2id$(EXEEXT) \
|
||||
randombytes$(EXEEXT) scalarmult$(EXEEXT) scalarmult2$(EXEEXT) \
|
||||
scalarmult5$(EXEEXT) scalarmult6$(EXEEXT) scalarmult7$(EXEEXT) \
|
||||
scalarmult8$(EXEEXT) secretbox$(EXEEXT) secretbox2$(EXEEXT) \
|
||||
secretbox7$(EXEEXT) secretbox8$(EXEEXT) \
|
||||
secretbox_easy$(EXEEXT) secretbox_easy2$(EXEEXT) \
|
||||
hash3$(EXEEXT) ipcrypt$(EXEEXT) kdf$(EXEEXT) keygen$(EXEEXT) \
|
||||
kx$(EXEEXT) metamorphic$(EXEEXT) misuse$(EXEEXT) \
|
||||
onetimeauth$(EXEEXT) onetimeauth2$(EXEEXT) \
|
||||
onetimeauth7$(EXEEXT) pwhash_argon2i$(EXEEXT) \
|
||||
pwhash_argon2id$(EXEEXT) randombytes$(EXEEXT) \
|
||||
scalarmult$(EXEEXT) scalarmult2$(EXEEXT) scalarmult5$(EXEEXT) \
|
||||
scalarmult6$(EXEEXT) scalarmult7$(EXEEXT) scalarmult8$(EXEEXT) \
|
||||
secretbox$(EXEEXT) secretbox2$(EXEEXT) secretbox7$(EXEEXT) \
|
||||
secretbox8$(EXEEXT) secretbox_easy$(EXEEXT) \
|
||||
secretbox_easy2$(EXEEXT) \
|
||||
secretstream_xchacha20poly1305$(EXEEXT) shorthash$(EXEEXT) \
|
||||
sign$(EXEEXT) sodium_core$(EXEEXT) sodium_utils$(EXEEXT) \
|
||||
sodium_version$(EXEEXT) stream$(EXEEXT) stream2$(EXEEXT) \
|
||||
@@ -282,6 +283,9 @@ hash_DEPENDENCIES = $(TESTS_LDADD)
|
||||
hash3_SOURCES = hash3.c
|
||||
hash3_OBJECTS = hash3.$(OBJEXT)
|
||||
hash3_DEPENDENCIES = $(TESTS_LDADD)
|
||||
ipcrypt_SOURCES = ipcrypt.c
|
||||
ipcrypt_OBJECTS = ipcrypt.$(OBJEXT)
|
||||
ipcrypt_DEPENDENCIES = $(TESTS_LDADD)
|
||||
kdf_SOURCES = kdf.c
|
||||
kdf_OBJECTS = kdf.$(OBJEXT)
|
||||
kdf_DEPENDENCIES = $(TESTS_LDADD)
|
||||
@@ -458,7 +462,8 @@ am__depfiles_remade = ./$(DEPDIR)/aead_aegis128l.Po \
|
||||
./$(DEPDIR)/core_ristretto255.Po \
|
||||
./$(DEPDIR)/ed25519_convert.Po ./$(DEPDIR)/generichash.Po \
|
||||
./$(DEPDIR)/generichash2.Po ./$(DEPDIR)/generichash3.Po \
|
||||
./$(DEPDIR)/hash.Po ./$(DEPDIR)/hash3.Po ./$(DEPDIR)/kdf.Po \
|
||||
./$(DEPDIR)/hash.Po ./$(DEPDIR)/hash3.Po \
|
||||
./$(DEPDIR)/ipcrypt.Po ./$(DEPDIR)/kdf.Po \
|
||||
./$(DEPDIR)/kdf_hkdf.Po ./$(DEPDIR)/keygen.Po \
|
||||
./$(DEPDIR)/kx.Po ./$(DEPDIR)/metamorphic.Po \
|
||||
./$(DEPDIR)/misuse.Po ./$(DEPDIR)/onetimeauth.Po \
|
||||
@@ -511,19 +516,19 @@ SOURCES = aead_aegis128l.c aead_aegis256.c aead_aes256gcm.c \
|
||||
codecs.c core1.c core2.c core3.c core4.c core5.c core6.c \
|
||||
core_ed25519.c core_keccak1600.c core_ristretto255.c \
|
||||
ed25519_convert.c generichash.c generichash2.c generichash3.c \
|
||||
hash.c hash3.c kdf.c kdf_hkdf.c keygen.c kx.c metamorphic.c \
|
||||
misuse.c onetimeauth.c onetimeauth2.c onetimeauth7.c \
|
||||
pwhash_argon2i.c pwhash_argon2id.c pwhash_scrypt.c \
|
||||
pwhash_scrypt_ll.c randombytes.c scalarmult.c scalarmult2.c \
|
||||
scalarmult5.c scalarmult6.c scalarmult7.c scalarmult8.c \
|
||||
scalarmult_ed25519.c scalarmult_ristretto255.c secretbox.c \
|
||||
secretbox2.c secretbox7.c secretbox8.c secretbox_easy.c \
|
||||
secretbox_easy2.c secretstream_xchacha20poly1305.c shorthash.c \
|
||||
sign.c siphashx24.c sodium_core.c sodium_utils.c \
|
||||
sodium_utils2.c sodium_utils3.c sodium_version.c stream.c \
|
||||
stream2.c stream3.c stream4.c verify1.c xchacha20.c \
|
||||
xof_shake128.c xof_shake256.c xof_turboshake128.c \
|
||||
xof_turboshake256.c
|
||||
hash.c hash3.c ipcrypt.c kdf.c kdf_hkdf.c keygen.c kx.c \
|
||||
metamorphic.c misuse.c onetimeauth.c onetimeauth2.c \
|
||||
onetimeauth7.c pwhash_argon2i.c pwhash_argon2id.c \
|
||||
pwhash_scrypt.c pwhash_scrypt_ll.c randombytes.c scalarmult.c \
|
||||
scalarmult2.c scalarmult5.c scalarmult6.c scalarmult7.c \
|
||||
scalarmult8.c scalarmult_ed25519.c scalarmult_ristretto255.c \
|
||||
secretbox.c secretbox2.c secretbox7.c secretbox8.c \
|
||||
secretbox_easy.c secretbox_easy2.c \
|
||||
secretstream_xchacha20poly1305.c shorthash.c sign.c \
|
||||
siphashx24.c sodium_core.c sodium_utils.c sodium_utils2.c \
|
||||
sodium_utils3.c sodium_version.c stream.c stream2.c stream3.c \
|
||||
stream4.c verify1.c xchacha20.c xof_shake128.c xof_shake256.c \
|
||||
xof_turboshake128.c xof_turboshake256.c
|
||||
DIST_SOURCES = aead_aegis128l.c aead_aegis256.c aead_aes256gcm.c \
|
||||
aead_aes256gcm2.c aead_chacha20poly1305.c \
|
||||
aead_chacha20poly13052.c aead_xchacha20poly1305.c auth.c \
|
||||
@@ -532,19 +537,19 @@ DIST_SOURCES = aead_aegis128l.c aead_aegis256.c aead_aes256gcm.c \
|
||||
codecs.c core1.c core2.c core3.c core4.c core5.c core6.c \
|
||||
core_ed25519.c core_keccak1600.c core_ristretto255.c \
|
||||
ed25519_convert.c generichash.c generichash2.c generichash3.c \
|
||||
hash.c hash3.c kdf.c kdf_hkdf.c keygen.c kx.c metamorphic.c \
|
||||
misuse.c onetimeauth.c onetimeauth2.c onetimeauth7.c \
|
||||
pwhash_argon2i.c pwhash_argon2id.c pwhash_scrypt.c \
|
||||
pwhash_scrypt_ll.c randombytes.c scalarmult.c scalarmult2.c \
|
||||
scalarmult5.c scalarmult6.c scalarmult7.c scalarmult8.c \
|
||||
scalarmult_ed25519.c scalarmult_ristretto255.c secretbox.c \
|
||||
secretbox2.c secretbox7.c secretbox8.c secretbox_easy.c \
|
||||
secretbox_easy2.c secretstream_xchacha20poly1305.c shorthash.c \
|
||||
sign.c siphashx24.c sodium_core.c sodium_utils.c \
|
||||
sodium_utils2.c sodium_utils3.c sodium_version.c stream.c \
|
||||
stream2.c stream3.c stream4.c verify1.c xchacha20.c \
|
||||
xof_shake128.c xof_shake256.c xof_turboshake128.c \
|
||||
xof_turboshake256.c
|
||||
hash.c hash3.c ipcrypt.c kdf.c kdf_hkdf.c keygen.c kx.c \
|
||||
metamorphic.c misuse.c onetimeauth.c onetimeauth2.c \
|
||||
onetimeauth7.c pwhash_argon2i.c pwhash_argon2id.c \
|
||||
pwhash_scrypt.c pwhash_scrypt_ll.c randombytes.c scalarmult.c \
|
||||
scalarmult2.c scalarmult5.c scalarmult6.c scalarmult7.c \
|
||||
scalarmult8.c scalarmult_ed25519.c scalarmult_ristretto255.c \
|
||||
secretbox.c secretbox2.c secretbox7.c secretbox8.c \
|
||||
secretbox_easy.c secretbox_easy2.c \
|
||||
secretstream_xchacha20poly1305.c shorthash.c sign.c \
|
||||
siphashx24.c sodium_core.c sodium_utils.c sodium_utils2.c \
|
||||
sodium_utils3.c sodium_version.c stream.c stream2.c stream3.c \
|
||||
stream4.c verify1.c xchacha20.c xof_shake128.c xof_shake256.c \
|
||||
xof_turboshake128.c xof_turboshake256.c
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
@@ -996,6 +1001,7 @@ EXTRA_DIST = \
|
||||
generichash3.exp \
|
||||
hash.exp \
|
||||
hash3.exp \
|
||||
ipcrypt.exp \
|
||||
kdf.exp \
|
||||
kdf_hkdf.exp \
|
||||
keygen.exp \
|
||||
@@ -1084,6 +1090,7 @@ DISTCLEANFILES = \
|
||||
hash.res \
|
||||
hash2.res \
|
||||
hash3.res \
|
||||
ipcrypt.res \
|
||||
kdf.res \
|
||||
kdf_hkdf.res \
|
||||
keygen.res \
|
||||
@@ -1147,7 +1154,7 @@ TESTS_TARGETS = aead_aegis128l aead_aegis256 aead_aes256gcm \
|
||||
box2 box7 box8 box_easy box_easy2 box_seal box_seed chacha20 \
|
||||
codecs core_keccak1600 core1 core2 core3 core4 core5 core6 \
|
||||
ed25519_convert generichash generichash2 generichash3 hash \
|
||||
hash3 kdf keygen kx metamorphic misuse onetimeauth \
|
||||
hash3 ipcrypt kdf keygen kx metamorphic misuse onetimeauth \
|
||||
onetimeauth2 onetimeauth7 pwhash_argon2i pwhash_argon2id \
|
||||
randombytes scalarmult scalarmult2 scalarmult5 scalarmult6 \
|
||||
scalarmult7 scalarmult8 secretbox secretbox2 secretbox7 \
|
||||
@@ -1235,6 +1242,8 @@ hash_SOURCE = cmptest.h hash.c
|
||||
hash_LDADD = $(TESTS_LDADD)
|
||||
hash3_SOURCE = cmptest.h hash3.c
|
||||
hash3_LDADD = $(TESTS_LDADD)
|
||||
ipcrypt_SOURCE = cmptest.h ipcrypt.c
|
||||
ipcrypt_LDADD = $(TESTS_LDADD)
|
||||
kdf_SOURCE = cmptest.h kdf.c
|
||||
kdf_LDADD = $(TESTS_LDADD)
|
||||
kdf_hkdf_SOURCE = cmptest.h kdf_hkdf.c
|
||||
@@ -1520,6 +1529,10 @@ hash3$(EXEEXT): $(hash3_OBJECTS) $(hash3_DEPENDENCIES) $(EXTRA_hash3_DEPENDENCIE
|
||||
@rm -f hash3$(EXEEXT)
|
||||
$(AM_V_CCLD)$(LINK) $(hash3_OBJECTS) $(hash3_LDADD) $(LIBS)
|
||||
|
||||
ipcrypt$(EXEEXT): $(ipcrypt_OBJECTS) $(ipcrypt_DEPENDENCIES) $(EXTRA_ipcrypt_DEPENDENCIES)
|
||||
@rm -f ipcrypt$(EXEEXT)
|
||||
$(AM_V_CCLD)$(LINK) $(ipcrypt_OBJECTS) $(ipcrypt_LDADD) $(LIBS)
|
||||
|
||||
kdf$(EXEEXT): $(kdf_OBJECTS) $(kdf_DEPENDENCIES) $(EXTRA_kdf_DEPENDENCIES)
|
||||
@rm -f kdf$(EXEEXT)
|
||||
$(AM_V_CCLD)$(LINK) $(kdf_OBJECTS) $(kdf_LDADD) $(LIBS)
|
||||
@@ -1752,6 +1765,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generichash3.Po@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Po@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash3.Po@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipcrypt.Po@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kdf.Po@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kdf_hkdf.Po@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keygen.Po@am__quote@ # am--include-marker
|
||||
@@ -2306,6 +2320,13 @@ hash3.log: hash3$(EXEEXT)
|
||||
--log-file $$b.log --trs-file $$b.trs \
|
||||
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
|
||||
"$$tst" $(AM_TESTS_FD_REDIRECT)
|
||||
ipcrypt.log: ipcrypt$(EXEEXT)
|
||||
@p='ipcrypt$(EXEEXT)'; \
|
||||
b='ipcrypt'; \
|
||||
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
|
||||
--log-file $$b.log --trs-file $$b.trs \
|
||||
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
|
||||
"$$tst" $(AM_TESTS_FD_REDIRECT)
|
||||
kdf.log: kdf$(EXEEXT)
|
||||
@p='kdf$(EXEEXT)'; \
|
||||
b='kdf'; \
|
||||
@@ -2781,6 +2802,7 @@ distclean: distclean-am
|
||||
-rm -f ./$(DEPDIR)/generichash3.Po
|
||||
-rm -f ./$(DEPDIR)/hash.Po
|
||||
-rm -f ./$(DEPDIR)/hash3.Po
|
||||
-rm -f ./$(DEPDIR)/ipcrypt.Po
|
||||
-rm -f ./$(DEPDIR)/kdf.Po
|
||||
-rm -f ./$(DEPDIR)/kdf_hkdf.Po
|
||||
-rm -f ./$(DEPDIR)/keygen.Po
|
||||
@@ -2911,6 +2933,7 @@ maintainer-clean: maintainer-clean-am
|
||||
-rm -f ./$(DEPDIR)/generichash3.Po
|
||||
-rm -f ./$(DEPDIR)/hash.Po
|
||||
-rm -f ./$(DEPDIR)/hash3.Po
|
||||
-rm -f ./$(DEPDIR)/ipcrypt.Po
|
||||
-rm -f ./$(DEPDIR)/kdf.Po
|
||||
-rm -f ./$(DEPDIR)/kdf_hkdf.Po
|
||||
-rm -f ./$(DEPDIR)/keygen.Po
|
||||
|
||||
@@ -0,0 +1,591 @@
|
||||
#define TEST_NAME "ipcrypt"
|
||||
#include "cmptest.h"
|
||||
|
||||
static int
|
||||
check_expected(const char *test_name, const unsigned char *actual, const char *expected_hex,
|
||||
size_t len)
|
||||
{
|
||||
unsigned char expected[64];
|
||||
char actual_hex[129];
|
||||
|
||||
sodium_hex2bin(expected, sizeof expected, expected_hex, strlen(expected_hex), NULL, NULL, NULL);
|
||||
if (memcmp(actual, expected, len) != 0) {
|
||||
sodium_bin2hex(actual_hex, sizeof actual_hex, actual, len);
|
||||
printf("FAILED %s: expected %s, got %s\n", test_name, expected_hex, actual_hex);
|
||||
return 1;
|
||||
}
|
||||
printf("OK: %s\n", test_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
unsigned char key[crypto_ipcrypt_KEYBYTES];
|
||||
unsigned char ndx_key[crypto_ipcrypt_NDX_KEYBYTES];
|
||||
unsigned char pfx_key[crypto_ipcrypt_PFX_KEYBYTES];
|
||||
unsigned char input[crypto_ipcrypt_BYTES];
|
||||
unsigned char output[crypto_ipcrypt_BYTES];
|
||||
unsigned char nd_output[crypto_ipcrypt_ND_OUTPUTBYTES];
|
||||
unsigned char ndx_output[crypto_ipcrypt_NDX_OUTPUTBYTES];
|
||||
unsigned char pfx_output[crypto_ipcrypt_PFX_BYTES];
|
||||
unsigned char tweak_nd[crypto_ipcrypt_ND_TWEAKBYTES];
|
||||
unsigned char tweak_ndx[crypto_ipcrypt_NDX_TWEAKBYTES];
|
||||
unsigned char decrypted[crypto_ipcrypt_BYTES];
|
||||
unsigned char encrypted1[crypto_ipcrypt_PFX_BYTES];
|
||||
unsigned char encrypted2[crypto_ipcrypt_PFX_BYTES];
|
||||
size_t i;
|
||||
|
||||
printf("crypto_ipcrypt_BYTES: %zu\n", crypto_ipcrypt_bytes());
|
||||
printf("crypto_ipcrypt_KEYBYTES: %zu\n", crypto_ipcrypt_keybytes());
|
||||
printf("crypto_ipcrypt_ND_KEYBYTES: %zu\n", crypto_ipcrypt_nd_keybytes());
|
||||
printf("crypto_ipcrypt_ND_TWEAKBYTES: %zu\n", crypto_ipcrypt_nd_tweakbytes());
|
||||
printf("crypto_ipcrypt_ND_INPUTBYTES: %zu\n", crypto_ipcrypt_nd_inputbytes());
|
||||
printf("crypto_ipcrypt_ND_OUTPUTBYTES: %zu\n", crypto_ipcrypt_nd_outputbytes());
|
||||
printf("crypto_ipcrypt_NDX_KEYBYTES: %zu\n", crypto_ipcrypt_ndx_keybytes());
|
||||
printf("crypto_ipcrypt_NDX_TWEAKBYTES: %zu\n", crypto_ipcrypt_ndx_tweakbytes());
|
||||
printf("crypto_ipcrypt_NDX_INPUTBYTES: %zu\n", crypto_ipcrypt_ndx_inputbytes());
|
||||
printf("crypto_ipcrypt_NDX_OUTPUTBYTES: %zu\n", crypto_ipcrypt_ndx_outputbytes());
|
||||
printf("crypto_ipcrypt_PFX_KEYBYTES: %zu\n", crypto_ipcrypt_pfx_keybytes());
|
||||
printf("crypto_ipcrypt_PFX_BYTES: %zu\n", crypto_ipcrypt_pfx_bytes());
|
||||
|
||||
printf("\nipcrypt-deterministic test vectors\n");
|
||||
|
||||
sodium_hex2bin(key, sizeof key, "0123456789abcdeffedcba9876543210", 32, NULL, NULL, NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
|
||||
crypto_ipcrypt_encrypt(output, input, key);
|
||||
if (check_expected("deterministic vector 1 (0.0.0.0)", output,
|
||||
"bde96789d353824cd7c6f58a6bd226eb", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_decrypt(decrypted, output, key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: deterministic vector 1 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sodium_hex2bin(key, sizeof key, "1032547698badcfeefcdab8967452301", 32, NULL, NULL, NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 0xff;
|
||||
input[13] = 0xff;
|
||||
input[14] = 0xff;
|
||||
input[15] = 0xff;
|
||||
|
||||
crypto_ipcrypt_encrypt(output, input, key);
|
||||
if (check_expected("deterministic vector 2 (255.255.255.255)", output,
|
||||
"aed292f6ea2358c348fd08b874e845d8", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_decrypt(decrypted, output, key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: deterministic vector 2 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sodium_hex2bin(key, sizeof key, "2b7e151628aed2a6abf7158809cf4f3c", 32, NULL, NULL, NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 192;
|
||||
input[13] = 0;
|
||||
input[14] = 2;
|
||||
input[15] = 1;
|
||||
|
||||
crypto_ipcrypt_encrypt(output, input, key);
|
||||
if (check_expected("deterministic vector 3 (192.0.2.1)", output,
|
||||
"1dbdc1b9fff175867d0b67b4e76e4777", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_decrypt(decrypted, output, key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: deterministic vector 3 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("\nipcrypt-nd test vectors\n");
|
||||
|
||||
sodium_hex2bin(key, sizeof key, "0123456789abcdeffedcba9876543210", 32, NULL, NULL, NULL);
|
||||
sodium_hex2bin(tweak_nd, sizeof tweak_nd, "08e0c289bff23b7c", 16, NULL, NULL, NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
|
||||
crypto_ipcrypt_nd_encrypt(nd_output, input, tweak_nd, key);
|
||||
if (check_expected("nd vector 1 (0.0.0.0)", nd_output,
|
||||
"08e0c289bff23b7cb349aadfe3bcef56221c384c7c217b16", 24) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_nd_decrypt(decrypted, nd_output, key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: nd vector 1 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sodium_hex2bin(key, sizeof key, "1032547698badcfeefcdab8967452301", 32, NULL, NULL, NULL);
|
||||
sodium_hex2bin(tweak_nd, sizeof tweak_nd, "21bd1834bc088cd2", 16, NULL, NULL, NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 192;
|
||||
input[13] = 0;
|
||||
input[14] = 2;
|
||||
input[15] = 1;
|
||||
|
||||
crypto_ipcrypt_nd_encrypt(nd_output, input, tweak_nd, key);
|
||||
if (check_expected("nd vector 2 (192.0.2.1)", nd_output,
|
||||
"21bd1834bc088cd2e5e1fe55f95876e639faae2594a0caad", 24) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_nd_decrypt(decrypted, nd_output, key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: nd vector 2 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sodium_hex2bin(key, sizeof key, "2b7e151628aed2a6abf7158809cf4f3c", 32, NULL, NULL, NULL);
|
||||
sodium_hex2bin(tweak_nd, sizeof tweak_nd, "b4ecbe30b70898d7", 16, NULL, NULL, NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[15] = 0x01;
|
||||
|
||||
crypto_ipcrypt_nd_encrypt(nd_output, input, tweak_nd, key);
|
||||
if (check_expected("nd vector 3 (2001:db8::1)", nd_output,
|
||||
"b4ecbe30b70898d7553ac8974d1b4250eafc4b0aa1f80c96", 24) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_nd_decrypt(decrypted, nd_output, key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: nd vector 3 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("\nipcrypt-ndx test vectors\n");
|
||||
|
||||
sodium_hex2bin(ndx_key, sizeof ndx_key,
|
||||
"0123456789abcdeffedcba98765432101032547698badcfeefcdab8967452301", 64, NULL,
|
||||
NULL, NULL);
|
||||
sodium_hex2bin(tweak_ndx, sizeof tweak_ndx, "21bd1834bc088cd2b4ecbe30b70898d7", 32, NULL, NULL,
|
||||
NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
|
||||
crypto_ipcrypt_ndx_encrypt(ndx_output, input, tweak_ndx, ndx_key);
|
||||
if (check_expected("ndx vector 1 (0.0.0.0)", ndx_output,
|
||||
"21bd1834bc088cd2b4ecbe30b70898d782db0d4125fdace61db35b8339f20ee5",
|
||||
32) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_ndx_decrypt(decrypted, ndx_output, ndx_key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: ndx vector 1 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sodium_hex2bin(ndx_key, sizeof ndx_key,
|
||||
"1032547698badcfeefcdab89674523010123456789abcdeffedcba9876543210", 64, NULL,
|
||||
NULL, NULL);
|
||||
sodium_hex2bin(tweak_ndx, sizeof tweak_ndx, "08e0c289bff23b7cb4ecbe30b70898d7", 32, NULL, NULL,
|
||||
NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 192;
|
||||
input[13] = 0;
|
||||
input[14] = 2;
|
||||
input[15] = 1;
|
||||
|
||||
crypto_ipcrypt_ndx_encrypt(ndx_output, input, tweak_ndx, ndx_key);
|
||||
if (check_expected("ndx vector 2 (192.0.2.1)", ndx_output,
|
||||
"08e0c289bff23b7cb4ecbe30b70898d7766a533392a69edf1ad0d3ce362ba98a",
|
||||
32) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_ndx_decrypt(decrypted, ndx_output, ndx_key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: ndx vector 2 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sodium_hex2bin(ndx_key, sizeof ndx_key,
|
||||
"2b7e151628aed2a6abf7158809cf4f3c3c4fcf098815f7aba6d2ae2816157e2b", 64, NULL,
|
||||
NULL, NULL);
|
||||
sodium_hex2bin(tweak_ndx, sizeof tweak_ndx, "21bd1834bc088cd2b4ecbe30b70898d7", 32, NULL, NULL,
|
||||
NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[15] = 0x01;
|
||||
|
||||
crypto_ipcrypt_ndx_encrypt(ndx_output, input, tweak_ndx, ndx_key);
|
||||
if (check_expected("ndx vector 3 (2001:db8::1)", ndx_output,
|
||||
"21bd1834bc088cd2b4ecbe30b70898d76089c7e05ae30c2d10ca149870a263e4",
|
||||
32) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_ndx_decrypt(decrypted, ndx_output, ndx_key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: ndx vector 3 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("\nipcrypt-pfx test vectors\n");
|
||||
|
||||
sodium_hex2bin(pfx_key, sizeof pfx_key,
|
||||
"0123456789abcdeffedcba98765432101032547698badcfeefcdab8967452301", 64, NULL,
|
||||
NULL, NULL);
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx vector 1 (0.0.0.0)", pfx_output, "00000000000000000000ffff97529b86",
|
||||
16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_pfx_decrypt(decrypted, pfx_output, pfx_key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: pfx vector 1 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 255;
|
||||
input[13] = 255;
|
||||
input[14] = 255;
|
||||
input[15] = 255;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx vector 2 (255.255.255.255)", pfx_output,
|
||||
"00000000000000000000ffff5eb9a959", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_pfx_decrypt(decrypted, pfx_output, pfx_key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: pfx vector 2 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 192;
|
||||
input[13] = 0;
|
||||
input[14] = 2;
|
||||
input[15] = 1;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx vector 3 (192.0.2.1)", pfx_output, "00000000000000000000ffff64734883",
|
||||
16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_pfx_decrypt(decrypted, pfx_output, pfx_key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: pfx vector 3 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[15] = 0x01;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx vector 4 (2001:db8::1)", pfx_output, "c1805dd42587352430abfa656ab60f88",
|
||||
16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_pfx_decrypt(decrypted, pfx_output, pfx_key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: pfx vector 4 round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("\nipcrypt-pfx prefix preservation\n");
|
||||
|
||||
sodium_hex2bin(pfx_key, sizeof pfx_key,
|
||||
"2b7e151628aed2a6abf7158809cf4f3ca9f5ba40db214c3798f2e1c23456789a", 64, NULL,
|
||||
NULL, NULL);
|
||||
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 10;
|
||||
input[13] = 0;
|
||||
input[14] = 0;
|
||||
input[15] = 47;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx /24 test (10.0.0.47)", pfx_output, "00000000000000000000ffff13d6d2f4",
|
||||
16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
input[15] = 129;
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted1, input, pfx_key);
|
||||
if (check_expected("pfx /24 test (10.0.0.129)", encrypted1, "00000000000000000000ffff13d6d250",
|
||||
16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
input[15] = 234;
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted2, input, pfx_key);
|
||||
if (check_expected("pfx /24 test (10.0.0.234)", encrypted2, "00000000000000000000ffff13d6d21e",
|
||||
16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (memcmp(pfx_output + 12, encrypted1 + 12, 3) != 0 ||
|
||||
memcmp(pfx_output + 12, encrypted2 + 12, 3) != 0) {
|
||||
printf("FAILED: IPv4 /24 prefix not preserved\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK: IPv4 /24 prefix preserved for 10.0.0.x\n");
|
||||
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[12] = 172;
|
||||
input[13] = 16;
|
||||
input[14] = 5;
|
||||
input[15] = 193;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx /16 test (172.16.5.193)", pfx_output,
|
||||
"00000000000000000000ffffd24ee588", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
input[14] = 97;
|
||||
input[15] = 42;
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted1, input, pfx_key);
|
||||
if (check_expected("pfx /16 test (172.16.97.42)", encrypted1,
|
||||
"00000000000000000000ffffd24eb3f1", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
input[14] = 248;
|
||||
input[15] = 177;
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted2, input, pfx_key);
|
||||
if (check_expected("pfx /16 test (172.16.248.177)", encrypted2,
|
||||
"00000000000000000000ffffd24e79d7", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (memcmp(pfx_output + 12, encrypted1 + 12, 2) != 0 ||
|
||||
memcmp(pfx_output + 12, encrypted2 + 12, 2) != 0) {
|
||||
printf("FAILED: IPv4 /16 prefix not preserved\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK: IPv4 /16 prefix preserved for 172.16.x.x\n");
|
||||
|
||||
/* 2001:db8::a5c9:4e2f:bb91:5a7d */
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[8] = 0xa5;
|
||||
input[9] = 0xc9;
|
||||
input[10] = 0x4e;
|
||||
input[11] = 0x2f;
|
||||
input[12] = 0xbb;
|
||||
input[13] = 0x91;
|
||||
input[14] = 0x5a;
|
||||
input[15] = 0x7d;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx /64 test (2001:db8::a5c9:4e2f:bb91:5a7d)", pfx_output,
|
||||
"7cec702c12430f7019560125b9bd1aba", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 2001:db8::7234:d8f1:3c6e:9a52 */
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[8] = 0x72;
|
||||
input[9] = 0x34;
|
||||
input[10] = 0xd8;
|
||||
input[11] = 0xf1;
|
||||
input[12] = 0x3c;
|
||||
input[13] = 0x6e;
|
||||
input[14] = 0x9a;
|
||||
input[15] = 0x52;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted1, input, pfx_key);
|
||||
if (check_expected("pfx /64 test (2001:db8::7234:d8f1:3c6e:9a52)", encrypted1,
|
||||
"7cec702c12430f70a3ef0c8e95c1cd0d", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 2001:db8::f1e0:937b:26d4:8c1a */
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[8] = 0xf1;
|
||||
input[9] = 0xe0;
|
||||
input[10] = 0x93;
|
||||
input[11] = 0x7b;
|
||||
input[12] = 0x26;
|
||||
input[13] = 0xd4;
|
||||
input[14] = 0x8c;
|
||||
input[15] = 0x1a;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted2, input, pfx_key);
|
||||
if (check_expected("pfx /64 test (2001:db8::f1e0:937b:26d4:8c1a)", encrypted2,
|
||||
"7cec702c12430f70443c0c8e6a62b64d", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (memcmp(pfx_output, encrypted1, 8) != 0 || memcmp(pfx_output, encrypted2, 8) != 0) {
|
||||
printf("FAILED: IPv6 /64 prefix not preserved\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK: IPv6 /64 prefix preserved for 2001:db8::/64\n");
|
||||
|
||||
/* 2001:db8:3a5c:0:e7d1:4b9f:2c8a:f673 */
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[4] = 0x3a;
|
||||
input[5] = 0x5c;
|
||||
input[8] = 0xe7;
|
||||
input[9] = 0xd1;
|
||||
input[10] = 0x4b;
|
||||
input[11] = 0x9f;
|
||||
input[12] = 0x2c;
|
||||
input[13] = 0x8a;
|
||||
input[14] = 0xf6;
|
||||
input[15] = 0x73;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(pfx_output, input, pfx_key);
|
||||
if (check_expected("pfx /32 test (2001:db8:3a5c:0:e7d1:4b9f:2c8a:f673)", pfx_output,
|
||||
"7cec702c35030befe61696bdbe33a9b9", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 2001:db8:9f27:0:b4e2:7a3d:5f91:c8e6 */
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[4] = 0x9f;
|
||||
input[5] = 0x27;
|
||||
input[8] = 0xb4;
|
||||
input[9] = 0xe2;
|
||||
input[10] = 0x7a;
|
||||
input[11] = 0x3d;
|
||||
input[12] = 0x5f;
|
||||
input[13] = 0x91;
|
||||
input[14] = 0xc8;
|
||||
input[15] = 0xe6;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted1, input, pfx_key);
|
||||
if (check_expected("pfx /32 test (2001:db8:9f27:0:b4e2:7a3d:5f91:c8e6)", encrypted1,
|
||||
"7cec702ca504b74e194a3d90b0472d1a", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 2001:db8:d8b4:0:193c:a5e7:8b2f:46d1 */
|
||||
memset(input, 0, sizeof input);
|
||||
input[0] = 0x20;
|
||||
input[1] = 0x01;
|
||||
input[2] = 0x0d;
|
||||
input[3] = 0xb8;
|
||||
input[4] = 0xd8;
|
||||
input[5] = 0xb4;
|
||||
input[8] = 0x19;
|
||||
input[9] = 0x3c;
|
||||
input[10] = 0xa5;
|
||||
input[11] = 0xe7;
|
||||
input[12] = 0x8b;
|
||||
input[13] = 0x2f;
|
||||
input[14] = 0x46;
|
||||
input[15] = 0xd1;
|
||||
|
||||
crypto_ipcrypt_pfx_encrypt(encrypted2, input, pfx_key);
|
||||
if (check_expected("pfx /32 test (2001:db8:d8b4:0:193c:a5e7:8b2f:46d1)", encrypted2,
|
||||
"7cec702cf840aa6701b8e84fac9d77fb", 16) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (memcmp(pfx_output, encrypted1, 4) != 0 || memcmp(pfx_output, encrypted2, 4) != 0) {
|
||||
printf("FAILED: IPv6 /32 prefix not preserved\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK: IPv6 /32 prefix preserved for 2001:db8::/32\n");
|
||||
|
||||
printf("\nfunctional tests\n");
|
||||
|
||||
crypto_ipcrypt_keygen(key);
|
||||
crypto_ipcrypt_ndx_keygen(ndx_key);
|
||||
crypto_ipcrypt_pfx_keygen(pfx_key);
|
||||
printf("OK: Key generation functions\n");
|
||||
|
||||
memset(key, 0x55, sizeof key);
|
||||
memset(input, 0xaa, sizeof input);
|
||||
crypto_ipcrypt_encrypt(output, input, key);
|
||||
memcpy(decrypted, input, sizeof input);
|
||||
crypto_ipcrypt_encrypt(decrypted, decrypted, key);
|
||||
if (memcmp(output, decrypted, sizeof output) != 0) {
|
||||
printf("FAILED: In-place encryption differs\n");
|
||||
return 1;
|
||||
}
|
||||
crypto_ipcrypt_decrypt(decrypted, decrypted, key);
|
||||
if (memcmp(input, decrypted, sizeof input) != 0) {
|
||||
printf("FAILED: In-place round-trip\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK: In-place encryption/decryption\n");
|
||||
|
||||
crypto_ipcrypt_encrypt(output, input, key);
|
||||
crypto_ipcrypt_encrypt(decrypted, input, key);
|
||||
if (memcmp(output, decrypted, sizeof output) != 0) {
|
||||
printf("FAILED: Deterministic encryption\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK: Deterministic encryption\n");
|
||||
|
||||
memset(key, 0x42, sizeof key);
|
||||
for (i = 0; i < 4; i++) {
|
||||
memset(input, 0, sizeof input);
|
||||
input[10] = 0xff;
|
||||
input[11] = 0xff;
|
||||
input[15] = (unsigned char) i;
|
||||
crypto_ipcrypt_encrypt(output, input, key);
|
||||
if (i > 0) {
|
||||
if (memcmp(output, decrypted, sizeof output) == 0) {
|
||||
printf("FAILED: Different inputs produced same output\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
memcpy(decrypted, output, sizeof output);
|
||||
}
|
||||
printf("OK: Different inputs produce different outputs\n");
|
||||
|
||||
printf("\nAll specification test vectors passed!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
crypto_ipcrypt_BYTES: 16
|
||||
crypto_ipcrypt_KEYBYTES: 16
|
||||
crypto_ipcrypt_ND_KEYBYTES: 16
|
||||
crypto_ipcrypt_ND_TWEAKBYTES: 8
|
||||
crypto_ipcrypt_ND_INPUTBYTES: 16
|
||||
crypto_ipcrypt_ND_OUTPUTBYTES: 24
|
||||
crypto_ipcrypt_NDX_KEYBYTES: 32
|
||||
crypto_ipcrypt_NDX_TWEAKBYTES: 16
|
||||
crypto_ipcrypt_NDX_INPUTBYTES: 16
|
||||
crypto_ipcrypt_NDX_OUTPUTBYTES: 32
|
||||
crypto_ipcrypt_PFX_KEYBYTES: 32
|
||||
crypto_ipcrypt_PFX_BYTES: 16
|
||||
|
||||
ipcrypt-deterministic test vectors
|
||||
OK: deterministic vector 1 (0.0.0.0)
|
||||
OK: deterministic vector 2 (255.255.255.255)
|
||||
OK: deterministic vector 3 (192.0.2.1)
|
||||
|
||||
ipcrypt-nd test vectors
|
||||
OK: nd vector 1 (0.0.0.0)
|
||||
OK: nd vector 2 (192.0.2.1)
|
||||
OK: nd vector 3 (2001:db8::1)
|
||||
|
||||
ipcrypt-ndx test vectors
|
||||
OK: ndx vector 1 (0.0.0.0)
|
||||
OK: ndx vector 2 (192.0.2.1)
|
||||
OK: ndx vector 3 (2001:db8::1)
|
||||
|
||||
ipcrypt-pfx test vectors
|
||||
OK: pfx vector 1 (0.0.0.0)
|
||||
OK: pfx vector 2 (255.255.255.255)
|
||||
OK: pfx vector 3 (192.0.2.1)
|
||||
OK: pfx vector 4 (2001:db8::1)
|
||||
|
||||
ipcrypt-pfx prefix preservation
|
||||
OK: pfx /24 test (10.0.0.47)
|
||||
OK: pfx /24 test (10.0.0.129)
|
||||
OK: pfx /24 test (10.0.0.234)
|
||||
OK: IPv4 /24 prefix preserved for 10.0.0.x
|
||||
OK: pfx /16 test (172.16.5.193)
|
||||
OK: pfx /16 test (172.16.97.42)
|
||||
OK: pfx /16 test (172.16.248.177)
|
||||
OK: IPv4 /16 prefix preserved for 172.16.x.x
|
||||
OK: pfx /64 test (2001:db8::a5c9:4e2f:bb91:5a7d)
|
||||
OK: pfx /64 test (2001:db8::7234:d8f1:3c6e:9a52)
|
||||
OK: pfx /64 test (2001:db8::f1e0:937b:26d4:8c1a)
|
||||
OK: IPv6 /64 prefix preserved for 2001:db8::/64
|
||||
OK: pfx /32 test (2001:db8:3a5c:0:e7d1:4b9f:2c8a:f673)
|
||||
OK: pfx /32 test (2001:db8:9f27:0:b4e2:7a3d:5f91:c8e6)
|
||||
OK: pfx /32 test (2001:db8:d8b4:0:193c:a5e7:8b2f:46d1)
|
||||
OK: IPv6 /32 prefix preserved for 2001:db8::/32
|
||||
|
||||
functional tests
|
||||
OK: Key generation functions
|
||||
OK: In-place encryption/decryption
|
||||
OK: Deterministic encryption
|
||||
OK: Different inputs produce different outputs
|
||||
|
||||
All specification test vectors passed!
|
||||
Reference in New Issue
Block a user