1 ; **************************************************************************** 2 ; passwd386.s (passwd2.s) - by Erdogan Tan - 30/04/2022 3 ; ---------------------------------------------------------------------------- 4 ; Retro UNIX 386 v1.2 - passwd - change user's password 5 ; 6 ; [ Last Modification: 01/05/2022 ] 7 ; 8 ; Derived from (original) UNIX v5 'passwd.s' source Code 9 ; Ref: 10 ; www.tuhs.org (https://minnie.tuhs.org) 11 ; v5root.tar.gz 12 ; **************************************************************************** 13 ; [ usr/source/s2/passwd.s (archive date: 27-11-1974) ] 14 15 ; passwd0.s - Retro UNIX 8086 v1 (16 bit version of 'passwd1.s') 16 ; passwd1.s - Retro UNIX 386 v1 & v1.1 (unix v1 inode structure) 17 ; passwd2.s - Retro UNIX 386 v1.2 (& v2) (modified unix v7 inode) 18 19 ; UNIX v1 system calls 20 _rele equ 0 21 _exit equ 1 22 _fork equ 2 23 _read equ 3 24 _write equ 4 25 _open equ 5 26 _close equ 6 27 _wait equ 7 28 _creat equ 8 29 _link equ 9 30 _unlink equ 10 31 _exec equ 11 32 _chdir equ 12 33 _time equ 13 34 _mkdir equ 14 35 _chmod equ 15 36 _chown equ 16 37 _break equ 17 38 _stat equ 18 39 _seek equ 19 40 _tell equ 20 41 _mount equ 21 42 _umount equ 22 43 _setuid equ 23 44 _getuid equ 24 45 _stime equ 25 46 _quit equ 26 47 _intr equ 27 48 _fstat equ 28 49 _emt equ 29 50 _mdate equ 30 51 _stty equ 31 52 _gtty equ 32 53 _ilgins equ 33 54 _sleep equ 34 ; Retro UNIX 8086 v1 feature only ! 55 _msg equ 35 ; Retro UNIX 386 v1 feature only ! 56 57 ;;; 58 ESCKey equ 1Bh 59 EnterKey equ 0Dh 60 61 %macro sys 1-4 62 ; 03/09/2015 63 ; 13/04/2015 64 ; Retro UNIX 386 v1 system call. 65 %if %0 >= 2 66 mov ebx, %2 67 %if %0 >= 3 68 mov ecx, %3 69 %if %0 = 4 70 mov edx, %4 71 %endif 72 %endif 73 %endif 74 mov eax, %1 75 int 30h 76 %endmacro 77 78 ; Retro UNIX 386 v1 system call format: 79 ; sys systemcall (eax) , , 80 81 [BITS 32] ; 32-bit intructions (for 80386 protected mode) 82 83 [ORG 0] 84 85 START_CODE: 86 ; 01/05/2022 87 ; 30/04/2022 88 89 ;cmp (sp)+,$3 90 ;bge 1f 91 ;jsr r5,mesg 92 ; ; .even 93 ;sys exit 94 95 00000000 58 pop eax ; eax = number of arguments 96 97 ;cmp eax, 3 98 00000001 3C03 cmp al, 3 99 00000003 7311 jnb short pswd_1 100 101 00000005 B8[21040000] mov eax, usage_msg 102 0000000A E802020000 call print_msg 103 exit: 104 sys _exit 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 0000000F B801000000 <1> mov eax, %1 75 00000014 CD30 <1> int 30h 105 ;hang: 106 ; nop 107 ; jmp short hang 108 109 pswd_1: 110 ;1: 111 ;tst (sp)+ 112 ;mov (sp)+,uidp 113 ;mov (sp)+,r0 114 ;tstb (r0) 115 ;beq 1f 116 ;jsr pc,crypt 117 ;clrb 8(r0) 118 119 00000016 58 pop eax ; argument 0 - binary file name 120 121 00000017 8F05[C40F0000] pop dword [uidp] ; argument 1 - user id 122 0000001D 5E pop esi ; argument 2 - password 123 124 ; 01/05/2022 125 0000001E E810020000 call strlen 126 00000023 3C08 cmp al, 8 127 00000025 7733 ja short max_8_chars 128 129 00000027 E811020000 call crypt 130 ; esi = encyrpted password address 131 0000002C C6460800 mov byte [esi+8], 0 132 pswd_2: 133 ;1: 134 ;mov r0,cryptp 135 ;mov $passwf,r0 136 ;jsr r5,fopen; ibuf 137 ;bec 1f 138 ;jsr r5,mesg 139 ; ; .even 140 ;sys exit 141 142 00000030 8935[C00F0000] mov [cryptp], esi 143 144 sys _open, passwf, 0 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000036 BB[0B040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000003B B900000000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000040 B805000000 <1> mov eax, %1 75 00000045 CD30 <1> int 30h 145 00000047 7318 jnc short pswd_3 146 147 00000049 B8[40040000] mov eax, cant_open_msg 148 write_msg_and_exit: 149 0000004E E8BE010000 call print_msg 150 sys _exit 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000053 B801000000 <1> mov eax, %1 75 00000058 CD30 <1> int 30h 151 152 ;hangemhigh: 153 ; nop 154 ; jmp short hangemhigh 155 156 max_8_chars: 157 0000005A B8[04050000] mov eax, long_pswd_msg 158 0000005F EBED jmp short write_msg_and_exit 159 160 pswd_3: 161 ;1: 162 ; 30/04/2022 163 ;mov [ibuf], ax ; file descriptor 164 00000061 A3[B00B0000] mov [ibuf], eax ; file descriptor 165 pswd_4: 166 ;sys stat; tempf; obuf+20. 167 ;bec 2f 168 ;sys creat; tempf; 222 169 ;bec 1f 170 171 sys _stat, tempf, obuf+20 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000066 BB[17040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000006B B9[CC0D0000] <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000070 B812000000 <1> mov eax, %1 75 00000075 CD30 <1> int 30h 172 00000077 7313 jnc short pswd_5 173 174 ; set write permission only 175 ;;sys _creat, tempf, 101b ; unix v1 inode 176 ;sys _creat, tempf, 10010010b ; runix v2 inode 177 ; 01/05/2022 178 sys _creat, tempf, 110010010b ; runix v2 inode 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000079 BB[17040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000007E B992010000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000083 B808000000 <1> mov eax, %1 75 00000088 CD30 <1> int 30h 179 0000008A 7307 jnc short pswd_6 180 pswd_5: 181 ;2: 182 ;jsr r5,mesg 183 ; ; .even 184 ;sys exit 185 186 0000008C B8[5E040000] mov eax, tmpf_bsy_msg 187 00000091 EBBB jmp short write_msg_and_exit 188 189 pswd_6: 190 ;1: 191 ;mov r0,obuf 192 193 ;mov [obuf], ax ; file descriptor 194 00000093 A3[B80D0000] mov [obuf], eax ; file descriptor 195 196 ; / search for uid 197 198 comp: 199 ;mov uidp,r1 200 00000098 8B35[C40F0000] mov esi, [uidp] ; 01/05/2022 201 cmp_1: 202 ;1: 203 ;jsr pc,pcop 204 ;cmp r0,$': 205 ;beq 1f 206 ;cmpb r0,(r1)+ 207 ;beq 1b 208 209 0000009E E849010000 call pcop 210 000000A3 3C3A cmp al, ':' 211 000000A5 7417 je short cmp_3 212 000000A7 88C4 mov ah, al 213 000000A9 AC lodsb 214 000000AA 38E0 cmp al, ah 215 000000AC 74F0 je short cmp_1 216 cmp_2: 217 ;2: 218 ;jsr pc,pcop 219 ;cmp r0,$'\n 220 ;bne 2b 221 ;br comp 222 223 000000AE E839010000 call pcop 224 ; (skip remain bytes on row, get next line/row) 225 ; check cr byte of crlf (end of line chars) 226 000000B3 3C0D cmp al, EnterKey ; cmp al, 0Dh 227 000000B5 75F7 jne short cmp_2 228 ; get lf byte of crlf out 229 000000B7 E830010000 call pcop 230 000000BC EBDA jmp short comp ; next line 231 232 cmp_3: 233 ;1: 234 ;tstb (r1)+ 235 ;bne 2b 236 237 ; check end of uid input (match condition) 238 000000BE AC lodsb 239 000000BF 08C0 or al, al 240 000000C1 75EB jnz short cmp_2 ; uid is not same 241 ; skip remain bytes on line/row 242 243 ; uid (input) matches with uid in passwd file 244 245 ; / skip over old password 246 247 pswd_7: 248 ;1: 249 ;jsr pc,pget 250 ;cmp r0,$': 251 ;bne 1b 252 253 000000C3 E80D010000 call pget 254 000000C8 3C3A cmp al, ':' 255 000000CA 75F7 jne short pswd_7 256 257 ; / copy in new password 258 259 ;mov cryptp,r1 260 000000CC 8B35[C00F0000] mov esi, [cryptp] ; ptr to encyrpted passwd 261 pswd_8: 262 ;1: 263 ;movb (r1)+,r0 264 ;beq 1f 265 ;jsr pc,pput 266 ;br 1b 267 268 000000D2 AC lodsb 269 000000D3 20C0 and al, al 270 000000D5 7407 jz short pswd_9 271 000000D7 E8F4000000 call pput 272 000000DC EBF4 jmp short pswd_8 273 pswd_9: 274 ;1: 275 ;mov $':,r0 276 ;jsr pc,pput 277 278 000000DE B03A mov al, ':' 279 000000E0 E8EB000000 call pput 280 281 ; / validate permission 282 283 ;clr r1 284 000000E5 29C9 sub ecx, ecx ; 0 285 000000E7 BF0A000000 mov edi, 10 286 pswd_10: 287 ;1: 288 ;jsr pc,pcop 289 ;cmp r0,$': 290 ;beq 1f 291 ;mpy $10.,r1 292 ;sub $'0,r0 293 ;add r0,r1 294 ;br 1b 295 296 000000EC 51 push ecx 297 000000ED E8FA000000 call pcop 298 000000F2 59 pop ecx 299 ; (eax <= 255) 300 000000F3 3C3A cmp al, ':' 301 000000F5 740A je short pswd_11 302 000000F7 91 xchg eax, ecx 303 000000F8 F7E7 mul edi ; * 10 304 000000FA 80E930 sub cl, '0' 305 000000FD 01C1 add ecx, eax 306 000000FF EBEB jmp short pswd_10 307 308 pswd_11: 309 ;1: 310 ;sys getuid 311 ;tst r0 312 ;beq 1f 313 314 ; ecx = uid (as in passwd file) 315 316 sys _getuid 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000101 B818000000 <1> mov eax, %1 75 00000106 CD30 <1> int 30h 317 318 ;or al, al 319 ;;or ax, ax 320 00000108 09C0 or eax, eax 321 0000010A 7410 jz short pswd_12 ; root (superuser) 322 323 ;cmp r0,r1 324 ;beq 1f 325 326 ;cmp cl, al 327 ;;cmp cx, ax 328 0000010C 39C1 cmp ecx, eax 329 0000010E 740C je short pswd_12 330 331 ;jsr r5,mesg 332 ; ; .even 333 ;br done 334 335 00000110 B8[7E040000] mov eax, p_denied_msg 336 00000115 E8F7000000 call print_msg 337 0000011A EB0D jmp short done 338 339 pswd_12: 340 ;1: 341 ;inc sflg 342 343 ; set 1st stage (completed) flag 344 0000011C FE05[C80F0000] inc byte [sflg] ; 1st stage is ok 345 pswd_13: 346 ;1: 347 ;jsr pc,pcop 348 ;br 1b 349 350 00000122 E8C5000000 call pcop 351 352 ; pcop will return/jump to 'done' 353 ; after the last byte of (old) passwd file 354 ; (call return address will be discarded) 355 356 ; (but if there is a next byte to read/write 357 ; cpu will return here) 358 359 00000127 EBF9 jmp short pswd_13 ; r/w next byte 360 361 ; --------------------------- 362 363 done: 364 ;jsr r5,flush; obuf 365 ;mov obuf,r0 366 ;sys close 367 368 ;mov ebx, obuf 369 00000129 E885020000 call flush 370 ; (write buffer content to disk) 371 0000012E 0FB71D[B80D0000] movzx ebx, word [obuf] 372 sys _close ; (close output file) 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000135 B806000000 <1> mov eax, %1 75 0000013A CD30 <1> int 30h 373 374 ;mov ibuf,r0 375 ;sys close 376 377 ;movzx ebx, word [ibuf] 378 0000013C 668B1D[B00B0000] mov bx, [ibuf] 379 sys _close ; (close input file) 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000143 B806000000 <1> mov eax, %1 75 00000148 CD30 <1> int 30h 380 381 ;tst sflg 382 ;beq 1f 383 ;tst dflg 384 ;bne 1f 385 ;inc dflg 386 387 0000014A F605[C80F0000]FF test byte [sflg], 0FFh 388 00000151 7457 jz short done_4 ; 1st stage failed 389 ; unlink/remove tempf 390 ; 1st stage is ok 391 00000153 F605[C90F0000]FF test byte [dflg], 0FFh 392 0000015A 754E jnz short done_4 ; 2nd stage is ok (completed) 393 394 ; 2nd stage 395 ; (writing to tempf at 1st stage is ok) 396 0000015C FE05[C90F0000] inc byte [dflg] ; set 2nd stage flag 397 ; (open tempf for read and 398 ; write to new passwd file) 399 ;mov $tempf,r0 400 ;jsr r5,fopen; ibuf 401 ;bec 2f 402 403 sys _open, tempf, 0 ; open tempf for read 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000162 BB[17040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 00000167 B900000000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 0000016C B805000000 <1> mov eax, %1 75 00000171 CD30 <1> int 30h 404 00000173 730C jnc short done_1 405 406 ;jsr r5,mesg 407 ; ; .even 408 ;br 1f 409 410 00000175 B8[94040000] mov eax, cnro_tmpf_msg 411 0000017A E892000000 call print_msg 412 0000017F EB29 jmp short done_4 413 done_1: 414 ;2: 415 00000181 A3[B00B0000] mov [ibuf], eax 416 00000186 31C0 xor eax, eax ; 0 417 00000188 A3[B40B0000] mov [ibuf+4], eax 418 419 ;mov $passwf,r0 420 ;jsr r5,fcreat; obuf 421 ;bec 2f 422 423 ; retro unix v1 inode 424 ;sys _creat, passwf, 1100b ; rw-- 425 ; retro unix v2 inode 426 sys _creat, passwf, 110000000b ; rw------- 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 0000018D BB[0B040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 00000192 B980010000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000197 B808000000 <1> mov eax, %1 75 0000019C CD30 <1> int 30h 427 0000019E 731D jnc short done_2 428 429 ;jsr r5,mesg 430 ; ; .even 431 ;br 1f 432 433 000001A0 B8[B0040000] mov eax, cnro_pswdf_msg 434 000001A5 E867000000 call print_msg 435 ;jmp short done_4 436 437 done_4: 438 ;1: 439 ;sys unlink; tempf 440 ;sys exit 441 442 sys _unlink, tempf 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 000001AA BB[17040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 000001AF B80A000000 <1> mov eax, %1 75 000001B4 CD30 <1> int 30h 443 sys _exit 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 000001B6 B801000000 <1> mov eax, %1 75 000001BB CD30 <1> int 30h 444 445 done_2: 446 ;2: 447 ;jsr pc,pcop 448 ;br 2b 449 450 000001BD A3[B80D0000] mov [obuf], eax 451 000001C2 29C0 sub eax, eax ; 0 452 000001C4 A3[BC0D0000] mov [obuf+4], eax 453 done_3: ; 01/05/2022 454 000001C9 E81E000000 call pcop 455 000001CE EBF9 jmp short done_3 456 457 ;done_4: 458 ;;1: 459 ; ;sys unlink; tempf 460 ; ;sys exit 461 ; 462 ; sys _unlink, tempf 463 ; sys _exit 464 465 ; --------------------------- 466 467 pput: 468 ;jsr r5,putc; obuf 469 ;rts pc 470 471 ;mov ebx, obuf 472 ;call putc 473 ;retn 474 000001D0 E9C1010000 jmp putc 475 476 ; --------------------------- 477 478 pget: 479 ;jsr r5,getc; ibuf 480 ;bes 1f 481 ;rts pc 482 483 ;mov ebx, ibuf 484 000001D5 E87F010000 call getc 485 000001DA 7201 jc short pget_1 486 000001DC C3 retn 487 pget_1: 488 ;1: 489 ;jsr r5,mesg 490 ; ; .even 491 ;br done 492 493 000001DD B8[D0040000] mov eax, format_err_msg 494 000001E2 E82A000000 call print_msg 495 496 000001E7 E93DFFFFFF jmp done 497 498 ; --------------------------- 499 500 ; 30/04/2022 501 pcop: 502 ;jsr r5,getc; ibuf 503 ;bes 1f 504 ;jsr r5,putc; obuf 505 ;rts pc 506 507 ;mov ebx, ibuf 508 000001EC E868010000 call getc 509 000001F1 7205 jc short pcop_1 510 ;mov ebx, obuf 511 ;call putc 512 ;retn 513 000001F3 E99E010000 jmp putc 514 pcop_1: 515 ;1: 516 ;tst sflg 517 ;bne 1f 518 ;jsr r5,mesg 519 ; ; .even 520 521 000001F8 F605[C80F0000]FF test byte [sflg], 0FFh 522 000001FF 750A jnz short pcop_2 523 524 00000201 B8[F2040000] mov eax, not_valid_msg 525 00000206 E806000000 call print_msg 526 pcop_2: 527 ;1: 528 ;br done 529 0000020B 58 pop eax ; discard call return addr 530 0000020C E918FFFFFF jmp done 531 532 ; --------------------------- 533 534 print_msg: 535 ; 01/05/2022 536 ; 29/04/2022 537 ; Modified registers: eax, ebx, ecx, edx 538 539 00000211 E811000000 call _strlen ; 01/05/2022 540 print_str: 541 00000216 89DA mov edx, ebx 542 sys _write, 1, eax 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000218 BB01000000 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000021D 89C1 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 0000021F B804000000 <1> mov eax, %1 75 00000224 CD30 <1> int 30h 543 ; 544 00000226 C3 retn 545 546 ; 01/05/2022 547 ; 29/04/2022 548 _strlen: 549 ; eax = asciiz string address 550 00000227 89C3 mov ebx, eax 551 00000229 4B dec ebx 552 nextchr: 553 0000022A 43 inc ebx 554 0000022B 803B00 cmp byte [ebx], 0 555 0000022E 77FA ja short nextchr 556 ;cmp [ebx], 0Dh 557 ;ja short nextchr 558 00000230 29C3 sub ebx, eax 559 ; bx = asciiz string length 560 00000232 C3 retn 561 562 ; 01/05/2022 563 strlen: 564 00000233 89F0 mov eax, esi 565 00000235 E8EDFFFFFF call _strlen 566 0000023A 89D8 mov eax, ebx 567 0000023C C3 retn 568 569 ; --------------------------------------------------- 570 ; 30/04/2022 571 ; 'crypt' assembly source code 572 ; copied from: 'login386.s' (Erdogan Tan, 27/02/2022) 573 ; --------------------------------------------------- 574 575 ;/ crypt -- password incoding 576 ; 577 ;; Original Unix v5 (PDP-11) 'crypt' 578 ;; code has been converted to 579 ;; Retro UNIX 8086 v1 'crypt' 580 ;; procedure in 'login.asm' 581 ;; (by Erdogan Tan - 12/11/2013). 582 ; 583 ; 584 ;crypt: 585 ; mov r1,-(sp) 586 ; mov r2,-(sp) 587 ; mov r3,-(sp) 588 ; mov r4,-(sp) 589 ; mov r5,-(sp) 590 ; 591 ; mov r0,r1 592 ; mov $key,r0 593 ; movb $004,(r0)+ 594 ; movb $034,(r0)+ 595 596 ; 14/10/2015 - 32 bit version (Retro UNIX 386 v1) 597 598 crypt: 599 ; 30/04/2022 600 ; INPUT: 601 ; esi = password string address 602 ; OUTPUT: 603 ; esi = encyrpted password str address 604 ; 605 ; Modified registers: 606 ; eax, ebx, ecx, edx, esi, edi, ebp 607 608 ;mov esi, passwd 609 0000023D BF[24050000] mov edi, key 610 00000242 B004 mov al, 4 611 00000244 AA stosb 612 00000245 B01C mov al, 28 613 00000247 AA stosb 614 615 ;1: 616 ; cmp r0,$key+64. 617 ; bhis 1f 618 ; movb (r1)+,(r0)+ 619 ; bne 1b 620 ;1: 621 ; dec r0 622 623 cryp0: 624 00000248 AC lodsb 625 00000249 AA stosb 626 0000024A 20C0 and al, al 627 0000024C 7408 jz short cryp1 628 0000024E 81FF[64050000] cmp edi, key + 64 629 00000254 72F2 jb short cryp0 630 cryp1: 631 00000256 4F dec edi 632 ;/ 633 ;/ 634 ;/ fill out key space with clever junk 635 ;/ 636 ; mov $key,r1 637 ;1: 638 ; movb -1(r0),r2 639 ; movb (r1)+,r3 640 ; xor r3,r2 641 ; movb r2,(r0)+ 642 ; cmp r0,$key+128. 643 ; blo 1b 644 645 646 ;/ fill out key space with clever junk 647 648 00000257 BE[24050000] mov esi, key 649 cryp2: 650 0000025C 8A5FFF mov bl, [edi-1] 651 0000025F AC lodsb 652 00000260 30D8 xor al, bl 653 00000262 AA stosb 654 00000263 81FF[A4050000] cmp edi, key + 128 655 00000269 72F1 jb short cryp2 656 ; 657 ;/ 658 ;/ 659 ;/ establish wheel codes and cage codes 660 ;/ 661 ; mov $wheelcode,r4 662 ; mov $cagecode,r5 663 ; mov $256.,-(sp) 664 ;2: 665 ; clr r2 666 ; clr (r4) 667 ; mov $wheeldiv,r3 668 ;3: 669 ; clr r0 670 ; mov (sp),r1 671 ; div (r3)+,r0 672 ; add r1,r2 673 ; bic $40,r2 674 ; bis shift(r2),(r4) 675 ; cmp r3,$wheeldiv+6. 676 ; bhis 4f 677 ; bis shift+4(r2),(r5) 678 ;4: 679 ; cmp r3,$wheeldiv+10. 680 ; blo 3b 681 ; sub $2,(sp) 682 ; tst (r4)+ 683 ; tst (r5)+ 684 ; cmp r4,$wheelcode+256. 685 ; blo 2b 686 ; tst (sp)+ 687 ;/ 688 689 ;/ establish wheel codes and cage codes 690 691 0000026B BE[B0090000] mov esi, wheelcode 692 00000270 BF[B0070000] mov edi, cagecode 693 00000275 66B80001 mov ax, 256 694 00000279 6650 push ax ; * 695 0000027B 89E5 mov ebp, esp 696 cryp3: 697 0000027D 6629D2 sub dx, dx ; 0 698 00000280 668916 mov [esi], dx ; 0 699 00000283 BB[06040000] mov ebx, wheeldiv 700 cryp4: 701 00000288 668B4500 mov ax, [ebp] 702 0000028C 8A0B mov cl, [ebx] 703 0000028E F6F1 div cl 704 00000290 00E2 add dl, ah 705 00000292 43 inc ebx 706 00000293 80E21F and dl, 01Fh 707 00000296 53 push ebx 708 00000297 BB[E2030000] mov ebx, shift 709 0000029C 01D3 add ebx, edx 710 0000029E 668B03 mov ax, [ebx] 711 000002A1 660906 or [esi], ax 712 000002A4 59 pop ecx 713 000002A5 81F9[09040000] cmp ecx, wheeldiv + 3 714 000002AB 7309 jnb short cryp5 715 000002AD 83C304 add ebx, 4 716 000002B0 668B03 mov ax, [ebx] 717 000002B3 660907 or [edi], ax 718 cryp5: 719 000002B6 89CB mov ebx, ecx 720 000002B8 81FB[0B040000] cmp ebx, wheeldiv + 5 721 000002BE 72C8 jb short cryp4 722 000002C0 66836D0002 sub word [ebp], 2 723 000002C5 66AD lodsw 724 000002C7 47 inc edi 725 000002C8 47 inc edi 726 000002C9 81FE[B00A0000] cmp esi, wheelcode + 256 727 000002CF 72AC jb short cryp3 728 000002D1 6658 pop ax ; * 729 730 ; .data 731 ;shift: 1;2;4;10;20;40;100;200;400;1000;2000;4000;10000;20000;40000;100000 732 ; 1;2 733 ;wheeldiv: 32.; 18.; 10.; 6.; 4. 734 ; .bss 735 ;cagecode: .=.+256. 736 ;wheelcode: .=.+256. 737 ; .text 738 ;/ 739 ;/ 740 ;/ make the internal settings of the machine 741 ;/ both the lugs on the 128 cage bars and the lugs 742 ;/ on the 16 wheels are set from the expanded key 743 ;/ 744 ; mov $key,r0 745 ; mov $cage,r2 746 ; mov $wheel,r3 747 ;1: 748 ; movb (r0)+,r1 749 ; bic $!177,r1 750 ; asl r1 751 ; mov cagecode(r1),(r2)+ 752 ; mov wheelcode(r1),(r3)+ 753 ; cmp r0,$key+128. 754 ; blo 1b 755 756 ;/ make the internal settings of the machine 757 ;/ both the lugs on the 128 cage bars and the lugs 758 ;/ on the 16 wheels are set from the expanded key 759 cryp6: 760 000002D3 BB[24050000] mov ebx, key 761 000002D8 BE[B0050000] mov esi, cage 762 000002DD BF[B0060000] mov edi, wheel 763 cryp7: 764 000002E2 8A0B mov cl, [ebx] 765 000002E4 43 inc ebx 766 000002E5 83E17F and ecx, 7Fh 767 000002E8 D0E1 shl cl, 1 768 000002EA 87CB xchg ecx, ebx 769 000002EC 668B83[B0070000] mov ax, [ebx+cagecode] 770 000002F3 668906 mov [esi], ax 771 000002F6 46 inc esi 772 000002F7 46 inc esi 773 000002F8 668B83[B0090000] mov ax, [ebx+wheelcode] 774 000002FF 66AB stosw 775 00000301 89CB mov ebx, ecx 776 00000303 81FB[A4050000] cmp ebx, key + 128 777 00000309 72D7 jb short cryp7 778 ;/ 779 ;/ 780 ;/ now spin the cage against the wheel to produce output. 781 ;/ 782 ; mov $word,r4 783 ; mov $wheel+128.,r3 784 ;3: 785 ; mov -(r3),r2 786 ; mov $cage,r0 787 ; clr r5 788 ;1: 789 ; bit r2,(r0)+ 790 ; beq 2f 791 ; incb r5 792 ;2: 793 ; cmp r0,$cage+256. 794 ; blo 1b 795 796 ;/ 797 ;/ now spin the cage against the wheel to produce output. 798 ;/ 799 cryp8: 800 0000030B BF[A4050000] mov edi, _word 801 00000310 BB[30070000] mov ebx, wheel + 128 802 cryp9: 803 00000315 4B dec ebx 804 00000316 4B dec ebx 805 00000317 668B13 mov dx, [ebx] 806 0000031A BE[B0050000] mov esi, cage 807 0000031F 6629C9 sub cx, cx ; 0 808 cryp10: 809 00000322 66AD lodsw 810 00000324 6685D0 test ax, dx 811 00000327 7402 jz short cryp11 812 00000329 FEC1 inc cl 813 cryp11: 814 0000032B 81FE[B0060000] cmp esi, cage + 256 815 00000331 72EF jb short cryp10 816 817 ;/ 818 ;/ we have a piece of output from current wheel 819 ;/ it needs to be folded to remove lingering hopes of 820 ;/ inverting the function 821 ;/ 822 ; mov r4,-(sp) 823 ; clr r4 824 ; div $26.+26.+10.,r4 825 ; add $'0,r5 826 ; cmp r5,$'9 827 ; blos 1f 828 ; add $'A-'9-1,r5 829 ; cmp r5,$'Z 830 ; blos 1f 831 ; add $'a-'Z-1,r5 832 ;1: 833 ; mov (sp)+,r4 834 ; movb r5,(r4)+ 835 ; cmp r4,$word+8. 836 ; blo 3b 837 ;/ 838 ; 839 ; mov (sp)+,r5 840 ; mov (sp)+,r4 841 ; mov (sp)+,r3 842 ; mov (sp)+,r2 843 ; mov (sp)+,r1 844 ; mov $word,r0 845 ; rts pc 846 ; .bss 847 ;key: .=.+128. 848 ;word: .=.+32. 849 ;cage: .=.+256. 850 ;wheel: .=.+256. 851 852 ;/ 853 ;/ we have a piece of output from current wheel 854 ;/ it needs to be folded to remove lingering hopes of 855 ;/ inverting the function 856 ;/ 857 00000333 6689C8 mov ax, cx 858 00000336 B23E mov dl, 26+26+10 859 00000338 F6F2 div dl 860 0000033A 88E0 mov al, ah 861 0000033C 0430 add al, '0' 862 0000033E 3C39 cmp al, '9' 863 00000340 7608 jna short cryp12 864 00000342 0407 add al, 'A'-'9'-1 865 00000344 3C5A cmp al, 'Z' 866 00000346 7602 jna short cryp12 867 00000348 0406 add al, 'a'-'Z'-1 868 cryp12: 869 0000034A AA stosb 870 0000034B 81FF[AC050000] cmp edi, _word + 8 871 00000351 72C2 jb short cryp9 872 00000353 BE[A4050000] mov esi, _word 873 00000358 C3 retn 874 875 ; --------------------------------------------------- 876 ; 30/04/2022 877 ; 'getc' assembly source code 878 ; copied from: 'chown1.s' (Erdogan Tan, 30/04/2022) 879 ; (derived from unix v5 'get.s') 880 ; --------------------------------------------------- 881 882 getc: 883 ; 30/04/2022 884 ; 29/04/2022 885 886 ; INPUT: 887 ; ibuf = read buffer (header) address 888 ; OUTPUT: 889 ; al = character (if cf=0) 890 ; (if cf = 1 -> read error) 891 892 ; Modified registers: eax, ebx, ecx, edx, ebp 893 894 00000359 BD[B00B0000] mov ebp, ibuf 895 ;mov ax, [ebp+2] 896 0000035E 0FB74502 movzx eax, word [ebp+2] ; char count 897 ;and ax, ax 898 00000362 21C0 and eax, eax 899 00000364 751F jnz short gch1 900 gch0: 901 00000366 0FB75D00 movzx ebx, word [ebp] 902 0000036A B9[B80B0000] mov ecx, ibuf+8 ; read buff. (data) addr. 903 0000036F 894D04 mov [ebp+4], ecx ; char offset 904 ;mov [ebp+2], ax ; 0 905 00000372 29D2 sub edx, edx 906 00000374 B602 mov dh, 2 907 ;mov edx, 512 908 sys _read ; sys _read, ebx, ecx, edx 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000376 B803000000 <1> mov eax, %1 75 0000037B CD30 <1> int 30h 909 0000037D 7216 jc short gch2 910 0000037F 09C0 or eax, eax 911 ;jz short gch3 912 00000381 7502 jnz short gch1 913 ; 914 00000383 F9 stc 915 00000384 C3 retn 916 gch1: 917 ;dec ax 918 00000385 48 dec eax 919 00000386 66894502 mov [ebp+2], ax 920 0000038A 8B5D04 mov ebx, [ebp+4] 921 ;xor eax, eax 922 0000038D 30E4 xor ah, ah 923 0000038F 8A03 mov al, [ebx] 924 00000391 43 inc ebx 925 00000392 895D04 mov [ebp+4], ebx 926 ;;xor ah, ah 927 ;retn 928 gch2: 929 ;;xor ax, ax 930 ;xor eax, eax 931 00000395 C3 retn 932 ;gch3: 933 ;stc 934 ;retn 935 936 ; --------------------------------------------------- 937 ; 30/04/2022 (Erdogan Tan) 938 ; 'putc' assembly source code 939 ; (derived from unix v5 'put.s') 940 ; --------------------------------------------------- 941 942 putc: 943 ; 30/04/2022 944 ; 29/04/2022 945 946 ; INPUT: 947 ; al = character (to be written) 948 ; obuf = write buffer (header) address 949 ; OUTPUT: 950 ; al = character (if cf=0) 951 ; (if cf = 1 -> write error) 952 953 ; Modified registers: eax, ebx, ecx, edx, ebp 954 955 00000396 BD[B80D0000] mov ebp, obuf 956 pch0: 957 0000039B 66FF4D02 dec word [ebp+2] ; char count 958 0000039F 7D09 jge short pch1 959 000003A1 50 push eax 960 000003A2 E811000000 call _fl_ 961 000003A7 58 pop eax 962 000003A8 EBF1 jmp short pch0 963 pch1: 964 000003AA 8B5D04 mov ebx, [ebp+4] ; char offset 965 000003AD 8803 mov [ebx], al 966 ;inc ebx 967 ;mov [ebp+4], ebx 968 000003AF FF4504 inc dword [ebp+4] 969 000003B2 C3 retn 970 flush: 971 000003B3 BD[B80D0000] mov ebp, obuf 972 _fl_: 973 000003B8 89EA mov edx, ebp ; buffer header address 974 000003BA 83C208 add edx, 8 ; + 8 975 ; edx = buffer data address 976 000003BD 52 push edx 977 000003BE 8B4504 mov eax, [ebp+4] ; char offset 978 000003C1 09C0 or eax, eax 979 000003C3 7413 jz short pch2 ; empty/new buffer 980 000003C5 29D0 sub eax, edx ; char count 981 ; [ebp] = file descriptor 982 000003C7 0FB74D00 movzx ecx, word [ebp] 983 ;movzx ecx, byte [ebp] ; < 256 984 ; ; (<=10 for retro unix v1) 985 sys _write, ecx, edx, eax 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 000003CB 89CB <1> mov ebx, %2 67 <1> %if %0 >= 3 68 000003CD 89D1 <1> mov ecx, %3 69 <1> %if %0 = 4 70 000003CF 89C2 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 000003D1 B804000000 <1> mov eax, %1 75 000003D6 CD30 <1> int 30h 986 pch2: 987 000003D8 8F4504 pop dword [ebp+4]; character offset 988 000003DB 66C745020002 mov word [ebp+2], 512 989 ; available char count 990 ; to write in buffer 991 ; (before flushing) 992 000003E1 C3 retn 993 994 ;----------------------------------------------------------------- 995 ; data - initialized data 996 ;----------------------------------------------------------------- 997 998 ;align 4 999 1000 ; 30/04/2022 1001 1002 ; cryprt.s 1003 1004 000003E2 010002000400080010- shift: dw 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 1004 000003EB 002000400080000001- 1004 000003F4 0002 1005 000003F6 000400080010002000- dw 1024, 2048, 4096, 8192, 16384, 32768 1005 000003FF 400080 1006 00000402 01000200 dw 1, 2 1007 wheeldiv: 1008 00000406 20120A0604 db 32, 18, 10, 6, 4 1009 1010 ; passwd.s 1011 1012 0000040B 2F6574632F70617373- passwf: db "/etc/passwd", 0 ; password file 1012 00000414 776400 1013 00000417 2F746D702F70746D70- tempf: db "/tmp/ptmp", 0 ; temporary file 1013 00000420 00 1014 1015 usage_msg: 1016 00000421 0D0A db 0Dh, 0Ah 1017 00000423 55736167653A207061- db "Usage: passwd uid password", 0Dh, 0Ah, 0 1017 0000042C 737377642075696420- 1017 00000435 70617373776F72640D- 1017 0000043E 0A00 1018 cant_open_msg: 1019 00000440 0D0A db 0Dh, 0Ah 1020 00000442 63616E6E6F74206F70- db "cannot open password file", 0Dh, 0Ah, 0 1020 0000044B 656E2070617373776F- 1020 00000454 72642066696C650D0A- 1020 0000045D 00 1021 tmpf_bsy_msg: 1022 0000045E 0D0A db 0Dh, 0Ah 1023 00000460 74656D702066696C65- db "temp file busy -- try again", 0Dh, 0Ah, 0 1023 00000469 2062757379202D2D20- 1023 00000472 74727920616761696E- 1023 0000047B 0D0A00 1024 p_denied_msg: 1025 0000047E 0D0A db 0Dh, 0Ah 1026 00000480 7065726D697373696F- db "permission denied", 0Dh, 0Ah, 0 1026 00000489 6E2064656E6965640D- 1026 00000492 0A00 1027 cnro_tmpf_msg: 1028 00000494 0D0A db 0Dh, 0Ah 1029 00000496 63616E6E6F74207265- db "cannot reopen temp file", 0Dh, 0Ah, 0 1029 0000049F 6F70656E2074656D70- 1029 000004A8 2066696C650D0A00 1030 cnro_pswdf_msg: 1031 000004B0 0D0A db 0Dh, 0Ah 1032 000004B2 63616E6E6F74207265- db "cannot reopen password file", 0Dh, 0Ah, 0 1032 000004BB 6F70656E2070617373- 1032 000004C4 776F72642066696C65- 1032 000004CD 0D0A00 1033 format_err_msg: 1034 000004D0 0D0A db 0Dh, 0Ah 1035 000004D2 666F726D6174206572- db "format error on password file", 0Dh, 0Ah, 0 1035 000004DB 726F72206F6E207061- 1035 000004E4 7373776F7264206669- 1035 000004ED 6C650D0A00 1036 not_valid_msg: 1037 000004F2 0D0A db 0Dh, 0Ah 1038 000004F4 756964206E6F742076- db "uid not valid", 0Dh, 0Ah, 0 1038 000004FD 616C69640D0A00 1039 1040 ; 01/05/2022 1041 long_pswd_msg: 1042 00000504 0D0A db 0Dh, 0Ah 1043 00000506 70617373776F726420- db "password length > 8 chars", 0Dh, 0Ah, 0 1043 0000050F 6C656E677468203E20- 1043 00000518 382063686172730D0A- 1043 00000521 00 1044 1045 ;----------------------------------------------------------------- 1046 ; bss - uninitialized data 1047 ;----------------------------------------------------------------- 1048 1049 00000522 90 align 4 1050 1051 bss_start: 1052 1053 ABSOLUTE bss_start 1054 1055 ; 30/04/2022 1056 1057 ; crypt.s 1058 1059 00000524 key: resb 128 1060 ;_word: resb 32 1061 000005A4 _word: resb 10 1062 000005AE ???? resb 2 1063 000005B0 cage: resb 256 1064 000006B0 wheel: resb 256 1065 000007B0 cagecode: resw 256 ; resb 256 1066 000009B0 wheelcode: resw 256 ; resb 256 1067 1068 ; passwd.s 1069 1070 00000BB0 ibuf: resb 520 1071 00000DB8 obuf: resb 520 1072 00000FC0 ???? cryptp: resw 1 1073 00000FC2 ???? resw 1 ; 32 bit pointer for Retro UNIX 386 v1 1074 00000FC4 ???? uidp: resw 1 1075 00000FC6 ???? resw 1 ; 32 bit pointer for Retro UNIX 386 v1 1076 00000FC8 ?? sflg: resb 1 ; resw 1 1077 00000FC9 ?? dflg: resb 1 ; resw 1 1078 1079 ; 30/04/2022 1080 1081 ;----------------------------------------------------------------- 1082 ; Original UNIX v5 - /bin/passwd source code (passwd.s) 1083 ; in PDP-11 (unix) assembly language 1084 ;----------------------------------------------------------------- 1085 ; 1086 ;/ passwd -- change user's password 1087 ; 1088 ;.globl mesg 1089 ;.globl crypt 1090 ;.globl getc 1091 ;.globl flush 1092 ;.globl fcreat 1093 ;.globl putc 1094 ;.globl fopen 1095 ; 1096 ; cmp (sp)+,$3 1097 ; bge 1f 1098 ; jsr r5,mesg 1099 ; ; .even 1100 ; sys exit 1101 ;1: 1102 ; tst (sp)+ 1103 ; mov (sp)+,uidp 1104 ; mov (sp)+,r0 1105 ; tstb (r0) 1106 ; beq 1f 1107 ; jsr pc,crypt 1108 ; clrb 8(r0) 1109 ;1: 1110 ; mov r0,cryptp 1111 ; mov $passwf,r0 1112 ; jsr r5,fopen; ibuf 1113 ; bec 1f 1114 ; jsr r5,mesg 1115 ; ; .even 1116 ; sys exit 1117 ;1: 1118 ; sys stat; tempf; obuf+20. 1119 ; bec 2f 1120 ; sys creat; tempf; 222 1121 ; bec 1f 1122 ;2: 1123 ; jsr r5,mesg 1124 ; ; .even 1125 ; sys exit 1126 ;1: 1127 ; mov r0,obuf 1128 ; 1129 ;/ search for uid 1130 ; 1131 ;comp: 1132 ; mov uidp,r1 1133 ;1: 1134 ; jsr pc,pcop 1135 ; cmp r0,$': 1136 ; beq 1f 1137 ; cmpb r0,(r1)+ 1138 ; beq 1b 1139 ;2: 1140 ; jsr pc,pcop 1141 ; cmp r0,$'\n 1142 ; bne 2b 1143 ; br comp 1144 ;1: 1145 ; tstb (r1)+ 1146 ; bne 2b 1147 ; 1148 ;/ skip over old password 1149 ; 1150 ;1: 1151 ; jsr pc,pget 1152 ; cmp r0,$': 1153 ; bne 1b 1154 ; 1155 ;/ copy in new password 1156 ; 1157 ; mov cryptp,r1 1158 ;1: 1159 ; movb (r1)+,r0 1160 ; beq 1f 1161 ; jsr pc,pput 1162 ; br 1b 1163 ;1: 1164 ; mov $':,r0 1165 ; jsr pc,pput 1166 ; 1167 ;/ validate permission 1168 ; 1169 ; clr r1 1170 ;1: 1171 ; jsr pc,pcop 1172 ; cmp r0,$': 1173 ; beq 1f 1174 ; mpy $10.,r1 1175 ; sub $'0,r0 1176 ; add r0,r1 1177 ; br 1b 1178 ;1: 1179 ; sys getuid 1180 ; tst r0 1181 ; beq 1f 1182 ; cmp r0,r1 1183 ; beq 1f 1184 ; jsr r5,mesg 1185 ; ; .even 1186 ; br done 1187 ;1: 1188 ; inc sflg 1189 ;1: 1190 ; jsr pc,pcop 1191 ; br 1b 1192 ; 1193 ;done: 1194 ; jsr r5,flush; obuf 1195 ; mov obuf,r0 1196 ; sys close 1197 ; mov ibuf,r0 1198 ; sys close 1199 ; tst sflg 1200 ; beq 1f 1201 ; tst dflg 1202 ; bne 1f 1203 ; inc dflg 1204 ; mov $tempf,r0 1205 ; jsr r5,fopen; ibuf 1206 ; bec 2f 1207 ; jsr r5,mesg 1208 ; ; .even 1209 ; br 1f 1210 ;2: 1211 ; mov $passwf,r0 1212 ; jsr r5,fcreat; obuf 1213 ; bec 2f 1214 ; jsr r5,mesg 1215 ; ; .even 1216 ; br 1f 1217 ;2: 1218 ; jsr pc,pcop 1219 ; br 2b 1220 ;1: 1221 ; sys unlink; tempf 1222 ; sys exit 1223 ; 1224 ;pput: 1225 ; jsr r5,putc; obuf 1226 ; rts pc 1227 ; 1228 ;pget: 1229 ; jsr r5,getc; ibuf 1230 ; bes 1f 1231 ; rts pc 1232 ;1: 1233 ; jsr r5,mesg 1234 ; ; .even 1235 ; br done 1236 ; 1237 ;pcop: 1238 ; jsr r5,getc; ibuf 1239 ; bes 1f 1240 ; jsr r5,putc; obuf 1241 ; rts pc 1242 ;1: 1243 ; tst sflg 1244 ; bne 1f 1245 ; jsr r5,mesg 1246 ; ; .even 1247 ;1: 1248 ; br done 1249 ; 1250 ;.data 1251 ;passwf: 1252 ;tempf: 1253 ;.even 1254 ;.bss 1255 ;ibuf: .=.+520. 1256 ;obuf: .=.+520. 1257 ;cryptp: .=.+2 1258 ;uidp: .=.+2 1259 ;sflg: .=.+2 1260 ;dflg: .=.+2 1261 1262 ; 30/04/2022 1263 1264 ;----------------------------------------------------------------- 1265 ; Original UNIX v5 - 'crypt' source code (crypt.s) 1266 ; in PDP-11 (unix) assembly language 1267 ;----------------------------------------------------------------- 1268 ;/usr/source/s3/crypt.s -- password incoding 1269 ; 1270 ;/ crypt -- password incoding 1271 ; 1272 ;/ mov $key,r0 1273 ;/ jsr pc,crypt 1274 ; 1275 ;.globl crypt, word 1276 ; 1277 ;crypt: 1278 ; mov r1,-(sp) 1279 ; mov r2,-(sp) 1280 ; mov r3,-(sp) 1281 ; mov r4,-(sp) 1282 ; mov r5,-(sp) 1283 ; 1284 ; mov r0,r1 1285 ; mov $key,r0 1286 ; movb $004,(r0)+ 1287 ; movb $034,(r0)+ 1288 ;1: 1289 ; cmp r0,$key+64. 1290 ; bhis 1f 1291 ; movb (r1)+,(r0)+ 1292 ; bne 1b 1293 ;1: 1294 ; dec r0 1295 ;/ 1296 ;/ 1297 ;/ fill out key space with clever junk 1298 ;/ 1299 ; mov $key,r1 1300 ;1: 1301 ; movb -1(r0),r2 1302 ; movb (r1)+,r3 1303 ; xor r3,r2 1304 ; movb r2,(r0)+ 1305 ; cmp r0,$key+128. 1306 ; blo 1b 1307 ;/ 1308 ;/ 1309 ;/ establish wheel codes and cage codes 1310 ;/ 1311 ; mov $wheelcode,r4 1312 ; mov $cagecode,r5 1313 ; mov $256.,-(sp) 1314 ;2: 1315 ; clr r2 1316 ; clr (r4) 1317 ; mov $wheeldiv,r3 1318 ;3: 1319 ; clr r0 1320 ; mov (sp),r1 1321 ; div (r3)+,r0 1322 ; add r1,r2 1323 ; bic $40,r2 1324 ; bis shift(r2),(r4) 1325 ; cmp r3,$wheeldiv+6. 1326 ; bhis 4f 1327 ; bis shift+4(r2),(r5) 1328 ;4: 1329 ; cmp r3,$wheeldiv+10. 1330 ; blo 3b 1331 ; sub $2,(sp) 1332 ; tst (r4)+ 1333 ; tst (r5)+ 1334 ; cmp r4,$wheelcode+256. 1335 ; blo 2b 1336 ; tst (sp)+ 1337 ;/ 1338 ; .data 1339 ;shift: 1;2;4;10;20;40;100;200;400;1000;2000;4000;10000;20000;40000;100000 1340 ; 1;2 1341 ;wheeldiv: 32.; 18.; 10.; 6.; 4. 1342 ; .bss 1343 ;cagecode: .=.+256. 1344 ;wheelcode: .=.+256. 1345 ; .text 1346 ;/ 1347 ;/ 1348 ;/ make the internal settings of the machine 1349 ;/ both the lugs on the 128 cage bars and the lugs 1350 ;/ on the 16 wheels are set from the expanded key 1351 ;/ 1352 ; mov $key,r0 1353 ; mov $cage,r2 1354 ; mov $wheel,r3 1355 ;1: 1356 ; movb (r0)+,r1 1357 ; bic $!177,r1 1358 ; asl r1 1359 ; mov cagecode(r1),(r2)+ 1360 ; mov wheelcode(r1),(r3)+ 1361 ; cmp r0,$key+128. 1362 ; blo 1b 1363 ;/ 1364 ;/ 1365 ;/ now spin the cage against the wheel to produce output. 1366 ;/ 1367 ; mov $word,r4 1368 ; mov $wheel+128.,r3 1369 ;3: 1370 ; mov -(r3),r2 1371 ; mov $cage,r0 1372 ; clr r5 1373 ;1: 1374 ; bit r2,(r0)+ 1375 ; beq 2f 1376 ; incb r5 1377 ;2: 1378 ; cmp r0,$cage+256. 1379 ; blo 1b 1380 ;/ 1381 ;/ we have a piece of output from current wheel 1382 ;/ it needs to be folded to remove lingering hopes of 1383 ;/ inverting the function 1384 ;/ 1385 ; mov r4,-(sp) 1386 ; clr r4 1387 ; div $26.+26.+10.,r4 1388 ; add $'0,r5 1389 ; cmp r5,$'9 1390 ; blos 1f 1391 ; add $'A-'9-1,r5 1392 ; cmp r5,$'Z 1393 ; blos 1f 1394 ; add $'a-'Z-1,r5 1395 ;1: 1396 ; mov (sp)+,r4 1397 ; movb r5,(r4)+ 1398 ; cmp r4,$word+8. 1399 ; blo 3b 1400 ;/ 1401 ; 1402 ; mov (sp)+,r5 1403 ; mov (sp)+,r4 1404 ; mov (sp)+,r3 1405 ; mov (sp)+,r2 1406 ; mov (sp)+,r1 1407 ; mov $word,r0 1408 ; rts pc 1409 ; 1410 ; .bss 1411 ;key: .=.+128. 1412 ;word: .=.+32. 1413 ;cage: .=.+256. 1414 ;wheel: .=.+256. 1415 1416 ; 30/04/2022 1417 1418 ;----------------------------------------------------------------- 1419 ; Original UNIX v5 - 'getc' & 'fopen' source code (get.s) 1420 ; in PDP-11 (unix) assembly language 1421 ;----------------------------------------------------------------- 1422 ;/usr/source/s3/get.s 1423 ;-------------------- 1424 ;/ getw/getc -- get words/characters from input file 1425 ;/ fopen -- open a file for use by get(c|w) 1426 ;/ 1427 ;/ calling sequences -- 1428 ;/ 1429 ;/ mov $filename,r0 1430 ;/ jsr r5,fopen; ioptr 1431 ;/ 1432 ;/ on return ioptr buffer is set up or error bit is set if 1433 ;/ file could not be opened. 1434 ;/ 1435 ;/ jsr r5,get(c|w)1; ioptr 1436 ;/ 1437 ;/ on return char/word is in r0; error bit is 1438 ;/ set on error or end of file. 1439 ;/ 1440 ;/ ioptr is the address of a 518-byte buffer 1441 ;/ whose layout is as follows: 1442 ;/ 1443 ;/ ioptr: .=.+2 / file descriptor 1444 ;/ .=.+2 / charact+2 / pointer to next character (reset if no. chars=0) 1445 ;/ .=.+512. / the buffer 1446 ; 1447 ; .globl getc,getw,fopen 1448 ; 1449 ;fopen: 1450 ; mov r1,-(sp) 1451 ; mov (r5)+,r1 1452 ; mov r0,0f 1453 ; sys 0; 9f 1454 ;.data 1455 ;9: 1456 ; sys open; 0:..; 0 1457 ;.text 1458 ; bes 1f 1459 ; mov r0,(r1)+ 1460 ; clr (r1)+ 1461 ; mov (sp)+,r1 1462 ; rts r5 1463 ;1: 1464 ; mov $-1,(r1) 1465 ; mov (sp)+,r1 1466 ; sec 1467 ; rts r5 1468 ; 1469 ;.data 1470 ;getw: 1471 ; mov (r5),9f 1472 ; mov (r5)+,8f 1473 ; jsr r5,getc; 8:.. 1474 ; bec 1f 1475 ; rts r5 1476 ;1: 1477 ; mov r0,-(sp) 1478 ; jsr r5,getc; 9:.. 1479 ; swab r0 1480 ; bis (sp)+,r0 1481 ; rts r5 1482 ;.text 1483 ; 1484 ;getc: 1485 ; mov r1,-(sp) 1486 ; mov (r5)+,r1 1487 ; dec 2(r1) 1488 ; bge 1f 1489 ; mov r1,r0 1490 ; add $6,r0 1491 ; mov r0,0f 1492 ; mov r0,4(r1) 1493 ; mov (r1),r0 1494 ; sys 0; 9f 1495 ;.data 1496 ;9: 1497 ; sys read; 0:..; 512. 1498 ;.text 1499 ; bes 2f 1500 ; tst r0 1501 ; bne 3f 1502 ;2: 1503 ; mov (sp)+,r1 1504 ; sec 1505 ; rts r5 1506 ;3: 1507 ; dec r0 1508 ; mov r0,2(r1) 1509 ;1: 1510 ; clr r0 1511 ; bisb *4(r1),r0 1512 ; inc 4(r1) 1513 ; mov (sp)+,r1 1514 ; rts r5 1515 1516 ; 30/04/2022 1517 1518 ;----------------------------------------------------------------- 1519 ; Original UNIX v5 - 'putc' & 'flush' & 'fcreat' source code 1520 ; (put.s) in PDP-11 (unix) assembly language 1521 ;----------------------------------------------------------------- 1522 ;/usr/source/s3/put.s 1523 ;-------------------- 1524 ;/ putw/putc -- write words/characters on output file 1525 ;/ 1526 ;/ fcreat -- create an output file for use by put(w|c) 1527 ;/ 1528 ;/ calling sequences -- 1529 ;/ 1530 ;/ mov $filename,r0 1531 ;/ jsr r5,fcreat; ioptr 1532 ;/ 1533 ;/ on return ioptr is set up for use by put or error 1534 ;/ bit is set if file could not be created. 1535 ;/ 1536 ;/ mov(b) thing,r0 1537 ;/ jsr r5,put(w|c)1; ioptr 1538 ;/ 1539 ;/ the character or word is written out. 1540 ;/ 1541 ;/ jsr r5,flush; ioptr 1542 ;/ 1543 ;/ the buffer is fled. 1544 ;/ 1545 ; 1546 ; .globl putc, putw, flush, fcreat 1547 ; 1548 ;fcreat: 1549 ; mov r1,-(sp) 1550 ; mov (r5)+,r1 1551 ; mov r0,0f 1552 ; sys 0; 9f 1553 ;.data 1554 ;9: 1555 ; sys creat; 0:..; 666 1556 ;.text 1557 ; bes 1f 1558 ; mov r0,(r1)+ 1559 ;2: 1560 ; clr (r1)+ 1561 ; clr (r1)+ 1562 ; mov (sp)+,r1 1563 ; rts r5 1564 ;1: 1565 ; mov $-1,(r1)+ 1566 ; mov (sp)+,r1 1567 ; sec 1568 ; rts r5 1569 ; 1570 ;.data 1571 ;putw: 1572 ; mov (r5),8f 1573 ; mov (r5)+,9f 1574 ; mov r0,-(sp) 1575 ; jsr r5,putc; 8:.. 1576 ; mov (sp)+,r0 1577 ; swab r0 1578 ; jsr r5,putc; 9:.. 1579 ; rts r5 1580 ;.text 1581 ; 1582 ;putc: 1583 ; mov r1,-(sp) 1584 ; mov (r5)+,r1 1585 ;1: 1586 ; dec 2(r1) 1587 ; bge 1f 1588 ; mov r0,-(sp) 1589 ; jsr pc,fl 1590 ; mov (sp)+,r0 1591 ; br 1b 1592 ;1: 1593 ; movb r0,*4(r1) 1594 ; inc 4(r1) 1595 ; mov (sp)+,r1 1596 ; rts r5 1597 ; 1598 ;flush: 1599 ; mov r0,-(sp) 1600 ; mov r1,-(sp) 1601 ; mov (r5)+,r1 1602 ; jsr pc,fl 1603 ; mov (sp)+,r1 1604 ; mov (sp)+,r0 1605 ; rts r5 1606 ; 1607 ;fl: 1608 ; mov r1,r0 1609 ; add $6,r0 1610 ; mov r0,-(sp) 1611 ; mov r0,0f 1612 ; mov 4(r1),0f+2 1613 ; beq 1f 1614 ; sub (sp),0f+2 1615 ; mov (r1),r0 1616 ; sys 0; 9f 1617 ;.data 1618 ;9: 1619 ; sys write; 0:..; .. 1620 ;.text 1621 ;1: 1622 ; mov (sp)+,4(r1) 1623 ; mov $512.,2(r1) 1624 ; rts pc