.TITLE ENCRYPT - FAST ENCRYPTION UTILITY .IDENT /X01-02/ .SBTTL HEADER AND DEFINITIONS .PAGE ;++ ; ; Copyright (c) 1988 James F. Duff ; General permission to copy or modify is hereby granted under the ; conditions that copy is not used for the purposes of profit and that ; the above copyright notice is included and reference made to the fact ; that reproduction privileges were granted by James F. Duff. ; The author makes no warranties, express or implied, as to the ; usefulness or correctness of this software. ; No publication is made or suggested by use of this copyright notice. ; ;-- ;++ ; FACILITY: SECURITY ; ; ABSTRACT: ; ; This program is a fast encryption utility. Unlike most encryption ; utilities available, there are no limits on types of file or line ; lengths that this program can handle. ; ; The program is written to be called from DCL by replacing the verb ; "ENCRYPT" in the DCL tables. The parameters it takes are exactly the ; same as DIGITAL's encryption facility, which is available only under ; licence. ; ; The program works by using exclusive OR on bytes in the input file. ; It XORs each byte with a byte from the supplied password and also ; a random number generated by a seed taken from the first 4 bytes of ; the password. Using XOR means that there is only one program for both ; encryption and decryption. ; ; Due to this program being a DCL routine, the password is not case ; sensitive, thus reducing the available security somewhat. Hopefully, ; this restriction will eventually be removed. ; ; ENVIRONMENT: User mode ; ; AUTHOR: JAMES F. DUFF ; ; CREATION DATE: 12-JAN-1988 ; ; MODIFIED BY: ; ; Jim Duff 17-Aug-1990 X01-02 ; Fixed a bug which caused the first byte of the password ; to never be used. Also performed some code standardization. ; ;-- $IODEF $SSDEF $FIBDEF $SECDEF $CLIDEF .MACRO JMPERR ADDR=ERROR, ?B ; ; This macro tests the low order bit of R0 and jumps to a user ; supplied error routine if it is clear. ; BLBS R0,B JMP ADDR B: .ENDM JMPERR .SBTTL READ ONLY DATA .PAGE .PSECT ENC$RODATA PIC,USR,CON,REL,LCL,SHR,NOEXE,RD,NOWRT,NOVEC,LONG EXP_STR_D: .LONG 255 .ADDRESS - EXP_STR FIB_BLK_D: .LONG 48 .ADDRESS - FIB_BLK ENT1_D: .ASCID /FILES/ ENT2_D: .ASCID /PSWD/ .SBTTL READ WRITE DATA .PAGE .PSECT ENC$RWDATA PIC,USR,CON,REL,LCL,NOSHR,NOEXE,RD,WRT,NOVEC,LONG OUT_ARRAY: .BLKQ 1 IO_STATUS: .BLKQ 1 PSWD_D: .LONG 255 .ADDRESS - PSWD INP_STR_D: .LONG 255 .ADDRESS - INP_STR .ALIGN LONG ; Align for RMS data blocks NAM_BLK:$NAM RSA=RES_STR, - ; NAM block RSS=255, - ESA=EXP_STR, - ESS=255 FAB_BLK:$FAB FOP=NAM, - ; Use NAM block NAM=NAM_BLK, - ; Address of NAM block FNA=INP_STR ; File name FIB_BLK:.BLKL 12 CHANNEL:.BLKW 1 PSWD: .BLKB 255 EXP_STR:.BLKB 255 ; Expanded file name from $PARSE RES_STR:.BLKB 255 ; Resultant name from $PARSE INP_STR:.BLKB 255 .SBTTL MAIN LINE CODE .PAGE .PSECT ENC$CODE PIC,USR,CON,REL,LCL,SHR,EXE,RD,NOWRT,NOVEC,BYTE .ENTRY ENCRYPT,^M<> PUSHAW PSWD_D ; Return length PUSHAQ PSWD_D ; Buffer descriptor to store str PUSHAQ ENT2_D ; Entity desc 2 "PSWD" CALLS #3,G^CLI$GET_VALUE ; Get value of entity JMPERR ; Error ? START: PUSHAW INP_STR_D ; Return length PUSHAQ INP_STR_D ; Buffer descriptor to store str PUSHAQ ENT1_D ; Entity desc 1 "FILES" CALLS #3,G^CLI$GET_VALUE ; Get value of entity CMPL #CLI$_ABSENT,R0 ; Value absent ? BNEQ 5$ ; No, branch JMP EXIT ; Yes, so we have finished 5$: JMPERR ; Other error ? MOVL INP_STR_D,FAB_BLK+FAB$B_FNS ; Indicate len of file to RMS $PARSE FAB=FAB_BLK ; Call RMS to parse the file JMPERR F_ERR ; Error ? $SEARCH FAB=FAB_BLK ; Call RMS to locate the file JMPERR F_ERR ; Error ? MOVAL FIB_BLK,R5 ; Address of FIB to R5 MOVAL NAM_BLK+NAM$W_FID,R0 ; Address of FID to R0 MOVL (R0)+,FIB$W_FID(R5) ; Move 1st longword of FID ... ; ... to FIB MOVW (R0),FIB$W_FID+4(R5) ; Move 3rd word MOVL #FIB$M_WRITE,FIB$L_ACCTL(R5) ; Specify write access to file $ASSIGN_S - ; Assign a channel CHAN=CHANNEL, - DEVNAM=EXP_STR_D JMPERR ; Error ? $QIOW_S FUNC = #IO$_ACCESS!IO$M_ACCESS, - ; Access the file... CHAN = CHANNEL, - ; ... on the channel IOSB = IO_STATUS, - P1 = FIB_BLK_D ; Use FIB JMPERR ; Error ? MOVL IO_STATUS,R0 ; IO STATUS to R0 JMPERR ; IO Error ? $CRMPSC_S - ; Map a section INADR=OUT_ARRAY, - RETADR=OUT_ARRAY, - FLAGS=#SEC$M_EXPREG!SEC$M_WRT, - CHAN=CHANNEL ; on the file JMPERR ; Error ? MOVL PSWD,R9 ; Construct an F float number- ROTL #-7,R9,R9 ; Get the magnitude to a ... MOVB #40,R9 ; ...reasonable size... ROTL #7,R9,R9 ; and rotate it back MOVQ OUT_ARRAY,R6 ; Start/End addr of section to ; R6/R7 CLRL R8 ; Clear password pointer LOOP: CMPL R6,R7 ; Begin loop. Finished ? BGTR LOOP_EXIT ; Yes, branch TSTL R8 ; Are we pointing to a byte in ; the password ? BGEQ 5$ ; Yes, branch MOVZWL PSWD_D,R8 ; No, point to the last byte 5$: XORB3 (R6),PSWD[R8],(R6) ; XOR the value in the section ; with the byte of the password BSBW RAND ; Get the next random number XORB3 (R6),R0,(R6) ; XOR it in INCL R6 ; Next byte of the section DECL R8 ; Next byte of the password BRB LOOP ; Loop til done LOOP_EXIT: ; Finished $UPDSEC_S - ; Write the section back to file INADR = OUT_ARRAY JMPERR ; Error ? $DELTVA_S - ; Delete the section INADR = OUT_ARRAY JMPERR ; Error ? $DASSGN_S - ; Deassign the file CHAN = CHANNEL JMPERR ; Error ? JMP START ; Go see if the file parameter ; has any more specs in the list .SBTTL RANDOM NUMBER GENERATOR .PAGE RAND: EMUL R9,#69069,#1,R0 ; Extended mult so no overflow MOVL R0,R9 ; Next seed to R9 EXTZV #8,#24,R9,R0 ; Normalize... CVTLF R0,R0 BEQL 10$ SUBW #24@7,R0 10$: MULF2 #2863,R0 ; Multiply by arbitary number CVTFL R0,R0 ; Get integer part ADDL #1,R0 ; Add one RSB ; Return with value in R0 .SBTTL ERROR AND EXIT POINTS .PAGE F_ERR: PUSHL FAB_BLK+FAB$L_STV ; RMS error PUSHL FAB_BLK+FAB$L_STS CALLS #2,G^LIB$SIGNAL EXIT: MOVL #SS$_NORMAL,R0 ; Indicate normal completion ERROR: $EXIT_S R0 ; Exit with status .END ENCRYPT