From: Niels Möller Date: Sun, 17 Jun 2001 07:11:48 +0000 (+0200) Subject: * testsuite/Makefile.am (TS_PROGS): Added cast128 test. X-Git-Tag: release_nettle_0.2.20010617~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09ae0ad8be55c86c8535b2f9982e1cab9579fbaf;p=thirdparty%2Fnettle.git * testsuite/Makefile.am (TS_PROGS): Added cast128 test. Rev: src/nettle/testsuite/Makefile.am:1.6 Rev: src/nettle/testsuite/cast128-test.m4:1.1 --- diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index afee947e..c3e89900 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -1,7 +1,8 @@ CFLAGS = -I$(top_srcdir) @CFLAGS@ -O0 CPPFLAGS = @CPPFLAGS@ -TS_PROGS = aes-test arcfour-test blowfish-test des-test md5-test sha1-test \ +TS_PROGS = aes-test arcfour-test blowfish-test cast128-test des-test \ + md5-test sha1-test \ serpent-test twofish-test noinst_PROGRAMS = $(TS_PROGS) diff --git a/testsuite/cast128-test.m4 b/testsuite/cast128-test.m4 new file mode 100644 index 00000000..e640cdd6 --- /dev/null +++ b/testsuite/cast128-test.m4 @@ -0,0 +1,50 @@ +#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; +