kry_http grows a streaming file sink (kry_http_download) with byte and fraction progress, sized for artifacts instead of in-memory bodies. kry_sha256 adds dependency-free FIPS 180-4 hashing (streaming + file + hex compare). kry_update ties them together: appcast-channel downloads staged under XDG_DATA_HOME/LOCALAPPDATA with sha256 verification (bad files are removed), AppImage staging that copies next to the running image and atomically renames over it (plus re-exec in apply), and a Windows portable swap script spawned detached from %TEMP%. Tests cover hash vectors, verified/failed downloads via file://, and AppImage staging; the exec'ing apply path stays untested by design.
44 lines
1.2 KiB
C
44 lines
1.2 KiB
C
/*
|
|
* kry_sha256.h - Kry standard library: SHA-256 (FIPS 180-4).
|
|
*
|
|
* Streaming interface plus a one-shot file hasher used by kry_update to
|
|
* verify downloaded artifacts against an appcast digest. No external
|
|
* dependencies; the ksync crypto stack intentionally stays separate.
|
|
*/
|
|
#ifndef KRYON_KRY_SHA256_H
|
|
#define KRYON_KRY_SHA256_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct {
|
|
unsigned int state[8];
|
|
unsigned long long bit_len;
|
|
unsigned char buf[64];
|
|
size_t buf_len;
|
|
} KrySha256;
|
|
|
|
void kry_sha256_init(KrySha256 *ctx);
|
|
void kry_sha256_update(KrySha256 *ctx, const void *data, size_t len);
|
|
void kry_sha256_final(KrySha256 *ctx, unsigned char out[32]);
|
|
|
|
/* Lowercase hex (64 chars + NUL) into `out` (65 bytes). Returns `out`. */
|
|
char *kry_sha256_hex(const unsigned char digest[32], char out[65]);
|
|
|
|
/* One-shot: hash a file in chunks. Returns 1 on success, 0 when the file
|
|
* cannot be read. `hex_out` needs 65 bytes. */
|
|
int kry_sha256_file(const char *path, char hex_out[65]);
|
|
|
|
/* Constant-time comparison of two hex digests (case-insensitive). Returns
|
|
* 1 when equal. NULL arguments compare unequal. */
|
|
int kry_sha256_hex_equal(const char *a, const char *b);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|