summaryrefslogtreecommitdiff
path: root/cesar/cp/secu/src
diff options
context:
space:
mode:
authorlaranjeiro2009-05-28 11:01:25 +0000
committerlaranjeiro2009-05-28 11:01:25 +0000
commit2570672c2b8c835860235048b5249ad44e261793 (patch)
tree514b31f214a6d03bcbce3cd9cc81506d01b1390e /cesar/cp/secu/src
parentbd8a1f55b89cd5203126c05a9ef857507aaf3acd (diff)
* cp/secu:
* Removed the define DEFS_BIG_ENDIAN and used the correct function to store and get the data from/to the character buffers. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@4716 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp/secu/src')
-rw-r--r--cesar/cp/secu/src/secu.c50
1 files changed, 8 insertions, 42 deletions
diff --git a/cesar/cp/secu/src/secu.c b/cesar/cp/secu/src/secu.c
index 694662a8f3..0e0004d3d0 100644
--- a/cesar/cp/secu/src/secu.c
+++ b/cesar/cp/secu/src/secu.c
@@ -107,29 +107,17 @@ cp_secu_aes_generate_key (const uint num, cp_key_t *output)
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
+ PUT_UINT32(num, input, 0);
/* Call the real function to generate an AES key. */
cp_secu_pbkdf1 (input, sizeof (input),
buffer , sizeof(buffer),
CP_SECU_SALT_SPIDCOM);
-#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
-
}
/**
@@ -142,36 +130,25 @@ cp_nid_t
cp_secu_nmk2nid(const cp_key_t nmk, const u8 security_level)
{
cp_nid_t nid = 0;
- u8 input [sizeof(cp_key_t)]__attribute__((aligned(sizeof (cp_key_t))));
- u8 output[CP_NID_SIZE]__attribute__((aligned(sizeof (cp_nid_t))));
+ u8 input [sizeof(cp_key_t)];
+ u8 output[CP_NID_SIZE];
dbg_assert (security_level <= 2);
-#if DEFS_BIG_ENDIAN
- GET_UINT32(*(u32*) input, (u8*) &nmk.key, 0);
- GET_UINT32(*(u32*) (input + 4) , (u8*) &nmk.key, 4);
- GET_UINT32(*(u32*) (input + 8) , (u8*) &nmk.key, 8);
- GET_UINT32(*(u32*) (input + 12), (u8*) &nmk.key, 12);
-#else
- memcpy (input, &nmk.key, sizeof (cp_key_t));
-#endif
+ PUT_UINT32(nmk.key[0], input, 0);
+ PUT_UINT32(nmk.key[1], input, 4);
+ PUT_UINT32(nmk.key[2], input, 8);
+ PUT_UINT32(nmk.key[3], input, 12);
cp_secu_pbkdf1 (input, sizeof (cp_key_t), output, CP_NID_SIZE,
CP_SECU_SALT_KEY_NID);
output[CP_NID_SIZE-1] = output[CP_NID_SIZE-1] >> 4;
-#if DEFS_BIG_ENDIAN
uint w1, w2;
GET_UINT32 (w1, output, 0);
GET_UINT32 (w2, output, 4);
nid = ((u64) (w2 & 0xFFFFFF) << 32) | w1;
-#else
- memcpy (&nid, output, CP_NID_SIZE);
- nid = nid & 0xFFFFFFFFFFFFFull;
-#endif
-
nid |= ((u64) security_level << 52);
-
return nid;
}
@@ -180,12 +157,11 @@ cp_secu_tek_gen (const u32 left[], const u32 right[], cp_key_t *output)
{
u8 sha_buff[CP_SECU_HASH_KEY_FOR_TEK_SIZE * 2];
u8 output_buffer [CP_SECU_SHA256_SIZE];
+ uint i, j;
dbg_assert (left);
dbg_assert (right);
dbg_assert (output);
-#if DEFS_BIG_ENDIAN
- uint i, j;
for (i = 0; i < CP_SECU_HASH_KEY_FOR_TEK_SIZE; i += 4)
PUT_UINT32 (right[i/4], sha_buff, i);
@@ -193,12 +169,6 @@ cp_secu_tek_gen (const u32 left[], const u32 right[], cp_key_t *output)
j < CP_SECU_HASH_KEY_FOR_TEK_SIZE;
j += 4, i += 4)
PUT_UINT32 (left[j/4], sha_buff, i);
-#else
- /* Insert the left part in the left part of the sha_buf. */
- memcpy (sha_buff + CP_SECU_HASH_KEY_FOR_TEK_SIZE, left,
- CP_SECU_HASH_KEY_FOR_TEK_SIZE);
- memcpy (sha_buff, right, CP_SECU_HASH_KEY_FOR_TEK_SIZE);
-#endif
/* Salt is NULL, no salt use for the tek
* the first 0 is for the salt length
@@ -208,14 +178,10 @@ cp_secu_tek_gen (const u32 left[], const u32 right[], cp_key_t *output)
output_buffer);
/* Copy the leftmost 16 bytes. */
-#if DEFS_BIG_ENDIAN
GET_UINT32 (output->key[0], output_buffer, 0);
GET_UINT32 (output->key[1], output_buffer, 4);
GET_UINT32 (output->key[2], output_buffer, 8);
GET_UINT32 (output->key[3], output_buffer, 12);
-#else
- memcpy (output->key, output_buffer, 16);
-#endif
}
void