WIFI_API_20150524e

Committer:
Marcomissyou
Date:
Tue Jun 09 06:04:13 2015 +0000
Revision:
0:a2de37bf5f3d
update to WIFI_API_20150524e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Marcomissyou 0:a2de37bf5f3d 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
Marcomissyou 0:a2de37bf5f3d 2 *
Marcomissyou 0:a2de37bf5f3d 3 * The information contained herein is property of Nordic Semiconductor ASA.
Marcomissyou 0:a2de37bf5f3d 4 * Terms and conditions of usage are described in detail in NORDIC
Marcomissyou 0:a2de37bf5f3d 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
Marcomissyou 0:a2de37bf5f3d 6 *
Marcomissyou 0:a2de37bf5f3d 7 * Licensees are granted free, non-transferable use of the information. NO
Marcomissyou 0:a2de37bf5f3d 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
Marcomissyou 0:a2de37bf5f3d 9 * the file.
Marcomissyou 0:a2de37bf5f3d 10 *
Marcomissyou 0:a2de37bf5f3d 11 * $LastChangedRevision: 25419 $
Marcomissyou 0:a2de37bf5f3d 12 */
Marcomissyou 0:a2de37bf5f3d 13
Marcomissyou 0:a2de37bf5f3d 14 /**
Marcomissyou 0:a2de37bf5f3d 15 * @file
Marcomissyou 0:a2de37bf5f3d 16 * @brief Implementation of AES ECB driver
Marcomissyou 0:a2de37bf5f3d 17 */
Marcomissyou 0:a2de37bf5f3d 18
Marcomissyou 0:a2de37bf5f3d 19
Marcomissyou 0:a2de37bf5f3d 20 //lint -e438
Marcomissyou 0:a2de37bf5f3d 21
Marcomissyou 0:a2de37bf5f3d 22 #include <stdlib.h>
Marcomissyou 0:a2de37bf5f3d 23 #include <stdbool.h>
Marcomissyou 0:a2de37bf5f3d 24 #include <string.h>
Marcomissyou 0:a2de37bf5f3d 25 #include "nrf51.h" // Tsungta
Marcomissyou 0:a2de37bf5f3d 26 #include "nrf_ecb.h"
Marcomissyou 0:a2de37bf5f3d 27
Marcomissyou 0:a2de37bf5f3d 28 static uint8_t ecb_data[48]; ///< ECB data structure for RNG peripheral to access.
Marcomissyou 0:a2de37bf5f3d 29 static uint8_t* ecb_key; ///< Key: Starts at ecb_data
Marcomissyou 0:a2de37bf5f3d 30 static uint8_t* ecb_cleartext; ///< Cleartext: Starts at ecb_data + 16 bytes.
Marcomissyou 0:a2de37bf5f3d 31 static uint8_t* ecb_ciphertext; ///< Ciphertext: Starts at ecb_data + 32 bytes.
Marcomissyou 0:a2de37bf5f3d 32
Marcomissyou 0:a2de37bf5f3d 33 bool nrf_ecb_init(void)
Marcomissyou 0:a2de37bf5f3d 34 {
Marcomissyou 0:a2de37bf5f3d 35 ecb_key = ecb_data;
Marcomissyou 0:a2de37bf5f3d 36 ecb_cleartext = ecb_data + 16;
Marcomissyou 0:a2de37bf5f3d 37 ecb_ciphertext = ecb_data + 32;
Marcomissyou 0:a2de37bf5f3d 38
Marcomissyou 0:a2de37bf5f3d 39 NRF_ECB->ECBDATAPTR = (uint32_t)ecb_data;
Marcomissyou 0:a2de37bf5f3d 40 return true;
Marcomissyou 0:a2de37bf5f3d 41 }
Marcomissyou 0:a2de37bf5f3d 42
Marcomissyou 0:a2de37bf5f3d 43
Marcomissyou 0:a2de37bf5f3d 44 bool nrf_ecb_crypt(uint8_t * dest_buf, const uint8_t * src_buf)
Marcomissyou 0:a2de37bf5f3d 45 {
Marcomissyou 0:a2de37bf5f3d 46 uint32_t counter = 0x1000000;
Marcomissyou 0:a2de37bf5f3d 47 if(src_buf != ecb_cleartext)
Marcomissyou 0:a2de37bf5f3d 48 {
Marcomissyou 0:a2de37bf5f3d 49 memcpy(ecb_cleartext,src_buf,16);
Marcomissyou 0:a2de37bf5f3d 50 }
Marcomissyou 0:a2de37bf5f3d 51 NRF_ECB->EVENTS_ENDECB = 0;
Marcomissyou 0:a2de37bf5f3d 52 NRF_ECB->TASKS_STARTECB = 1;
Marcomissyou 0:a2de37bf5f3d 53 while(NRF_ECB->EVENTS_ENDECB == 0)
Marcomissyou 0:a2de37bf5f3d 54 {
Marcomissyou 0:a2de37bf5f3d 55 counter--;
Marcomissyou 0:a2de37bf5f3d 56 if(counter == 0)
Marcomissyou 0:a2de37bf5f3d 57 {
Marcomissyou 0:a2de37bf5f3d 58 return false;
Marcomissyou 0:a2de37bf5f3d 59 }
Marcomissyou 0:a2de37bf5f3d 60 }
Marcomissyou 0:a2de37bf5f3d 61 NRF_ECB->EVENTS_ENDECB = 0;
Marcomissyou 0:a2de37bf5f3d 62 if(dest_buf != ecb_ciphertext)
Marcomissyou 0:a2de37bf5f3d 63 {
Marcomissyou 0:a2de37bf5f3d 64 memcpy(dest_buf,ecb_ciphertext,16);
Marcomissyou 0:a2de37bf5f3d 65 }
Marcomissyou 0:a2de37bf5f3d 66 return true;
Marcomissyou 0:a2de37bf5f3d 67 }
Marcomissyou 0:a2de37bf5f3d 68
Marcomissyou 0:a2de37bf5f3d 69 void nrf_ecb_set_key(const uint8_t * key)
Marcomissyou 0:a2de37bf5f3d 70 {
Marcomissyou 0:a2de37bf5f3d 71 memcpy(ecb_key,key,16);
Marcomissyou 0:a2de37bf5f3d 72 }
Marcomissyou 0:a2de37bf5f3d 73