summaryrefslogtreecommitdiffstats
path: root/stack/smp/smp_cmac.c
diff options
context:
space:
mode:
authorAndre Eisenbach <andre@broadcom.com>2012-09-18 01:35:44 -0700
committerMatthew Xie <mattx@google.com>2012-09-18 16:26:28 -0700
commit6ef101187774e30ddba6b46bbedef549a42196ad (patch)
treef36eb347f03083671640fbc750171e3b951e0082 /stack/smp/smp_cmac.c
parentf80d3d045eab5f002be4b5e8a3d2d376fdf7581a (diff)
downloadexternal_bluetooth_bluedroid-6ef101187774e30ddba6b46bbedef549a42196ad.zip
external_bluetooth_bluedroid-6ef101187774e30ddba6b46bbedef549a42196ad.tar.gz
external_bluetooth_bluedroid-6ef101187774e30ddba6b46bbedef549a42196ad.tar.bz2
Initual Bluetooth open source release
First release under Apache source license with updated header files and whitespace cleanups. Also fixed file permission to remove executable bit from source files. Change-Id: I7155903edfc2f491c1cbbd0db108f207852caaa0
Diffstat (limited to 'stack/smp/smp_cmac.c')
-rw-r--r--stack/smp/smp_cmac.c76
1 files changed, 44 insertions, 32 deletions
diff --git a/stack/smp/smp_cmac.c b/stack/smp/smp_cmac.c
index d72c3b5..44e776e 100644
--- a/stack/smp/smp_cmac.c
+++ b/stack/smp/smp_cmac.c
@@ -1,14 +1,26 @@
-/*****************************************************************************
-**
-** Name: smp_cmac.c
-**
-** Description: This file contains the implementation of the AES128 CMAC
-** algorithm.
-**
-**
-** Copyright (c) 2008-2009, Broadcom Corp., All Rights Reserved.
-** Broadcom Bluetooth Core. Proprietary and confidential.
-******************************************************************************/
+/******************************************************************************
+ *
+ * Copyright (C) 2008-2012 Broadcom Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains the implementation of the AES128 CMAC algorithm.
+ *
+ ******************************************************************************/
#include "bt_target.h"
@@ -26,7 +38,7 @@ typedef struct
UINT16 len;
UINT16 round;
}tCMAC_CB;
-
+
tCMAC_CB cmac_cb;
/* Rb for AES-128 as block cipher, LSB as [0] */
@@ -45,8 +57,8 @@ void print128(BT_OCTET16 x, const UINT8 *key_name)
for (i = 0; i < 4; i ++)
{
- SMP_TRACE_WARNING4("%02x %02x %02x %02x",
- p[BT_OCTET16_LEN - i*4 -1], p[BT_OCTET16_LEN - i*4 -2],
+ SMP_TRACE_WARNING4("%02x %02x %02x %02x",
+ p[BT_OCTET16_LEN - i*4 -1], p[BT_OCTET16_LEN - i*4 -2],
p[BT_OCTET16_LEN - i*4 -3], p[BT_OCTET16_LEN - i*4 -4]);
}
#endif
@@ -56,11 +68,11 @@ void print128(BT_OCTET16 x, const UINT8 *key_name)
**
** Function padding
**
-** Description utility function to padding the given text to be a 128 bits
+** Description utility function to padding the given text to be a 128 bits
** data. The parameter dest is input and output parameter, it
** must point to a BT_OCTET16_LEN memory space; where include
** length bytes valid data.
-**
+**
** Returns void
**
*******************************************************************************/
@@ -76,7 +88,7 @@ static void padding ( BT_OCTET16 dest, UINT8 length )
** Function leftshift_onebit
**
** Description utility function to left shift one bit for a 128 bits value.
-**
+**
** Returns void
**
*******************************************************************************/
@@ -98,12 +110,12 @@ static void leftshift_onebit(UINT8 *input, UINT8 *output)
** Function cmac_aes_cleanup
**
** Description clean up function for AES_CMAC algorithm.
-**
+**
** Returns void
**
*******************************************************************************/
static void cmac_aes_cleanup(void)
-{
+{
if (cmac_cb.text != NULL)
{
GKI_freebuf(cmac_cb.text);
@@ -116,7 +128,7 @@ static void cmac_aes_cleanup(void)
** Function cmac_aes_k_calculate
**
** Description This function is the calculation of block cipher using AES-128.
-**
+**
** Returns void
**
*******************************************************************************/
@@ -138,7 +150,7 @@ static BOOLEAN cmac_aes_k_calculate(BT_OCTET16 key, UINT8 *p_signature, UINT16 t
err = 1;
break;
}
-
+
memcpy(x, output.param_buf, BT_OCTET16_LEN);
i ++;
}
@@ -149,9 +161,9 @@ static BOOLEAN cmac_aes_k_calculate(BT_OCTET16 key, UINT8 *p_signature, UINT16 t
memcpy(p_signature, p_mac, tlen);
SMP_TRACE_DEBUG2("tlen = %d p_mac = %d", tlen, p_mac);
- SMP_TRACE_DEBUG4("p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = 0x%02x",
+ SMP_TRACE_DEBUG4("p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = 0x%02x",
*p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3));
- SMP_TRACE_DEBUG4("p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = 0x%02x",
+ SMP_TRACE_DEBUG4("p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = 0x%02x",
*(p_mac + 4), *(p_mac + 5), *(p_mac + 6), *(p_mac + 7));
return TRUE;
@@ -166,7 +178,7 @@ static BOOLEAN cmac_aes_k_calculate(BT_OCTET16 key, UINT8 *p_signature, UINT16 t
**
** Description This function proceeed to prepare the last block of message
** Mn depending on the size of the message.
-**
+**
** Returns void
**
*******************************************************************************/
@@ -197,7 +209,7 @@ static void cmac_prepare_last_block (BT_OCTET16 k1, BT_OCTET16 k2)
** Function cmac_subkey_cont
**
** Description This is the callback function when CIPHk(0[128]) is completed.
-**
+**
** Returns void
**
*******************************************************************************/
@@ -242,9 +254,9 @@ static void cmac_subkey_cont(tSMP_ENC *p)
** Function cmac_generate_subkey
**
** Description This is the function to generate the two subkeys.
-**
+**
** Parameters key - CMAC key, expect SRK when used by SMP.
-**
+**
** Returns void
**
*******************************************************************************/
@@ -269,13 +281,13 @@ static BOOLEAN cmac_generate_subkey(BT_OCTET16 key)
** Function AES_CMAC
**
** Description This is the AES-CMAC Generation Function with tlen implemented.
-**
+**
** Parameters key - CMAC key in little endian order, expect SRK when used by SMP.
** input - text to be signed in little endian byte order.
** length - length of the input in byte.
** tlen - lenth of mac desired
** p_signature - data pointer to where signed data to be stored, tlen long.
-**
+**
** Returns void
**
*******************************************************************************/
@@ -288,7 +300,7 @@ BOOLEAN AES_CMAC ( BT_OCTET16 key, UINT8 *input, UINT16 length,
SMP_TRACE_EVENT0 ("AES_CMAC ");
- if (n == 0) n = 1;
+ if (n == 0) n = 1;
len = n * BT_OCTET16_LEN;
SMP_TRACE_WARNING1("AES128_CMAC started, allocate buffer size = %d", len);
@@ -314,7 +326,7 @@ BOOLEAN AES_CMAC ( BT_OCTET16 key, UINT8 *input, UINT16 length,
/* start calculation */
ret = cmac_aes_k_calculate(key, p_signature, tlen);
}
- /* clean up */
+ /* clean up */
cmac_aes_cleanup();
}
else
@@ -322,7 +334,7 @@ BOOLEAN AES_CMAC ( BT_OCTET16 key, UINT8 *input, UINT16 length,
ret = FALSE;
SMP_TRACE_ERROR0("No resources");
}
-
+
return ret;
}