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 / build / tlsbuild.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/build/tlsbuild.om: Pure seeded-Omega TLS 1.3 Builder & FIPS Integrity Coordinator. |
| 3 | note Replaces om/tls/build.sh completely. Zero shell. |
| 4 | note Build: cat seed/build/common.om seed/build/tlsbuild.om | seed/out/omc > build/om-tlsbuild |
| 5 | note Usage: |
| 6 | note om-tlsbuild OMC PROGRAM.om OUT |
| 7 | note om-tlsbuild -p OMC BIN (integrity stamp only) |
| 8 | |
| 9 | text tb_usage "usage: om-tlsbuild OMC PROGRAM.om OUT | om-tlsbuild -p OMC BIN\n" |
| 10 | text tb_fp "-p" |
| 11 | text tb_om2 "om2\n" |
| 12 | text tb_dir "om/tls/" |
| 13 | text tb_env_dir "OMTLS_DIR" |
| 14 | text tb_env_run "OMTLS_RUN" |
| 15 | text tb_u01 "sha2.om" |
| 16 | text tb_u02 "hkdf.om" |
| 17 | text tb_u03 "drbg.om" |
| 18 | text tb_u04 "x25519.om" |
| 19 | text tb_u05 "sha3.om" |
| 20 | text tb_u06 "mlkem.om" |
| 21 | text tb_u07 "chacha.om" |
| 22 | text tb_u08 "aesgcm.om" |
| 23 | text tb_u09 "ec.om" |
| 24 | text tb_u10 "ecdh.om" |
| 25 | text tb_u11 "rsa.om" |
| 26 | text tb_u12 "x509.om" |
| 27 | text tb_u13 "rev.om" |
| 28 | text tb_u14 "fips.om" |
| 29 | text tb_u15 "tls.om" |
| 30 | text tb_itmain "fn main to int\nret fips_itool\nend\n" |
| 31 | text tb_sunit ".unit.om" |
| 32 | text tb_stmp ".tmp" |
| 33 | text tb_sitom ".itool.om" |
| 34 | text tb_sit ".itool" |
| 35 | text tb_eio "tlsbuild: I/O error\n" |
| 36 | text tb_eint "tlsbuild: integrity step failed (exit " |
| 37 | text tb_eend ")\n" |
| 38 | |
| 39 | global tb_omc uchar 4096 |
| 40 | global tb_omcl ulong 1 |
| 41 | global tb_arg2 uchar 4096 |
| 42 | global tb_arg2l ulong 1 |
| 43 | global tb_out uchar 4096 |
| 44 | global tb_outl ulong 1 |
| 45 | global tb_dirb uchar 4096 |
| 46 | global tb_dirl ulong 1 |
| 47 | global tb_run uchar 4096 |
| 48 | global tb_runl ulong 1 |
| 49 | |
| 50 | fn tb_init_env to void |
| 51 | if cb_getenv tb_env_dir |
| 52 | n = get cb_n 4 |
| 53 | if gt n 0 |
| 54 | for i ulong n bound 4095 |
| 55 | put tb_dirb i get cb_pb i |
| 56 | end |
| 57 | if ne get tb_dirb sub n 1 47 |
| 58 | put tb_dirb n 47 |
| 59 | n = add n 1 |
| 60 | end |
| 61 | put tb_dirl 0 n |
| 62 | end |
| 63 | end |
| 64 | if eq get tb_dirl 0 0 |
| 65 | m = len tb_dir |
| 66 | for i ulong m bound 4096 |
| 67 | put tb_dirb i get tb_dir i |
| 68 | end |
| 69 | put tb_dirl 0 m |
| 70 | end |
| 71 | put tb_runl 0 0 |
| 72 | if cb_getenv tb_env_run |
| 73 | rn = get cb_n 4 |
| 74 | if gt rn 0 |
| 75 | for i ulong rn bound 4096 |
| 76 | put tb_run i get cb_pb i |
| 77 | end |
| 78 | put tb_runl 0 rn |
| 79 | end |
| 80 | end |
| 81 | end |
| 82 | |
| 83 | fn tb_app_unit u view uchar * to bool |
| 84 | cb_pa_clr |
| 85 | for i ulong get tb_dirl 0 bound 4096 |
| 86 | cb_pa_ch get tb_dirb i |
| 87 | end |
| 88 | cb_pa_tx u |
| 89 | ret cb_append_pa_to_wb |
| 90 | end |
| 91 | |
| 92 | fn tb_append_all_units to bool |
| 93 | if not tb_app_unit tb_u01 |
| 94 | ret false |
| 95 | end |
| 96 | if not tb_app_unit tb_u02 |
| 97 | ret false |
| 98 | end |
| 99 | if not tb_app_unit tb_u03 |
| 100 | ret false |
| 101 | end |
| 102 | if not tb_app_unit tb_u04 |
| 103 | ret false |
| 104 | end |
| 105 | if not tb_app_unit tb_u05 |
| 106 | ret false |
| 107 | end |
| 108 | if not tb_app_unit tb_u06 |
| 109 | ret false |
| 110 | end |
| 111 | if not tb_app_unit tb_u07 |
| 112 | ret false |
| 113 | end |
| 114 | if not tb_app_unit tb_u08 |
| 115 | ret false |
| 116 | end |
| 117 | if not tb_app_unit tb_u09 |
| 118 | ret false |
| 119 | end |
| 120 | if not tb_app_unit tb_u10 |
| 121 | ret false |
| 122 | end |
| 123 | if not tb_app_unit tb_u11 |
| 124 | ret false |
| 125 | end |
| 126 | if not tb_app_unit tb_u12 |
| 127 | ret false |
| 128 | end |
| 129 | if not tb_app_unit tb_u13 |
| 130 | ret false |
| 131 | end |
| 132 | if not tb_app_unit tb_u14 |
| 133 | ret false |
| 134 | end |
| 135 | ret tb_app_unit tb_u15 |
| 136 | end |
| 137 | |
| 138 | fn tb_set_pa_out suf view uchar * to void |
| 139 | cb_pa_clr |
| 140 | n = get tb_outl 0 |
| 141 | for i ulong n bound 4096 |
| 142 | cb_pa_ch get tb_out i |
| 143 | end |
| 144 | cb_pa_tx suf |
| 145 | end |
| 146 | |
| 147 | fn tb_set_pb_out suf view uchar * to void |
| 148 | cb_pb_clr |
| 149 | n = get tb_outl 0 |
| 150 | for i ulong n bound 4096 |
| 151 | cb_pb_ch get tb_out i |
| 152 | end |
| 153 | cb_pb_tx suf |
| 154 | end |
| 155 | |
| 156 | fn tb_set_pc_omc to ulong |
| 157 | n = get tb_omcl 0 |
| 158 | for i ulong n bound 4096 |
| 159 | put cb_pc i get tb_omc i |
| 160 | end |
| 161 | ret n |
| 162 | end |
| 163 | |
| 164 | fn tb_integ bin_is_tmp bool to ulong |
| 165 | cb_wb_clr |
| 166 | cb_wb_tx tb_om2 |
| 167 | if not tb_append_all_units |
| 168 | cb_err tb_eio |
| 169 | ret 3 |
| 170 | end |
| 171 | cb_wb_tx tb_itmain |
| 172 | tb_set_pa_out tb_sitom |
| 173 | if not cb_write_wb_pa 420 |
| 174 | cb_err tb_eio |
| 175 | ret 3 |
| 176 | end |
| 177 | omcl = tb_set_pc_omc |
| 178 | tb_set_pa_out tb_sitom |
| 179 | tb_set_pb_out tb_sit |
| 180 | rc = cb_run_omc omcl 493 -1 |
| 181 | if ne rc 0 |
| 182 | tb_set_pa_out tb_sitom |
| 183 | z0 = unlink cb_pa 0 get cb_n 3 |
| 184 | tb_set_pa_out tb_sit |
| 185 | z1 = unlink cb_pa 0 get cb_n 3 |
| 186 | ret rc |
| 187 | end |
| 188 | cb_av_clr |
| 189 | if gt get tb_runl 0 0 |
| 190 | cb_pa_clr |
| 191 | for i ulong get tb_runl 0 bound 4096 |
| 192 | cb_pa_ch get tb_run i |
| 193 | end |
| 194 | cb_av_push_pa |
| 195 | end |
| 196 | tb_set_pa_out tb_sit |
| 197 | cb_av_push_pa |
| 198 | if bin_is_tmp |
| 199 | tb_set_pa_out tb_stmp |
| 200 | else |
| 201 | cb_pa_clr |
| 202 | for i ulong get tb_outl 0 bound 4096 |
| 203 | cb_pa_ch get tb_out i |
| 204 | end |
| 205 | end |
| 206 | cb_av_push_pa |
| 207 | rc = cb_spawn_fds -1 -1 -1 false |
| 208 | tb_set_pa_out tb_sitom |
| 209 | z2 = unlink cb_pa 0 get cb_n 3 |
| 210 | tb_set_pa_out tb_sit |
| 211 | z3 = unlink cb_pa 0 get cb_n 3 |
| 212 | if ne rc 0 |
| 213 | cb_err tb_eint |
| 214 | cb_wnum 2 rc |
| 215 | cb_err tb_eend |
| 216 | end |
| 217 | ret rc |
| 218 | end |
| 219 | |
| 220 | fn main to int |
| 221 | tb_init_env |
| 222 | ac = argcnt |
| 223 | if ne ac 4 |
| 224 | cb_err tb_usage |
| 225 | ret 2 |
| 226 | end |
| 227 | if not cb_pa_arg 1 |
| 228 | cb_err tb_usage |
| 229 | ret 2 |
| 230 | end |
| 231 | if cb_pa_eq tb_fp |
| 232 | note -p OMC BIN |
| 233 | if not cb_pa_arg 2 |
| 234 | cb_err tb_usage |
| 235 | ret 2 |
| 236 | end |
| 237 | for i ulong get cb_n 3 bound 4096 |
| 238 | put tb_omc i get cb_pa i |
| 239 | end |
| 240 | put tb_omcl 0 get cb_n 3 |
| 241 | if not cb_pa_arg 3 |
| 242 | cb_err tb_usage |
| 243 | ret 2 |
| 244 | end |
| 245 | for i ulong get cb_n 3 bound 4096 |
| 246 | put tb_out i get cb_pa i |
| 247 | end |
| 248 | put tb_outl 0 get cb_n 3 |
| 249 | ret int tb_integ false |
| 250 | end |
| 251 | note OMC PROGRAM.om OUT |
| 252 | for i ulong get cb_n 3 bound 4096 |
| 253 | put tb_omc i get cb_pa i |
| 254 | end |
| 255 | put tb_omcl 0 get cb_n 3 |
| 256 | if not cb_pa_arg 2 |
| 257 | cb_err tb_usage |
| 258 | ret 2 |
| 259 | end |
| 260 | for i ulong get cb_n 3 bound 4096 |
| 261 | put tb_arg2 i get cb_pa i |
| 262 | end |
| 263 | put tb_arg2l 0 get cb_n 3 |
| 264 | if not cb_pa_arg 3 |
| 265 | cb_err tb_usage |
| 266 | ret 2 |
| 267 | end |
| 268 | for i ulong get cb_n 3 bound 4096 |
| 269 | put tb_out i get cb_pa i |
| 270 | end |
| 271 | put tb_outl 0 get cb_n 3 |
| 272 | |
| 273 | cb_wb_clr |
| 274 | cb_wb_tx tb_om2 |
| 275 | if not tb_append_all_units |
| 276 | cb_err tb_eio |
| 277 | ret 3 |
| 278 | end |
| 279 | cb_pa_clr |
| 280 | for i ulong get tb_arg2l 0 bound 4096 |
| 281 | cb_pa_ch get tb_arg2 i |
| 282 | end |
| 283 | if not cb_append_pa_to_wb |
| 284 | cb_err tb_eio |
| 285 | ret 3 |
| 286 | end |
| 287 | tb_set_pa_out tb_sunit |
| 288 | if not cb_write_wb_pa 420 |
| 289 | cb_err tb_eio |
| 290 | ret 3 |
| 291 | end |
| 292 | cb_pa_clr |
| 293 | for i ulong get tb_outl 0 bound 4096 |
| 294 | cb_pa_ch get tb_out i |
| 295 | end |
| 296 | z0 = unlink cb_pa 0 get cb_n 3 |
| 297 | omcl = tb_set_pc_omc |
| 298 | tb_set_pa_out tb_sunit |
| 299 | tb_set_pb_out tb_stmp |
| 300 | rc = cb_run_omc omcl 493 -1 |
| 301 | if ne rc 0 |
| 302 | tb_set_pa_out tb_stmp |
| 303 | z1 = unlink cb_pa 0 get cb_n 3 |
| 304 | ret int rc |
| 305 | end |
| 306 | irc = tb_integ true |
| 307 | if ne irc 0 |
| 308 | tb_set_pa_out tb_stmp |
| 309 | z2 = unlink cb_pa 0 get cb_n 3 |
| 310 | ret int irc |
| 311 | end |
| 312 | tb_set_pa_out tb_stmp |
| 313 | cb_pb_clr |
| 314 | for i ulong get tb_outl 0 bound 4096 |
| 315 | cb_pb_ch get tb_out i |
| 316 | end |
| 317 | if not cb_rename_pa_pb |
| 318 | cb_err tb_eio |
| 319 | ret 3 |
| 320 | end |
| 321 | ret 0 |
| 322 | end |