summaryrefslogtreecommitdiff
path: root/cesar/cp2/secu/test
diff options
context:
space:
mode:
authorlaranjeiro2008-06-19 16:59:57 +0000
committerlaranjeiro2008-06-19 16:59:57 +0000
commitfbf55098c163d496ec9e222a64dd479b8e160707 (patch)
tree224fa50069b7c0beca2753bd78635c32935f3a33 /cesar/cp2/secu/test
parentb8d4acf74552ca08526d73a7abf56ec624b01cd4 (diff)
cp2/secu: Fixed pbkdf1 nmk and DAK generation.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2392 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/secu/test')
-rw-r--r--cesar/cp2/secu/test/host-Makefile8
-rw-r--r--cesar/cp2/secu/test/src/test-nmk.c138
-rw-r--r--cesar/cp2/secu/test/src/test-pbkdf1.c33
-rw-r--r--cesar/cp2/secu/test/src/test-sha2.c6
4 files changed, 145 insertions, 40 deletions
diff --git a/cesar/cp2/secu/test/host-Makefile b/cesar/cp2/secu/test/host-Makefile
index d211f23e3f..fe0ffde9cf 100644
--- a/cesar/cp2/secu/test/host-Makefile
+++ b/cesar/cp2/secu/test/host-Makefile
@@ -1,6 +1,6 @@
BASE = ../../..
-HOST_PROGRAMS = test-sha2 test-aes test-pbkdf1 test-prun
+HOST_PROGRAMS = test-sha2 test-aes test-prun test-nmk
test-sha2_SOURCES = test-sha2.c
test-sha2_MODULES = lib cp2/secu
@@ -8,12 +8,12 @@ test-sha2_MODULES = lib cp2/secu
test-aes_SOURCES = test-aes.c
test-aes_MODULES = lib cp2/secu
-test-pbkdf1_SOURCES = test-pbkdf1.c
-test-pbkdf1_MODULES = lib cp2/secu
-
test-prun_SOURCES = test-prun.c
test-prun_MODULES = lib cp2/secu
+test-nmk_SOURCES = test-nmk.c
+test-nmk_MODULES = lib cp2/secu
+
VARIANT = host
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp2/secu/test/src/test-nmk.c b/cesar/cp2/secu/test/src/test-nmk.c
new file mode 100644
index 0000000000..730094a373
--- /dev/null
+++ b/cesar/cp2/secu/test/src/test-nmk.c
@@ -0,0 +1,138 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/test-nmk.c
+ * \brief Test the generation of the NMK
+ * \ingroup cp2_secu
+ *
+ * Test the generation of the NMK with the data provided in section 13.5 table
+ * 13-342.
+ * Entry buffer "HomePlugAV0123"
+ * NMK 0xb59319d7e8157ba001b018669cce
+ */
+#include "common/std.h"
+#include "string.h"
+#include "stdio.h"
+#include "lib/test.h"
+
+#include "cp2/secu/secu.h"
+#include "cp2/secu/aes.h"
+#include "cp2/secu/sha256.h"
+
+#include "cp2/secu/inc/pbkdf1.h"
+
+void
+test_case_nmk_generation (test_t test)
+{
+ uint i;
+ uint memcpy_result;
+ u8 buffer[64] __attribute__((aligned(64))) = "HomePlugAV0123\0";
+ u8 result [64] __attribute__((aligned(64))) = {0xb5, 0x93, 0x19, 0xd7,
+ 0xe8, 0x15, 0x7b, 0xa0, 0x01, 0xb0, 0x18, 0x66, 0x9c, 0xce, 0xe3, 0x0d};
+
+ cp_secu_npw2nmk (buffer, 14);
+
+ test_case_begin (test, "NMK generation");
+
+ memcpy_result = memcmp(buffer, result, 16);
+ test_begin (test, "verify")
+ {
+ test_fail_if (memcpy_result != 0, "Wrong nmk");
+ }
+ test_end;
+
+ if (memcpy_result)
+ {
+ for ( i = 0; i < 16; i++)
+ {
+ printf ("%02x ", buffer[i]);
+ }
+ printf ("\n");
+ }
+}
+
+void
+test_case_dak_generation (test_t test)
+{
+ uint i;
+ uint memcpy_result;
+ u8 buffer[64] __attribute__((aligned(64)));
+ u8 result [64] __attribute__((aligned(64))) = {0xEE, 0x7F, 0x57, 0x88,
+ 0xE2, 0xA0, 0x21, 0xC9, 0x99, 0x46, 0x9A, 0xC5, 0x2A, 0xF3, 0x0A,
+ 0x06};
+
+
+ strcpy ((char *)buffer, "DAK_Password\0");
+
+ cp_secu_dak_gen (buffer, 12);
+
+ test_case_begin (test, "DAK generation");
+
+ memcpy_result = memcmp(buffer, result, 16);
+ test_begin (test, "verify")
+ {
+ test_fail_if (memcpy_result != 0, "Wrong DAK");
+ }
+ test_end;
+
+ if (memcpy_result)
+ {
+ for ( i = 0; i < 16; i++)
+ {
+ printf ("%02x ", buffer[i]);
+ }
+ printf ("\n");
+ }
+}
+
+void
+test_case_nid_generation (test_t test)
+{
+ uint i;
+ uint memcpy_result;
+ u8 buffer [64] __attribute__((aligned(64))) = {0xb5, 0x93, 0x19, 0xd7,
+ 0xe8, 0x15, 0x7b, 0xa0, 0x01, 0xb0, 0x18, 0x66, 0x9c, 0xce, 0xe3, 0x0d};
+ u8 result [64] __attribute__((aligned(64))) = {0x02, 0x6b, 0xcb, 0xa5,
+ 0x35, 0x4e, 0x18};
+
+ cp_secu_nmk2nid (buffer, 0x1);
+
+ test_case_begin (test, "NID generation");
+
+ memcpy_result = memcmp(buffer, result, 7);
+ test_begin (test, "verify")
+ {
+ test_fail_if (memcpy_result != 0, "Wrong NID");
+ }
+ test_end;
+
+ if (memcpy_result)
+ {
+ for ( i = 0; i < 7; i++)
+ {
+ printf ("%02x ", buffer[i]);
+ }
+ printf ("\n");
+ }
+}
+
+
+int
+main (void)
+{
+ test_t test;
+
+ test_init (test, 0, NULL);
+
+ test_case_nmk_generation (test);
+ test_case_dak_generation (test);
+ test_case_nid_generation (test);
+
+ test_result (test);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}
diff --git a/cesar/cp2/secu/test/src/test-pbkdf1.c b/cesar/cp2/secu/test/src/test-pbkdf1.c
index e069ba80b2..2ef5b99d8d 100644
--- a/cesar/cp2/secu/test/src/test-pbkdf1.c
+++ b/cesar/cp2/secu/test/src/test-pbkdf1.c
@@ -18,39 +18,6 @@
#include "cp2/secu/defs.h"
#include "cp2/secu/pbkdf1.h"
#include "cp2/secu/sha256.h"
-
-void
-test_case_pbkdf1 (test_t test)
-{
- uint i;
-
- u8 buffer [128] __attribute__((aligned(128))) = "HOMEPLUG_AV123\0";
- u8 result [128] __attribute__((aligned(128))) = "HOMEPLUG_AV123\0";
-
- result[14] = 0x08;
- result[15] = 0x85;
- result[16] = 0x6D;
- result[17] = 0xAF;
- result[18] = 0x7C;
- result[19] = 0xF5;
- result[20] = 0x81;
- result[21] = 0x86;
-
- for (i = 0; i < 1000; i++)
- {
- cp_secu_sha256(result);
- }
-
- cp_secu_pbkdf1 (buffer, CP_SECU_SALT_KEY_NMK_HS);
-
- test_begin (test, "PBKDF1")
- {
- test_fail_if (memcmp (buffer, result, CP_SECU_OUTPUT_KEY_SIZE) != 0,
- "Wrong Hash");
- }
- test_end;
-}
-
int
main (void)
{
diff --git a/cesar/cp2/secu/test/src/test-sha2.c b/cesar/cp2/secu/test/src/test-sha2.c
index c8094494c6..f7dd34a058 100644
--- a/cesar/cp2/secu/test/src/test-sha2.c
+++ b/cesar/cp2/secu/test/src/test-sha2.c
@@ -43,7 +43,7 @@ test_case_sha2 (test_t test)
0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8,
0x55};
- cp_secu_sha256 (buffer);
+ cp_secu_sha256 (buffer, strlen((char*)buffer), buffer);
test_case_begin (test, "SHA 256");
@@ -54,7 +54,7 @@ test_case_sha2 (test_t test)
}
test_end;
- cp_secu_sha256 (buffer2);
+ cp_secu_sha256 (buffer2, strlen((char*)buffer2), buffer2);
test_begin (test, "SHA 256 Test 2")
{
@@ -63,7 +63,7 @@ test_case_sha2 (test_t test)
}
test_end;
- cp_secu_sha256 (buffer3);
+ cp_secu_sha256 (buffer3, strlen((char*)buffer3), buffer3);
test_begin (test, "SHA 256 Test 3")
{