From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 28-MAY-1993 14:17:19.11
To:	EVERHART
CC:	
Subj:	Re: MACRO source examples for $GETUAI and $HASH_PASSWORD

Date: Thu, 27 May 1993 17:32:10 -0400 (EDT)
From: "Lawrence MacIntyre - 615.576.0824" <LPZ@LUDWIG.CTD.ORNL.GOV>
To: info-vax@kl.sri.com
Cc: leonardi@dialix.oz.au
Message-Id: <930527173210.24200118@LUDWIG.CTD.ORNL.GOV>
Subject: Re: MACRO source examples for $GETUAI and $HASH_PASSWORD

Ian:

Here's an example I wrote for a MACRO class I taught a few years back...

		.Title Guess_Password

; A simple screen locker for a terminal.  Won't let you out until you type in
; the password of the user who is logged in.  Example of several system
; services.
		$IODEF
		$JPIDEF
		$LIBDEF
		$QIODEF
		$UAIDEF

Old_Mask:	.Blkl	1		;What used to be enabled
Disable_Mask:	.Long	Lib$m_Cli_Ctrly ;What we are about to disable
Prompt:	.ASCII	"Password: "		;Prompt for the password
Prompt_Length=.-Prompt			;It's this long
TT_Chan:	.Blkw	1		;Channel for $QIO
TT_Desc:	.ASCID	"Sys$Input"	;Read from here
Input:		.Word	32		;Size of buffer
		.Byte	14		;ASCII text
		.Byte	1		;Static buffer
		.Address Buffer		;Address of Buffer
Buffer:		.Blkl	32		;Password input buffer
IOSB:		.Blkq	1		;Status from System Service
JPI_Itemlist:	.Word	12		;It's this long
		.Word	Jpi$_Username	;Get this information
		.Address Username	; Put it here
		.Address Username_Size	;  Tell me how long it is
		.Long	0		;End of the itemlist

UAI_Itemlist:	.Word	1		;It's this long
		.Word	Uai$_Encrypt	;the encryption algorithm
		.Address Encryption	;store it here
		.Blkl	1		;the length would go here, but it's 1
		.Word	8		;It's this long
		.Word	Uai$_Pwd	;the hashed password
		.Address Password	;Store it here
		.Blkl	1		;the length would go here, but it's 8
		.Word	2		;It's this long
		.Word	Uai$_Salt	;The salt value
		.Address Salt		;Store it here
		.Blkl	1		;the length would go here, but it's 2
		.Long	0		;End of list
Encryption:	.Blkl	1		;Store the encryption algorithm
Password:	.Blkq	1		;Store the real encrypted password
Salt:		.Blkw	1		;Store the salt
PID:		.Long	0		;Get mine!
Username_Desc:	.Blkw	1		;Length goes here
		.Byte	14		;ASCII
		.Byte	1		;Static descriptor
		.Address Username	;Here's the data
GPassword:	.Blkq	1		;The encrypted guess
Username:	.Blkb	12		;Just like it sounds
Username_Size:	.Blkl	1		;# of characters in Username

	.ENTRY	Main,0			;Start here

	PUSHAL	Old_Mask		;Disable Ctrl-Y
	PUSHAL	Disable_Mask
	CALLS	#2,G^Lib$Disable_Ctrl
	BLBS	R0,3$
	BRW	Die
3$:	$GETJPIW_S	PIDADR=Pid, -	;Get my username
			ITMLST=JPI_ItemList, -
			IOSB=IOSB
	BLBS	R0,5$
	BRW	Die
5$:	MOVZWL	IOSB,R0
	BLBS	R0,6$
	BRW	Die
6$:	MOVW	Username_Size,Username_Desc	;Fix the username descriptor
	$GETUAI_S	USRNAM=Username_Desc,-	;Get my password info
			ITMLST=UAI_ItemList
	BLBS	R0,10$
	BRW	Die

10$:	$ASSIGN_S DEVNAM=TT_Desc, -		;Assign a channel to Sys$Input
		  CHAN=TT_Chan
	BLBS	R0,Guess
	BRW	Die
GUESS:	$QIOW_S	CHAN=TT_Chan, -			;Read the password *silently*
		FUNC=#IO$_ReadPrompt!IO$m_CvtLow!IO$m_NoEcho!IO$m_Purge, -
		IOSB=IOSB, -
		P1=@Input+4, -
		P2=#Input, -
		P5=#Prompt, -
		P6=#Prompt_Length
	BLBS	R0,20$
20$:	MOVZWL	IOSB,R0
	BLBS	R0,30$

30$:	MOVW	IOSB+2,INPUT			;Fix the descriptor (length)
	$HASH_PASSWORD_S  PWD=Input, -		;Hash the guess
			ALG=Encryption, -
			SALT=Salt, -
			USRNAM=Username_Desc,-
			HASH=GPassword
	BLBC	R0,Die
	CMPL	Password,GPassword		;Are the first lws identical?
	BNEQU	50$
40$:	CMPL	Password+4,GPassword+4		;How about the second ones?
	BEQLU	Die				;YES!
50$:	$QIOW_S	CHAN=TT_Chan, -			;NO!  Write a newline for the
		FUNC=#IO$_WriteVBlk, -		; next guess.
		IOSB=IOSB, -
		P1=@Input+4, -
		P2=#0, -
		P4=#^X00010000		;NewLine
	BLBS	R0,60$
60$:	MOVZWL	IOSB,R0
	BLBC	R0,Die

	BRW	Guess

DIE:	PUSHAL	Old_Mask			;We won, or something didn't
						; work
	CALLS	#1,G^Lib$Enable_Ctrl
	BLBC	R0,Die

	$Exit_S	R0

	.END	Main
-----------------------------------------------------------------------------
Internet: MACINTYRELP@ORNL.GOV   RealWorld: Lawrence MacIntyre
          LPZ@ORNL.GOV                AT&T: 615.576.0824

