Commit 9d4b4dfe authored by Niels Möller's avatar Niels Möller

Don't use m4 for geneerating test programs, it's way overkill. Use

	the C preprocessor instead.
	* testsuite/*-test.c: New file.

Rev: src/nettle/testsuite/.cvsignore:1.12
Rev: src/nettle/testsuite/Makefile.am:1.17
Rev: src/nettle/testsuite/aes-test.c:1.1
Rev: src/nettle/testsuite/aes-test.m4:1.4(DEAD)
Rev: src/nettle/testsuite/arcfour-test.c:1.1
Rev: src/nettle/testsuite/arcfour-test.m4:1.2(DEAD)
Rev: src/nettle/testsuite/bignum-test.c:1.1
Rev: src/nettle/testsuite/bignum-test.m4:1.2(DEAD)
Rev: src/nettle/testsuite/blowfish-test.c:1.1
Rev: src/nettle/testsuite/blowfish-test.m4:1.5(DEAD)
Rev: src/nettle/testsuite/cast128-test.c:1.1
Rev: src/nettle/testsuite/cast128-test.m4:1.2(DEAD)
Rev: src/nettle/testsuite/cbc-test.c:1.1
Rev: src/nettle/testsuite/cbc-test.m4:1.3(DEAD)
Rev: src/nettle/testsuite/des-test.c:1.1
Rev: src/nettle/testsuite/des-test.m4:1.3(DEAD)
Rev: src/nettle/testsuite/des3-test.c:1.1
Rev: src/nettle/testsuite/des3-test.m4:1.3(DEAD)
Rev: src/nettle/testsuite/macros.m4:1.3(DEAD)
Rev: src/nettle/testsuite/md5-compat-test.c:1.1
Rev: src/nettle/testsuite/md5-compat-test.m4:1.2(DEAD)
Rev: src/nettle/testsuite/md5-test.c:1.1
Rev: src/nettle/testsuite/md5-test.m4:1.4(DEAD)
Rev: src/nettle/testsuite/serpent-test.c:1.1
Rev: src/nettle/testsuite/serpent-test.m4:1.3(DEAD)
Rev: src/nettle/testsuite/sha1-test.c:1.1
Rev: src/nettle/testsuite/sha1-test.m4:1.4(DEAD)
Rev: src/nettle/testsuite/sha256-test.c:1.1
Rev: src/nettle/testsuite/sha256-test.m4:1.3(DEAD)
Rev: src/nettle/testsuite/testutils.c:1.5
Rev: src/nettle/testsuite/testutils.h:1.3
Rev: src/nettle/testsuite/twofish-test.c:1.1
Rev: src/nettle/testsuite/twofish-test.m4:1.3(DEAD)
parent 7699f2d5
......@@ -2,32 +2,18 @@
Makefile
Makefile.in
aes-test
aes-test.c
arcfour-test
arcfour-test.c
bignum-test
bignum-test.c
blowfish-test
blowfish-test.c
cast128-test
cast128-test.c
cbc-test
cbc-test.c
des-compat-test
des-test
des-test.c
des3-test
des3-test.c
md5-compat-test
md5-compat-test.c
md5-test
md5-test.c
serpent-test
serpent-test.c
sha1-test
sha1-test.c
sha256-test
sha256-test.c
twofish-test
twofish-test.c
yarrow-test
......@@ -2,32 +2,18 @@
/Makefile
/Makefile.in
/aes-test
/aes-test.c
/arcfour-test
/arcfour-test.c
/bignum-test
/bignum-test.c
/blowfish-test
/blowfish-test.c
/cast128-test
/cast128-test.c
/cbc-test
/cbc-test.c
/des-compat-test
/des-test
/des-test.c
/des3-test
/des3-test.c
/md5-compat-test
/md5-compat-test.c
/md5-test
/md5-test.c
/serpent-test
/serpent-test.c
/sha1-test
/sha1-test.c
/sha256-test
/sha256-test.c
/twofish-test
/twofish-test.c
/yarrow-test
......@@ -7,23 +7,23 @@ TS_PROGS = aes-test arcfour-test blowfish-test cast128-test \
serpent-test twofish-test \
cbc-test bignum-test yarrow-test
M4_FILES = aes-test.m4 arcfour-test.m4 blowfish-test.m4 cast128-test.m4 \
des-test.m4 des3-test.m4 \
md5-test.m4 md5-compat-test.m4 sha1-test.m4 sha256-test.m4 \
serpent-test.m4 twofish-test.m4 \
cbc-test.m4 bignum-test.m4
# M4_FILES = aes-test.m4 arcfour-test.m4 blowfish-test.m4 cast128-test.m4 \
# des-test.m4 des3-test.m4 \
# md5-test.m4 md5-compat-test.m4 sha1-test.m4 sha256-test.m4 \
# serpent-test.m4 twofish-test.m4 \
# cbc-test.m4 bignum-test.m4
noinst_PROGRAMS = $(TS_PROGS)
LDADD = testutils.o ../libnettle.a
EXTRA_DIST = $(M4_FILES) macros.m4 testutils.c testutils.h \
EXTRA_DIST = testutils.c testutils.h \
run-tests rfc1750.txt
# M4FLAGS = -P -s
M4FLAGS = -P
$(M4_FILES:.m4=.c): %.c: macros.m4 %.m4
$(M4) $(M4FLAGS) $^ > $@T
test -s $@T && mv -f $@T $@
# # M4FLAGS = -P -s
# M4FLAGS = -P
# $(M4_FILES:.m4=.c): %.c: macros.m4 %.m4
# $(M4) $(M4FLAGS) $^ > $@T
# test -s $@T && mv -f $@T $@
.PHONY: check run-tests
......
#include "testutils.h"
#include "aes.h"
int
main(int argc, char **argv)
{
/* 128 bit keys */
test_cipher(&nettle_aes128,
HL("0001020305060708 0A0B0C0D0F101112"),
HL("506812A45F08C889 B97F5980038B8359"),
H("D8F532538289EF7D 06B506A4FD5BE9C9"));
test_cipher(&nettle_aes128,
HL("14151617191A1B1C 1E1F202123242526"),
HL("5C6D71CA30DE8B8B 00549984D2EC7D4B"),
H("59AB30F4D4EE6E4F F9907EF65B1FB68C"));
test_cipher(&nettle_aes128,
HL("28292A2B2D2E2F30 323334353738393A"),
HL("53F3F4C64F8616E4 E7C56199F48F21F6"),
H("BF1ED2FCB2AF3FD4 1443B56D85025CB1"));
test_cipher(&nettle_aes128,
HL("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"),
HL("F5F4F7F684878689 A6A7A0A1D2CDCCCF"),
H("CE52AF650D088CA5 59425223F4D32694"));
/* 192 bit keys */
test_cipher(&nettle_aes192,
HL("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"),
HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
H("DFF4945E0336DF4C 1C56BC700EFF837F"));
/* 256 bit keys */
test_cipher(&nettle_aes256,
HL("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"),
HL("834EADFCCAC7E1B30664B1ABA44815AB"),
H("1946DABF6A03A2A2 C3D0B05080AED6FC"));
/* This test case has been problematic with the CBC test case */
test_cipher(&nettle_aes256,
HL("8d ae 93 ff fc 78 c9 44"
"2a bd 0c 1e 68 bc a6 c7"
"05 c7 84 e3 5a a9 11 8b"
"d3 16 aa 54 9b 44 08 9e"),
HL("a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"),
/* In the cbc test, I once got the bad value
* "b2 a0 6c d2 2f df 7d 2c 26 d2 42 88 8f 20 74 a2" */
H("1f 94 fc 85 f2 36 21 06"
"4a ea e3 c9 cc 38 01 0e"));
/* From draft NIST spec on AES modes.
*
* F.1 ECB Example Vectors
* F.1.1 ECB-AES128-Encrypt
*/
test_cipher(&nettle_aes128,
HL("2b7e151628aed2a6abf7158809cf4f3c"),
HL("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
H("3ad77bb40d7a3660a89ecaf32466ef97"
"f5d3d58503b9699de785895a96fdbaaf"
"43b1cd7f598ece23881b00e3ed030688"
"7b0c785e27e8ad3f8223207104725dd4"));
/* F.1.3 ECB-AES192-Encrypt */
test_cipher(&nettle_aes192,
HL("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"),
HL("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
H("bd334f1d6e45f25ff712a214571fa5cc"
"974104846d0ad3ad7734ecb3ecee4eef"
"ef7afd2270e2e60adce0ba2face6444e"
"9a4b41ba738d6c72fb16691603c18e0e"));
/* F.1.5 ECB-AES256-Encrypt */
test_cipher(&nettle_aes256,
HL("603deb1015ca71be2b73aef0857d7781"
"1f352c073b6108d72d9810a30914dff4"),
HL("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
H("f3eed1bdb5d2a03c064b5a7e3db181f8"
"591ccb10d410ed26dc5ba74a31362870"
"b6ed21b99ca6f4f9f153e7b1beafed1d"
"23304b7a39f9f3ff067d8d8f9e24ecc7"));
SUCCESS();
}
#include "aes.h"
BEGIN_TEST
struct aes_ctx ctx;
uint8_t msg[AES_BLOCK_SIZE];
uint8_t cipher[AES_BLOCK_SIZE];
uint8_t clear[AES_BLOCK_SIZE];
/* 128 bit keys */
H(msg, "506812A45F08C889 B97F5980038B8359");
aes_set_key(&ctx, 16, H("0001020305060708 0A0B0C0D0F101112"));
aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(16, cipher, H("D8F532538289EF7D 06B506A4FD5BE9C9")))
FAIL;
aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(16, msg, clear))
FAIL;
H(msg, "5C6D71CA30DE8B8B 00549984D2EC7D4B");
aes_set_key(&ctx, 16, H("14151617191A1B1C 1E1F202123242526"));
aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(16, cipher, H("59AB30F4D4EE6E4F F9907EF65B1FB68C")))
FAIL;
aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(16, msg, clear))
FAIL;
H(msg, "53F3F4C64F8616E4 E7C56199F48F21F6");
aes_set_key(&ctx, 16, H("28292A2B2D2E2F30 323334353738393A"));
aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(16, cipher, H("BF1ED2FCB2AF3FD4 1443B56D85025CB1")))
FAIL;
aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(16, msg, clear))
FAIL;
H(msg, "F5F4F7F684878689 A6A7A0A1D2CDCCCF");
aes_set_key(&ctx, 16, H("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"));
aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(16, cipher, H("CE52AF650D088CA5 59425223F4D32694")))
FAIL;
aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(16, msg, clear))
FAIL;
/* 192 bit keys */
H(msg, "2D33EEF2C0430A8A 9EBF45E809C40BB6");
aes_set_key(&ctx, 24, H("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"));
aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(16, cipher, H("DFF4945E0336DF4C 1C56BC700EFF837F")))
FAIL;
aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(16, msg, clear))
FAIL;
/* 256 bit keys */
H(msg, "834EADFCCAC7E1B30664B1ABA44815AB");
aes_set_key(&ctx, 32, H("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"));
aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(16, cipher, H("1946DABF6A03A2A2 C3D0B05080AED6FC")))
FAIL;
aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(16, msg, clear))
FAIL;
/* This test case has been problematic with the CBC test case */
H(msg, "a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37");
aes_set_key(&ctx, 32, H("8d ae 93 ff fc 78 c9 44"
"2a bd 0c 1e 68 bc a6 c7"
"05 c7 84 e3 5a a9 11 8b"
"d3 16 aa 54 9b 44 08 9e"));
aes_encrypt(&ctx, AES_BLOCK_SIZE, cipher, msg);
/* In the cbc test, I once got the bad value
* "b2 a0 6c d2 2f df 7d 2c 26 d2 42 88 8f 20 74 a2" */
if (!MEMEQ(16, cipher, H("1f 94 fc 85 f2 36 21 06"
"4a ea e3 c9 cc 38 01 0e")))
FAIL;
aes_decrypt(&ctx, AES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(16, msg, clear))
FAIL;
/* From draft NIST spec on AES modes.
F.1 ECB Example Vectors
F.1.1 ECB-AES128-Encrypt
Key 2b7e151628aed2a6abf7158809cf4f3c
Block #1
Plaintext 6bc1bee22e409f96e93d7e117393172a
Input Block 6bc1bee22e409f96e93d7e117393172a
Output Block 3ad77bb40d7a3660a89ecaf32466ef97
Ciphertext 3ad77bb40d7a3660a89ecaf32466ef97
Block #2
Plaintext ae2d8a571e03ac9c9eb76fac45af8e51
Input Block ae2d8a571e03ac9c9eb76fac45af8e51
Output Block f5d3d58503b9699de785895a96fdbaaf
Ciphertext f5d3d58503b9699de785895a96fdbaaf
Block #3
Plaintext 30c81c46a35ce411e5fbc1191a0a52ef
Input Block 30c81c46a35ce411e5fbc1191a0a52ef
Output Block 43b1cd7f598ece23881b00e3ed030688
Ciphertext 43b1cd7f598ece23881b00e3ed030688
Block #4
Plaintext f69f2445df4f9b17ad2b417be66c3710
Input Block f69f2445df4f9b17ad2b417be66c3710
Output Block 7b0c785e27e8ad3f8223207104725dd4
Ciphertext 7b0c785e27e8ad3f8223207104725dd4
F.1.2 ECB-AES128-Decrypt
Key 2b7e151628aed2a6abf7158809cf4f3c
Block #1
Ciphertext 3ad77bb40d7a3660a89ecaf32466ef97
Input Block 3ad77bb40d7a3660a89ecaf32466ef97
Output Block 6bc1bee22e409f96e93d7e117393172a
Plaintext 6bc1bee22e409f96e93d7e117393172a
Block #2
Ciphertext f5d3d58503b9699de785895a96fdbaaf
Input Block f5d3d58503b9699de785895a96fdbaaf
Output Block ae2d8a571e03ac9c9eb76fac45af8e51
Plaintext ae2d8a571e03ac9c9eb76fac45af8e51
Block #3
Ciphertext 43b1cd7f598ece23881b00e3ed030688
Input Block 43b1cd7f598ece23881b00e3ed030688
Output Block 30c81c46a35ce411e5fbc1191a0a52ef
Plaintext 30c81c46a35ce411e5fbc1191a0a52ef
Block #4
Ciphertext 7b0c785e27e8ad3f8223207104725dd4
Input Block 7b0c785e27e8ad3f8223207104725dd4
Output Block f69f2445df4f9b17ad2b417be66c3710
Plaintext f69f2445df4f9b17ad2b417be66c3710
F.1.3 ECB-AES192-Encrypt
Key 8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b
Block #1
Plaintext 6bc1bee22e409f96e93d7e117393172a
Input Block 6bc1bee22e409f96e93d7e117393172a
Output Block bd334f1d6e45f25ff712a214571fa5cc
Ciphertext bd334f1d6e45f25ff712a214571fa5cc
Block #2
Plaintext ae2d8a571e03ac9c9eb76fac45af8e51
Input Block ae2d8a571e03ac9c9eb76fac45af8e51
Output Block 974104846d0ad3ad7734ecb3ecee4eef
Ciphertext 974104846d0ad3ad7734ecb3ecee4eef
Block #3
Plaintext 30c81c46a35ce411e5fbc1191a0a52ef
Input Block 30c81c46a35ce411e5fbc1191a0a52ef
Output Block ef7afd2270e2e60adce0ba2face6444e
Ciphertext ef7afd2270e2e60adce0ba2face6444e
Block #4
Plaintext f69f2445df4f9b17ad2b417be66c3710
Input Block f69f2445df4f9b17ad2b417be66c3710
Output Block 9a4b41ba738d6c72fb16691603c18e0e
Ciphertext 9a4b41ba738d6c72fb16691603c18e0e
F.1.4 ECB-AES192-Decrypt
Key 8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b
Block #1
Ciphertext bd334f1d6e45f25ff712a214571fa5cc
Input Block bd334f1d6e45f25ff712a214571fa5cc
Output Block 6bc1bee22e409f96e93d7e117393172a
Plaintext 6bc1bee22e409f96e93d7e117393172a
Block #2
Ciphertext 974104846d0ad3ad7734ecb3ecee4eef
Input Block 974104846d0ad3ad7734ecb3ecee4eef
Output Block ae2d8a571e03ac9c9eb76fac45af8e51
Plaintext ae2d8a571e03ac9c9eb76fac45af8e51
Block #3
Ciphertext ef7afd2270e2e60adce0ba2face6444e
Input Block ef7afd2270e2e60adce0ba2face6444e
Output Block 30c81c46a35ce411e5fbc1191a0a52ef
Plaintext 30c81c46a35ce411e5fbc1191a0a52ef
Block #4
Ciphertext 9a4b41ba738d6c72fb16691603c18e0e
Input Block 9a4b41ba738d6c72fb16691603c18e0e
Output Block f69f2445df4f9b17ad2b417be66c3710
Plaintext f69f2445df4f9b17ad2b417be66c3710
F.1.5 ECB-AES256-Encrypt
Key 603deb1015ca71be2b73aef0857d7781
1f352c073b6108d72d9810a30914dff4
Block #1
Plaintext 6bc1bee22e409f96e93d7e117393172a
Input Block 6bc1bee22e409f96e93d7e117393172a
Output Block f3eed1bdb5d2a03c064b5a7e3db181f8
Ciphertext f3eed1bdb5d2a03c064b5a7e3db181f8
Block #2
Plaintext ae2d8a571e03ac9c9eb76fac45af8e51
Input Block ae2d8a571e03ac9c9eb76fac45af8e51
Output Block 591ccb10d410ed26dc5ba74a31362870
Ciphertext 591ccb10d410ed26dc5ba74a31362870
Block #3
Plaintext 30c81c46a35ce411e5fbc1191a0a52ef
Input Block 30c81c46a35ce411e5fbc1191a0a52ef
Output Block b6ed21b99ca6f4f9f153e7b1beafed1d
Ciphertext b6ed21b99ca6f4f9f153e7b1beafed1d
Block #4
Plaintext f69f2445df4f9b17ad2b417be66c3710
Input Block f69f2445df4f9b17ad2b417be66c3710
Output Block 23304b7a39f9f3ff067d8d8f9e24ecc7
Ciphertext 23304b7a39f9f3ff067d8d8f9e24ecc7
F.1.6 ECB-AES256-Decrypt
Key 603deb1015ca71be2b73aef0857d7781
1f352c073b6108d72d9810a30914dff4
Block #1
Ciphertext f3eed1bdb5d2a03c064b5a7e3db181f8
Input Block f3eed1bdb5d2a03c064b5a7e3db181f8
Output Block 6bc1bee22e409f96e93d7e117393172a
Plaintext 6bc1bee22e409f96e93d7e117393172a
Block #2
Ciphertext 591ccb10d410ed26dc5ba74a31362870
Input Block 591ccb10d410ed26dc5ba74a31362870
Output Block ae2d8a571e03ac9c9eb76fac45af8e51
Plaintext ae2d8a571e03ac9c9eb76fac45af8e51
Block #3
Ciphertext b6ed21b99ca6f4f9f153e7b1beafed1d
Input Block b6ed21b99ca6f4f9f153e7b1beafed1d
Output Block 30c81c46a35ce411e5fbc1191a0a52ef
Plaintext 30c81c46a35ce411e5fbc1191a0a52ef
Block #4
Ciphertext 23304b7a39f9f3ff067d8d8f9e24ecc7
Input Block 23304b7a39f9f3ff067d8d8f9e24ecc7
Output Block f69f2445df4f9b17ad2b417be66c3710
Plaintext f69f2445df4f9b17ad2b417be66c3710
*/
#include "testutils.h"
#include "arcfour.h"
int
main(int argc, char **argv)
{
test_cipher(&nettle_arcfour128,
HL("01234567 89ABCDEF 00000000 00000000"),
HL("01234567 89ABCDEF"),
H("69723659 1B5242B1"));
SUCCESS();
}
#include "arcfour.h"
BEGIN_TEST
struct arcfour_ctx ctx;
const uint8_t *clear = H("01234567 89ABCDEF");
uint8_t cipher[8];
arcfour_set_key(&ctx, 16, H("01234567 89ABCDEF 00000000 00000000"));
arcfour_crypt(&ctx, 8, cipher, clear);
if (!MEMEQ(8, cipher, H("69723659 1B5242B1")))
FAIL;
#include "testutils.h"
#if HAVE_CONFIG_H
#include "config.h"
......@@ -20,28 +21,30 @@ test_bignum(const char *hex, unsigned length, const uint8_t *base256)
nettle_mpz_init_set_str_256(b, length, base256);
if (mpz_cmp(a, b))
FAIL;
FAIL();
buf = alloca(length + 1);
memset(buf, 17, length + 1);
nettle_mpz_get_str_256(length, buf, a);
if (!MEMEQ(length, buf, base256))
FAIL;
FAIL();
if (buf[length] != 17)
FAIL;
FAIL();
mpz_clear(a); mpz_clear(b);
}
#endif /* HAVE_LIBGMP */
BEGIN_TEST
int
main(int argc, char **argv)
{
#if HAVE_LIBGMP
test_bignum("0", 0, "");
test_bignum("010203040506", 7, H("00010203040506"));
test_bignum("0", 0, "");
test_bignum("010203040506", 7, H("00010203040506"));
SUCCESS();
#else /* !HAVE_LIBGMP */
SKIP
SKIP();
#endif /* !HAVE_LIBGMP */
}
#include "testutils.h"
#include "nettle-internal.h"
#include "blowfish.h"
BEGIN_TEST
struct blowfish_ctx ctx;
uint8_t msg[BLOWFISH_BLOCK_SIZE];
uint8_t cipher[BLOWFISH_BLOCK_SIZE];
uint8_t clear[BLOWFISH_BLOCK_SIZE];
/* 208 bit key. Test from GNUPG. */
blowfish_set_key(&ctx, 26, "abcdefghijklmnopqrstuvwxyz");
blowfish_encrypt(&ctx, BLOWFISH_BLOCK_SIZE, cipher, "BLOWFISH");
if (!MEMEQ(BLOWFISH_BLOCK_SIZE, cipher, H("32 4E D0 FE F4 13 A2 03")))
FAIL;
blowfish_decrypt(&ctx, BLOWFISH_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(BLOWFISH_BLOCK_SIZE, "BLOWFISH", clear))
FAIL;
int
main(int argc, char **argv)
{
/* 208 bit key. Test from GNUPG. */
test_cipher(&nettle_blowfish128,
26, "abcdefghijklmnopqrstuvwxyz",
BLOWFISH_BLOCK_SIZE, "BLOWFISH",
H("32 4E D0 FE F4 13 A2 03"));
SUCCESS();
}
/* FIXME: All values below are bogus. */
#if 0
......
#include "testutils.h"
#include "cast128.h"
int
main(int argc, char **argv)
{
/* Test vectors from B.1. Single Plaintext-Key-Ciphertext Sets, RFC
* 2144 */
/* 128 bit key */
test_cipher(&nettle_cast128,
HL("01 23 45 67 12 34 56 78"
"23 45 67 89 34 56 78 9A"),
HL("01 23 45 67 89 AB CD EF"),
H("23 8B 4F E5 84 7E 44 B2"));
/* 80 bit key */
test_cipher(&nettle_cast128,
HL("01 23 45 67 12 34 56 78 23 45"),
HL("01 23 45 67 89 AB CD EF"),
H("EB 6A 71 1A 2C 02 27 1B"));
/* 40 bit key */
test_cipher(&nettle_cast128,
HL("01 23 45 67 12"),
HL("01 23 45 67 89 AB CD EF"),
H("7A C8 16 D1 6E 9B 30 2E"));
SUCCESS();
}
#include "cast128.h"
BEGIN_TEST
struct cast128_ctx ctx;
uint8_t msg[CAST128_BLOCK_SIZE];
uint8_t cipher[CAST128_BLOCK_SIZE];
uint8_t clear[CAST128_BLOCK_SIZE];
/* Test vectors from B.1. Single Plaintext-Key-Ciphertext Sets, RFC
* 2144 */
/* 128 bit key */
H(msg, "01 23 45 67 89 AB CD EF");
cast128_set_key(&ctx, 16, H("01 23 45 67 12 34 56 78"
"23 45 67 89 34 56 78 9A"));
cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(CAST128_BLOCK_SIZE, cipher, H("23 8B 4F E5 84 7E 44 B2")))
FAIL;
cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(CAST128_BLOCK_SIZE, msg, clear))
FAIL;
/* 80 bit key */
H(msg, "01 23 45 67 89 AB CD EF");
cast128_set_key(&ctx, 10, H("01 23 45 67 12 34 56 78 23 45"));
cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(CAST128_BLOCK_SIZE, cipher, H("EB 6A 71 1A 2C 02 27 1B")))
FAIL;
cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(CAST128_BLOCK_SIZE, msg, clear))
FAIL;
/* 40 bit key */
H(msg, "01 23 45 67 89 AB CD EF");
cast128_set_key(&ctx, 5, H("01 23 45 67 12"));
cast128_encrypt(&ctx, CAST128_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(CAST128_BLOCK_SIZE, cipher, H("7A C8 16 D1 6E 9B 30 2E")))
FAIL;
cast128_decrypt(&ctx, CAST128_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(CAST128_BLOCK_SIZE, msg, clear))
FAIL;
#include "testutils.h"
#include "aes.h"
#include "cbc.h"
int
main(int argc, char **argv)
{
uint8_t msg[2 * AES_BLOCK_SIZE] = "Listen, I'll say this only once!";
/* Intermediate values:
* iv XOR first message block:
* "a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"
* First ciphertext block, c1:
* "1f 94 fc 85 f2 36 21 06 4a ea e3 c9 cc 38 01 0e"
* c1 XOR second message block:
* "3f e0 94 ec 81 16 4e 68 26 93 c3 a6 a2 5b 64 2f"
* Second ciphertext block, c1:
* "7b f6 5f c5 02 59 2e 71 af bf 34 87 c0 36 2a 16"
*/
test_cipher_cbc(&nettle_aes256,
HL("8d ae 93 ff fc 78 c9 44"
"2a bd 0c 1e 68 bc a6 c7"
"05 c7 84 e3 5a a9 11 8b"
"d3 16 aa 54 9b 44 08 9e"),
2 * AES_BLOCK_SIZE, msg,
H("1f 94 fc 85 f2 36 21 06"
"4a ea e3 c9 cc 38 01 0e"
"7b f6 5f c5 02 59 2e 71"