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 bdf0b6a9ab
commit e4d7b311b7

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

@ -114,8 +114,11 @@ 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)) {}
if (out)
{
aes_memcpy(out, (void*)SAM_AES_ODATAR, AES_BLOCK_SIZE); 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();
@ -188,9 +194,21 @@ int aes_cypher(void *out, const void *in, uint32_t size, const void *iv,
} }
while (size) while (size)
{
if ((mode & AES_MODE_MAC) == 0)
{ {
aes_encryptblock(out, in); aes_encryptblock(out, in);
out = (char*)out + AES_BLOCK_SIZE; 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;
} }