mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
crypto/aes.c: Make refernce to key const
This commit is contained in:
@@ -11093,4 +11093,7 @@
|
|||||||
file calculated partition boundries based on page block sizes but
|
file calculated partition boundries based on page block sizes but
|
||||||
mtd_partition() is expecting calculations based on erase block size.
|
mtd_partition() is expecting calculations based on erase block size.
|
||||||
From Alan Carvalho de Assis (2015-11-16).
|
From Alan Carvalho de Assis (2015-11-16).
|
||||||
|
* Move rivers/wireless/cc3000/security.c to crypto/aes.c; move
|
||||||
|
include/nuttx/wireless/cc3000/security.h to include/nuttx/crypto/aes.h
|
||||||
|
(2015-11-16).
|
||||||
|
|
||||||
|
|||||||
+16
-10
@@ -121,7 +121,7 @@ static uint8_t g_expanded_key[176];
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void expand_key(FAR uint8_t *expanded_key, FAR uint8_t *key)
|
static void expand_key(FAR uint8_t *expanded_key, FAR const uint8_t *key)
|
||||||
{
|
{
|
||||||
uint16_t buf1;
|
uint16_t buf1;
|
||||||
uint16_t ii;
|
uint16_t ii;
|
||||||
@@ -185,25 +185,28 @@ static uint8_t galois_mul2(uint8_t value)
|
|||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Internal implementation of AES128 encryption.
|
* Internal implementation of AES128 encryption.
|
||||||
* Straight forward aes encryption implementation. First the group of operations
|
* Straight forward aes encryption implementation. First the group of
|
||||||
|
* operations:
|
||||||
|
*
|
||||||
* - addRoundKey
|
* - addRoundKey
|
||||||
* - subbytes
|
* - subbytes
|
||||||
* - shiftrows
|
* - shiftrows
|
||||||
* - mixcolums
|
* - mixcolums
|
||||||
|
*
|
||||||
* is executed 9 times, after this addroundkey to finish the 9th round, after
|
* is executed 9 times, after this addroundkey to finish the 9th round, after
|
||||||
* that the 10th round without mixcolums no further subfunctions to save
|
* that the 10th round without mixcolums no further subfunctions to save
|
||||||
* cycles for function calls no structuring with "for (....)" to save cycles.
|
* cycles for function calls no structuring with "for (....)" to save cycles.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* expanded_key expanded AES128 key
|
* expanded_key expanded AES128 key
|
||||||
* state 16 bytes of plain text and cipher text
|
* state 16 bytes of plain text and cipher text
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void aes_encr(FAR uint8_t *state, FAR uint8_t *expanded_key)
|
static void aes_encr(FAR uint8_t *state, FAR const uint8_t *expanded_key)
|
||||||
{
|
{
|
||||||
uint8_t buf1;
|
uint8_t buf1;
|
||||||
uint8_t buf2;
|
uint8_t buf2;
|
||||||
@@ -342,23 +345,25 @@ static void aes_encr(FAR uint8_t *state, FAR uint8_t *expanded_key)
|
|||||||
* Internal implementation of AES128 decryption.
|
* Internal implementation of AES128 decryption.
|
||||||
* Straight forward aes decryption implementation. The order of substeps is
|
* Straight forward aes decryption implementation. The order of substeps is
|
||||||
* the exact reverse of decryption inverse functions:
|
* the exact reverse of decryption inverse functions:
|
||||||
|
*
|
||||||
* - addRoundKey is its own inverse
|
* - addRoundKey is its own inverse
|
||||||
* - rsbox is inverse of sbox
|
* - rsbox is inverse of sbox
|
||||||
* - rightshift instead of leftshift
|
* - rightshift instead of leftshift
|
||||||
* - invMixColumns = barreto + mixColumns
|
* - invMixColumns = barreto + mixColumns
|
||||||
|
*
|
||||||
* No further subfunctions to save cycles for function calls no structuring
|
* No further subfunctions to save cycles for function calls no structuring
|
||||||
* with "for (....)" to save cycles
|
* with "for (....)" to save cycles
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* expanded_key expanded AES128 key
|
* expanded_key expanded AES128 key
|
||||||
* state 16 bytes of cipher text and plain text
|
* state 16 bytes of cipher text and plain text
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void aes_decr(FAR uint8_t *state, FAR uint8_t *expanded_key)
|
static void aes_decr(FAR uint8_t *state, FAR const uint8_t *expanded_key)
|
||||||
{
|
{
|
||||||
uint8_t buf1;
|
uint8_t buf1;
|
||||||
uint8_t buf2;
|
uint8_t buf2;
|
||||||
@@ -537,7 +542,7 @@ static void aes_decr(FAR uint8_t *state, FAR uint8_t *expanded_key)
|
|||||||
* Name: aes_encrypt
|
* Name: aes_encrypt
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* AES128 encryption: Given AES128 key and 16 bytes plain text, cipher
|
* AES128 encryption: Given AES128 key and 16 bytes plain text, cipher
|
||||||
* text of 16 bytes is computed. The AES implementation is in mode ECB
|
* text of 16 bytes is computed. The AES implementation is in mode ECB
|
||||||
* (Electronic Code Book).
|
* (Electronic Code Book).
|
||||||
*
|
*
|
||||||
@@ -550,7 +555,7 @@ static void aes_decr(FAR uint8_t *state, FAR uint8_t *expanded_key)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key)
|
void aes_encrypt(FAR uint8_t *state, FAR const uint8_t *key)
|
||||||
{
|
{
|
||||||
/* Expand the key into 176 bytes */
|
/* Expand the key into 176 bytes */
|
||||||
|
|
||||||
@@ -562,7 +567,7 @@ void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key)
|
|||||||
* Name: aes_decrypt
|
* Name: aes_decrypt
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* AES128 decryption: Given AES128 key and 16 bytes cipher text, plain
|
* AES128 decryption: Given AES128 key and 16 bytes cipher text, plain
|
||||||
* text of 16 bytes is computed The AES implementation is in mode ECB
|
* text of 16 bytes is computed The AES implementation is in mode ECB
|
||||||
* (Electronic Code Book).
|
* (Electronic Code Book).
|
||||||
*
|
*
|
||||||
@@ -575,8 +580,9 @@ void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void aes_decrypt(FAR uint8_t *state, FAR uint8_t *key)
|
void aes_decrypt(FAR uint8_t *state, FAR const uint8_t *key)
|
||||||
{
|
{
|
||||||
expand_key(g_expanded_key, key); /* Expand the key into 176 bytes */
|
expand_key(g_expanded_key, key); /* Expand the key into 176 bytes */
|
||||||
aes_decr(state, g_expanded_key);
|
aes_decr(state, g_expanded_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ extern "C"
|
|||||||
* Name: aes_encrypt
|
* Name: aes_encrypt
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* AES128 encryption: Given AES128 key and 16 bytes plain text, cipher
|
* AES128 encryption: Given AES128 key and 16 bytes plain text, cipher
|
||||||
* text of 16 bytes is computed. The AES implementation is in mode ECB
|
* text of 16 bytes is computed. The AES implementation is in mode ECB
|
||||||
* (Electronic Code Book).
|
* (Electronic Code Book).
|
||||||
*
|
*
|
||||||
@@ -80,13 +80,13 @@ extern "C"
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key);
|
void aes_encrypt(FAR uint8_t *state, FAR const uint8_t *key);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: aes_decrypt
|
* Name: aes_decrypt
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* AES128 decryption: Given AES128 key and 16 bytes cipher text, plain
|
* AES128 decryption: Given AES128 key and 16 bytes cipher text, plain
|
||||||
* text of 16 bytes is computed The AES implementation is in mode ECB
|
* text of 16 bytes is computed The AES implementation is in mode ECB
|
||||||
* (Electronic Code Book).
|
* (Electronic Code Book).
|
||||||
*
|
*
|
||||||
@@ -99,7 +99,7 @@ void aes_encrypt(FAR uint8_t *state, FAR uint8_t *key);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void aes_decrypt(FAR uint8_t *state, FAR uint8_t *key);
|
void aes_decrypt(FAR uint8_t *state, FAR const uint8_t *key);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user