summaryrefslogtreecommitdiff
path: root/cesar/cp/secu/src
diff options
context:
space:
mode:
authorlaranjeiro2008-09-10 11:49:06 +0000
committerlaranjeiro2008-09-10 11:49:06 +0000
commit7c5ddd9e3a2f95aee644f747c1f3c63b55660a90 (patch)
treedc0e23bfe2d0f2c242483cb65f49f496c2a2b2ea /cesar/cp/secu/src
parent1f4b13c8419cca498f617a092461e71a29af223e (diff)
cp/secu:
* Modified the function to generate the keys i.e. nmk dak to return cp_key_t types. * Same thing with the nid generation. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2922 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp/secu/src')
-rw-r--r--cesar/cp/secu/src/pbkdf1.c11
-rw-r--r--cesar/cp/secu/src/secu.c19
2 files changed, 20 insertions, 10 deletions
diff --git a/cesar/cp/secu/src/pbkdf1.c b/cesar/cp/secu/src/pbkdf1.c
index 542ed5c9e8..0c1c7a65e9 100644
--- a/cesar/cp/secu/src/pbkdf1.c
+++ b/cesar/cp/secu/src/pbkdf1.c
@@ -22,7 +22,7 @@
#include "cp/secu/inc/pbkdf1.h"
void
-secu_pbkdf1 (u8 input[], uint input_len, u8 salt[],
+secu_pbkdf1 (const u8 input[], uint input_len, u8 salt[],
uint salt_len, uint it_count, u8 output_key[])
{
@@ -76,11 +76,12 @@ secu_pbkdf1 (u8 input[], uint input_len, u8 salt[],
* \param key key kind.
*/
void
-cp_secu_pbkdf1 (u8 *buffer, uint length, cp_secu_salt_kind_t key)
+cp_secu_pbkdf1 (const u8 *in, u8 *out, uint length, cp_secu_salt_kind_t key)
{
u8 salt [8] = {0x08, 0x85, 0x6d, 0xaf, 0x7c, 0xf5, 0x81, 0x00};
- dbg_assert (buffer);
+ dbg_assert (in);
+ dbg_assert (out);
dbg_assert (key < CP_SECU_SALT_KEY_NB);
switch (key)
@@ -99,8 +100,8 @@ cp_secu_pbkdf1 (u8 *buffer, uint length, cp_secu_salt_kind_t key)
dbg_assert (false);
}
- secu_pbkdf1 (buffer, length, salt,
+ secu_pbkdf1 (in, length, salt,
CP_SECU_SALT_SIZE,
- CP_SECU_PBKDF1_ITERATION, buffer);
+ CP_SECU_PBKDF1_ITERATION, out);
}
diff --git a/cesar/cp/secu/src/secu.c b/cesar/cp/secu/src/secu.c
index eece5764ed..4f141162b5 100644
--- a/cesar/cp/secu/src/secu.c
+++ b/cesar/cp/secu/src/secu.c
@@ -109,21 +109,27 @@ cp_secu_aes_generate_key (uint num, u8 *output)
dbg_assert (output);
memcpy (output, &num, 4);
- cp_secu_pbkdf1 (output, CP_SECU_AES_SIZE, CP_SECU_SALT_SPIDCOM);
+ cp_secu_pbkdf1 (output, output, CP_SECU_AES_SIZE, CP_SECU_SALT_SPIDCOM);
}
/**
* Generate the NID from the NMK and the security level.
* \param buffer the buffer containing the NMK.
* \param the Security level.
- * \warn the buffer will contain the NID at the end.
+ * \return the NID computed.
*/
-void
-cp_secu_nmk2nid(u8 *buffer, u8 security_level)
+cp_nid_t
+cp_secu_nmk2nid(cp_key_t nmk, u8 security_level)
{
- dbg_assert (buffer);
+ uint i;
+ cp_nid_t nid;
+ u8 buffer[CP_NMK_SIZE];
+
dbg_assert (security_level <= 2);
+ for (i = 0; i < 4; i++)
+ memcpy (buffer + i * 4, &nmk.key[i], 4);
+
secu_pbkdf1 (buffer, CP_NMK_SIZE, NULL, 0, CP_SECU_PBKDF1_ITERATION_NID,
buffer);
@@ -136,5 +142,8 @@ cp_secu_nmk2nid(u8 *buffer, u8 security_level)
/* ... and then, insert the Security Level */
buffer[CP_NID_SIZE - 1] |= ((security_level << 4) & 0xF0);
+
+ memcpy (&nid, buffer, CP_NID_SIZE);
+ return nid;
}