10-batch.c (1537B)
1 // Forces the pre-image batch to chunk, so the multi-chunk path is exercised 2 #define SFINX_BATCH_KEY_BUDGET 260u 3 4 #include <string.h> 5 6 #include "_tap.c" 7 #include "ref/sfinx_ref.c" 8 #include "src/sfinx.c" 9 10 int main(void) { 11 static const uint8_t seed[] = "sfinx batch chunk seed"; 12 static const uint8_t prefix[] = {0x11, 0x22, 0x33}; 13 static const int bits[] = {224, 512}; 14 size_t seed_len = sizeof(seed) - 1; 15 16 // key_len is 22 + 3 + 1 = 26, so the 260 budget makes chunk 10, not a lane multiple 17 tap_begin("sfinx batch chunking"); 18 19 for (size_t s = 0; s < sizeof(bits) / sizeof(bits[0]); s++) { 20 int bit = bits[s]; 21 sfinx_hash hash = (sfinx_hash)bit; 22 size_t len = sfinx_hash_len(hash); 23 uint8_t lib_root[SFINX_HASH_LEN_MAX]; 24 uint8_t ref_root[SFINX_HASH_LEN_MAX]; 25 uint8_t lib_auth[8 * SFINX_HASH_LEN_MAX]; 26 uint8_t ref_auth[8 * SFINX_HASH_LEN_MAX]; 27 char label[64]; 28 29 tap(_sfinx_subtree_build(NULL, hash, seed, seed_len, prefix, sizeof(prefix), 0x5a, lib_root, lib_auth) != 0, 30 "chunked subtree builds", "build failed"); 31 ref_subtree(bit, seed, seed_len, prefix, sizeof(prefix), 0x5a, ref_root, ref_auth); 32 33 snprintf(label, sizeof(label), "L%zu chunked root matches reference", len); 34 tap(memcmp(lib_root, ref_root, len) == 0, label, "root differs"); 35 snprintf(label, sizeof(label), "L%zu chunked auth matches reference", len); 36 tap(memcmp(lib_auth, ref_auth, 8 * len) == 0, label, "auth differs"); 37 } 38 39 return tap_plan(); 40 }