Commit fc94439b authored by Terry Ellison's avatar Terry Ellison
Browse files

crypto.c: Clarify comments on use of userdata for header + context + key opad blocks

parent 52897354
...@@ -172,7 +172,8 @@ static int crypto_lhash (lua_State *L) ...@@ -172,7 +172,8 @@ static int crypto_lhash (lua_State *L)
static int crypto_new_hash_hmac (lua_State *L, int what) static int crypto_new_hash_hmac (lua_State *L, int what)
{ {
/* get pointer to relevant hash_mechs table entry in app/crypto/digest.c */ // get pointer to relevant hash_mechs table entry in app/crypto/digest.c. Note that
// the size of the table needed is dependent on the the digest type
const digest_mech_info_t *mi = crypto_digest_mech (luaL_checkstring (L, 1)); const digest_mech_info_t *mi = crypto_digest_mech (luaL_checkstring (L, 1));
if (!mi) if (!mi)
return bad_mech (L); return bad_mech (L);
...@@ -182,22 +183,24 @@ static int crypto_new_hash_hmac (lua_State *L, int what) ...@@ -182,22 +183,24 @@ static int crypto_new_hash_hmac (lua_State *L, int what)
uint8_t *k_opad = NULL; uint8_t *k_opad = NULL;
if (what == WANT_HMAC) if (what == WANT_HMAC)
{ { // The key and k_opad are only used for HMAC; these default to NULLs for HASH
key = luaL_checklstring (L, 2, &len); key = luaL_checklstring (L, 2, &len);
k_opad_len = mi->block_size; k_opad_len = mi->block_size;
} }
// create a userdatum with specific metatable. This comprises the ud header, // create a userdatum with specific metatable. This comprises the ud header,
// the encrypto context block, and an optional HMAC block // the encrypto context block, and an optional HMAC block as a single allocation
// unit
udlen = sizeof(digest_user_datum_t) + mi->ctx_size + k_opad_len; udlen = sizeof(digest_user_datum_t) + mi->ctx_size + k_opad_len;
digest_user_datum_t *dudat = (digest_user_datum_t *)lua_newuserdata(L, udlen); digest_user_datum_t *dudat = (digest_user_datum_t *)lua_newuserdata(L, udlen);
void *ctx = (char *)(dudat + 1); luaL_getmetatable(L, "crypto.hash"); // and set its metatable to the crypto.hash table
mi->create (ctx);
luaL_getmetatable(L, "crypto.hash");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
void *ctx = dudat + 1; // The context block immediately follows the digest_user_datum
mi->create (ctx);
if (what == WANT_HMAC) { if (what == WANT_HMAC) {
// The k_opad block immediately follows the context block
k_opad = (char *)ctx + mi->ctx_size; k_opad = (char *)ctx + mi->ctx_size;
crypto_hmac_begin (ctx, mi, key, len, k_opad); crypto_hmac_begin (ctx, mi, key, len, k_opad);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment