ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
crypto/handshake/common.h
Go to the documentation of this file.
1#pragma once
2
9#include <stdint.h>
10#include <stdbool.h>
11#include "../../platform/socket.h"
12#include "../../crypto/crypto.h"
13#include "../../crypto/keys.h"
14#include "../../network/packet/packet.h"
15
16struct acip_transport;
17
26#define AUTH_REQUIRE_PASSWORD 0x01
28#define AUTH_REQUIRE_CLIENT_KEY 0x02
29
48
114
129asciichat_error_t crypto_handshake_init(const char *name, crypto_handshake_context_t *ctx, bool is_server);
130
138 const crypto_parameters_packet_t *params);
139
148 size_t packet_size);
149
161 const char *password);
162
168
175
182
194 size_t plaintext_len, uint8_t *ciphertext, size_t ciphertext_size,
195 size_t *ciphertext_len);
196
208 size_t ciphertext_len, uint8_t *plaintext, size_t plaintext_size,
209 size_t *plaintext_len);
210
223 const uint8_t *plaintext, size_t plaintext_len,
224 uint8_t *ciphertext, size_t ciphertext_size,
225 size_t *ciphertext_len);
226
239 const uint8_t *ciphertext, size_t ciphertext_len,
240 uint8_t *plaintext, size_t plaintext_size,
241 size_t *plaintext_len);
242
255
263
271
280 size_t packet_len);
281
290 size_t packet_len);
291
300 size_t packet_len);
301
308
asciichat_error_t crypto_handshake_rekey_complete(crypto_handshake_context_t *ctx, struct acip_transport *transport)
Send REKEY_COMPLETE packet (initiator side)
asciichat_error_t crypto_handshake_init(const char *name, crypto_handshake_context_t *ctx, bool is_server)
Initialize named crypto handshake context.
const crypto_context_t * crypto_handshake_get_context(const crypto_handshake_context_t *ctx)
Get the crypto context for encryption/decryption.
asciichat_error_t crypto_handshake_init_with_password(const char *name, crypto_handshake_context_t *ctx, bool is_server, const char *password)
Initialize named crypto handshake context with password authentication.
void crypto_handshake_destroy(crypto_handshake_context_t *ctx)
Cleanup crypto handshake context with secure memory wiping.
asciichat_error_t crypto_handshake_decrypt_packet(const crypto_handshake_context_t *ctx, const uint8_t *ciphertext, size_t ciphertext_len, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_len)
Decrypt a packet using the established crypto context.
asciichat_error_t crypto_handshake_process_rekey_request(crypto_handshake_context_t *ctx, const uint8_t *packet, size_t packet_len)
Process received REKEY_REQUEST packet (responder side)
asciichat_error_t crypto_handshake_validate_packet_size(const crypto_handshake_context_t *ctx, uint16_t packet_type, size_t packet_size)
Validate crypto packet size based on session parameters.
asciichat_error_t crypto_handshake_encrypt_packet(const crypto_handshake_context_t *ctx, const uint8_t *plaintext, size_t plaintext_len, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_len)
Encrypt a packet using the established crypto context.
bool crypto_handshake_is_ready(const crypto_handshake_context_t *ctx)
Check if handshake is complete and encryption is ready.
bool crypto_handshake_should_rekey(const crypto_handshake_context_t *ctx)
Check if rekeying should be triggered for this handshake context.
asciichat_error_t crypto_handshake_set_parameters(crypto_handshake_context_t *ctx, const crypto_parameters_packet_t *params)
Set crypto parameters from crypto_parameters_packet_t.
asciichat_error_t crypto_handshake_process_rekey_response(crypto_handshake_context_t *ctx, const uint8_t *packet, size_t packet_len)
Process received REKEY_RESPONSE packet (initiator side)
asciichat_error_t crypto_handshake_rekey_request(crypto_handshake_context_t *ctx, struct acip_transport *transport)
Send REKEY_REQUEST packet (initiator side)
asciichat_error_t crypto_encrypt_packet_or_passthrough(const crypto_handshake_context_t *ctx, bool crypto_ready, const uint8_t *plaintext, size_t plaintext_len, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_len)
Encrypt with automatic passthrough if crypto not ready.
asciichat_error_t crypto_decrypt_packet_or_passthrough(const crypto_handshake_context_t *ctx, bool crypto_ready, const uint8_t *ciphertext, size_t ciphertext_len, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_len)
Decrypt with automatic passthrough if crypto not ready.
asciichat_error_t crypto_handshake_process_rekey_complete(crypto_handshake_context_t *ctx, const uint8_t *packet, size_t packet_len)
Process received REKEY_COMPLETE packet (responder side)
asciichat_error_t crypto_handshake_rekey_response(crypto_handshake_context_t *ctx, struct acip_transport *transport)
Send REKEY_RESPONSE packet (responder side)
unsigned short uint16_t
Definition common.h:57
unsigned char uint8_t
Definition common.h:56
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
crypto_handshake_state_t
Cryptographic handshake state enumeration.
@ CRYPTO_HANDSHAKE_FAILED
@ CRYPTO_HANDSHAKE_AUTHENTICATING
@ CRYPTO_HANDSHAKE_INIT
@ CRYPTO_HANDSHAKE_DISABLED
@ CRYPTO_HANDSHAKE_KEY_EXCHANGE
@ CRYPTO_HANDSHAKE_READY
ClangTool/LibTooling compatibility shim for stdbool.h.
Transport instance structure.
Definition transport.h:214
Cryptographic context structure.
Cryptographic handshake context structure.
crypto_handshake_state_t state
Crypto parameters packet structure (Packet Type 15)
Definition packet.h:981
Private key structure (for server –ssh-key)
Definition key_types.h:91
Public key structure.
Definition key_types.h:69
#define PLATFORM_MAX_PATH_LENGTH
Definition system.c:69