dist.h (2223B)
1 #ifndef KIT_DIST_DIST_H 2 #define KIT_DIST_DIST_H 3 4 #include <stddef.h> 5 #include <stdint.h> 6 7 /* Shared constants and small helpers for the code-distribution subsystem 8 * (`kit pkg`). See doc/DISTRIBUTE.md for the design. 9 * 10 * Cryptographic and compression primitives under driver/dist/ are vendored so 11 * the package pipeline (manifest -> sign -> bundle -> verify -> unpack) has no 12 * runtime dependency on host crypto/compression libraries. */ 13 14 /* Primitive output sizes. */ 15 #define DIST_BLAKE2B_LEN 32u 16 #define DIST_HASH_LEN DIST_BLAKE2B_LEN 17 #define DIST_MINISIG_PREHASH_LEN 64u 18 #define DIST_ED25519_PK_LEN 32u 19 #define DIST_ED25519_SK_LEN 64u 20 #define DIST_ED25519_SIG_LEN 64u 21 #define DIST_ED25519_SEED_LEN 32u 22 #define DIST_KEYID_LEN 8u 23 24 /* Fixed parse/build capacities. These caps bound a single package's metadata 25 * and member count. create-from-root emits one [artifact] overlay per tree 26 * file, so DIST_MAX_ARTIFACTS must stay >= DIST_MAX_FILES or a package with 27 * more than DIST_MAX_ARTIFACTS files cannot be built (e.g. a kit release, which 28 * ships its headers + rt sources). */ 29 #define DIST_MAX_FILES 256u 30 #define DIST_MAX_ARTIFACTS 256u 31 #define DIST_MAX_DEPS 64u 32 #define DIST_MAX_OUTPUTS 16u 33 34 /* (No per-blob chunk cap: dist_blob_root computes the chunk Merkle root in 35 * bounded memory, so a blob may have any number of chunks. See blob.c.) */ 36 37 /* String field caps inside in-memory manifest structs. */ 38 #define DIST_NAME_MAX 128u 39 #define DIST_VERSION_MAX 64u 40 #define DIST_DESC_MAX 256u 41 #define DIST_PATH_MAX 100u /* matches ustar name field */ 42 #define DIST_TRIPLE_MAX 64u 43 #define DIST_KIND_MAX 16u 44 #define DIST_PCONSTRAINT_MAX 64u 45 #define DIST_URL_MAX 1024u /* URL / URL-template fields (not ustar names) */ 46 47 /* Result convention: 0 = ok, non-zero = error. */ 48 #define DIST_OK 0 49 #define DIST_ERR 1 50 51 /* Lowercase-hex encode `n` bytes into `out`, which must hold 2*n+1 chars 52 * (NUL-terminated). */ 53 void dist_hex_encode(char* out, const uint8_t* in, size_t n); 54 55 /* Decode exactly `n` bytes of lowercase/uppercase hex from `in` (which must 56 * have >= 2*n hex chars) into `out`. Returns DIST_OK on success, DIST_ERR on a 57 * non-hex character. */ 58 int dist_hex_decode(uint8_t* out, const char* in, size_t n); 59 60 #endif