mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +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).
|
||||||
|
|
||||||
|
|||||||
+12
-6
@@ -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,11 +185,14 @@ 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.
|
||||||
@@ -203,7 +206,7 @@ static uint8_t galois_mul2(uint8_t value)
|
|||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
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,10 +345,12 @@ 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
|
||||||
*
|
*
|
||||||
@@ -358,7 +363,7 @@ static void aes_encr(FAR uint8_t *state, FAR uint8_t *expanded_key)
|
|||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
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;
|
||||||
@@ -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 */
|
||||||
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ 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
|
||||||
@@ -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