[Harbour] Harbour SHA2 and SHA2-HMAC support

Viktor Szakáts harbour.01 at syenar.hu
Mon Jan 19 14:02:55 EST 2009


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

Brgds,
Viktor

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

> Hi,
>
>
>  We will need an HB_STRXOR(). Does this seem okay (UCHAR vs. BYTE might be
>> wrong here):
>>
>
> Oh, yes, I forgot it's my function, not Harbour's. I use code:
>
> HB_FUNC( HB_STRXOR )
> {
>   PHB_ITEM    pItem, pItem2;
>   ULONG       ulLen1, ulLen2, ul, ul2;
>   const char  *pStr1, *pStr2;
>   char*       pRet;
>
>   pItem = hb_param( 1, HB_IT_STRING );
>   if( pItem )
>   {
>      pStr1 = hb_itemGetCPtr( pItem );
>      ulLen1 = hb_itemGetCLen( pItem );
>
>      if( ( pItem2 = hb_param( 2, HB_IT_STRING ) ) != NULL )
>      {
>         ulLen2 = hb_itemGetCLen( pItem2 );
>         if( ulLen2 )
>         {
>            pStr2 = hb_itemGetCPtr( pItem2 );
>
>            pRet = ( char* ) hb_xgrab( ulLen1 + 1 );
>            memcpy( pRet, pStr1, ulLen1 + 1 );
>            ul2 = 0;
>            for( ul = 0; ul < ulLen1; ul++ )
>            {
>               pRet[ ul ] ^= pStr2[ ul2 ];
>               if( ++ul2 == ulLen2 )
>                  ul2 = 0;
>            }
>            hb_retclen_buffer( pRet, ulLen1 );
>         }
>         else
>            hb_itemReturn( pItem );
>
>         return;
>      }
>      else if( ( pItem2 = hb_param( 2, HB_IT_NUMERIC ) ) != NULL )
>      {
>         char  bChar = ( char ) hb_itemGetNI( pItem2 );
>
>         if( bChar )
>         {
>            pRet = ( char* ) hb_xgrab( ulLen1 + 1 );
>            memcpy( pRet, pStr1, ulLen1 + 1 );
>            for( ul = 0; ul < ulLen1; ul++ )
>               pRet[ ul ] ^= bChar;
>
>            hb_retclen_buffer( pRet, ulLen1 );
>         }
>         else
>            hb_itemReturn( pItem );
>
>         return;
>      }
>   }
>   hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME,
> HB_ERR_ARGS_BASEPARAMS );
> }
>
>
> It has syntax:
>   HB_STRXOR( cString, cKey ) --> cXoredString
> or
>   HB_STRXOR( cString, nByte ) --> cXoredString
>
> Some parameter error detection is done (I'm not sure that error subcode we
> should use, so, I've used 3012, just like in HB_STRTOHEX()). String is not
> reallocated if xor'ing to empty string or zero byte. Feel free to commit
> this code.
>
>
> Best regards,
>
> Mindaugas
>
> _______________________________________________
> 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/20090119/ff851bec/attachment.html


More information about the Harbour mailing list