From f725a88e5493380894d52a4529a981022db6cb21 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Wed, 8 Jul 2009 06:43:10 +0000
Subject: [PATCH] - Added test suite for XTEA
---
tests/CMakeLists.txt | 1 +
tests/suites/test_suite_xtea.data | 38 +++++++++++++++++
tests/suites/test_suite_xtea.function | 60 +++++++++++++++++++++++++++
3 files changed, 99 insertions(+)
create mode 100644 tests/suites/test_suite_xtea.data
create mode 100644 tests/suites/test_suite_xtea.function
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 0bc984f682..28b6734e9a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -22,3 +22,4 @@ add_test_suite(aes)
add_test_suite(camellia)
add_test_suite(des)
add_test_suite(rsa)
+add_test_suite(xtea)
diff --git a/tests/suites/test_suite_xtea.data b/tests/suites/test_suite_xtea.data
new file mode 100644
index 0000000000..209ead0b0d
--- /dev/null
+++ b/tests/suites/test_suite_xtea.data
@@ -0,0 +1,38 @@
+XTEA Encrypt_ecb #1
+xtea_encrypt_ecb:"000102030405060708090a0b0c0d0e0f":"4142434445464748":"497df3d072612cb5"
+
+XTEA Encrypt_ecb #2
+xtea_encrypt_ecb:"000102030405060708090a0b0c0d0e0f":"4141414141414141":"e78f2d13744341d8"
+
+XTEA Encrypt_ecb #3
+xtea_encrypt_ecb:"000102030405060708090a0b0c0d0e0f":"5a5b6e278948d77f":"4141414141414141"
+
+XTEA Encrypt_ecb #4
+xtea_encrypt_ecb:"00000000000000000000000000000000":"4142434445464748":"a0390589f8b8efa5"
+
+XTEA Encrypt_ecb #5
+xtea_encrypt_ecb:"00000000000000000000000000000000":"4141414141414141":"ed23375a821a8c2d"
+
+XTEA Encrypt_ecb #6
+xtea_encrypt_ecb:"00000000000000000000000000000000":"70e1225d6e4e7655":"4141414141414141"
+
+XTEA Decrypt_ecb #1
+xtea_decrypt_ecb:"000102030405060708090a0b0c0d0e0f":"497df3d072612cb5":"4142434445464748"
+
+XTEA Decrypt_ecb #2
+xtea_decrypt_ecb:"000102030405060708090a0b0c0d0e0f":"e78f2d13744341d8":"4141414141414141"
+
+XTEA Decrypt_ecb #3
+xtea_decrypt_ecb:"000102030405060708090a0b0c0d0e0f":"4141414141414141":"5a5b6e278948d77f"
+
+XTEA Decrypt_ecb #4
+xtea_decrypt_ecb:"00000000000000000000000000000000":"a0390589f8b8efa5":"4142434445464748"
+
+XTEA Decrypt_ecb #5
+xtea_decrypt_ecb:"00000000000000000000000000000000":"ed23375a821a8c2d":"4141414141414141"
+
+XTEA Decrypt_ecb #6
+xtea_decrypt_ecb:"00000000000000000000000000000000":"4141414141414141":"70e1225d6e4e7655"
+
+XTEA Selftest
+xtea_selftest:
diff --git a/tests/suites/test_suite_xtea.function b/tests/suites/test_suite_xtea.function
new file mode 100644
index 0000000000..e75d0a707f
--- /dev/null
+++ b/tests/suites/test_suite_xtea.function
@@ -0,0 +1,60 @@
+BEGIN_HEADER
+#include
+END_HEADER
+
+BEGIN_CASE
+xtea_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
+{
+ unsigned char key_str[100];
+ unsigned char src_str[100];
+ unsigned char dst_str[100];
+ unsigned char output[100];
+ xtea_context ctx;
+
+ memset(key_str, 0x00, 100);
+ memset(src_str, 0x00, 100);
+ memset(dst_str, 0x00, 100);
+ memset(output, 0x00, 100);
+
+ unhexify( key_str, {hex_key_string} );
+ unhexify( src_str, {hex_src_string} );
+
+ xtea_setup( &ctx, key_str );
+ xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, src_str, output );
+ hexify( dst_str, output, 8 );
+
+ TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
+}
+END_CASE
+
+BEGIN_CASE
+xtea_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
+{
+ unsigned char key_str[100];
+ unsigned char src_str[100];
+ unsigned char dst_str[100];
+ unsigned char output[100];
+ xtea_context ctx;
+
+ memset(key_str, 0x00, 100);
+ memset(src_str, 0x00, 100);
+ memset(dst_str, 0x00, 100);
+ memset(output, 0x00, 100);
+
+ unhexify( key_str, {hex_key_string} );
+ unhexify( src_str, {hex_src_string} );
+
+ xtea_setup( &ctx, key_str );
+ xtea_crypt_ecb( &ctx, XTEA_DECRYPT, src_str, output );
+ hexify( dst_str, output, 8 );
+
+ TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
+}
+END_CASE
+
+BEGIN_CASE
+xtea_selftest:
+{
+ TEST_ASSERT( xtea_self_test( 0 ) == 0 );
+}
+END_CASE