*============================================================================================* * * * SLCALCSHA1 * * Examples on how to use MI CIPHER function to calculate SHA1. * * * * * * This program is provided as it is. Use at your own risk. * * http://www.datacrush.info * * * *============================================================================================* * Maintenance Log * * --------------- * * Trace Date Pgmr. Remarks * * ------------------------------------------------------------------------------------------ * * Datacrush * *============================================================================================* * H AltSeq(*None) * D GenHash... D Pr ExtProc('_CIPHER') D * Value D * Value D * Value * * Use with Secure Hash Algorithm D SHA Ds Qualified D Func 5I 0 Inz(5) D Alg 1A Inz(X'01') D Mode 1A Inz(X'00') D Len 10I 0 Inz(*Zeros) D Rsv 8A Inz(*Loval) D Init * Inz(%Addr(HashWork)) * * Use with hex value conversion D Ds D HxInt 1 2I 0 Inz(*Zeros) D HxIntA 2 2A * * Use with Secure Hash Algorithm D HashData S 12288A Inz(*Blanks) D Hash S 20A Inz(*Blanks) D Hash@ S * D Plain@ S * D Control@ S * Inz(%Addr(SHA)) D HashWork S 96A Inz(*Loval) D HEnc S 40A Inz(*Blanks) * * Use with hex value conversion D HxChrA S 1A Inz(*Blanks) D HxChrB S 1A Inz(*Blanks) D HxOfsA S 5I 0 Inz(*Zeros) D HxOfsB S 5I 0 Inz(*Zeros) D HxCnt S 10I 0 Inz(*Zeros) * * Use with hex value conversion D CHex C Const('0123456789abcdef') * *--------------------------------------------------------------------------------------------- * Main logic *--------------------------------------------------------------------------------------------- * C Eval HashData = 'yourdatahere' C ExSr SrGenHash * C Eval *InLr = *On * *--------------------------------------------------------------------------------------------- * Subroutine SrGenHash * Generates Secure Hash Algorithm one-way hashing *--------------------------------------------------------------------------------------------- * C SrGenHash BegSr * C Reset HashWork C Reset SHA C Move *Blanks Hash * C ' ' CheckR HashData SHA.Len C Eval Plain@ = %Addr(HashData) C Eval Hash@ = %Addr(Hash) * C CallP(E) GenHash(%Addr(Hash@):Control@:%Addr(Plain@)) * C For HxCnt = 1 By 1 To 20 C Eval HxIntA = %Subst(Hash:HxCnt:1) C ExSr SrGetHexStr C Eval %Subst(HEnc:(HxCnt*2)-1:1) = HxChrA C Eval %Subst(HEnc:(HxCnt*2):1) = HxChrB C EndFor * C EndSr * *--------------------------------------------------------------------------------------------- * Subroutine SrGetHexStr * Get string from hex characters *--------------------------------------------------------------------------------------------- * C SrGetHexStr BegSr * C HxInt Div 16 HxOfsA C Mvr HxOfsB * C Add 1 HxOfsA C 1 Subst CHex:HxOfsA HxChrA C Add 1 HxOfsB C 1 Subst CHex:HxOfsB HxChrB * C EndSr *