/* Hash throughput bench — the Phase 2 gate (SHA-256 >= 1.5 GB/s/core). */ #include "naut/hash.h" #include #include #include #include static double now(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec + t.tv_nsec * 1e-9; } static double bench(const char *name, void (*h)(const void *, size_t, uint8_t *), uint8_t *buf, size_t len, int iters, int outlen) { uint8_t out[32]; /* warm */ h(buf, len, out); double t0 = now(); for (int i = 0; i < iters; i++) h(buf, len, out); double dt = now() - t0; double gb = (double)len * iters / 1e9; printf(" %-10s %6.2f GB/s (%d-byte digest)\n", name, gb / dt, outlen); return gb / dt; } static void s1(const void *d, size_t n, uint8_t *o) { naut_sha1(d, n, o); } static void s256(const void *d, size_t n, uint8_t *o) { naut_sha256(d, n, o); } int main(int argc, char **argv) { size_t len = (argc > 1) ? (size_t)atoll(argv[1]) * 1024 * 1024 : 256u * 1024 * 1024; int iters = (argc > 2) ? atoi(argv[2]) : 8; uint8_t *buf = malloc(len); if (!buf) { perror("malloc"); return 1; } memset(buf, 0xa5, len); printf("buffer %zu MiB x %d iters | sha256 backend: %s\n", len >> 20, iters, naut_sha256_backend()); double s256_gbs = bench("sha256", s256, buf, len, iters, 32); bench("sha1", s1, buf, len, iters, 20); free(buf); /* gate: a single core must clear the 1.25 GB/s line rate with margin */ if (s256_gbs < 1.5) { fprintf(stderr, "GATE FAIL: sha256 %.2f GB/s < 1.5 GB/s\n", s256_gbs); return 1; } printf("GATE PASS: sha256 %.2f GB/s >= 1.5 GB/s\n", s256_gbs); return 0; }