Skip to content

Commit

Permalink
Merge pull request linux4sam#46 from baruchsiach/secure-endianness
Browse files Browse the repository at this point in the history
Secure boot keys endianness improvements
  • Loading branch information
wenyouya authored Oct 31, 2016
2 parents 4874e09 + 7ed43ed commit dbe9f0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Config.in.secure
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ config CONFIG_AES_KEY_SIZE_256

endchoice

comment "Big-endian order: Word0 is the most significant word"

config CONFIG_AES_CIPHER_KEY_WORD0
hex "Cipher Key Word0"
default "0x00000000"
Expand Down
17 changes: 13 additions & 4 deletions driver/at91_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#include "board.h"
#include "string.h"

#define swab32(x) ( \
(((x) & 0x000000ffUL) << 24) | \
(((x) & 0x0000ff00UL) << 8) | \
(((x) & 0x00ff0000UL) >> 8) | \
(((x) & 0xff000000UL) >> 24))

static inline unsigned int aes_readl(unsigned int reg)
{
Expand Down Expand Up @@ -87,8 +92,10 @@ static inline void at91_aes_set_iv(const unsigned int *iv)
{
unsigned int i, reg = AES_IVR0;

for (i = 0; i < AT91_AES_IV_SIZE_WORD; ++i, reg += 4)
aes_writel(reg, iv[i]);
for (i = 0; i < AT91_AES_IV_SIZE_WORD; ++i, reg += 4) {
unsigned int iv_be = swab32(iv[i]);
aes_writel(reg, iv_be);
}
}

static inline int at91_aes_set_opmode(at91_aes_operation_t operation,
Expand Down Expand Up @@ -224,8 +231,10 @@ static inline int at91_aes_set_key(at91_aes_key_size_t key_size,
return -1;
}

for (i = 0; i < num_words; ++i, reg += 4)
aes_writel(reg, key[i]);
for (i = 0; i < num_words; ++i, reg += 4) {
unsigned int key_be = swab32(key[i]);
aes_writel(reg, key_be);
}

return 0;
}
Expand Down

0 comments on commit dbe9f0c

Please sign in to comment.