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-x25519.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | note RFC7748 sections5.2/6.1 official scalar/u/public/shared vectors. |
| 3 | note https://www.rfc-editor.org/rfc/rfc7748 ; attribution/license in tls-crypto-fixture.om. |
| 4 | note Negative/metamorphic cases exercise specified clamping, top-bit masking, noncanonical input, |
| 5 | note small-order rejection, preserved input buffers, and cleared internal scalar/field scratch. |
| 6 | text Vs "a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac44b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb" |
| 7 | text Vu "e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4ce5210f12786811d3f4b7959d0538ae2c31dbe7106fc03c3efc4cd549c715a4938520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6ade9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f" |
| 8 | text Vx "c3da55379de9c6908e94ea4df28d084f32eccf03491c71f754b4075577a2855295cbde9476e8907d7aade45cb4b873f88b595a68799fa152e6f8f7647aac79574a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742422c8e7a6227d7bca1350b3e2bb7279f7897b87bb6854b783c60e80311ae3079" |
| 9 | |
| 10 | fn tvxload slot ulong peer ulong to void |
| 11 | for i ulong 32 |
| 12 | p = add mul slot 64 mul i 2 |
| 13 | put Tcxpriv i tvbyte get Vs p get Vs add p 1 |
| 14 | p = add mul peer 64 mul i 2 |
| 15 | put Tcxpeer i tvbyte get Vu p get Vu add p 1 |
| 16 | end |
| 17 | end |
| 18 | |
| 19 | fn tvxwant slot ulong to void |
| 20 | for i ulong 32 |
| 21 | p = add mul slot 64 mul i 2 |
| 22 | v = tvbyte get Vx p get Vx add p 1 |
| 23 | tvcheck eq get Tcxshare i v 10 |
| 24 | end |
| 25 | tvscrub |
| 26 | end |
| 27 | |
| 28 | fn tvxpub slot ulong to void |
| 29 | for i ulong 32 |
| 30 | p = add mul slot 64 mul i 2 |
| 31 | v = tvbyte get Vu p get Vu add p 1 |
| 32 | tvcheck eq get Tcxpub i v 11 |
| 33 | p = add mul slot 64 mul i 2 |
| 34 | v = tvbyte get Vs p get Vs add p 1 |
| 35 | tvcheck eq get Tcxpriv i v 12 |
| 36 | end |
| 37 | tvscrub |
| 38 | end |
| 39 | |
| 40 | fn tvxzero to void |
| 41 | tvcheck not tcx25519 20 |
| 42 | for i ulong 32 |
| 43 | tvcheck eq get Tcxshare i 0 21 |
| 44 | end |
| 45 | tvscrub |
| 46 | end |
| 47 | |
| 48 | fn main to int |
| 49 | tcwipe |
| 50 | tvxload 0 0 |
| 51 | tvcheck tcx25519 1 |
| 52 | tvxwant 0 |
| 53 | put Tcxpeer 31 xor get Tcxpeer 31 128 |
| 54 | tvcheck tcx25519 2 |
| 55 | tvxwant 0 |
| 56 | put Tcxpriv 0 xor get Tcxpriv 0 7 |
| 57 | put Tcxpriv 31 xor get Tcxpriv 31 192 |
| 58 | tvcheck tcx25519 3 |
| 59 | tvxwant 0 |
| 60 | tvxload 1 1 |
| 61 | tvcheck tcx25519 4 |
| 62 | tvxwant 1 |
| 63 | tvxload 2 3 |
| 64 | tvcheck tcxpublic 5 |
| 65 | tvxpub 2 |
| 66 | tvcheck tcx25519 6 |
| 67 | tvxwant 2 |
| 68 | tvxload 3 2 |
| 69 | tvcheck tcxpublic 7 |
| 70 | tvxpub 3 |
| 71 | tvcheck tcx25519 8 |
| 72 | tvxwant 2 |
| 73 | for i ulong 32 |
| 74 | put Tcxpeer i 0 |
| 75 | end |
| 76 | tvxzero |
| 77 | put Tcxpeer 0 1 |
| 78 | tvxzero |
| 79 | note p and p+1 are noncanonical encodings of small-order u=0 and u=1. |
| 80 | for i ulong 32 |
| 81 | put Tcxpeer i 255 |
| 82 | end |
| 83 | put Tcxpeer 31 127 |
| 84 | put Tcxpeer 0 237 |
| 85 | tvxzero |
| 86 | put Tcxpeer 0 238 |
| 87 | tvxzero |
| 88 | note p+9 is a valid noncanonical encoding of the base point u=9. |
| 89 | put Tcxpeer 0 246 |
| 90 | tvcheck tcx25519 22 |
| 91 | for i ulong 32 |
| 92 | tvcheck eq get Tcxshare i get Tcxpub i 23 |
| 93 | end |
| 94 | tcwipe |
| 95 | put Tcxpriv 0 9 |
| 96 | put Tcxpeer 0 9 |
| 97 | tvcheck tcx25519 24 |
| 98 | tvxwant 3 |
| 99 | tcwipe |
| 100 | tvscrub |
| 101 | for i ulong 32 |
| 102 | tvcheck eq get Tcxshare i 0 25 |
| 103 | tvcheck eq get Tcxpriv i 0 25 |
| 104 | end |
| 105 | ret 0 |
| 106 | end |