pw_length
equ
129
;length of password
;this routine allows the user to enter a password to encrypt, and verifies ;it has been entered correctly before proceeeding. master_pass proc near mov si,offset enc_pass1 ;display this message call disp_string ;and fall through to get_pass call decryp_pass ;get the password mov di,offset passvr mov si,offset passwd mov cx,pw_length push di push si push cx rep movsb mov si,offset enc_pass2 ;display verify message call verify_pass ;and fall through to get_pass pop cx pop si pop di repz cmpsb ;are they the same? jcxz mpe mov si,offset bad_pass ;else display this call disp_string jmp master_pass ;and try again mpe: ret master_pass endp ;this routine allows the user to enter a password to decrypt. only one try ;is allowed. decryp_pass: mov si,offset dec_pass ;display this message verify_pass: call disp_string ;and fall through to get_pass ;this routine allows the user to enter the password from the keyboard get_pass proc near mov di,offset passwd gpl: mov ah,0 int 16h ;get a character cmp al,0dh ;carriage return? jz gpe ;yes, done, exit cmp al,8 jz gpbs ;backspace? go handle it cmp di,offset passwd +pw_length-1 ;end of password buffer? jz gpl ;yes, ignore the character stosb ;anything else, just store it jmp gpl gpbs: cmp di,offset passwd ;don't backspace past 0 jz gpl dec di ;handle a backspace jmp gpl gpe:
mov sub xor rep mov
cx,offset passwd + pw_length cx,di ;cx=bytes left al,al stosb ;zero rest of password ax,0e0dh ;cr/lf
int mov int call ret get_pass
10h ax,0e0ah 10h hash_pass
;always hash entered password into hpp
endp
;this routine hashes passwd down into the 16 byte hpp for direct use by ;the encryption algorithm. hash_pass proc near mov [rand_seed],14e7h ;pick a seed mov cx,16 ;clear hpp xor al,al mov di,[hpp] rep stosb mov dx,di mov bl,al mov si,offset passwd hplp0: mov di,[hpp] hplp1: lodsb ;get a byte or al,al ;go until done jz hpend push bx mov cl,4 shr bl,cl mov cl,bl pop bx inc bl rol al,cl ;rotate al by position/16 bits xor [di],al ;and xor it with hpp location call get_random ;now get a random number xor [di],ah ;and xor with upper part inc di cmp di,dx jnz hplp1 jmp hplp0 hpend: cmp di,dx jz hpe call get_random xor [di],ah inc di jmp short hpend hpe: ret hash_pass endp enc_pass1 dec_pass enc_pass2 bad_pass
db db db db
'enter ',0 'passphrase: ',0 'verify passphrase: ',0 'verify failed!',13,10,0