As the title says... Chat on...

User avatar
By dnc40085
#18797 This post is in reference to the post by cal101 on NodeMCU issue #419

I tried the following code:
Code: Select allint     hmac_sha1 (const u8 *key, size_t key_len, const u8 *data, size_t data_len, u8 *mac);

static int hmactest( lua_State* L )
{
   u8 *key="over9000";
   u8 *data="Hello World!";
   u8 mac[128];
   hmac_sha1(key, os_strlen(key), data, os_strlen(data), mac);
   c_printf("the key is %s\n", key);
   c_printf("the key length is %d\n", os_strlen(key));
   c_printf("the data is %s\n", data);
   c_printf("the data length is %d\n", os_strlen(data));
   c_printf("the hmac_sha1 string is %s\n", mac);
}


This is the result:
Code: Select allcrypto.hmactest()
the key is over9000
the key length is 8
the data is Hello World!
the data length is 12
the hmac_sha1 string is %<�i,��lќ �-`�����#@���?̔$@
>


I'm thinking maybe this needs mem_init() just like base64_encode in this post, I tried adding it but had no luck
User avatar
By dnc40085
#18822 Hello,

when you say "check return value" do you mean the return value of hmac_sha1?

like this:
Code: Select allvoid mem_init(void * start_addr);
int     hmac_sha1 (const u8 *key, size_t key_len, const u8 *data, size_t data_len, u8 *mac);

static int crypto_hmacsha1( lua_State* L )
{
    const char* key = luaL_checkstring(L, 1);
    const char* data = luaL_checkstring(L, 2);

   u8 mac[20];
   if (hmac_sha1(key, os_strlen(key), data, os_strlen(data), mac)==0)
   {
     char* out = (char*)c_malloc(40);
     int i, j = 0;
     for (i = 0; i < 20; i++)
     {
      out[j++] = byteshex[mac[i] >> 4];
       out[j++] = byteshex[mac[i] & 0xf];
     }
     CRYPTO_DBG("the key is %s\n", key);
     CRYPTO_DBG("the key length is %d\n", os_strlen(key));
     CRYPTO_DBG("the data is %s\n", data);
     CRYPTO_DBG("the data length is %d\n", os_strlen(data));
     CRYPTO_DBG("the hmac_sha1 string is %s\n", out);
     lua_pushlstring(L, out, 40);
     c_free(out);
   return 1;
   }
   else
   {
     return luaL_error( L, "hmac_sha1 error" );
   }
}


Also, What is hmac_sha1_vector for?
User avatar
By cal
#18824
dnc40085 wrote:Hello,

when you say "check return value" do you mean the return value of hmac_sha1?

Yes.

like this:
Code: Select all...
     char* out = (char*)c_malloc(40);
...
     CRYPTO_DBG("the hmac_sha1 string is %s\n", out);
...



You may rethink this part ;) It's C ...

Also, What is hmac_sha1_vector for?


http://docs.ros.org/diamondback/api/wpa ... a1_8c.html

You have your data scattered around in blocks and want an sha1 of the whole.

Cal