sam4cm: add CFB and MAC AES modes. From Max Neklyudov

This commit is contained in:
Max Neklyudov 2015-06-22 06:42:37 -06:00 committed by Gregory Nutt
parent 61af0d511f
commit 01a35ff27f
2 changed files with 28 additions and 5 deletions

26
arch/arm/src/sam34/sam_aes.c Normal file → Executable file
View File

@ -114,7 +114,10 @@ static void aes_encryptblock(void *out, const void *in)
while(!(getreg32(SAM_AES_ISR) & AES_ISR_DATRDY)) {} while(!(getreg32(SAM_AES_ISR) & AES_ISR_DATRDY)) {}
aes_memcpy(out, (void*)SAM_AES_ODATAR, AES_BLOCK_SIZE); if (out)
{
aes_memcpy(out, (void*)SAM_AES_ODATAR, AES_BLOCK_SIZE);
}
} }
static int aes_setup_mr(uint32_t keysize, int mode, int encrypt) static int aes_setup_mr(uint32_t keysize, int mode, int encrypt)
@ -152,6 +155,9 @@ static int aes_setup_mr(uint32_t keysize, int mode, int encrypt)
case AES_MODE_CTR: case AES_MODE_CTR:
regval |= AES_MR_OPMOD_CTR; regval |= AES_MR_OPMOD_CTR;
break; break;
case AES_MODE_CFB:
regval |= AES_MR_OPMOD_CFB;
break;
default: default:
return -EINVAL; return -EINVAL;
} }
@ -174,7 +180,7 @@ int aes_cypher(void *out, const void *in, uint32_t size, const void *iv,
aes_lock(); aes_lock();
res = aes_setup_mr(keysize, mode, encrypt); res = aes_setup_mr(keysize, mode & AES_MODE_MASK, encrypt);
if (res) if (res)
{ {
aes_unlock(); aes_unlock();
@ -189,8 +195,20 @@ int aes_cypher(void *out, const void *in, uint32_t size, const void *iv,
while (size) while (size)
{ {
aes_encryptblock(out, in); if ((mode & AES_MODE_MAC) == 0)
out = (char*)out + AES_BLOCK_SIZE; {
aes_encryptblock(out, in);
out = (char*)out + AES_BLOCK_SIZE;
}
else if (size == AES_BLOCK_SIZE)
{
aes_encryptblock(out, in);
}
else
{
aes_encryptblock(NULL, in);
}
in = (char*)in + AES_BLOCK_SIZE; in = (char*)in + AES_BLOCK_SIZE;
size -= AES_BLOCK_SIZE; size -= AES_BLOCK_SIZE;
} }

View File

@ -53,8 +53,13 @@
# define AES_MODE_ECB 1 # define AES_MODE_ECB 1
# define AES_MODE_CBC 2 # define AES_MODE_CBC 2
# define AES_MODE_CTR 3 # define AES_MODE_CTR 3
# define AES_MODE_CFB 4
# define AES_MODE_MAX 3 # define AES_MODE_MAX 4
# define AES_MODE_MAC 0x80000000
# define AES_MODE_MASK 0xffff
#endif #endif
#define CYPHER_ENCRYPT 1 #define CYPHER_ENCRYPT 1