Home | History | Annotate | Download | only in rsn
      1 /** \file keyDeriveAes.c
      2  * \brief AES encryption key derivation implementation.
      3  *
      4  * \see aesBroadcastKeyDerivation.h
      5 */
      6 /****************************************************************************
      7 **+-----------------------------------------------------------------------+**
      8 **|                                                                       |**
      9 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
     10 **| All rights reserved.                                                  |**
     11 **|                                                                       |**
     12 **| Redistribution and use in source and binary forms, with or without    |**
     13 **| modification, are permitted provided that the following conditions    |**
     14 **| are met:                                                              |**
     15 **|                                                                       |**
     16 **|  * Redistributions of source code must retain the above copyright     |**
     17 **|    notice, this list of conditions and the following disclaimer.      |**
     18 **|  * Redistributions in binary form must reproduce the above copyright  |**
     19 **|    notice, this list of conditions and the following disclaimer in    |**
     20 **|    the documentation and/or other materials provided with the         |**
     21 **|    distribution.                                                      |**
     22 **|  * Neither the name Texas Instruments nor the names of its            |**
     23 **|    contributors may be used to endorse or promote products derived    |**
     24 **|    from this software without specific prior written permission.      |**
     25 **|                                                                       |**
     26 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     27 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     28 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     29 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     30 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     31 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     32 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     33 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     34 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     35 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     36 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     37 **|                                                                       |**
     38 **+-----------------------------------------------------------------------+**
     39 ****************************************************************************/
     40 
     41 /****************************************************************************
     42  *                                                                          *
     43  *   MODULE:	AES broadcast key derivation                                *
     44  *   PURPOSE:   AES broadcast key derivation                                *
     45  *                                                                          *
     46  ****************************************************************************/
     47 
     48 #include "osApi.h"
     49 #include "utils.h"
     50 #include "report.h"
     51 #include "rsnApi.h"
     52 
     53 #include "keyDerive.h"
     54 #include "keyDeriveAes.h"
     55 
     56 #include "mainKeysSm.h"
     57 
     58 /**
     59 *
     60 * keyDeriveAes_config
     61 *
     62 * \b Description:
     63 *
     64 * AES broadcast key derivation configuration function:
     65 *			- Initializes the derive & remove callback functions
     66 * \b ARGS:
     67 *
     68 *  None
     69 *
     70 * \b RETURNS:
     71 *
     72 *  OK on success, NOK otherwise.
     73 */
     74 
     75 TI_STATUS keyDeriveAes_config(struct _keyDerive_t *pKeyDerive)
     76 {
     77 	pKeyDerive->derive = keyDeriveAes_derive;
     78 	pKeyDerive->remove = keyDeriveAes_remove;
     79 
     80 	return OK;
     81 }
     82 
     83 
     84 /**
     85 *
     86 * keyDeriveAes_derive
     87 *
     88 * \b Description:
     89 *
     90 * AES key derivation function:
     91 *					- Decodes the key material.
     92 *					- Distribute the decoded key material to the driver.
     93 *
     94 * \b ARGS:
     95 *
     96 *  I - p - Pointer to the encoded key material.
     97 *
     98 * \b RETURNS:
     99 *
    100 *  OK on success, NOK otherwise.
    101 */
    102 
    103 TI_STATUS keyDeriveAes_derive(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey)
    104 {
    105 	TI_STATUS status;
    106 	securityKeys_t	key;
    107 	keyMaterialAes_t   *keyMaterialAes = NULL;
    108 
    109 	/* Small verification */
    110 	if ((pEncodedKey==NULL) || (pKeyDerive == NULL))
    111 	{
    112 		return NOK;
    113 	}
    114 
    115 	if (pEncodedKey->keyLen < sizeof(keyMaterialAes_t))
    116 	{
    117 		WLAN_REPORT_ERROR(pKeyDerive->hReport, RSN_MODULE_LOG,
    118 						("KEY_DERIVE_AES: ERROR: wrong key length %d !!!\n",
    119 						pEncodedKey->keyLen));
    120 		return NOK;
    121 	}
    122 
    123 	keyMaterialAes = (keyMaterialAes_t*)pEncodedKey->pData;
    124 
    125 
    126 	/* Fill security key structure */
    127 	os_memoryZero(pKeyDerive->hOs, &key, sizeof(securityKeys_t));
    128 
    129 	key.keyType   = AES_KEY;
    130 	key.keyIndex  = (UINT8)pEncodedKey->keyId;
    131 	key.encLen    = DERIVE_AES_KEY_LEN;
    132 	os_memoryCopy(pKeyDerive->hOs, (void *)key.encKey, pEncodedKey->pData + MAC_ADDR_LEN+KEY_RSC_LEN,
    133 		          DERIVE_AES_KEY_LEN);
    134 
    135 	/* Copy MAC address key */
    136 	os_memoryCopy(pKeyDerive->hOs, (void *)key.macAddress.addr, (void *)keyMaterialAes->macAddress, MAC_ADDR_LEN);
    137 
    138 	/* Copy RSC */
    139 	os_memoryCopy(pKeyDerive->hOs, (void *)key.keyRsc, (void *)keyMaterialAes->keyRSC, KEY_RSC_LEN);
    140 
    141 	status = pKeyDerive->pMainKeys->setKey(pKeyDerive->pMainKeys, &key);
    142 	if (status == OK)
    143 	{
    144 		os_memoryCopy(pKeyDerive->hOs, &pKeyDerive->key, pEncodedKey, sizeof(encodedKeyMaterial_t));
    145 	}
    146 
    147 	return status;
    148 }
    149 
    150 /**
    151 *
    152 * keyDeriveAes_remove
    153 *
    154 * \b Description:
    155 *
    156 * AES key remove function:
    157 *			- Remove the key material from the driver.
    158 *
    159 * \b ARGS:
    160 *
    161 *  None.
    162 *
    163 * \b RETURNS:
    164 *
    165 *  OK on success, NOK otherwise.
    166 */
    167 
    168 TI_STATUS keyDeriveAes_remove(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey)
    169 {
    170 	TI_STATUS status;
    171 	securityKeys_t	key;
    172 
    173 	if ((pEncodedKey==NULL) || (pKeyDerive == NULL))
    174 	{
    175 		return NOK;
    176 	}
    177 
    178 	if (pEncodedKey->keyLen != DERIVE_AES_KEY_LEN)
    179 	{
    180 		return NOK;
    181 	}
    182 
    183 	os_memoryZero(pKeyDerive->hOs, &key, sizeof(securityKeys_t));
    184 	key.keyType  = AES_KEY;
    185 	key.keyIndex = (UINT8)pEncodedKey->keyId;
    186 	key.encLen   = (UINT16)pEncodedKey->keyLen;
    187 	os_memoryCopy(pKeyDerive->hOs, (void *)key.macAddress.addr, pEncodedKey->pData, MAC_ADDR_LEN);
    188 
    189 	status = pKeyDerive->pMainKeys->removeKey(pKeyDerive->pMainKeys, &key);
    190 	if (status == OK)
    191 	{
    192 		os_memoryZero(pKeyDerive->hOs, &pKeyDerive->key, sizeof(encodedKeyMaterial_t));
    193 	}
    194 
    195 	return status;
    196 }
    197 
    198