Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/allen/tls.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / allen / tls.om` 1303 lines ยท 18959 bytes Raw Blame History 1 note RFC8446 bounded TLS1.3 client: api.github.com, X25519, 1303, CV0403. 2 note Concatenate tls-crypto.om and tls-cert.om before this file. No platform I/O. 3 note tlsinput(n): NEW bytes in Tlsin[0..n); internal residual retained; Tlsinlen becomes0. 4 note tlswrite(n)->bool: atomic acceptance, n<=16384; false means retain plaintext. 5 note tlssent acknowledges the ENTIRE output queue, then pumps deferred work. 6 note Tlsstate:0 lifecycle idle0 handshake1 open2 closed3 error4;1 error;2 peer close_notify. 7 note Errors:1 API bounds,2 capacity,3 crypto,4 record overflow,5 unexpected record, 8 note 6 bad MAC,7 malformed,8 unsupported,9 transcript cap,10 certificate,11 CV, 9 note 12 Finished,13 sequence limit,14 peer alert,15 HRR unsupported,16 key boundary, 10 note 17 KeyUpdate unsupported,18 absent time. Fatal/reset discards and wipes all queues. 11 note Limits: handshake and transcript65536, ciphertext16640, record plaintext16384, 12 note receive residual65536, app262144, epoch2^32-1 records. No tickets used or early data. 13 global Tlsin uchar 65536 14 global Tlsout uchar 65536 15 global Tlsplain uchar 65536 16 global Tlsapp uchar 262144 17 global Tlsrand uchar 64 18 global Tlsinlen ulong 1 19 global Tlsoutn ulong 1 20 global Tlsappn ulong 1 21 global Tlsstate ulong 8 22 global Tsrecv uchar 65536 23 global Tshand uchar 65536 24 global Tstrans uchar 65536 25 global Tsmsg uchar 1024 26 global Tssec uchar 192 27 global Tskey uchar 128 28 global Tsiv uchar 48 29 global Tshash uchar 32 30 global Tslbl uchar 16 31 global Tsseen uchar 8192 32 global Tsseq ulong 2 33 note Tsctl:0 recvlen,1 handlen,2 transcriptlen,3 localclose requested, 34 note 4 localclose queued,5 peerclose,6 phase,7 msglen,8 labellen,9 validated epoch time. 35 note phase0 SH,1 EE,2 Certificate,3 CV,4 Finished,5 application,6 client Finished pending. 36 global Tsctl ulong 10 37 text Tshost "api.github.com" 38 text Tsalpn "http/1.1" 39 text Tsprefix "tls13 " 40 text Tsderiv "derived" 41 text Tschs "c hs traffic" 42 text Tsshs "s hs traffic" 43 text Tscap "c ap traffic" 44 text Tssap "s ap traffic" 45 text Tsklab "key" 46 text Tsvlab "iv" 47 text Tsflab "finished" 48 text Tscvctx "TLS 1.3, server CertificateVerify" 49 text Tshrr "`cf21ad74e59a6111be1d8c021e65b891c2a211167abb8c5e079e09e2c8a8339c`" 50 fn tshex c uchar to uchar 51 if le c 57 52 ret sub c 48 53 end 54 ret sub c 87 55 end 56 fn tswipe to void 57 for i ulong 192 58 put Tssec i 0 59 end 60 for i ulong 128 61 put Tskey i 0 62 end 63 for i ulong 48 64 put Tsiv i 0 65 end 66 for i ulong 32 67 put Tshash i 0 68 end 69 for i ulong 16 70 put Tslbl i 0 71 end 72 for i ulong 2 73 put Tsseq i 0 74 end 75 tcwipe 76 certreset 77 end 78 fn tsclear to void 79 tswipe 80 for i ulong 65536 81 put Tlsin i 0 82 put Tlsout i 0 83 put Tlsplain i 0 84 put Tsrecv i 0 85 put Tshand i 0 86 put Tstrans i 0 87 end 88 for i ulong 262144 89 put Tlsapp i 0 90 end 91 for i ulong 1024 92 put Tsmsg i 0 93 end 94 for i ulong 8192 95 put Tsseen i 0 96 end 97 for i ulong 10 98 put Tsctl i 0 99 end 100 for i ulong 8 101 put Tlsstate i 0 102 end 103 put Tlsinlen 0 0 104 put Tlsoutn 0 0 105 put Tlsappn 0 0 106 end 107 fn tsfail code ulong to void 108 tsclear 109 for i ulong 64 110 put Tlsrand i 0 111 end 112 put Tlsstate 0 4 113 put Tlsstate 1 code 114 end 115 fn tsh16 p ulong to ulong 116 ret add shl ulong get Tshand p 8 ulong get Tshand add p 1 117 end 118 fn tsh24 p ulong to ulong 119 ret add shl ulong get Tshand p 16 tsh16 add p 1 120 end 121 fn tsput c uchar to void 122 p = get Tsctl 7 123 put Tsmsg p c 124 put Tsctl 7 add p 1 125 end 126 fn tsu16 x ulong to void 127 tsput uchar and shr x 8 255 128 tsput uchar and x 255 129 end 130 fn tsu24 x ulong to void 131 tsput uchar and shr x 16 255 132 tsu16 and x 65535 133 end 134 fn tshashdo to bool 135 n = get Tsctl 2 136 for i ulong n 137 put Tcbuf i get Tstrans i 138 end 139 if not tcsha n 140 ret false 141 end 142 for i ulong 32 143 put Tshash i get Tcdigest i 144 end 145 ret true 146 end 147 fn tsempty to bool 148 if not tcsha 0 149 ret false 150 end 151 for i ulong 32 152 put Tshash i get Tcdigest i 153 end 154 ret true 155 end 156 fn tssave p ulong to void 157 for i ulong 32 158 put Tssec add p i get Tcdigest i 159 end 160 end 161 fn tslab which ulong to void 162 put Tsctl 8 0 163 if eq which 0 164 for i ulong len Tsderiv 165 put Tslbl i get Tsderiv i 166 end 167 put Tsctl 8 len Tsderiv 168 end 169 if eq which 1 170 for i ulong len Tschs 171 put Tslbl i get Tschs i 172 end 173 put Tsctl 8 len Tschs 174 end 175 if eq which 2 176 for i ulong len Tsshs 177 put Tslbl i get Tsshs i 178 end 179 put Tsctl 8 len Tsshs 180 end 181 if eq which 3 182 for i ulong len Tscap 183 put Tslbl i get Tscap i 184 end 185 put Tsctl 8 len Tscap 186 end 187 if eq which 4 188 for i ulong len Tssap 189 put Tslbl i get Tssap i 190 end 191 put Tsctl 8 len Tssap 192 end 193 if eq which 5 194 for i ulong len Tsklab 195 put Tslbl i get Tsklab i 196 end 197 put Tsctl 8 len Tsklab 198 end 199 if eq which 6 200 for i ulong len Tsvlab 201 put Tslbl i get Tsvlab i 202 end 203 put Tsctl 8 len Tsvlab 204 end 205 if eq which 7 206 for i ulong len Tsflab 207 put Tslbl i get Tsflab i 208 end 209 put Tsctl 8 len Tsflab 210 end 211 end 212 note All expansions <=Hash.length, so RFC5869 has exactly one block T(1). 213 fn tsexpand which ulong secat ulong ctx bool olen ulong to bool 214 if or eq olen 0 gt olen 32 215 ret false 216 end 217 tslab which 218 n = get Tsctl 8 219 if eq n 0 220 ret false 221 end 222 for i ulong 32 223 put Tckey i get Tssec add secat i 224 end 225 put Tcbuf 0 0 226 put Tcbuf 1 uchar olen 227 put Tcbuf 2 uchar add n 6 228 for i ulong 6 229 put Tcbuf add i 3 get Tsprefix i 230 end 231 for i ulong n 232 put Tcbuf add i 9 get Tslbl i 233 end 234 p = add n 9 235 put Tcbuf p 0 236 if ctx 237 put Tcbuf p 32 238 p = add p 1 239 for i ulong 32 240 put Tcbuf add p i get Tshash i 241 end 242 p = add p 32 243 else 244 p = add p 1 245 end 246 put Tcbuf p 1 247 ret tchmac 32 add p 1 248 end 249 fn tstraff secat ulong keyat ulong ivat ulong to bool 250 if not tsexpand 5 secat false 32 251 ret false 252 end 253 for i ulong 32 254 put Tskey add keyat i get Tcdigest i 255 end 256 if not tsexpand 6 secat false 12 257 ret false 258 end 259 for i ulong 12 260 put Tsiv add ivat i get Tcdigest i 261 end 262 ret true 263 end 264 fn tshkeys to bool 265 note HKDF-Extract(zeros32,zeros32), then Derive-Secret early derived Hash(empty). 266 for i ulong 32 267 put Tckey i 0 268 put Tcbuf i 0 269 end 270 if not tchmac 32 32 271 ret false 272 end 273 tssave 0 274 if not tsempty 275 ret false 276 end 277 if not tsexpand 0 0 true 32 278 ret false 279 end 280 for i ulong 32 281 put Tckey i get Tcdigest i 282 put Tcbuf i get Tcxshare i 283 end 284 if not tchmac 32 32 285 ret false 286 end 287 tssave 0 288 if not tshashdo 289 ret false 290 end 291 if not tsexpand 1 0 true 32 292 ret false 293 end 294 tssave 32 295 if not tsexpand 2 0 true 32 296 ret false 297 end 298 tssave 64 299 if not tstraff 32 0 0 300 ret false 301 end 302 if not tstraff 64 32 12 303 ret false 304 end 305 if not tsempty 306 ret false 307 end 308 if not tsexpand 0 0 true 32 309 ret false 310 end 311 for i ulong 32 312 put Tckey i get Tcdigest i 313 put Tcbuf i 0 314 end 315 if not tchmac 32 32 316 ret false 317 end 318 tssave 96 319 for i ulong 32 320 put Tssec i 0 321 put Tcxpriv i 0 322 put Tcxshare i 0 323 end 324 put Tsseq 0 0 325 put Tsseq 1 0 326 ret true 327 end 328 fn tsakeys to bool 329 if not tshashdo 330 ret false 331 end 332 if not tsexpand 3 96 true 32 333 ret false 334 end 335 tssave 128 336 if not tsexpand 4 96 true 32 337 ret false 338 end 339 tssave 160 340 if not tstraff 128 64 24 341 ret false 342 end 343 if not tstraff 160 96 36 344 ret false 345 end 346 for i ulong 32 347 put Tssec add i 96 0 348 end 349 put Tsseq 1 0 350 ret true 351 end 352 fn tsfinmac secat ulong to bool 353 if not tshashdo 354 ret false 355 end 356 if not tsexpand 7 secat false 32 357 ret false 358 end 359 for i ulong 32 360 put Tckey i get Tcdigest i 361 put Tcbuf i get Tshash i 362 end 363 ret tchmac 32 32 364 end 365 fn tsnonce keyat ulong ivat ulong seq ulong to void 366 for i ulong 32 367 put Tckey i get Tskey add keyat i 368 end 369 for i ulong 12 370 put Tciv i get Tsiv add ivat i 371 end 372 for i ulong 8 373 p = sub ulong 11 i 374 b = uchar and shr seq mul i 8 255 375 put Tciv p xor get Tciv p b 376 end 377 end 378 note Tcbuf contains plaintext before tsseal; queue is published only after authentication. 379 fn tsseal n ulong typ uchar epoch ulong to bool 380 if ne get Tlsoutn 0 0 381 ret false 382 end 383 if gt n 16384 384 ret false 385 end 386 s = get Tsseq 0 387 if ge s `4294967295` 388 ret false 389 end 390 tsnonce mul epoch 64 mul epoch 24 s 391 put Tcbuf n typ 392 put Tcaad 0 23 393 put Tcaad 1 3 394 put Tcaad 2 3 395 put Tcaad 3 uchar shr add n 17 8 396 put Tcaad 4 uchar and add n 17 255 397 if not tcseal add n 1 5 398 ret false 399 end 400 for i ulong 5 401 put Tlsout i get Tcaad i 402 end 403 for i ulong add n 1 404 put Tlsout add i 5 get Tcbuf i 405 end 406 for i ulong 16 407 put Tlsout add add n 6 i get Tctag i 408 end 409 put Tlsoutn 0 add n 22 410 put Tsseq 0 add s 1 411 ret true 412 end 413 fn tstradd n ulong to bool 414 p = get Tsctl 2 415 if gt n sub ulong 65536 p 416 ret false 417 end 418 for i ulong n 419 put Tstrans add p i get Tshand i 420 end 421 put Tsctl 2 add p n 422 ret true 423 end 424 fn tsseen0 to void 425 for i ulong 8192 426 put Tsseen i 0 427 end 428 end 429 fn tsunique typ ulong to bool 430 p = div typ 8 431 b = uchar shl ulong 1 rem typ 8 432 if ne and get Tsseen p b 0 433 ret false 434 end 435 put Tsseen p or get Tsseen p b 436 ret true 437 end 438 fn tsshare p ulong n ulong to bool 439 if ne n 36 440 ret false 441 end 442 if or ne tsh16 p 29 ne tsh16 add p 2 32 443 ret false 444 end 445 for i ulong 32 446 put Tcxpeer i get Tshand add add p 4 i 447 end 448 ret true 449 end 450 fn tssh n ulong to bool 451 if lt n 44 452 ret false 453 end 454 if ne tsh16 4 771 455 ret false 456 end 457 note Exact HRR random is refused; never interpreted as an ordinary random. 458 d = uchar 0 459 for i ulong 32 460 b = add shl tshex get Tshrr mul i 2 4 tshex get Tshrr add mul i 2 1 461 d = or d xor get Tshand add i 6 b 462 end 463 if eq d 0 464 tsfail 15 465 ret false 466 end 467 if ne get Tshand 38 0 468 ret false 469 end 470 if or ne tsh16 39 4867 ne get Tshand 41 0 471 ret false 472 end 473 if ne tsh16 42 sub n 44 474 ret false 475 end 476 tsseen0 477 p = ulong 44 478 flags = ulong 0 479 while lt p n bound 16384 480 if lt sub n p 4 481 ret false 482 end 483 t = tsh16 p 484 z = tsh16 add p 2 485 p = add p 4 486 if gt z sub n p 487 ret false 488 end 489 if not tsunique t 490 ret false 491 end 492 if eq t 43 493 if ne z 2 494 ret false 495 end 496 if ne tsh16 p 772 497 ret false 498 end 499 flags = or flags 1 500 else 501 if eq t 51 502 if not tsshare p z 503 ret false 504 end 505 flags = or flags 2 506 else 507 ret false 508 end 509 end 510 p = add p z 511 end 512 ret eq flags 3 513 end 514 fn tsext p ulong z ulong typ ulong to bool 515 if eq typ 0 516 ret eq z 0 517 end 518 if eq typ 16 519 if ne z 11 520 ret false 521 end 522 if or ne tsh16 p 9 ne get Tshand add p 2 8 523 ret false 524 end 525 for i ulong 8 526 if ne get Tshand add add p 3 i get Tsalpn i 527 ret false 528 end 529 end 530 ret true 531 end 532 if eq typ 10 533 if lt z 4 534 ret false 535 end 536 if or ne rem z 2 0 ne tsh16 p sub z 2 537 ret false 538 end 539 ret true 540 end 541 ret false 542 end 543 fn tsee n ulong to bool 544 if lt n 6 545 ret false 546 end 547 if ne tsh16 4 sub n 6 548 ret false 549 end 550 tsseen0 551 p = ulong 6 552 while lt p n bound 16384 553 if lt sub n p 4 554 ret false 555 end 556 t = tsh16 p 557 z = tsh16 add p 2 558 p = add p 4 559 if gt z sub n p 560 ret false 561 end 562 if not tsunique t 563 ret false 564 end 565 if not tsext p z t 566 ret false 567 end 568 p = add p z 569 end 570 ret true 571 end 572 fn tscert n ulong to bool 573 z = sub n 4 574 for i ulong z 575 put Certbuf i get Tshand add i 4 576 end 577 put Certlen 0 z 578 note Cert owner may reset its state; supply this session's time immediately before checking. 579 put Certnow 0 get Tsctl 9 580 ret certcheck 581 end 582 fn tscv n ulong to bool 583 if lt n 8 584 ret false 585 end 586 if ne tsh16 4 1027 587 ret false 588 end 589 z = tsh16 6 590 if or gt z 128 ne z sub n 8 591 ret false 592 end 593 if not tshashdo 594 ret false 595 end 596 for i ulong 64 597 put Certmsg i 32 598 end 599 for i ulong len Tscvctx 600 put Certmsg add i 64 get Tscvctx i 601 end 602 p = add ulong 64 len Tscvctx 603 put Certmsg p 0 604 p = add p 1 605 for i ulong 32 606 put Certmsg add p i get Tshash i 607 end 608 for i ulong z 609 put Certsig i get Tshand add i 8 610 end 611 ret certsig add p 32 z 612 end 613 note NewSessionTicket syntax is checked, including duplicate extensions; nothing is retained. 614 fn tsticket n ulong to bool 615 if lt n 17 616 ret false 617 end 618 life = add shl tsh16 4 16 tsh16 6 619 if gt life 604800 620 ret false 621 end 622 p = add ulong 13 ulong get Tshand 12 623 if gt p n 624 ret false 625 end 626 if lt sub n p 2 627 ret false 628 end 629 z = tsh16 p 630 p = add p 2 631 if or eq z 0 gt z sub n p 632 ret false 633 end 634 p = add p z 635 if lt sub n p 2 636 ret false 637 end 638 z = tsh16 p 639 p = add p 2 640 if ne z sub n p 641 ret false 642 end 643 tsseen0 644 while lt p n bound 16384 645 if lt sub n p 4 646 ret false 647 end 648 t = tsh16 p 649 z = tsh16 add p 2 650 p = add p 4 651 if gt z sub n p 652 ret false 653 end 654 if not tsunique t 655 ret false 656 end 657 if and eq t 42 ne z 4 658 ret false 659 end 660 p = add p z 661 end 662 ret true 663 end 664 fn tsfinish n ulong to bool 665 if ne n 36 666 ret false 667 end 668 if not tsfinmac 64 669 ret false 670 end 671 d = uchar 0 672 for i ulong 32 673 d = or d xor get Tcdigest i get Tshand add i 4 674 end 675 ret eq d 0 676 end 677 fn tshmsg n ulong to void 678 p = get Tsctl 6 679 t = get Tshand 0 680 if eq p 5 681 if eq t 4 682 if not tsticket n 683 tsfail 7 684 end 685 ret 686 end 687 if eq t 24 688 tsfail 17 689 ret 690 end 691 tsfail 8 692 ret 693 end 694 if eq p 0 695 if ne t 2 696 tsfail 8 697 ret 698 end 699 if not tssh n 700 if ne get Tlsstate 0 4 701 tsfail 7 702 end 703 ret 704 end 705 if not tcx25519 706 tsfail 3 707 ret 708 end 709 d = uchar 0 710 for i ulong 32 711 d = or d get Tcxshare i 712 end 713 if eq d 0 714 tsfail 3 715 ret 716 end 717 else 718 if eq p 1 719 if ne t 8 720 tsfail 8 721 ret 722 end 723 if not tsee n 724 tsfail 7 725 ret 726 end 727 else 728 if eq p 2 729 if ne t 11 730 tsfail 8 731 ret 732 end 733 if not tscert n 734 tsfail 10 735 ret 736 end 737 else 738 if eq p 3 739 if ne t 15 740 tsfail 8 741 ret 742 end 743 if not tscv n 744 tsfail 11 745 ret 746 end 747 else 748 if ne t 20 749 tsfail 8 750 ret 751 end 752 if not tsfinish n 753 tsfail 12 754 ret 755 end 756 end 757 end 758 end 759 end 760 if not tstradd n 761 tsfail 9 762 ret 763 end 764 if eq p 0 765 if not tshkeys 766 tsfail 3 767 ret 768 end 769 end 770 if eq p 4 771 if not tsakeys 772 tsfail 3 773 ret 774 end 775 put Tsctl 6 6 776 else 777 put Tsctl 6 add p 1 778 end 779 end 780 fn tshfeed n ulong to void 781 if eq n 0 782 tsfail 5 783 ret 784 end 785 p = get Tsctl 1 786 if gt n sub ulong 65536 p 787 tsfail 2 788 ret 789 end 790 for i ulong n 791 put Tshand add p i get Tcbuf i 792 end 793 put Tsctl 1 add p n 794 while ge get Tsctl 1 4 bound 16384 795 z = add ulong 4 tsh24 1 796 if gt z 65536 797 tsfail 2 798 ret 799 end 800 p = get Tsctl 1 801 if gt z p 802 ret 803 end 804 t = get Tshand 0 805 if or or eq t 2 eq t 20 eq t 24 806 if ne z p 807 tsfail 16 808 ret 809 end 810 end 811 tshmsg z 812 if eq get Tlsstate 0 4 813 ret 814 end 815 p = sub p z 816 for i ulong p 817 put Tshand i get Tshand add i z 818 end 819 for i ulong z 820 put Tshand add p i 0 821 end 822 put Tsctl 1 p 823 end 824 end 825 fn tsalert n ulong secure bool to void 826 if ne n 2 827 tsfail 7 828 ret 829 end 830 if ne get Tsctl 1 0 831 tsfail 16 832 ret 833 end 834 if or eq get Tcbuf 0 0 gt get Tcbuf 0 2 835 tsfail 7 836 ret 837 end 838 if eq get Tcbuf 1 0 839 if or not secure ne get Tsctl 6 5 840 tsfail 5 841 ret 842 end 843 put Tsctl 5 1 844 put Tsctl 3 1 845 put Tlsstate 0 3 846 put Tlsstate 2 1 847 ret 848 end 849 a = ulong get Tcbuf 1 850 tsfail 14 851 put Tlsstate 3 a 852 end 853 fn tsinner n ulong to void 854 while gt n 0 bound 16640 855 if ne get Tcbuf sub n 1 0 856 break 857 end 858 n = sub n 1 859 end 860 if eq n 0 861 tsfail 5 862 ret 863 end 864 n = sub n 1 865 t = get Tcbuf n 866 if gt n 16384 867 tsfail 4 868 ret 869 end 870 if eq t 22 871 tshfeed n 872 ret 873 end 874 if eq t 21 875 tsalert n true 876 ret 877 end 878 if ne t 23 879 tsfail 5 880 ret 881 end 882 if or ne get Tsctl 6 5 ne get Tsctl 1 0 883 tsfail 5 884 ret 885 end 886 if ne get Tsctl 5 0 887 tsfail 5 888 ret 889 end 890 p = get Tlsappn 0 891 if gt n sub ulong 262144 p 892 tsfail 2 893 ret 894 end 895 for i ulong n 896 put Tlsapp add p i get Tcbuf i 897 end 898 put Tlsappn 0 add p n 899 end 900 fn tsopen n ulong to void 901 if lt n 17 902 tsfail 7 903 ret 904 end 905 if eq get Tsctl 6 0 906 tsfail 5 907 ret 908 end 909 s = get Tsseq 1 910 if ge s `4294967295` 911 tsfail 13 912 ret 913 end 914 epoch = ulong 0 915 if eq get Tsctl 6 5 916 epoch = 1 917 end 918 tsnonce add ulong 32 mul epoch 64 add ulong 12 mul epoch 24 s 919 for i ulong 5 920 put Tcaad i get Tsrecv i 921 end 922 n = sub n 16 923 for i ulong n 924 put Tcbuf i get Tsrecv add i 5 925 end 926 for i ulong 16 927 put Tctag i get Tsrecv add add i n 5 928 end 929 if not tcopen n 5 930 tsfail 6 931 ret 932 end 933 put Tsseq 1 add s 1 934 tsinner n 935 end 936 fn tsrecord n ulong to void 937 t = get Tsrecv 0 938 if eq t 20 939 if or ne n 1 ne get Tsrecv 5 1 940 tsfail 5 941 ret 942 end 943 if or ne get Tlsstate 0 1 ne get Tsctl 1 0 944 tsfail 5 945 ret 946 end 947 if eq get Tsctl 6 6 948 tsfail 5 949 end 950 ret 951 end 952 if eq t 23 953 if or ne get Tsrecv 1 3 ne get Tsrecv 2 3 954 tsfail 7 955 ret 956 end 957 tsopen n 958 ret 959 end 960 if ne get Tsctl 6 0 961 tsfail 5 962 ret 963 end 964 for i ulong n 965 put Tcbuf i get Tsrecv add i 5 966 end 967 if eq t 22 968 tshfeed n 969 ret 970 end 971 if eq t 21 972 tsalert n false 973 ret 974 end 975 tsfail 5 976 end 977 fn tssendf to void 978 if not tsfinmac 32 979 tsfail 3 980 ret 981 end 982 put Tsmsg 0 20 983 put Tsmsg 1 0 984 put Tsmsg 2 0 985 put Tsmsg 3 32 986 for i ulong 32 987 put Tsmsg add i 4 get Tcdigest i 988 end 989 for i ulong 36 990 put Tcbuf i get Tsmsg i 991 end 992 if not tsseal 36 22 0 993 tsfail 3 994 ret 995 end 996 note No resumption/exporter: discard transcript and handshake secrets after client Finished. 997 for i ulong 192 998 put Tssec i 0 999 end 1000 for i ulong 64 1001 put Tskey i 0 1002 end 1003 for i ulong 24 1004 put Tsiv i 0 1005 end 1006 for i ulong 65536 1007 put Tstrans i 0 1008 end 1009 put Tsctl 2 0 1010 put Tsseq 0 0 1011 put Tsctl 6 5 1012 put Tlsstate 0 2 1013 tcwipe 1014 certreset 1015 end 1016 fn tsclosing to void 1017 if eq get Tsctl 3 0 1018 ret 1019 end 1020 if ne get Tsctl 4 0 1021 if ne get Tsctl 5 0 1022 tswipe 1023 end 1024 ret 1025 end 1026 if ne get Tlsoutn 0 0 1027 ret 1028 end 1029 put Tcbuf 0 1 1030 put Tcbuf 1 0 1031 if not tsseal 2 21 1 1032 tsfail 3 1033 ret 1034 end 1035 put Tsctl 4 1 1036 put Tlsstate 0 3 1037 if ne get Tsctl 5 0 1038 tswipe 1039 end 1040 end 1041 fn tspump to void 1042 if or eq get Tlsstate 0 0 eq get Tlsstate 0 4 1043 ret 1044 end 1045 if eq get Tsctl 6 6 1046 if ne get Tlsoutn 0 0 1047 ret 1048 end 1049 tssendf 1050 if eq get Tlsstate 0 4 1051 ret 1052 end 1053 end 1054 while ge get Tsctl 0 5 bound 13108 1055 if ne get Tsctl 5 0 1056 break 1057 end 1058 n = add shl ulong get Tsrecv 3 8 ulong get Tsrecv 4 1059 lim = ulong 16384 1060 if eq get Tsrecv 0 23 1061 lim = 16640 1062 end 1063 if gt n lim 1064 tsfail 4 1065 ret 1066 end 1067 z = add n 5 1068 if gt z get Tsctl 0 1069 break 1070 end 1071 tsrecord n 1072 if eq get Tlsstate 0 4 1073 ret 1074 end 1075 p = sub get Tsctl 0 z 1076 for i ulong p 1077 put Tsrecv i get Tsrecv add i z 1078 end 1079 for i ulong z 1080 put Tsrecv add p i 0 1081 end 1082 put Tsctl 0 p 1083 if eq get Tsctl 6 6 1084 if ne get Tlsoutn 0 0 1085 ret 1086 end 1087 tssendf 1088 if eq get Tlsstate 0 4 1089 ret 1090 end 1091 end 1092 end 1093 if ne get Tsctl 5 0 1094 for i ulong get Tsctl 0 1095 put Tsrecv i 0 1096 end 1097 put Tsctl 0 0 1098 end 1099 if eq get Tsctl 6 5 1100 tsclosing 1101 end 1102 end 1103 fn tlsinput n ulong to void 1104 if gt n 65536 1105 tsfail 1 1106 ret 1107 end 1108 if or eq get Tlsstate 0 0 eq get Tlsstate 0 4 1109 ret 1110 end 1111 if ne get Tsctl 5 0 1112 for i ulong n 1113 put Tlsin i 0 1114 end 1115 put Tlsinlen 0 0 1116 ret 1117 end 1118 p = get Tsctl 0 1119 if gt n sub ulong 65536 p 1120 tsfail 2 1121 ret 1122 end 1123 for i ulong n 1124 put Tsrecv add p i get Tlsin i 1125 put Tlsin i 0 1126 end 1127 put Tsctl 0 add p n 1128 put Tlsinlen 0 0 1129 tspump 1130 end 1131 fn tlssent to void 1132 n = get Tlsoutn 0 1133 for i ulong n 1134 put Tlsout i 0 1135 end 1136 put Tlsoutn 0 0 1137 tspump 1138 end 1139 fn tlswrite n ulong to bool 1140 if or ne get Tlsstate 0 2 ne get Tsctl 3 0 1141 ret false 1142 end 1143 if ne get Tlsoutn 0 0 1144 ret false 1145 end 1146 if gt n 16384 1147 ret false 1148 end 1149 if ge get Tsseq 0 `4294967295` 1150 tsfail 13 1151 ret false 1152 end 1153 for i ulong n 1154 put Tcbuf i get Tlsplain i 1155 end 1156 if not tsseal n 23 1 1157 tsfail 3 1158 ret false 1159 end 1160 for i ulong n 1161 put Tlsplain i 0 1162 end 1163 tcwipe 1164 ret true 1165 end 1166 fn tlsconsume n ulong to void 1167 p = get Tlsappn 0 1168 if gt n p 1169 tsfail 1 1170 ret 1171 end 1172 p = sub p n 1173 for i ulong p 1174 put Tlsapp i get Tlsapp add i n 1175 end 1176 for i ulong n 1177 put Tlsapp add p i 0 1178 end 1179 put Tlsappn 0 p 1180 end 1181 fn tlsclose to void 1182 if or eq get Tlsstate 0 0 eq get Tlsstate 0 4 1183 ret 1184 end 1185 if eq get Tlsstate 0 1 1186 tsclear 1187 for i ulong 64 1188 put Tlsrand i 0 1189 end 1190 put Tlsstate 0 3 1191 ret 1192 end 1193 put Tsctl 3 1 1194 tsclosing 1195 end 1196 fn tshello to void 1197 put Tsctl 7 0 1198 tsput 1 1199 tsu24 0 1200 tsu16 771 1201 for i ulong 32 1202 tsput get Tlsrand i 1203 end 1204 tsput 0 1205 tsu16 2 1206 tsu16 4867 1207 tsput 1 1208 tsput 0 1209 note Extension total patched after serializing exact offered values. 1210 tsu16 0 1211 tsu16 0 1212 tsu16 add ulong 5 len Tshost 1213 tsu16 add ulong 3 len Tshost 1214 tsput 0 1215 tsu16 len Tshost 1216 for i ulong len Tshost 1217 tsput get Tshost i 1218 end 1219 tsu16 43 1220 tsu16 3 1221 tsput 2 1222 tsu16 772 1223 tsu16 10 1224 tsu16 4 1225 tsu16 2 1226 tsu16 29 1227 tsu16 13 1228 tsu16 4 1229 tsu16 2 1230 tsu16 1027 1231 tsu16 50 1232 tsu16 6 1233 tsu16 4 1234 tsu16 1027 1235 tsu16 1283 1236 tsu16 51 1237 tsu16 38 1238 tsu16 36 1239 tsu16 29 1240 tsu16 32 1241 for i ulong 32 1242 tsput get Tcxpub i 1243 end 1244 tsu16 16 1245 tsu16 11 1246 tsu16 9 1247 tsput 8 1248 for i ulong 8 1249 tsput get Tsalpn i 1250 end 1251 n = get Tsctl 7 1252 put Tsmsg 1 uchar and shr sub n 4 16 255 1253 put Tsmsg 2 uchar and shr sub n 4 8 255 1254 put Tsmsg 3 uchar and sub n 4 255 1255 put Tsmsg 45 uchar shr sub n 47 8 1256 put Tsmsg 46 uchar and sub n 47 255 1257 for i ulong n 1258 put Tstrans i get Tsmsg i 1259 put Tlsout add i 5 get Tsmsg i 1260 end 1261 put Tsctl 2 n 1262 put Tlsout 0 22 1263 put Tlsout 1 3 1264 put Tlsout 2 1 1265 put Tlsout 3 uchar shr n 8 1266 put Tlsout 4 uchar and n 255 1267 put Tlsoutn 0 add n 5 1268 end 1269 fn tlsinit now ulong to void 1270 note Parent supplies FRESH secure Tlsrand before every init; reset preserves only this input. 1271 tsclear 1272 if eq now 0 1273 tsfail 18 1274 ret 1275 end 1276 z1 = true 1277 z2 = true 1278 for i ulong 32 1279 if ne get Tlsrand i 0 1280 z1 = false 1281 end 1282 if ne get Tlsrand add i 32 0 1283 z2 = false 1284 end 1285 end 1286 if or z1 z2 1287 tsfail 3 1288 ret 1289 end 1290 put Tsctl 9 now 1291 for i ulong 32 1292 put Tcxpriv i get Tlsrand add i 32 1293 end 1294 if not tcxpublic 1295 tsfail 3 1296 ret 1297 end 1298 tshello 1299 for i ulong 64 1300 put Tlsrand i 0 1301 end 1302 put Tlsstate 0 1 1303 end