Files
kryon/include/ksync_crypto.h
T
waozi c670587788 ksync: harden crypto, exports, JSON, delete, and sync transport
- Add shared ksync_crypto module: SHA-256, HMAC-SHA256, PBKDF2-SHA256,
  ChaCha20-Poly1305 (RFC 8439), hex helpers, random bytes; all verified
  against RFC test vectors in tests/ksync_crypto_test.c
- Encrypted account exports (v2): PBKDF2 (600k iterations) +
  ChaCha20-Poly1305, passphrase-protected import/export APIs; the v1
  plaintext format remains importable
- DeleteKsyncSyncAccount no longer transmits the private key: it signs
  a challenge against /api/v1/account/delete and falls back to the
  legacy delete-with-key endpoint on 404/405
- JSON writer escapes control characters (including \b, \f, \uXXXX);
  reader now decodes escapes, rejects substring keys and keys embedded
  in string values
- Token expiry accounts for server clock skew (server_time in the
  login response, clamped to +/-24h)
- Optional retry with exponential backoff for transport errors, 429,
  and 5xx via retry_max/retry_delay_ms/sleep_ms config fields
- Opt-in end-to-end payload encryption (encrypt_payload flag plus
  Wrap/UnwrapKsyncSyncPayload) derived from the account private key
2026-08-16 19:54:53 -03:00

32 lines
1.4 KiB
C

#ifndef KSYNC_CRYPTO_H
#define KSYNC_CRYPTO_H
#include <stddef.h>
#include <stdint.h>
void KsyncCryptoSha256(const uint8_t *data, size_t len, uint8_t out[32]);
void KsyncCryptoHmacSha256(const uint8_t *key, size_t key_len,
const uint8_t *data, size_t data_len,
uint8_t out[32]);
void KsyncCryptoPbkdf2Sha256(const uint8_t *password, size_t password_len,
const uint8_t *salt, size_t salt_len,
unsigned long iterations, uint8_t out[32]);
/* AEAD: ciphertext_and_tag must have plain_len + 16 bytes; returns 0 on
* forgery or bad input. */
int KsyncCryptoChaCha20Poly1305Seal(const uint8_t key[32], const uint8_t nonce[12],
const uint8_t *plain, size_t plain_len,
const uint8_t *aad, size_t aad_len,
uint8_t *ciphertext_and_tag);
int KsyncCryptoChaCha20Poly1305Open(const uint8_t key[32], const uint8_t nonce[12],
const uint8_t *ciphertext_and_tag, size_t total_len,
const uint8_t *aad, size_t aad_len,
uint8_t *plain);
void KsyncCryptoRandom(uint8_t *out, size_t len);
int KsyncCryptoBytesToHex(const uint8_t *bytes, size_t len, char *out, size_t out_size);
int KsyncCryptoHexToBytes(const char *hex, uint8_t *out, size_t out_len);
#endif