summaryrefslogtreecommitdiff
path: root/kernel/crypto
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-30 22:12:14 +0100
committerAnton Kling <anton@kling.gg>2023-10-31 00:18:38 +0100
commit8a9208612eec8ddae4c418485d848ecfa0613699 (patch)
tree2f4b29200c2f0c19ae52f45bdb9b38a41b356e30 /kernel/crypto
parentca76600acc8bf7a02346efa5bd8f17072210ec01 (diff)
Meta: Move kernel and userland to their own folders.
This is to allow both the kernel and the userland to share certain header files and to make the folder structure a bit more clear.
Diffstat (limited to 'kernel/crypto')
-rw-r--r--kernel/crypto/ChaCha20/chacha20.c29
-rw-r--r--kernel/crypto/ChaCha20/chacha20.h15
m---------kernel/crypto/SHA10
3 files changed, 44 insertions, 0 deletions
diff --git a/kernel/crypto/ChaCha20/chacha20.c b/kernel/crypto/ChaCha20/chacha20.c
new file mode 100644
index 0000000..5bf7aa2
--- /dev/null
+++ b/kernel/crypto/ChaCha20/chacha20.c
@@ -0,0 +1,29 @@
+#include "chacha20.h"
+
+#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))
+#define ROUNDS 20
+
+void chacha_block(uint32_t out[16], uint32_t const in[16])
+{
+ int i;
+ uint32_t 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]);
+
+ 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
new file mode 100644
index 0000000..17532f3
--- /dev/null
+++ b/kernel/crypto/ChaCha20/chacha20.h
@@ -0,0 +1,15 @@
+#ifndef CHACHA20_H
+#define CHACHA20_H
+#include <stdint.h>
+
+#define KEY 4
+#define KEY_SIZE 8*sizeof(uint32_t)
+#define COUNT 12
+#define COUNT_SIZE sizeof(uint32_t)
+#define COUNT_MAX (0x100000000-1) // 2^32 - 1
+#define NONCE 13
+#define NONCE_SIZE 2*sizeof(uint32_t)
+#define BLOCK_SIZE 16*sizeof(uint32_t)
+
+void chacha_block(uint32_t out[16], uint32_t const in[16]);
+#endif
diff --git a/kernel/crypto/SHA1 b/kernel/crypto/SHA1
new file mode 160000
+Subproject 237ea7023cad8402932dfbde337d69e5f4d515f