Google
 

Trailing-Edge - PDP-10 Archives - SRI_NIC_PERM_SRC_3_19910112 - utilities/hash.mac
There are no other files named hash.mac in the archive.
;<CLEMENTS>HASH.MAC.1,  5-Aug-77 15:43:13, EDIT BY CLEMENTS
TITLE HASH - HASHED PASSWORD ROUTINE EXTRACTED FROM TENEX

SEARCH MACSYM,MONSYM

A=1
B=2
C=3
D=4

Q3=16
E=14
F=13
Q2=12
Q1=11

P=17

OPDEF XCTBU [XCT]
HASH:	RESET			;LITTLE JACKET ROUTINE FOR TESTING
	MOVE P,PDP		;SET UP A STACK
	HRROI A,[ASCIZ /Password: /]
	PSOUT
	CALL GOBBLE
	MOVE B,A		;RIGHT AC FOR HASHPW
	ILDB C,A
	CAIL C,41
	JRST .-2
	MOVEI C,0		;TRIM OFF THE CRLF
	DPB C,A
	CALL HASHPW
	 JFCL
	DMOVEM C,ANS0		;SAVE ANSWER
	MOVEI A,101		;PRINT THE ANSWERS
	MOVE B,ANS0
	MOVEI C,10
	NOUT
	 JFCL
	MOVEI B,40
	BOUT
	MOVE B,ANS1
	NOUT
	 JFCL
	HRROI A,[BYTE (7)15,12,0]
	PSOUT
	HALTF
	JRST HASH
;ROUTINE TO CONVERT A STRING PASSWORD TO A HASHED PASSWORD.
;FOR MATHEMATICAL TECHNIQUE AND CREDITS, SEE PURDY, CACM AUG 74
;AND KNUTH VOLUME 2 SECTION 4.6.3.
;THIS IS A MODIFICATION OF THE SYSTEM USED BY JOHNSON AND THOMAS
;IN RSEXEC

;HASHPW ACCEPTS STRING POINTER IN B AND RETURNS HASH IN C AND D.
;A NULL PASSWORD IS FORCED TO BE A 2-WORD ZERO RESULT.

;THE FOLLOWING AC'S ARE USED HERE -- 
; Q1 = FIRST ARG TO ARITHMETIC ROUTINES. 
; Q2 = SECOND ARG
; Q3 = RESULT (ALL 3 OF THESE POINT TO A TWO-WORD DATUM)

HASHPW:	TLC B,-1		;CHECK FOR -1 IN LH OF STRING POINTER
	TLCN B,-1		; ..
	HRLI B,440700		;YES. NORMALIZE IT.
	TLZ B,37		;AVOID INDEX AND INDIRECT BITS
	MOVE A,B		;COPY THE STRING POINTER
	ILDB B,A		;GET FIRST CHAR FROM HERE
	JUMPE B,[SETZB C,D	;RETURN A DOUBLEWORD 0 IF SO
		JRST SKPRET]	;AND GIVE SUCCESS RETURN
;STRING IS NOT NULL.
	MOVEI E,0		;NO CHAR'S SEEN YET
	PUSH P,ZERO		;TWO WORDS OF ZERO ON THE STACK
	PUSH P,ZERO		; INTO WHICH WILL BE XOR'ED THE TEXT.
	JRST HSHP1A		; ALREADY HAVE FIRST CHARACTER
HPWL1:	ILDB B,A		;IF FLAG FROM HASHPM ENTRY
HSHP1A:	JUMPE B,HSHPW1		;JUMP IF END OF STRING
	MOVEI C,(E)		;CHARACTER NUMBER
	IDIVI C,^D10		;GET INDEX INTO SHIFT/XOR TABLES
	XCT HPWTB1(D)		;NOW SHIFT CHARACTER
	XCT HPWTB2(D)		;AND XOR IT ONTO STACK
	CAIGE E,^D39-1		;QUIT AT 39 CHARACTERS
	AOJA E,HPWL1		; MORE TO GO.
;FALL THRU
;FALLS THRU
HSHPW1:	POP P,D			;NOW HAVE FIRST LEVEL MESS ON STACK
	POP P,C			;GET IT BACK TO AC'S
	DMOVEM C,CINPUT		;COMPRESSED TEXT INPUT STORED HERE
	DMOVEM C,FF		; AT FF ALSO.
	MOVEI Q1,CINPUT	;MULMPD(CINPUT,CINPUT) TO T3
	MOVEI Q2,(Q1)	; ..
	MOVEI Q3,T3
	CALL MULMPD
	MOVEI Q1,T3		;MULMPD(T3,CINPUT) TO T2
	MOVEI Q2,CINPUT
	MOVEI Q3,T2
	CALL MULMPD
	PUSH P,[1B12]		;SLIDE A BIT ALONG TO COMPUTE SUM
HSHPW2:	MOVEI Q1,FF		;MULMPD(FF,FF) TO FF
	MOVEI Q2,(Q1)
	MOVEI Q3,(Q1)
	CALL MULMPD
	MOVE A,HASHN1		;CHECK BIT IN MAGIC CONSTANT
	TDNN A,0(P)		; ..
	JRST HSHPX1		;NOT ON, DON'T ADD IN THIS TERM
	MOVEI Q3,FF		;MULMPD(FF,CINPUT) TO FF
	MOVEI Q1,(Q3)
	MOVEI Q2,CINPUT
	CALL MULMPD
HSHPX1:	MOVE A,0(P)
	LSH A,-1		;SLIDE BIT TO RIGHT
	MOVEM A,0(P)
	JUMPN A,HSHPW2		;LOOP UNTIL 24 BITS DONE
;FALL THRU
;FALLS THRU
	POP P,(P)		;DONE. DISCARD FLOATING BIT
	DMOVE A,FF		;FF TO T1
	DMOVEM A,T1		; ..
	MOVEI Q1,T2		;MULMPD(T2,T2) TO FF
	MOVEI Q2,(Q1)	; P**6
	MOVEI Q3,FF
	CALL MULMPD
	MOVEI Q1,FF		;MULMPD(FF,FF) TO FF
	MOVEI Q2,(Q1)	; P**12
	MOVEI Q3,(Q1)
	CALL MULMPD
	MOVEI Q1,FF		; MULMPD(FF,T3) TO FF
	MOVEI Q2,T3		; P**14
	MOVEI Q3,FF
	CALL MULMPD
	MOVEI Q1,T1		; MULMPD(T1,FF) TO T0
	MOVEI Q2,FF		; P**N0
	MOVEI Q3,T0
	CALL MULMPD
HSHPW3:	MOVEI Q1,T0		;NOW COMPUTE TERMS OF FINAL SERIES
	MOVEI Q2,HASHA0	;T0=T0*A0
	MOVEI Q3,T0
	CALL MULMPD
	MOVEI Q1,T1		;T1=T1*A1
	MOVEI Q2,HASHA1
	MOVEI Q3,T1
	CALL MULMPD
	MOVEI Q1,T2		;T2=T2*A2
	MOVEI Q2,HASHA2
	MOVEI Q3,T2
	CALL MULMPD
	MOVEI Q1,T3		;T3=T3*A3
	MOVEI Q2,HASHA3
	MOVEI Q3,T3
	CALL MULMPD
;FALL THRU
;FALLS THRU
;NOW ADD UP THE TERMS OF THE SERIES
	DMOVE C,T0		;T0 TERM
	SETZB A,B		;3RD AND 4TH ORDER WORDS ARE 0
	DADD C,T1		;T1 TERM
	DDIV A,PRIME		;REDUCE MOD P
	SETZB A,B		;DISCARD QUOTIENT
	DADD C,T2		;T2 TERM
	DDIV A,PRIME		;REDUCE MOD P
	SETZB A,B		;DISCARD QUOTIENT
	DADD C,T3		;T3 TERM
	DDIV A,PRIME		;REDUCE MOD P
	SETZB A,B		;DISCARD QUOTIENT
	DADD C,HASHA4		;T4 TERM
	DDIV A,PRIME		;REDUCE MOD P
;THE REMAINDER, MODULO P, WHICH IS THE FINAL ANSWER, IS IN C,D
	JRST SKPRET		;AND SKIP RETURN, HASH IN C/D

;THE DOUBLE WORD MULTIPLY ROUTINE
MULMPD:	DMOVE A,(Q1)
	DMUL A,(Q2)
	DDIV A,PRIME
	DMOVEM C,(Q3)
	RET
;CONSTANTS

HPWTB1:	REPEAT 2,<	JFCL
	LSH B,7
	LSH B,^D14
	LSH B,^D21
	LSH B,^D28
>
HPWTB2:	REPEAT 5,<	XORM B,0(P)>
	REPEAT 5,<	XORM B,-1(P)>

HASHN1:	100,,13			;2**24+11.
PA==^D59
PRIME:	3777,,-1
	377777,,-PA
K270P:	0
	^D64*PA
HASHA0:	127,,533602
	240563,,422132
HASHA1:	053,,542132
	020301,,633454
HASHA2:	311,,555236
	347001,,45671
HASHA3:	123,,106405
	245330,,106744
HASHA4:	155,,226337
	124357,,220100
GOBBLE:	HRROI A,RDDBFR
	MOVE B,[RD%BRK+RD%BEL+RD%RAI+<5*NRBF>]
	MOVEI C,0
	RDTTY
	 JRST GOBBER
	TXNN B,RD%BTM
	JRST GOBBER
	MOVE A,[POINT 7,RDDBFR]
	RET

GOBBER:	HRROI A,[ASCIZ / Wha?
/]
	ESOUT
	JRST GOBBLE

ZERO:	0

SKPRET:	AOS (P)
R:	POPJ P,0

NRBF==20			;WORDS IN READ BUFFER
RDDBFR:	BLOCK NRBF

K1:	1367,,305654   
K2:	273510,,323536   
K3:	1151,,426705  
K4:	40665,,317710   
K5:	1601,,411316
K6:	244675,,70353   

PDP:	IOWD 40,PDL
PDL:	BLOCK 40

TST:	0			;ARG TO TEST
	0
ANS0:	0
ANS1:	0
ANS2:	0
ANS3:	0
T0:	EXP 0,0
T1:	EXP 0,0
T2:	EXP 0,0
T3:	EXP 0,0
FF:	EXP 0,0			;A NUMERICAL TEMP
CINPUT:	EXP 0,0			;COMPRESSED TEXT INPUT

	END HASH