Permalink
Browse files

adding basic hmac_sha1 support

  • Loading branch information...
1 parent c565a70 commit 5b260de057c27a4dbed941a6fef83e505a088575 @brainfucker committed Feb 13, 2010
View
Binary file not shown.
@@ -0,0 +1,2 @@
+version = 0x105010
+tools = [{'tool': 'ar', 'tooldir': None, 'funs': None}, {'tool': 'cxx', 'tooldir': None, 'funs': None}, {'tool': 'gxx', 'tooldir': None, 'funs': None}, {'tool': 'compiler_cxx', 'tooldir': None, 'funs': None}, {'tool': 'cc', 'tooldir': None, 'funs': None}, {'tool': 'gcc', 'tooldir': None, 'funs': None}, {'tool': 'compiler_cc', 'tooldir': None, 'funs': None}, {'tool': 'node_addon', 'tooldir': None, 'funs': None}]
@@ -0,0 +1,56 @@
+AR = '/usr/bin/ar'
+ARFLAGS = 'rcs'
+CC = ['/usr/bin/gcc']
+CCDEFINES_ST = '-D%s'
+CCFLAGS = ['-O3']
+CCFLAGS_DEBUG = ['-g']
+CCFLAGS_MACBUNDLE = ['-fPIC']
+CCFLAGS_RELEASE = ['-O2']
+CCLNK_SRC_F = ''
+CCLNK_TGT_F = ['-o', '']
+CC_NAME = 'gcc'
+CC_SRC_F = ''
+CC_TGT_F = ['-c', '-o', '']
+CC_VERSION = ('4', '4', '1')
+COMPILER_CC = 'gcc'
+COMPILER_CXX = 'g++'
+CPP = '/usr/bin/cpp'
+CPPFLAGS_NODE = '-DEV_MULTIPLICITY=0'
+CPPPATH_NODE = '/usr/local/include/node'
+CPPPATH_ST = '-I%s'
+CXX = ['/usr/bin/g++']
+CXXDEFINES_ST = '-D%s'
+CXXFLAGS_DEBUG = ['-g']
+CXXFLAGS_RELEASE = ['-O2']
+CXXLNK_SRC_F = ''
+CXXLNK_TGT_F = ['-o', '']
+CXX_NAME = 'gcc'
+CXX_SRC_F = ''
+CXX_TGT_F = ['-c', '-o', '']
+DEST_BINFMT = 'elf'
+DEST_CPU = 'x86_64'
+DEST_OS = 'linux'
+FULLSTATIC_MARKER = '-static'
+LIBPATH_NODE = '/usr/local/lib'
+LIBPATH_ST = '-L%s'
+LIB_ST = '-l%s'
+LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup']
+LINK_CC = ['/usr/bin/gcc']
+LINK_CXX = ['/usr/bin/g++']
+PREFIX = '/usr/local'
+PREFIX_NODE = '/usr/local'
+RANLIB = '/usr/bin/ranlib'
+RPATH_ST = '-Wl,-rpath,%s'
+SHLIB_MARKER = '-Wl,-Bdynamic'
+SONAME_ST = '-Wl,-h,%s'
+STATICLIBPATH_ST = '-L%s'
+STATICLIB_MARKER = '-Wl,-Bstatic'
+STATICLIB_ST = '-l%s'
+macbundle_PATTERN = '%s.bundle'
+program_PATTERN = '%s'
+shlib_CCFLAGS = ['-fPIC', '-DPIC']
+shlib_CXXFLAGS = ['-fPIC', '-DPIC']
+shlib_LINKFLAGS = ['-shared']
+shlib_PATTERN = 'lib%s.so'
+staticlib_LINKFLAGS = ['-Wl,-Bstatic']
+staticlib_PATTERN = 'lib%s.a'
View
@@ -0,0 +1,30 @@
+# project configured on Sat Feb 13 22:29:48 2010 by
+# waf 1.5.10 (abi 7, python 20604f0 on linux2)
+# using /usr/local/bin/node-waf configure build
+#
+Checking for program g++,c++
+
+find program=['g++', 'c++'] paths=[] var='CXX' -> '/usr/bin/g++'
+
+Checking for program cpp
+
+find program=['cpp'] paths=[] var='CPP' -> '/usr/bin/cpp'
+
+Checking for program ar
+
+find program=['ar'] paths=[] var='AR' -> '/usr/bin/ar'
+
+Checking for program ranlib
+
+find program=['ranlib'] paths=[] var='RANLIB' -> '/usr/bin/ranlib'
+
+Checking for g++
+
+Checking for program gcc,cc
+
+find program=['gcc', 'cc'] paths=[] var='CC' -> '/usr/bin/gcc'
+
+Checking for gcc
+
+Checking for node prefix
+
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
@@ -18,6 +18,9 @@ extern "C" {
#include "md5.h"
}
+#include "lib/sha/HMAC_SHA1.cpp"
+#include "lib/sha/SHA1.cpp"
+
#include "lib/sha/shamodule.c"
#include "lib/sha/sha256module.c"
#include "lib/sha/sha512module.c"
@@ -91,6 +94,37 @@ sha1(const Arguments& args)
return String::New((char*)hexdigest,40);
}
+Handle<Value>
+hmac_sha1(const Arguments& args)
+{
+ HandleScope scope;
+ using namespace sha1module;
+ String::Utf8Value data(args[1]->ToString());
+ String::Utf8Value ckey(args[0]->ToString());
+ //unsigned char digest[40];
+ //unsigned char hexdigest[40];
+
+ //BYTE Key[20];
+ //strcpy(Key,*ckey);
+ BYTE digest[20];
+
+ //memset(Key, 20, 0x0b) ;
+ CHMAC_SHA1 HMAC_SHA1 ;
+ //HMAC_SHA1.HMAC_SHA1((BYTE*)*data, strlen(*data), Key, sizeof(Key), digest);
+ HMAC_SHA1.HMAC_SHA1((BYTE*)*data, strlen(*data), (BYTE*)*ckey, strlen(*ckey), digest);
+
+
+ //SHAobject *sha;
+ //sha=new SHAobject;
+ //sha_init(sha);
+ //sha_update(sha, (unsigned char*) *data, data.length());
+ //sha_final(digest, sha);
+
+ //make_digest_ex(hexdigest, digest, 20);
+
+ return String::New((char*)digest,20);
+}
+
Handle<Value>
sha256(const Arguments& args)
@@ -309,6 +343,7 @@ extern "C" void init (Handle<Object> target)
target->Set(String::New("md6"), FunctionTemplate::New(md6)->GetFunction());
target->Set(String::New("sha"), FunctionTemplate::New(sha)->GetFunction());
target->Set(String::New("sha1"), FunctionTemplate::New(sha1)->GetFunction());
+ target->Set(String::New("hmac_sha1"), FunctionTemplate::New(hmac_sha1)->GetFunction());
target->Set(String::New("sha256"), FunctionTemplate::New(sha256)->GetFunction());
target->Set(String::New("sha512"), FunctionTemplate::New(sha512)->GetFunction());
View
@@ -0,0 +1,10 @@
+var hashlib = require("./build/default/hashlib");
+var sys = require("sys");
+var md5 = require("./test/md5");
+
+process.chdir(__dirname);
+
+sys.puts(hashlib.hmac_sha1('testsjdfhskjdfhskjfhsajkfhsakf','34'));
+sys.puts(hashlib.hmac_sha1('wow','smsm'));
+sys.puts(hashlib.hmac_sha1('HEY MAN','man man'));
+sys.puts(hashlib.hmac_sha1('HEY MAN','man man2'));
View
@@ -0,0 +1,64 @@
+//******************************************************************************
+//* HMAC_SHA1.cpp : Implementation of HMAC SHA1 algorithm
+//* Comfort to RFC 2104
+//*
+//******************************************************************************
+#include <iostream>
+#include <memory>
+#include "HMAC_SHA1.h"
+
+
+void CHMAC_SHA1::HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest)
+{
+ memset(SHA1_Key, 0, SHA1_BLOCK_SIZE);
+
+ /* repeated 64 times for values in ipad and opad */
+ memset(m_ipad, 0x36, sizeof(m_ipad));
+ memset(m_opad, 0x5c, sizeof(m_opad));
+
+ /* STEP 1 */
+ if (key_len > SHA1_DIGEST_LENGTH)
+ {
+ CSHA1::Reset();
+ CSHA1::Update((UINT_8 *)key, key_len);
+ CSHA1::Final();
+
+ CSHA1::GetHash((UINT_8 *)SHA1_Key);
+ }
+ else
+ memcpy(SHA1_Key, key, key_len);
+
+ /* STEP 2 */
+ for (int i=0; i<sizeof(m_ipad); i++)
+ {
+ m_ipad[i] ^= SHA1_Key[i];
+ }
+
+ /* STEP 3 */
+ memcpy(AppendBuf1, m_ipad, sizeof(m_ipad));
+ memcpy(AppendBuf1 + sizeof(m_ipad), text, text_len);
+
+ /* STEP 4 */
+ CSHA1::Reset();
+ CSHA1::Update((UINT_8 *)AppendBuf1, sizeof(m_ipad) + text_len);
+ CSHA1::Final();
+
+ CSHA1::GetHash((UINT_8 *)szReport);
+
+ /* STEP 5 */
+ for (int j=0; j<sizeof(m_opad); j++)
+ {
+ m_opad[j] ^= SHA1_Key[j];
+ }
+
+ /* STEP 6 */
+ memcpy(AppendBuf2, m_opad, sizeof(m_opad));
+ memcpy(AppendBuf2 + sizeof(m_opad), szReport, SHA1_DIGEST_LENGTH);
+
+ /*STEP 7 */
+ CSHA1::Reset();
+ CSHA1::Update((UINT_8 *)AppendBuf2, sizeof(m_opad) + SHA1_DIGEST_LENGTH);
+ CSHA1::Final();
+
+ CSHA1::GetHash((UINT_8 *)digest);
+}
View
@@ -0,0 +1,53 @@
+/*
+ 100% free public domain implementation of the HMAC-SHA1 algorithm
+ by Chien-Chung, Chung (Jim Chung) <jimchung1221@gmail.com>
+*/
+
+
+#ifndef __HMAC_SHA1_H__
+#define __HMAC_SHA1_H__
+
+#include "SHA1.h"
+
+typedef unsigned char BYTE ;
+
+class CHMAC_SHA1 : public CSHA1
+{
+ private:
+ BYTE m_ipad[64];
+ BYTE m_opad[64];
+
+ char * szReport ;
+ char * SHA1_Key ;
+ char * AppendBuf1 ;
+ char * AppendBuf2 ;
+
+
+ public:
+
+ enum {
+ SHA1_DIGEST_LENGTH = 20,
+ SHA1_BLOCK_SIZE = 64,
+ HMAC_BUF_LEN = 4096
+ } ;
+
+ CHMAC_SHA1()
+ :szReport(new char[HMAC_BUF_LEN]),
+ AppendBuf1(new char[HMAC_BUF_LEN]),
+ AppendBuf2(new char[HMAC_BUF_LEN]),
+ SHA1_Key(new char[HMAC_BUF_LEN])
+ {}
+
+ ~CHMAC_SHA1()
+ {
+ delete[] szReport ;
+ delete[] AppendBuf1 ;
+ delete[] AppendBuf2 ;
+ delete[] SHA1_Key ;
+ }
+
+ void HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest);
+};
+
+
+#endif /* __HMAC_SHA1_H__ */
Oops, something went wrong.

0 comments on commit 5b260de

Please sign in to comment.