aboutsummaryrefslogtreecommitdiff
path: root/05/src/crypto.h
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 05:31:06 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 06:14:42 +0000
commit9e1d304cac5367c3dbb1ca14700736680bd3a804 (patch)
tree31f328747acb934d365d423adfda144818ff5ad4 /05/src/crypto.h
downloadlab-01-05-master.tar.gz
publishHEADmaster
Diffstat (limited to '05/src/crypto.h')
-rw-r--r--05/src/crypto.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/05/src/crypto.h b/05/src/crypto.h
new file mode 100644
index 0000000..eb3330d
--- /dev/null
+++ b/05/src/crypto.h
@@ -0,0 +1,37 @@
1// crypto.h --- cryptography utilities
2//
3// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
4//
5// SPDX-License-Identifier: MIT
6//
7// Commentary:
8//
9// Code:
10
11#ifndef INCLUDED_CRYPTO_H
12#define INCLUDED_CRYPTO_H
13
14#include <stdint.h>
15#include <stdbool.h>
16
17#include "utils.h"
18
19#define X25519_PUBKEY_LEN 32
20#define SHA_DIGEST_SIZE 20
21#define AES_256_KEY_SIZE 32
22#define AES_BLOCK_SIZE 16
23#define AES_IV_SIZE 16
24
25typedef uint8_t aes_256_key[AES_256_KEY_SIZE];
26
27extern uint8_t local_pubkey[X25519_PUBKEY_LEN];
28
29bool crypto_init (void);
30ssize_t sha1_hash (uint8_t out[SHA_DIGEST_SIZE], struct memory_view in);
31bool hkdf_sha256 (const uint8_t peer_pubkey[X25519_PUBKEY_LEN], aes_256_key out);
32ssize_t aes_256_cbc_encrypt (struct memory_span out, struct memory_view in, const aes_256_key, bool salt);
33ssize_t aes_256_cbc_decrypt (struct memory_span out, struct memory_view in, const aes_256_key, bool salt);
34
35#endif // INCLUDED_CRYPTO_H
36
37// crypto.h ends here