[Harbour] Harbour SHA2 and SHA2-HMAC support

Viktor Szakáts harbour.01 at syenar.hu
Mon Jan 19 19:17:48 EST 2009


Hi Mindaugas,

Now it's better, but in order to make them give the right results with
SHA384 and SHA512, 64 has to be changed to 128. I'm
lost how to do this in a generic way.

Brgds,
Viktor

On Mon, Jan 19, 2009 at 10:03 PM, Mindaugas Kavaliauskas <dbtopas at dbtopas.lt
> wrote:

> 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.697170952 at 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 at harbour-project.org
> http://lists.harbour-project.org/mailman/listinfo/harbour
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.harbour-project.org/pipermail/harbour/attachments/20090120/32dd4c68/attachment-0001.html


More information about the Harbour mailing list