blob: eb3330d6a8931cb06606256f8b2c85cb57915aaa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// crypto.h --- cryptography utilities
//
// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
//
// SPDX-License-Identifier: MIT
//
// Commentary:
//
// Code:
#ifndef INCLUDED_CRYPTO_H
#define INCLUDED_CRYPTO_H
#include <stdint.h>
#include <stdbool.h>
#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
|