* Changed to write keys to CC2420 RAM big-endian order

* Fixed cc2420_aes_cipher() to wait for encryption to finish before reading result
This commit is contained in:
nifi 2010-03-15 23:04:54 +00:00
parent e834562455
commit 55e0fec37e
2 changed files with 12 additions and 7 deletions

View File

@ -28,12 +28,12 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: cc2420-aes.c,v 1.3 2009/04/07 09:22:58 nifi Exp $ * $Id: cc2420-aes.c,v 1.4 2010/03/15 23:04:54 nifi Exp $
*/ */
/** /**
* \file * \file
* AES encryption/decryption functions. * AES encryption functions.
* \author * \author
* Adam Dunkels <adam@sics.se> * Adam Dunkels <adam@sics.se>
*/ */
@ -56,16 +56,16 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
cc2420_aes_set_key(uint8_t *key, int index) cc2420_aes_set_key(const uint8_t *key, int index)
{ {
uint16_t f; uint16_t f;
switch(index) { switch(index) {
case 0: case 0:
FASTSPI_WRITE_RAM_LE(key, CC2420RAM_KEY0, KEYLEN, f); FASTSPI_WRITE_RAM_BE(key, CC2420RAM_KEY0, KEYLEN, f);
break; break;
case 1: case 1:
FASTSPI_WRITE_RAM_LE(key, CC2420RAM_KEY1, KEYLEN, f); FASTSPI_WRITE_RAM_BE(key, CC2420RAM_KEY1, KEYLEN, f);
break; break;
} }
} }
@ -75,11 +75,16 @@ static void
cipher16(uint8_t *data, int len) cipher16(uint8_t *data, int len)
{ {
uint16_t f; uint16_t f;
uint8_t status;
len = MIN(len, MAX_DATALEN); len = MIN(len, MAX_DATALEN);
FASTSPI_WRITE_RAM_LE(data, CC2420RAM_SABUF, len, f); FASTSPI_WRITE_RAM_LE(data, CC2420RAM_SABUF, len, f);
FASTSPI_STROBE(CC2420_SAES); FASTSPI_STROBE(CC2420_SAES);
/* Wait for the encryption to finish */
do {
FASTSPI_UPD_STATUS(status);
} while(status & BV(CC2420_ENC_BUSY));
FASTSPI_READ_RAM_LE(data, CC2420RAM_SABUF, len, f); FASTSPI_READ_RAM_LE(data, CC2420RAM_SABUF, len, f);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: cc2420-aes.h,v 1.2 2008/07/02 09:02:39 nifi Exp $ * $Id: cc2420-aes.h,v 1.3 2010/03/15 23:04:54 nifi Exp $
*/ */
/** /**
@ -56,7 +56,7 @@
* index is given by the 'index' parameter. * index is given by the 'index' parameter.
* *
*/ */
void cc2420_aes_set_key(uint8_t *key, int index); void cc2420_aes_set_key(const uint8_t *key, int index);
/** /**