1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

crypto: Fix code style

This commit is contained in:
Mathias Tausig 2018-10-26 16:24:24 +02:00 committed by Mathias Tausig
parent b8cd3c0724
commit 0352c7406d
3 changed files with 77 additions and 64 deletions

View File

@ -124,7 +124,8 @@ static const u32 Te0[256] = {
#define Te1(n) ((Te0[n] >> 8) | (Te0[n] << 24))
#define Te2(n) ((Te0[n] >> 16) | (Te0[n] << 16))
#define Te3(n) ((Te0[n] >> 24) | (Te0[n] << 8))
#define Te4(n) (((Te0[n] & 0x00FFFF00) >> 8) | ((Te0[n] & 0x00FFFF00) << 8))
#define Te4(n) (((Te0[n] & 0x00FFFF00) >> 8) | \
((Te0[n] & 0x00FFFF00) << 8))
#else /* MODULE_CRYPTO_AES_PRECALCULATED */
#define Te0(n) (Te0[n])
#define Te1(n) (Te1[n])
@ -476,7 +477,8 @@ static const u32 Td0[256] = {
* left shift by 24 into undefined behaviour */
#define Td4u(n) ((u32)Td4[n])
#define Td4(n) (Td4u(n) | (Td4u(n) << 8) | (Td4u(n) << 16) | (Td4u(n) << 24))
#define Td4(n) (Td4u(n) | (Td4u(n) << 8) | (Td4u(n) << 16) | \
(Td4u(n) << 24))
static const u8 Td4[256] = {
0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U,
@ -951,6 +953,7 @@ static int aes_set_decrypt_key(const unsigned char *userKey, const int bits,
/* first, start with an encryption schedule */
int status;
status = aes_set_encrypt_key(userKey, bits, key);
if (status < 0) {
@ -1027,6 +1030,7 @@ int aes_encrypt(const cipher_context_t *context, const uint8_t *plainBlock,
int res;
AES_KEY aeskey;
const AES_KEY *key = &aeskey;
res = aes_set_encrypt_key((unsigned char *)context->context,
AES_KEY_SIZE * 8, &aeskey);
if (res < 0) {
@ -1155,22 +1159,30 @@ int aes_encrypt(const cipher_context_t *context, const uint8_t *plainBlock,
if (key->rounds > 12) {
/* round 12: */
s0 = Te0(t0 >> 24) ^ Te1((t1 >> 16) & 0xff) ^ Te2((t2 >> 8) &
0xff) ^ Te3(t3 & 0xff) ^ rk[48];
0xff) ^ Te3(
t3 & 0xff) ^ rk[48];
s1 = Te0(t1 >> 24) ^ Te1((t2 >> 16) & 0xff) ^ Te2((t3 >> 8) &
0xff) ^ Te3(t0 & 0xff) ^ rk[49];
0xff) ^ Te3(
t0 & 0xff) ^ rk[49];
s2 = Te0(t2 >> 24) ^ Te1((t3 >> 16) & 0xff) ^ Te2((t0 >> 8) &
0xff) ^ Te3(t1 & 0xff) ^ rk[50];
0xff) ^ Te3(
t1 & 0xff) ^ rk[50];
s3 = Te0(t3 >> 24) ^ Te1((t0 >> 16) & 0xff) ^ Te2((t1 >> 8) &
0xff) ^ Te3(t2 & 0xff) ^ rk[51];
0xff) ^ Te3(
t2 & 0xff) ^ rk[51];
/* round 13: */
t0 = Te0(s0 >> 24) ^ Te1((s1 >> 16) & 0xff) ^ Te2((s2 >> 8) &
0xff) ^ Te3(s3 & 0xff) ^ rk[52];
0xff) ^ Te3(
s3 & 0xff) ^ rk[52];
t1 = Te0(s1 >> 24) ^ Te1((s2 >> 16) & 0xff) ^ Te2((s3 >> 8) &
0xff) ^ Te3(s0 & 0xff) ^ rk[53];
0xff) ^ Te3(
s0 & 0xff) ^ rk[53];
t2 = Te0(s2 >> 24) ^ Te1((s3 >> 16) & 0xff) ^ Te2((s0 >> 8) &
0xff) ^ Te3(s1 & 0xff) ^ rk[54];
0xff) ^ Te3(
s1 & 0xff) ^ rk[54];
t3 = Te0(s3 >> 24) ^ Te1((s0 >> 16) & 0xff) ^ Te2((s1 >> 8) &
0xff) ^ Te3(s2 & 0xff) ^ rk[55];
0xff) ^ Te3(
s2 & 0xff) ^ rk[55];
}
}
@ -1286,6 +1298,7 @@ int aes_decrypt(const cipher_context_t *context, const uint8_t *cipherBlock,
int res;
AES_KEY aeskey;
const AES_KEY *key = &aeskey;
res = aes_set_decrypt_key((unsigned char *)context->context,
AES_KEY_SIZE * 8, &aeskey);