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 / trace / sha256-test.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Standard SHA-256 vectors: empty, abc, one-block boundary, two blocks and 1000 bytes. |
| 3 | global fails ulong 1 |
| 4 | global checks ulong 1 |
| 5 | text digs "0123456789abcdef" |
| 6 | text v0 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" |
| 7 | text e1 "abc" |
| 8 | text v1 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" |
| 9 | text e2 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" |
| 10 | text v2 "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" |
| 11 | text e3 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" |
| 12 | text v3 "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1" |
| 13 | text v4 "41edece42d63e8d9bf515a9ba6932e1c20cbc9f5a5d134645adb5db1b9737ea3" |
| 14 | text passm "sha256 vectors=5 fails=0\n" |
| 15 | |
| 16 | fn hi b uchar to uchar |
| 17 | ret get digs shr b 4 |
| 18 | end |
| 19 | fn lo b uchar to uchar |
| 20 | ret get digs and b 15 |
| 21 | end |
| 22 | fn hexout d view uchar 32 o edit uchar 64 to void |
| 23 | for i ulong 32 |
| 24 | put o mul i 2 hi get d i |
| 25 | put o add mul i 2 1 lo get d i |
| 26 | end |
| 27 | end |
| 28 | fn cmp a view uchar 64 b view uchar 64 to void |
| 29 | for i ulong 64 |
| 30 | if ne get a i get b i |
| 31 | put fails 0 add get fails 0 1 |
| 32 | end |
| 33 | end |
| 34 | put checks 0 add get checks 0 1 |
| 35 | end |
| 36 | fn main to int |
| 37 | buf = new uchar 4096 0 |
| 38 | out = new uchar 32 0 |
| 39 | hxb = new uchar 64 0 |
| 40 | sha256 buf 0 out |
| 41 | hexout out hxb |
| 42 | cmp hxb v0 |
| 43 | for i ulong len e1 |
| 44 | put buf i get e1 i |
| 45 | end |
| 46 | sha256 buf len e1 out |
| 47 | hexout out hxb |
| 48 | cmp hxb v1 |
| 49 | for i ulong len e2 |
| 50 | put buf i get e2 i |
| 51 | end |
| 52 | sha256 buf len e2 out |
| 53 | hexout out hxb |
| 54 | cmp hxb v2 |
| 55 | for i ulong len e3 |
| 56 | put buf i get e3 i |
| 57 | end |
| 58 | sha256 buf len e3 out |
| 59 | hexout out hxb |
| 60 | cmp hxb v3 |
| 61 | for i ulong 1000 |
| 62 | put buf i 97 |
| 63 | end |
| 64 | sha256 buf 1000 out |
| 65 | hexout out hxb |
| 66 | cmp hxb v4 |
| 67 | if ne get fails 0 0 |
| 68 | ret 1 |
| 69 | end |
| 70 | nw = write 1 passm 0 len passm |
| 71 | if ne nw long len passm |
| 72 | ret 2 |
| 73 | end |
| 74 | ret 0 |
| 75 | end |