summaryrefslogtreecommitdiff
path: root/kernel/crypto
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-11-28 20:11:05 +0100
committerAnton Kling <anton@kling.gg>2023-11-28 20:12:20 +0100
commitd07fa25e04a19ccb9aa25bb6e2156d23d213db77 (patch)
tree25f2e4a6301f3ad7c5b158e74966a394862fdf39 /kernel/crypto
parent636858dbbd48ed9f5073793b46740302aa202f43 (diff)
Meta: Apply new clang-format rules to kernel
Diffstat (limited to 'kernel/crypto')
-rw-r--r--kernel/crypto/ChaCha20/chacha20.c39
-rw-r--r--kernel/crypto/ChaCha20/chacha20.h8
-rw-r--r--kernel/crypto/xoshiro256plusplus/xoshiro256plusplus.c4
3 files changed, 26 insertions, 25 deletions
diff --git a/kernel/crypto/ChaCha20/chacha20.c b/kernel/crypto/ChaCha20/chacha20.c
index 0f74844..4486d00 100644
--- a/kernel/crypto/ChaCha20/chacha20.c
+++ b/kernel/crypto/ChaCha20/chacha20.c
@@ -2,28 +2,27 @@
#define ROTL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
#define QR(a, b, c, d) \
- (a += b, d ^= a, d = ROTL(d, 16), c += d, b ^= c, b = ROTL(b, 12), \
- a += b, d ^= a, d = ROTL(d, 8), c += d, b ^= c, b = ROTL(b, 7))
+ (a += b, d ^= a, d = ROTL(d, 16), c += d, b ^= c, b = ROTL(b, 12), a += b, \
+ d ^= a, d = ROTL(d, 8), c += d, b ^= c, b = ROTL(b, 7))
#define ROUNDS 20
-void chacha_block(u32 out[16], u32 const in[16])
-{
- int i;
- u32 x[16];
+void chacha_block(u32 out[16], u32 const in[16]) {
+ int i;
+ u32 x[16];
- for (i = 0; i < 16; ++i)
- x[i] = in[i];
- for (i = 0; i < ROUNDS; i += 2) {
- QR(x[0], x[4], x[8], x[12]);
- QR(x[1], x[5], x[9], x[13]);
- QR(x[2], x[6], x[10], x[14]);
- QR(x[3], x[7], x[11], x[15]);
+ for (i = 0; i < 16; ++i)
+ x[i] = in[i];
+ for (i = 0; i < ROUNDS; i += 2) {
+ QR(x[0], x[4], x[8], x[12]);
+ QR(x[1], x[5], x[9], x[13]);
+ QR(x[2], x[6], x[10], x[14]);
+ QR(x[3], x[7], x[11], x[15]);
- QR(x[0], x[5], x[10], x[15]);
- QR(x[1], x[6], x[11], x[12]);
- QR(x[2], x[7], x[8], x[13]);
- QR(x[3], x[4], x[9], x[14]);
- }
- for (i = 0; i < 16; ++i)
- out[i] = x[i] + in[i];
+ QR(x[0], x[5], x[10], x[15]);
+ QR(x[1], x[6], x[11], x[12]);
+ QR(x[2], x[7], x[8], x[13]);
+ QR(x[3], x[4], x[9], x[14]);
+ }
+ for (i = 0; i < 16; ++i)
+ out[i] = x[i] + in[i];
}
diff --git a/kernel/crypto/ChaCha20/chacha20.h b/kernel/crypto/ChaCha20/chacha20.h
index 3278783..dd4a639 100644
--- a/kernel/crypto/ChaCha20/chacha20.h
+++ b/kernel/crypto/ChaCha20/chacha20.h
@@ -3,13 +3,13 @@
#include <typedefs.h>
#define KEY 4
-#define KEY_SIZE 8*sizeof(u32)
+#define KEY_SIZE 8 * sizeof(u32)
#define COUNT 12
#define COUNT_SIZE sizeof(u32)
-#define COUNT_MAX (0x100000000-1) // 2^32 - 1
+#define COUNT_MAX (0x100000000 - 1) // 2^32 - 1
#define NONCE 13
-#define NONCE_SIZE 2*sizeof(u32)
-#define BLOCK_SIZE 16*sizeof(u32)
+#define NONCE_SIZE 2 * sizeof(u32)
+#define BLOCK_SIZE 16 * sizeof(u32)
void chacha_block(u32 out[16], u32 const in[16]);
#endif
diff --git a/kernel/crypto/xoshiro256plusplus/xoshiro256plusplus.c b/kernel/crypto/xoshiro256plusplus/xoshiro256plusplus.c
index 414a5a4..f4833d6 100644
--- a/kernel/crypto/xoshiro256plusplus/xoshiro256plusplus.c
+++ b/kernel/crypto/xoshiro256plusplus/xoshiro256plusplus.c
@@ -26,7 +26,9 @@ static inline uint64_t rotl(const uint64_t x, int k) {
static uint64_t s[4];
-void seed_xoshiro_256_pp(uint64_t input[4]) { memcpy(s, input, sizeof(s)); }
+void seed_xoshiro_256_pp(uint64_t input[4]) {
+ memcpy(s, input, sizeof(s));
+}
uint64_t xoshiro_256_pp(void) {
const uint64_t result = rotl(s[0] + s[3], 23) + s[0];