Clang-format and clang-tidy fixes
This commit is contained in:
parent
2e2e4951c5
commit
f6da1e90b1
3
aes.c
3
aes.c
|
@ -29,8 +29,9 @@ void aes128_ecb(uint8_t *dest, uint8_t const *const in) {
|
|||
#else
|
||||
memmove(g_ecbdata.in, in, 16);
|
||||
NRF_ECB->TASKS_STARTECB = 1;
|
||||
while (!NRF_ECB->EVENTS_ENDECB)
|
||||
while (!NRF_ECB->EVENTS_ENDECB) {
|
||||
;
|
||||
}
|
||||
NRF_ECB->EVENTS_ENDECB = 0;
|
||||
#endif /* HOST_BUILD */
|
||||
memmove(dest, g_ecbdata.out, 16);
|
||||
|
|
12
block.c
12
block.c
|
@ -1,8 +1,6 @@
|
|||
/* Utility functions for manipulating block_t structures; 128bit
|
||||
blocks of data for AES & CMAC */
|
||||
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -13,16 +11,16 @@
|
|||
#endif
|
||||
#include "block.h"
|
||||
|
||||
#if defined (HOST_BUILD) || defined (DEBUG_UART)
|
||||
#if defined(HOST_BUILD) || defined(DEBUG_UART)
|
||||
void block_print(char const *const label, void const *const b) {
|
||||
block_print_bytes(label, b, 16);
|
||||
return;
|
||||
block_print_bytes(label, b, 16);
|
||||
return;
|
||||
}
|
||||
|
||||
void block_print_bytes(char const *const label, void const *const v,
|
||||
uint32_t num_bytes) {
|
||||
const uint8_t *b = v;
|
||||
printf("%s: ", label);
|
||||
const uint8_t *b = v;
|
||||
printf("%s: ", label);
|
||||
for (int i = 0; i < num_bytes; i++) {
|
||||
printf("%.2x", b[i]);
|
||||
if (!((i + 1) % 4)) {
|
||||
|
|
66
ckdf.c
66
ckdf.c
|
@ -13,41 +13,41 @@
|
|||
#include "cmac.h"
|
||||
|
||||
void ckdf_extract(uint8_t *prk, const uint8_t *salt, const uint8_t *ikm,
|
||||
uint32_t ikm_len) {
|
||||
uint8_t zeros[16] = {0};
|
||||
if (salt == NULL) {
|
||||
cmac_aes128_init(zeros);
|
||||
} else {
|
||||
cmac_aes128_init(salt);
|
||||
}
|
||||
cmac_aes128(prk, (uint8_t*) ikm, ikm_len, 16);
|
||||
uint32_t ikm_len) {
|
||||
uint8_t zeros[16] = {0};
|
||||
if (salt == NULL) {
|
||||
cmac_aes128_init(zeros);
|
||||
} else {
|
||||
cmac_aes128_init(salt);
|
||||
}
|
||||
cmac_aes128(prk, (uint8_t *)ikm, ikm_len, 16);
|
||||
}
|
||||
|
||||
void ckdf_expand(uint8_t *okm, uint8_t *prk, uint8_t *info,
|
||||
uint32_t info_len, uint32_t okm_len) {
|
||||
uint32_t num_blocks = okm_len / 16;
|
||||
/* Simulate ceiling division instead of C std floor */
|
||||
uint8_t remainder = okm_len % 16;
|
||||
if (remainder) {
|
||||
num_blocks++;
|
||||
}
|
||||
cmac_aes128_init(prk);
|
||||
uint8_t t[16+info_len+1];
|
||||
uint8_t *initial = &t[16];
|
||||
memset(t, 0, 16);
|
||||
for (uint32_t i = 0; i < num_blocks; i++) {
|
||||
*(initial+info_len) = i+1;
|
||||
if (i == 0) {
|
||||
memcpy(initial, info, info_len);
|
||||
cmac_aes128(t, initial, info_len+1, 16);
|
||||
} else {
|
||||
cmac_aes128(t, t, sizeof(t), 16);
|
||||
void ckdf_expand(uint8_t *okm, uint8_t *prk, uint8_t *info, uint32_t info_len,
|
||||
uint32_t okm_len) {
|
||||
uint32_t num_blocks = okm_len / 16;
|
||||
/* Simulate ceiling division instead of C std floor */
|
||||
uint8_t remainder = okm_len % 16;
|
||||
if (remainder) {
|
||||
num_blocks++;
|
||||
}
|
||||
if (i == num_blocks - 1 && remainder) {
|
||||
memcpy(okm+16*i, t, remainder);
|
||||
} else {
|
||||
memcpy(okm+16*i, t, 16);
|
||||
cmac_aes128_init(prk);
|
||||
uint8_t t[16 + info_len + 1];
|
||||
uint8_t *initial = &t[16];
|
||||
memset(t, 0, 16);
|
||||
for (uint32_t i = 0; i < num_blocks; i++) {
|
||||
*(initial + info_len) = i + 1;
|
||||
if (i == 0) {
|
||||
memcpy(initial, info, info_len);
|
||||
cmac_aes128(t, initial, info_len + 1, 16);
|
||||
} else {
|
||||
cmac_aes128(t, t, sizeof(t), 16);
|
||||
}
|
||||
if (i == num_blocks - 1 && remainder) {
|
||||
memcpy(okm + 16 * i, t, remainder);
|
||||
} else {
|
||||
memcpy(okm + 16 * i, t, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
|
1
ckdf.h
1
ckdf.h
|
@ -9,4 +9,3 @@
|
|||
|
||||
void ckdf_extract(uint8_t *, const uint8_t *, const uint8_t *, uint32_t);
|
||||
void ckdf_expand(uint8_t *, uint8_t *, uint8_t *, uint32_t, uint32_t);
|
||||
|
||||
|
|
2
ctr.c
2
ctr.c
|
@ -10,7 +10,7 @@ void aes128_ctr_init(uint8_t *key, uint8_t *counter) {
|
|||
memcpy(g_counter, counter, 16);
|
||||
}
|
||||
if (key != NULL) {
|
||||
aes128_init(key);
|
||||
aes128_init(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
eax.c
2
eax.c
|
@ -12,7 +12,7 @@ void aes128_eax_init(const uint8_t *key, uint8_t *nonce) {
|
|||
memcpy(g_nonce, nonce, 16);
|
||||
}
|
||||
if (key != NULL) {
|
||||
cmac_aes128_init(key);
|
||||
cmac_aes128_init(key);
|
||||
}
|
||||
aes128_ctr_init(key, nonce);
|
||||
return;
|
||||
|
|
3
rng.c
3
rng.c
|
@ -16,8 +16,9 @@ uint8_t rng_byte(void) {
|
|||
void rng_bytes(uint8_t *out, uint32_t num_bytes) {
|
||||
NRF_RNG->TASKS_START = 1;
|
||||
for (uint32_t i = 0; i < num_bytes; i++) {
|
||||
while (!NRF_RNG->EVENTS_VALRDY)
|
||||
while (!NRF_RNG->EVENTS_VALRDY) {
|
||||
;
|
||||
}
|
||||
out[i] = (uint8_t)NRF_RNG->VALUE;
|
||||
NRF_RNG->EVENTS_VALRDY = 0;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,5 @@ clang-tidy \
|
|||
-header-filter=.* \
|
||||
--checks=readability-braces-around-statements,misc-macro-parentheses \
|
||||
*.c \
|
||||
-- -I.
|
||||
-- -DNRF51 -I. -I ../../../nrf-sdk/6.1/nrf51822/Include -I ../../../nrf-sdk/6.1/nrf51822/Include/gcc
|
||||
clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4, AllowShortFunctionsOnASingleLine: None, KeepEmptyLinesAtTheStartOfBlocks: false}" -i *.{h,c}
|
||||
|
||||
|
|
Loading…
Reference in New Issue