Announcement

Collapse
No announcement yet.

C Header Conversion Problem :(

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C Header Conversion Problem :(

    Sorry to post another question on c header conversion, but I am
    just not getting this one:


    C Declaration:
    Code:
    'C Declaration
    'void _stdcall derive_key(const unsigned char pwd[],  /* the PASSWORD     */
    '               unsigned int pwd_len,        /* and its length   */
    '               const unsigned char salt[],  /* the SALT and its */
    '               unsigned int salt_len,       /* length           */
    '               unsigned int iter,   /* the number of iterations */
    '               unsigned char key[], /* space for the output key */
    '               unsigned int key_len)/* and its required length  */
    '{
    Here's a couple of my attempts Not even close!

    Code:
    DECLARE SUB derive_key LIB "HmacSha1.dll" ALIAS "derive_key" (bytPwd() as BYTE,pwdlen AS LONG,bytSalt() as BYTE,saltlen AS LONG,iter AS LONG,key() AS BYTE,keylen AS LONG)
    DECLARE SUB derive_key LIB "HmacSha1.dll" ALIAS "derive_key" (strPwd AS ASCIIZ PTR,pwdlen AS LONG,strSalt AS ASCIIZ PTR,saltlen AS LONG,iter AS LONG,key() AS BYTE,keylen AS LONG)
    Once again, sorry but I could use some help.

    -Ken


    ------------------


    [This message has been edited by Ken Myers (edited August 08, 2003).]
    Mac Application Reviews and More

  • #2
    Originally posted by Ken Myers:
    Sorry to post another question on c header conversion, but I am
    just not getting this one:


    C Declaration:
    Code:
    'C Declaration
    'void _stdcall derive_key(const unsigned char pwd[],  /* the PASSWORD     */
    '               unsigned int pwd_len,        /* and its length   */
    '               const unsigned char salt[],  /* the SALT and its */
    '               unsigned int salt_len,       /* length           */
    '               unsigned int iter,   /* the number of iterations */
    '               unsigned char key[], /* space for the output key */
    '               unsigned int key_len)/* and its required length  */
    '{
    Here's a couple of my attempts Not even close!

    Code:
    DECLARE SUB derive_key LIB "HmacSha1.dll" ALIAS "derive_key" (bytPwd() as BYTE,pwdlen AS LONG,bytSalt() as BYTE,saltlen AS LONG,iter AS LONG,key() AS BYTE,keylen AS LONG)
    DECLARE SUB derive_key LIB "HmacSha1.dll" ALIAS "derive_key" (strPwd AS ASCIIZ PTR,pwdlen AS LONG,strSalt AS ASCIIZ PTR,saltlen AS LONG,iter AS LONG,key() AS BYTE,keylen AS LONG)
    Once again, sorry but I could use some help.

    -Ken
    I would use BYVAL AS DWORD on all of them since all of them are either pointers to
    strings or unsigned ints (which are DWORDS). Then pass pointers to the string fields [].

    For example:
    Code:
    DECLARE SUB derive_key LIB "HmacSha1.dll" ALIAS "derive_key" (BYVAL strPwd AS DWORD, BYVAL pwdlen AS DWORD, BYVAL strSalt AS DWORD, BYVAL saltlen AS DWORD, BYVAL iter AS DWORD, BYVAL key AS DWORD, BYVAL keylen AS DWORD)
    Then I would call it using something like this:
    Code:
      DIM Password AS STRING
      DIM Salt AS STRING
      DIM Key AS STRING
      DIM MyKeyLen AS DWORD
      Password = "MyPassword" + CHR$(0)
      MyKeyLen = 64  '<--- change this to what every length you need
      Key = SPACE$(MyKeyLen + 1)   'set up a buffer to hold returning data (add 1 in case of Chr$(0))
      CALL derive_key(STRPTR(Password), BYVAL LEN(Password), STRPTR(Salt), BYVAL LEN(Salt), BYVAL 2, STRPTR(Key), BYVAL MyKeyLen)
    Hope that helps.

    ------------------
    "I haven't lost my mind... its backed up on tape... I think??"
    "I haven't lost my mind... its backed up on tape... I think??" :D

    Comment


    • #3
      Thank you very much. I will give it a shot and let you know how
      it works out. This is a dll that could be the bridge to supporting
      the new AES encryption built into Winzip 9.0 Beta. This is basically
      a wrapper for Dr. Brian Gladman's HmacSha1 c code.

      ------------------
      Mac Application Reviews and More

      Comment

      Working...
      X