.TITLE lookup - Encrypt input and look up in password table .IDENT /1.5/ .REM | *+ lookup - Encrypt input and look up in password table File:lookup.mac Version: 1.5 Author: Jim Bostwick 28-FEB-1985 Last Edit: 7-MAY-1985 23:09:04 Last Update: 7-May-1985 23:24:10 more indexing work *- | .LIBRARY /LB:[1,1]GLMAC.MLB/ .MCALL return,push,pop .SBTTL LOCAL DATA .psect ldat,d,lcl,con ; ; use this psect for scratch storage - it is not guaranteed to be saved ; across calls to the module ; .psect data,d,gbl,con ; ; Keytab includes the table of keys. It is generated separately (by KEYGEN) ; for inclusion here ; ; symbol KEYTAB points to a vector of addresses, one per password record, ; with a null terminator. .include /keytab.mac/ .PSECT ; code goes in the blank psect .SBTTL LOOKUP -- Look up command in password table .REM | LOOKUP is called with a plain-text command line. It first encrypts the command line, then searches the password table for a match. LOOKUP returns the offset of the matching entry in the command table, or 0 (zero) if no matching entry exists. Also, a no-match condition returns carry set. NOTE WELL: The returned index is the byte offset into the command table (NOT the password table). The password table contains one less entry (the entry with index=0) than the command table. In simple terms, add the base of the command table to r2 on return and look at the command. CALL jsr pc, lookup INPUT r0 -> command line r1 = length of command line OUTPUT r0 -> same command line, but encrypted now r2 = command index (0 -> no match) carry set -> no match carry clear -> match found REGS r2 modified, string referenced by r0 modified others preserved CALLS CRYPT NOTES: 1. In order to work properly, trailing whitespace (tab or space) should be stripped from command line. Leading whitespace is ok, allowing tricky passwords like hi there! 2. Source module KEYTAB.MAC is .INCLUDED in this module. It is generated by KEYGEN. | LOOKUP:: call crypt ; encrypt input string push mov #keytab, r2 ; init index ; ; look for a string with correct length ; loop: mov (r2)+, r3 ; point into password table, and ; check for end of table beq fail ; off end - barf cmp r1, (r3) ; length match? bne loop ; no - keep looking ; length matches, compare text mov (r3)+, r4 ; get byte count, and point to text mov 4(sp), r0 ; restore buffer address 100$: cmpb (r0)+,(r3)+ ; check a byte bne loop ; no match, try next entry sob r4,100$ ; loop thru all bytes sub #keytab, r2 ; compute offset ; ; here, a match has been found - it's index (byte offset) is in r2 ; adjusted for the fantom zero entry. ; NOTE WELL: the first password table entry corresponds to the SECOND ; command table entry!!! The first command table entry corresponds ; by definition to the no-match condition. ; clc ; show success br done fail: ; no length match clr r2 ; index is zero sec ; carry set on error done: pop return .end