You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
2.0 KiB
41 lines
2.0 KiB
/* AEAD-записи внешнего REALITY; состояние обнуляется при создании и принадлежит одному TCP-сеансу. |
|
* Wire: 17 03 03 | uint16_be(ciphertext_len) | AES-128-GCM(content || inner_type || zero_padding) | tag[16]. |
|
* AAD — пять байт заголовка; nonce[12] = base_iv XOR (zero[4] || uint64_be(sequence)). |
|
* Каждый успешный seal/open увеличивает свой sequence; повторно передаются только готовые wire-байты. |
|
* Ошибка требует закрытия сеанса. KeyUpdate последним сообщением под старым ключом меняет traffic secret |
|
* через HKDF("uTun-reality-update"), затем key/iv и sequence=0. Направления обновляются независимо. */ |
|
#ifndef REALITY_RECORD_H |
|
#define REALITY_RECORD_H |
|
#include <stdint.h> |
|
#include <stddef.h> |
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
#define REALITY_INNER_MAX 16385 |
|
#define REALITY_RECORD_MAX (5 + REALITY_INNER_MAX + 16) |
|
#ifndef REALITY_KEY_LIMIT |
|
#define REALITY_KEY_LIMIT (UINT64_C(1) << 20) |
|
#endif |
|
#define REALITY_TYPE_HANDSHAKE 22 |
|
#define REALITY_TYPE_APPLICATION 23 |
|
#define REALITY_TYPE_ALERT 21 |
|
|
|
struct reality_traffic { |
|
uint8_t secret[32], key[16], iv[12]; |
|
uint64_t sequence; |
|
uint32_t generation; |
|
}; |
|
|
|
int reality_kdf(const uint8_t *ikm, size_t ikm_len, const uint8_t *salt, size_t salt_len, |
|
const char *label, uint8_t *out, size_t out_len); |
|
int reality_traffic_init(struct reality_traffic *t, const uint8_t secret[32]); |
|
int reality_traffic_update(struct reality_traffic *t); |
|
int reality_record_seal(struct reality_traffic *t, uint8_t type, const uint8_t *data, size_t len, |
|
size_t padding, uint8_t *out, size_t cap, size_t *written); |
|
int reality_record_open(struct reality_traffic *t, const uint8_t *record, size_t len, |
|
uint8_t *out, size_t cap, size_t *written, uint8_t *type); |
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif
|
|
|