Define permanent group message identity from creation fields

This commit is contained in:
evgeny committed 2026-10-26 22:33:43 +01:00
1 parent b0d246913d
commit 5c638a60db
2 files changed
+8 -7

No files matched your search

+6 -5
View File
@@ -41,16 +41,17 @@ static int fb_db_error(struct UTUN_INSTANCE* inst, const char* channel, const ch
}
/* Канонический ID сообщения не зависит от локального порядкового номера. */
int chat_message_id(uint64_t channel_id, uint64_t timestamp, const uint8_t signature[64], uint8_t id[32]) {
static const char domain[] = "utun-chat-message-v1";
uint8_t body[sizeof(domain) - 1 + 16 + 64];
if (!channel_id || !signature || !id) {
int chat_message_id(uint64_t channel_id, uint64_t timestamp, uint64_t author, const uint8_t nonce[16], uint8_t id[32]) {
static const char domain[] = "utun-chat-message-v2";
uint8_t body[sizeof(domain) - 1 + 24 + 16];
if (!channel_id || !author || !nonce || !id) {
DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "feedback: invalid message identity arguments"); return -1;
}
memcpy(body, domain, sizeof(domain) - 1);
fb_write64(body + sizeof(domain) - 1, channel_id);
fb_write64(body + sizeof(domain) - 1 + 8, timestamp);
memcpy(body + sizeof(domain) - 1 + 16, signature, 64);
fb_write64(body + sizeof(domain) - 1 + 16, author);
memcpy(body + sizeof(domain) - 1 + 24, nonce, 16);
if (EVP_Digest(body, sizeof(body), id, NULL, EVP_sha256(), NULL) != 1) {
DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "feedback: message identity digest failed"); return -1;
}
+2 -2
View File
@@ -28,8 +28,8 @@ struct chat_feedback_record {
uint8_t signature[64];
};
/* Производный ID неизменяемого сообщения; 0/-1. Числа хешируются как BE64. */
int chat_message_id(uint64_t channel_id, uint64_t timestamp, const uint8_t signature[64], uint8_t id[32]);
/* Постоянный ID: канал, время создания, автор и случайный nonce[16]; 0/-1. Числа — BE64. */
int chat_message_id(uint64_t channel_id, uint64_t timestamp, uint64_t author, const uint8_t nonce[16], uint8_t id[32]);
/* Регистрирует FEEDBACK и восстанавливает индекс допущенных записей; 0/-1.
* Исключение или отсутствие зависимости автора не блокирует запуск и не удаляет историю. */
int chat_feedback_init(struct UTUN_INSTANCE* inst);