HMAC
From Pickwiki
Jump to navigationJump to search
* * All this is based on the examples shown on the Wikipedia HMAC page * X.I.PAD = OCONV("36", "MCXD") ;** x36 = DECIMAL 54 X.O.PAD = OCONV("5C", "MCXD") ;** x5C = DECIMAL 92 X.THE.BLOCK.SIZE=64 X.THE.KEY="" FOR I = 255 TO 250 STEP -1 X.THE.KEY := CHAR(I) NEXT I X.TO.BE.HASHED="input" X.I.KEY.FINAL="" X.O.KEY.FINAL="" IF X.THE.KEY = "" THEN X.THE.KEY = STR(CHAR(0) , X.THE.BLOCK.SIZE) END ELSE IF LEN(X.THE.KEY) > X.THE.BLOCK.SIZE THEN X.HASHED.VAL="" X.ALGORITHM="MD5" X.DATA.LOC=1 ;** Return data in a string (2=to a file) X.ERROR.FLAG=DIGEST(X.ALGORITHM, X.THE.KEY, X.DATA.LOC, X.HASHED.VAL) ;** "DIGEST" command actually does the MD5 hashing * X.HASHED.VAL=OCONV(X.HASHED.VAL,"[[MX0C]]") ;** convert binary to ascii hex string X.HASHED.VAL=DOWNCASE(X.HASHED.VAL) X.THE.KEY=X.HASHED.VAL END END * FOR I = 1 TO LEN(X.THE.KEY) X.DEC.VAL=SEQ(X.THE.KEY[I,1]) X.I.KEY.FINAL := CHAR(BITXOR(X.DEC.VAL , X.I.PAD)) X.O.KEY.FINAL := CHAR(BITXOR(X.DEC.VAL , X.O.PAD)) NEXT I * FOR I = 1 TO (X.THE.BLOCK.SIZE - LEN(X.THE.KEY)) X.I.KEY.FINAL := CHAR(BITXOR(0 , X.I.PAD)) X.O.KEY.FINAL := CHAR(BITXOR(0 , X.O.PAD)) NEXT I * X.INNER.HASH = X.I.KEY.FINAL : X.TO.BE.HASHED X.ERROR.FLAG=0 X.ERROR.MSG='' * X.HASHED.VAL="" X.ALGORITHM="MD5" X.DATA.LOC=1 ;** Return data in a string (2=to a file) X.ERROR.FLAG=DIGEST(X.ALGORITHM, X.INNER.HASH, X.DATA.LOC, X.HASHED.VAL) * X.OUTER.HASH = X.O.KEY.FINAL : X.HASHED.VAL X.ERROR.FLAG=0 X.ERROR.MSG='' * X.HASHED.VAL="" X.ALGORITHM="MD5" X.DATA.LOC=1 X.ERROR.FLAG=DIGEST(X.ALGORITHM, X.OUTER.HASH, X.DATA.LOC, X.HASHED.VAL) * X.HASHED.VAL=OCONV(X.HASHED.VAL,"[[MX0C]]") ;** convert binary to ascii hex string X.HASHED.VAL=DOWNCASE(X.HASHED.VAL) * CRT X.HASHED.VAL STOP