Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/test_sha256_freestanding_parity.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / test_sha256_freestanding_parity.c` 59 lines ยท 2625 bytes Raw Blame History 1 /* SHA-256 through the generated C API (src/sha256.h -> src/omega_api_decl.h), one source built twice by 2 * mk/omega-gpu-engine.mk: against the hosted binding src/omega_om_units.c and against the freestanding 3 * binding src/omega_om_units_fs.c compiled with GPU_FS_CFLAGS. Both print the same lines; the make 4 * target compares them byte for byte and checks the FIPS 180-2 digests. 5 * fips empty, "abc", the 448-bit message, one million 'a' (in uneven update calls) 6 * len n = 0..1100 (every padding boundary 55/56/63/64/65 and its block multiples), 4096, 7 * 65536 and `1048583` bytes from a fixed-seed xorshift64 stream, one-shot; the same 8 * bytes through init/update/final split at a seeded point must give the same digest 9 * (else "split-mismatch " and exit 1). */ 10 #include "sha256.h" 11 #include 12 #include 13 14 static void put(const char *tag, unsigned i, const uint8_t d[SHA256_DIGEST_SIZE]) 15 { 16 printf("%s %u ", tag, i); 17 for (int k = 0; k < SHA256_DIGEST_SIZE; k++) printf("%02x", d[k]); 18 printf("\n"); 19 } 20 21 static uint64_t rng = 0x9e3779b97f4a7c15ull; 22 static uint64_t next(void) 23 { 24 rng ^= rng << 13; rng ^= rng >> 7; rng ^= rng << 17; 25 return rng; 26 } 27 28 int main(void) 29 { 30 static const char *const fips[] = { "", "abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }; 31 enum { MILLION = `1000000`, LEN_MAX = `1048583` }; 32 static const unsigned big[] = { 4096, 65536, LEN_MAX }; 33 static uint8_t buf[LEN_MAX]; 34 uint8_t d[SHA256_DIGEST_SIZE], e[SHA256_DIGEST_SIZE]; 35 sha256_ctx c; 36 unsigned i; 37 for (i = 0; i < 3; i++) { sha256_hash((const uint8_t *)fips[i], strlen(fips[i]), d); put("fips", i, d); } 38 memset(buf, 'a', MILLION); 39 sha256_init(&c); 40 for (size_t off = 0, step = 1; off < MILLION; off += step, step = step * 3 + 7) { 41 size_t n = MILLION - off < step ? MILLION - off : step; 42 sha256_update(&c, buf + off, n); 43 } 44 sha256_final(&c, d); 45 put("fips", 3, d); 46 for (unsigned t = 0; t < 1101 + sizeof big / sizeof big[0]; t++) { 47 const unsigned n = t <= 1100 ? t : big[t - 1101]; 48 for (unsigned k = 0; k < n; k++) buf[k] = (uint8_t)next(); 49 sha256_hash(buf, n, d); 50 const unsigned cut = n ? (unsigned)(next() % (n + 1)) : 0; 51 sha256_init(&c); 52 sha256_update(&c, buf, cut); 53 sha256_update(&c, buf + cut, n - cut); 54 sha256_final(&c, e); 55 if (memcmp(d, e, sizeof d)) { printf("split-mismatch %u\n", n); return 1; } 56 put("len", n, d); 57 } 58 return 0; 59 }