From 9e1d304cac5367c3dbb1ca14700736680bd3a804 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Wed, 11 Nov 2026 08:31:06 +0300 Subject: publish --- 05/src/crypto.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 05/src/crypto.h (limited to '05/src/crypto.h') 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 @@ +// crypto.h --- cryptography utilities +// +// Copyright (c) 2026 Martin Michalec +// +// SPDX-License-Identifier: MIT +// +// Commentary: +// +// Code: + +#ifndef INCLUDED_CRYPTO_H +#define INCLUDED_CRYPTO_H + +#include +#include + +#include "utils.h" + +#define X25519_PUBKEY_LEN 32 +#define SHA_DIGEST_SIZE 20 +#define AES_256_KEY_SIZE 32 +#define AES_BLOCK_SIZE 16 +#define AES_IV_SIZE 16 + +typedef uint8_t aes_256_key[AES_256_KEY_SIZE]; + +extern uint8_t local_pubkey[X25519_PUBKEY_LEN]; + +bool crypto_init (void); +ssize_t sha1_hash (uint8_t out[SHA_DIGEST_SIZE], struct memory_view in); +bool hkdf_sha256 (const uint8_t peer_pubkey[X25519_PUBKEY_LEN], aes_256_key out); +ssize_t aes_256_cbc_encrypt (struct memory_span out, struct memory_view in, const aes_256_key, bool salt); +ssize_t aes_256_cbc_decrypt (struct memory_span out, struct memory_view in, const aes_256_key, bool salt); + +#endif // INCLUDED_CRYPTO_H + +// crypto.h ends here -- cgit v1.3.1