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 / aienux / allen / tests / tls-crypto-sha.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | note SHA256 empty/abc/56-byte standard FIPS180-4 examples; RFC4231 sections4.2..4.5 HMAC. |
| 3 | note HKDF RFC5869 Appendix A.1/A.3 extract and both expand blocks via public HMAC API. |
| 4 | note https://www.rfc-editor.org/rfc/rfc4231 https://www.rfc-editor.org/rfc/rfc5869 |
| 5 | note Attribution/license in required tls-crypto-fixture.om. Return0 means every assertion matched. |
| 6 | text Vhash "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff75bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e519ef24a32c717b167f33a91d6f648bdf96596776afdb6377ac434c1c293ccb04" |
| 7 | text Vokm "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b8871858658da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8" |
| 8 | text Vabc "abc" |
| 9 | text Vlong "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" |
| 10 | text Vhi "Hi There" |
| 11 | text Vjefe "Jefe" |
| 12 | text Vwhat "what do ya want for nothing?" |
| 13 | |
| 14 | fn tvhash slot ulong to void |
| 15 | for i ulong 32 |
| 16 | p = add mul slot 64 mul i 2 |
| 17 | v = tvbyte get Vhash p get Vhash add p 1 |
| 18 | tvcheck eq get Tcdigest i v 20 |
| 19 | end |
| 20 | tvscrub |
| 21 | end |
| 22 | |
| 23 | fn tvwipe to void |
| 24 | tcwipe |
| 25 | tvscrub |
| 26 | end |
| 27 | |
| 28 | fn tvsha to void |
| 29 | tvwipe |
| 30 | tvcheck tcsha 0 1 |
| 31 | tvhash 0 |
| 32 | for i ulong 3 |
| 33 | put Tcbuf i get Vabc i |
| 34 | end |
| 35 | put Tcbuf 3 201 |
| 36 | tvcheck tcsha 3 2 |
| 37 | tvhash 1 |
| 38 | for i ulong 3 |
| 39 | tvcheck eq get Tcbuf i get Vabc i 3 |
| 40 | end |
| 41 | tvcheck eq get Tcbuf 3 201 3 |
| 42 | for i ulong len Vlong |
| 43 | put Tcbuf i get Vlong i |
| 44 | end |
| 45 | tvcheck tcsha len Vlong 4 |
| 46 | tvhash 2 |
| 47 | tvcheck not tcsha 65537 5 |
| 48 | for i ulong 32 |
| 49 | tvcheck eq get Tcdigest i 0 5 |
| 50 | end |
| 51 | tvcheck not tcsha 18446744073709551615 5 |
| 52 | tvscrub |
| 53 | end |
| 54 | |
| 55 | fn tvhmac to void |
| 56 | tvwipe |
| 57 | for i ulong 20 |
| 58 | put Tckey i 11 |
| 59 | end |
| 60 | for i ulong len Vhi |
| 61 | put Tcbuf i get Vhi i |
| 62 | end |
| 63 | tvcheck tchmac 20 len Vhi 6 |
| 64 | tvhash 3 |
| 65 | for i ulong len Vhi |
| 66 | tvcheck eq get Tcbuf i get Vhi i 7 |
| 67 | end |
| 68 | for i ulong 4 |
| 69 | put Tckey i get Vjefe i |
| 70 | end |
| 71 | tvcheck tchmac 4 0 8 |
| 72 | for i ulong len Vwhat |
| 73 | put Tcbuf i get Vwhat i |
| 74 | end |
| 75 | tvcheck tchmac 4 len Vwhat 9 |
| 76 | tvhash 4 |
| 77 | for i ulong 20 |
| 78 | put Tckey i 170 |
| 79 | end |
| 80 | for i ulong 50 |
| 81 | put Tcbuf i 221 |
| 82 | end |
| 83 | tvcheck tchmac 20 50 10 |
| 84 | tvhash 5 |
| 85 | for i ulong 25 |
| 86 | put Tckey i uchar add i 1 |
| 87 | end |
| 88 | for i ulong 50 |
| 89 | put Tcbuf i 205 |
| 90 | end |
| 91 | tvcheck tchmac 25 50 11 |
| 92 | tvhash 6 |
| 93 | tvcheck not tchmac 33 50 12 |
| 94 | tvcheck not tchmac 32 65537 12 |
| 95 | tvcheck not tchmac 18446744073709551615 0 12 |
| 96 | for i ulong 32 |
| 97 | tvcheck eq get Tcdigest i 0 13 |
| 98 | end |
| 99 | tvcheck eq get Tcbuf 0 205 13 |
| 100 | tvscrub |
| 101 | end |
| 102 | |
| 103 | fn tvhkdf empty bool to void |
| 104 | tvwipe |
| 105 | for i ulong 22 |
| 106 | put Tcbuf i 11 |
| 107 | end |
| 108 | n = ulong 13 |
| 109 | z = ulong 10 |
| 110 | slot = ulong 7 |
| 111 | base = ulong 0 |
| 112 | if empty |
| 113 | n = 0 |
| 114 | z = 0 |
| 115 | slot = 8 |
| 116 | base = 84 |
| 117 | else |
| 118 | for i ulong 13 |
| 119 | put Tckey i uchar i |
| 120 | end |
| 121 | end |
| 122 | tvcheck tchmac n 22 14 |
| 123 | tvhash slot |
| 124 | for i ulong 32 |
| 125 | put Tckey i get Tcdigest i |
| 126 | end |
| 127 | for i ulong z |
| 128 | put Tcbuf i uchar add i 240 |
| 129 | end |
| 130 | put Tcbuf z 1 |
| 131 | tvcheck tchmac 32 add z 1 15 |
| 132 | for i ulong 32 |
| 133 | p = add base mul i 2 |
| 134 | v = tvbyte get Vokm p get Vokm add p 1 |
| 135 | tvcheck eq get Tcdigest i v 16 |
| 136 | put Tcbuf i get Tcdigest i |
| 137 | end |
| 138 | for i ulong z |
| 139 | put Tcbuf add i 32 uchar add i 240 |
| 140 | end |
| 141 | put Tcbuf add z 32 2 |
| 142 | tvcheck tchmac 32 add z 33 17 |
| 143 | for i ulong 10 |
| 144 | p = add add base 64 mul i 2 |
| 145 | v = tvbyte get Vokm p get Vokm add p 1 |
| 146 | tvcheck eq get Tcdigest i v 18 |
| 147 | end |
| 148 | tvscrub |
| 149 | end |
| 150 | |
| 151 | fn main to int |
| 152 | tvsha |
| 153 | tvhmac |
| 154 | tvhkdf false |
| 155 | tvhkdf true |
| 156 | tvwipe |
| 157 | ret 0 |
| 158 | end |