• Main Page
  • Modules
  • Index
  • File List
  • Globals

lib/crypt/lib_crypt.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic 
00004  * Semiconductor ASA.Terms and conditions of usage are described in detail 
00005  * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *              
00011  * $LastChangedRevision: 133 $
00012  */
00013 
00020 #include "lib_crypt.h"
00021 #include "hal_aes.h"
00022 #include "memdefs.h"
00023 
00037 static uint8_t aes_counter[16];
00038 
00039 void lib_crypt_init(uint8_t * key, const uint8_t * init_counter)
00040 {
00041     hal_aes_setup(false, ECB, key, NULL);
00042 
00043     if(init_counter)
00044     {
00045         lib_crypt_set_counter(init_counter);
00046     }
00047 }
00048 
00049 void lib_crypt_set_counter(const uint8_t * counter)
00050 {
00051     uint8_t i;
00052     for(i=0;i<16;i++)
00053     {
00054         aes_counter[i] = counter[i];
00055     }
00056 }
00057 
00058 void lib_crypt(uint8_t * dest_buf, const uint8_t * src_buf, uint8_t length,const uint8_t * ls5b_value)
00059 {
00060     uint8_t i;
00061   uint8_t encr_buffer[16];   //AES buffer. Needed to do XOR
00062 
00063   //Set LS5B
00064     for(i=0;i<5;i++)
00065     {
00066         aes_counter[i] = ls5b_value[i];
00067     }   
00068 
00069   //Run AES with aes_counter
00070     hal_aes_crypt(encr_buffer,aes_counter);
00071     
00072   //Encrypt data, based on XOR operation in AES counter mode.
00073     for(i=0;i<length; i++)
00074     {
00075         dest_buf[i] = src_buf[i] ^ encr_buffer[i];
00076     }
00077 }

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2