summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorlaranjeiro2009-04-29 14:35:55 +0000
committerlaranjeiro2009-04-29 14:35:55 +0000
commit02313010ee7fe74563fb50b5ff005e43c554a7a0 (patch)
treeaf8b51d9be74a1ddd780ddf01c9054f05462f3b4 /cesar
parent09ae60da759a274fcea9d6245774643bb2df069b (diff)
cp/secu:
* Change the nek generation to produce the same result on host or on proto. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@4565 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar')
-rw-r--r--cesar/cp/secu/src/secu.c26
-rw-r--r--cesar/cp/secu/test/src/test-nmk.c20
2 files changed, 41 insertions, 5 deletions
diff --git a/cesar/cp/secu/src/secu.c b/cesar/cp/secu/src/secu.c
index 2581098772..2bda3e57b5 100644
--- a/cesar/cp/secu/src/secu.c
+++ b/cesar/cp/secu/src/secu.c
@@ -101,16 +101,34 @@ cp_secu_protocol_next (cp_secu_protocol_run_t *prun, bool last)
void
cp_secu_aes_generate_key (const uint num, cp_key_t *output)
{
+ u8 input[4];
u8 buffer[sizeof(cp_key_t)];
- /* Check parameter. */
+
dbg_assert (output);
+#if DEFS_BIG_ENDIAN
+ GET_UINT32(*(u32*) input, (u8*) &num, 0);
+ GET_UINT32(*(u32*) (input + 4) , (u8*) &num, 4);
+ GET_UINT32(*(u32*) (input + 8) , (u8*) &num, 8);
+ GET_UINT32(*(u32*) (input + 12), (u8*) &num, 12);
+#else
+ memcpy (input, &num, sizeof (uint));
+#endif
+
/* Call the real function to generate an AES key. */
- cp_secu_pbkdf1 ((const u8 *) &num, sizeof (num),
+ cp_secu_pbkdf1 (input, sizeof (input),
buffer , sizeof(buffer),
CP_SECU_SALT_SPIDCOM);
- memcpy (output, buffer, sizeof (cp_key_t));
+#if DEFS_BIG_ENDIAN
+ GET_UINT32 (output->key[0], buffer, 0);
+ GET_UINT32 (output->key[1], buffer, 4);
+ GET_UINT32 (output->key[2], buffer, 8);
+ GET_UINT32 (output->key[3], buffer, 12);
+#else
+ memcpy (output->key, buffer, 16);
+#endif
+
}
/**
@@ -127,8 +145,6 @@ cp_secu_nmk2nid(const cp_key_t nmk, const u8 security_level)
u8 output[CP_NID_SIZE]__attribute__((aligned(sizeof (cp_nid_t))));
dbg_assert (security_level <= 2);
- memset (output, 0, sizeof (output));
- memset (input, 0, sizeof (input));
#if DEFS_BIG_ENDIAN
GET_UINT32(*(u32*) input, (u8*) &nmk.key, 0);
diff --git a/cesar/cp/secu/test/src/test-nmk.c b/cesar/cp/secu/test/src/test-nmk.c
index 4f552482e5..c8d8b0a491 100644
--- a/cesar/cp/secu/test/src/test-nmk.c
+++ b/cesar/cp/secu/test/src/test-nmk.c
@@ -154,6 +154,25 @@ test_case_tek_generation (test_t test)
test_end;
}
+void
+test_case_nek_generation (test_t test)
+{
+ test_case_begin (test, "Generate NEK");
+
+ test_begin (test, "nek")
+ {
+ cp_key_t output;
+
+ cp_secu_aes_generate_key (0x12345678, &output);
+
+ test_fail_unless (output.key[0] == 0x652c25a8);
+ test_fail_unless (output.key[1] == 0x5699ff58);
+ test_fail_unless (output.key[2] == 0x3a9fa973);
+ test_fail_unless (output.key[3] == 0xd01b60ec);
+ }
+ test_end;
+}
+
int
main (void)
{
@@ -165,6 +184,7 @@ main (void)
test_case_dak_generation (test);
test_case_nid_generation (test);
test_case_tek_generation (test);
+ test_case_nek_generation (test);
test_result (test);
return test_nb_failed (test) == 0 ? 0 : 1;