Changeset 2c77cc6f256e2dd45190aaf508321a230e0095d4

Show
Ignore:
Timestamp:
01/20/12 17:38:15 (2 years ago)
Author:
Theo Schlossnagle <jesus@lethargy.org>
git-committer:
Theo Schlossnagle <jesus@lethargy.org> 1327081095 -0800
git-parent:

[5326de642120020aa0f55432c3dbd84679c87c98], [50525e499873f7998d760f0e7601eb24f65625ff]

git-author:
Theo Schlossnagle <jesus@lethargy.org> 1327081095 -0800
Message:

Merge pull request #46 from TheTeaWeevil?/master

HMAC-SHA1 Encoding in lua_noit.c

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua_noit.c

    r9d3260a r50525e4  
    4747#include <libxml/tree.h> 
    4848#include <openssl/md5.h> 
     49#include <openssl/hmac.h> 
    4950 
    5051#include "noit_conf.h" 
     
    10671068  encoded_len = noit_b64_encode(message, inlen, encoded, encoded_len); 
    10681069  lua_pushlstring(L, (char *)encoded, encoded_len); 
     1070  return 1; 
     1071} 
     1072static int 
     1073nl_hmac_sha1_encode(lua_State *L) { 
     1074  size_t messagelen, keylen, encoded_len; 
     1075  const unsigned char *message, *key; 
     1076  unsigned char* result; 
     1077  char* encoded; 
     1078 
     1079  if(lua_gettop(L) != 2) luaL_error(L, "bad call to noit.hmac_sha1_encode"); 
     1080  encoded_len = 28; /* the length of the base64 encoded HMAC-SHA1 result will always be 28 */ 
     1081  encoded = malloc(encoded_len); 
     1082 
     1083  message = (const unsigned char *)lua_tolstring(L, 1, &messagelen); 
     1084  key = (const unsigned char *)lua_tolstring(L, 2, &keylen); 
     1085 
     1086  result = HMAC(EVP_sha1(), key, keylen, message, messagelen, NULL, NULL); 
     1087  encoded_len = noit_b64_encode(result, 20, encoded, encoded_len); /* the raw HMAC-SHA1 result will always be 20 */ 
     1088 
     1089  lua_pushlstring(L, (char *)encoded, encoded_len); 
     1090 
    10691091  return 1; 
    10701092} 
     
    19041926  { "base64_decode", nl_base64_decode }, 
    19051927  { "base64_encode", nl_base64_encode }, 
     1928  { "hmac_sha1_encode", nl_hmac_sha1_encode }, 
    19061929  { "md5_hex", nl_md5_hex }, 
    19071930  { "pcre", nl_pcre },