Hi,

For some reason I still cannot make pass your generic .prg HMAC function on the validation tests. Probably some stupid mistakes on my part.

No, on my one. I forgot one Hex->Bin conversion. It should be:

FUNC HB_HMAC(fHash, cMessage, cKey)
  IF LEN(cKey) > 64;   cKey := HB_HexToStr(EVAL(fHash, cKey))
  ENDIF
  cKey := PADR(cKey, 64, CHR(0))
RETURN EVAL(fHash, HB_STRXOR(cKey, 0x5C) + ;
HB_HexToStr(EVAL(fHash, HB_STRXOR(cKey, 0x36) + cMessage)))

Now
? HB_HMAC(@HB_MD5(), "<1896.697170...@postoffice.reston.mci.net>", "tanstaaftanstaaf") prints "b913a602c7eda7a495b4e6e7334d3890" (this test data is used in http://www.isi.edu/in-notes/rfc2195.txt).


Regards,
Mindaugas


P.S. sometimes one more optional parameter would be really usefull HB_{MD5|SHA1|...}( cMessage [, lBinary ] ), to avoid two unnecessary Bin->Hex->Bin conversion in function like HB_HMAC:

FUNC HB_HMAC(fHash, cMessage, cKey, lBinary)
  IF LEN(cKey) > 64;   cKey := EVAL(fHash, cKey, .T.)
  ENDIF
  cKey := PADR(cKey, 64, CHR(0))
RETURN EVAL(fHash, HB_STRXOR(cKey, 0x5C) + ;
EVAL(fHash, HB_STRXOR(cKey, 0x36) + cMessage, .T.), lBinary)

In many cases (ex., communication protocol implementation) we need binary digest result, and hex format is used for human readable representation only.
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to