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
omega-mv / seed / qualification / om2 / oracle / sha / trace_child.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * ORACLE (outside the delivered closure), L836 phaseB/sha-f5d14cb2, contract section 8 evidence (b). |
| 3 | * Child of trace.py: makes pairs of calls into the bound OM-2 SHA unit that differ only in message |
| 4 | * (and pending-buffer) bytes, never in lengths, call sequence or buffer addresses. It stops itself |
| 5 | * with SIGSTOP immediately before and immediately after each traced call sequence, so the tracer |
| 6 | * cuts the single-step trace into segments; message filling happens outside the traced segments. |
| 7 | * Traced segment order: for each case, message A then message B. |
| 8 | * Build: gcc -std=gnu11 -O2 -I<bind> trace_child.c -L<bind> -lomega_native -Wl,-rpath,<bind> */ |
| 9 | #include <signal.h> |
| 10 | #include <stdint.h> |
| 11 | #include <stdio.h> |
| 12 | #include <string.h> |
| 13 | |
| 14 | #include "omega_api.h" |
| 15 | |
| 16 | static uint64_t s; |
| 17 | static uint8_t nx(void) |
| 18 | { |
| 19 | uint64_t z = (s += 0x9E3779B97F4A7C15ull); |
| 20 | z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull; |
| 21 | z = (z ^ (z >> 27)) * 0x94D049BB133111EBull; |
| 22 | return (uint8_t)(z ^ (z >> 31)); |
| 23 | } |
| 24 | |
| 25 | static uint8_t buf[4096]; |
| 26 | static sha256_ctx ctx; |
| 27 | static uint8_t out[32]; |
| 28 | |
| 29 | static void fill(uint64_t seed, size_t n, int variant) |
| 30 | { |
| 31 | s = seed; |
| 32 | for (size_t i = 0; i < n; i++) |
| 33 | buf[i] = variant == 0 ? 0x00 : variant == 1 ? 0xff : nx(); |
| 34 | } |
| 35 | |
| 36 | int main(void) |
| 37 | { |
| 38 | static const size_t lens[] = {0, 1, 55, 56, 63, 64, 65, 119, 120, 200, 1000}; |
| 39 | uint64_t r; |
| 40 | /* untraced warm-up: a thread's first call maps the binding's stack (NATIVE-ABI.md), which would |
| 41 | * make only the first traced segment's binding path longer */ |
| 42 | if (omega2_sha256_hash(&r, buf, 0, out)) |
| 43 | return 4; |
| 44 | /* priming stop: the tracer attaches here with PTRACE_CONT; every traced segment then starts at a |
| 45 | * stop reached by single-stepping, so segment boundaries are uniform */ |
| 46 | raise(SIGSTOP); |
| 47 | /* hash: per length, pairs (zeros, ones) and (random seed 1, random seed 2) */ |
| 48 | for (size_t i = 0; i < sizeof lens / sizeof lens[0]; i++) { |
| 49 | for (int p = 0; p < 2; p++) { |
| 50 | for (int ab = 0; ab < 2; ab++) { |
| 51 | if (p == 0) |
| 52 | fill(0, lens[i], ab); |
| 53 | else |
| 54 | fill(100 + 2 * i + (uint64_t)ab, lens[i], 2); |
| 55 | raise(SIGSTOP); |
| 56 | { |
| 57 | /* sensitivity controls (negative, must make pair 7 differ): -DCONTROL=1 gives |
| 58 | * message B one byte more; -DCONTROL=2 hashes message B from buf + 64 */ |
| 59 | size_t n = lens[i], o = 0; |
| 60 | #if defined(CONTROL) |
| 61 | if (i == 3 && p == 1 && ab == 1) { |
| 62 | if (CONTROL == 1) |
| 63 | n++; |
| 64 | else |
| 65 | o = 64; |
| 66 | } |
| 67 | #endif |
| 68 | if (omega2_sha256_hash(&r, buf + o, n, out)) |
| 69 | return 2; |
| 70 | } |
| 71 | raise(SIGSTOP); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | /* stream: init, update(k), update(n-k), final with the same lengths; the second update absorbs |
| 76 | * a pending partial block whose bytes differ between A and B */ |
| 77 | static const size_t ks[][2] = {{3, 60}, {10, 100}, {63, 1}, {64, 64}, {100, 200}, {1, 0}}; |
| 78 | for (size_t i = 0; i < sizeof ks / sizeof ks[0]; i++) { |
| 79 | for (int ab = 0; ab < 2; ab++) { |
| 80 | fill(500 + 2 * i + (uint64_t)ab, ks[i][0] + ks[i][1], 2); |
| 81 | memset(&ctx, 0, sizeof ctx); |
| 82 | raise(SIGSTOP); |
| 83 | if (omega2_sha256_init(&r, (uint8_t *)&ctx) || omega2_sha256_update(&r, (uint8_t *)&ctx, buf, ks[i][0]) || |
| 84 | omega2_sha256_update(&r, (uint8_t *)&ctx, buf + ks[i][0], ks[i][1]) || |
| 85 | omega2_sha256_final(&r, (uint8_t *)&ctx, out)) |
| 86 | return 3; |
| 87 | raise(SIGSTOP); |
| 88 | } |
| 89 | } |
| 90 | raise(SIGSTOP); |
| 91 | return 0; |
| 92 | } |