diff options
| author | 2026-11-11 05:31:06 +0000 | |
|---|---|---|
| committer | 2026-11-11 06:14:42 +0000 | |
| commit | 9e1d304cac5367c3dbb1ca14700736680bd3a804 (patch) | |
| tree | 31f328747acb934d365d423adfda144818ff5ad4 /05/src/crypto.h | |
| download | lab-01-05-master.tar.gz | |
Diffstat (limited to '05/src/crypto.h')
| -rw-r--r-- | 05/src/crypto.h | 37 |
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 | |||
| 25 | typedef uint8_t aes_256_key[AES_256_KEY_SIZE]; | ||
| 26 | |||
| 27 | extern uint8_t local_pubkey[X25519_PUBKEY_LEN]; | ||
| 28 | |||
| 29 | bool crypto_init (void); | ||
| 30 | ssize_t sha1_hash (uint8_t out[SHA_DIGEST_SIZE], struct memory_view in); | ||
| 31 | bool hkdf_sha256 (const uint8_t peer_pubkey[X25519_PUBKEY_LEN], aes_256_key out); | ||
| 32 | ssize_t aes_256_cbc_encrypt (struct memory_span out, struct memory_view in, const aes_256_key, bool salt); | ||
| 33 | ssize_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 | ||
