Skip to content
Browse files

working hmac_sha1

  • Loading branch information...
1 parent 46ab2df commit 4aa692cd2c88ab2731e994b707f9a9479702ac76 @brainfucker committed
Showing with 54 additions and 148 deletions.
  1. +1 −1 .lock-wscript
  2. +53 −29 hashlib.cc
  3. +0 −64 lib/sha/HMAC_SHA1.cpp
  4. +0 −53 lib/sha/HMAC_SHA1.h
  5. +0 −1 makefile
View
2 .lock-wscript
@@ -2,7 +2,7 @@ argv = ['/usr/local/bin/node-waf', 'configure', 'build']
blddir = '/home/brainfucker/Projects/hashlib/build'
commands = {'dist': 0, 'configure': True, 'distcheck': 0, 'install': 0, 'build': True, 'clean': 0, 'distclean': 0, 'check': 0, 'uninstall': 0}
cwd = '/home/brainfucker/Projects/hashlib'
-environ = {'GDM_KEYBOARD_LAYOUT': 'us', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'LOGNAME': 'brainfucker', 'USER': 'brainfucker', 'HOME': '/home/brainfucker', 'PATH': '/var/lib/gems/1.8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/brainfucker/Dropbox/Bin', 'DISPLAY': ':0.0', 'MAKEFLAGS': '', 'SSH_AGENT_PID': '2284', 'LANG': 'en_US.UTF-8', 'SPEECHD_PORT': '7560', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XAUTHORITY': '/var/run/gdm/auth-for-brainfucker-ud7rdn/database', 'SESSION_MANAGER': 'local/brainfucker-laptop:@/tmp/.ICE-unix/1996,unix/brainfucker-laptop:/tmp/.ICE-unix/1996', 'XDG_DATA_DIRS': '/usr/share/gnome:/usr/local/share/:/usr/share/', '_': '/usr/bin/make', 'DESKTOP_AUTOSTART_ID': '107170046d54ad4dd9126597960634480800000019960000', 'MFLAGS': '', 'USERNAME': 'brainfucker', 'MAKELEVEL': '1', 'SSH_AUTH_SOCK': '/tmp/keyring-D5gCZf/socket.ssh', 'GNOME_KEYRING_SOCKET': '/tmp/keyring-D5gCZf/socket', 'GDMSESSION': 'gnome', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-0CYjd3B6cl,guid=a806ffff7afbbfb883fb11444b7550d4', 'ORBIT_SOCKETDIR': '/tmp/orbit-brainfucker', 'XDG_SESSION_COOKIE': '8143f1ef8b2173edae5c4ea34aed6323-1265979603.30574-1776746902', 'DESKTOP_SESSION': 'gnome', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'GTK_MODULES': 'canberra-gtk-module', 'OLDPWD': '/home/brainfucker', 'GDM_LANG': 'en_US.UTF-8', 'HISTCONTROL': 'ignoreboth', 'SHLVL': '1', 'PWD': '/home/brainfucker/Projects/hashlib', 'GTK_RC_FILES': '/etc/gtk/gtkrc:/home/brainfucker/.gtkrc-1.2-gnome2', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}
+environ = {'GDM_KEYBOARD_LAYOUT': 'us', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'LOGNAME': 'brainfucker', 'USER': 'brainfucker', 'HOME': '/home/brainfucker', 'PATH': '/var/lib/gems/1.8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/brainfucker/Dropbox/Bin', 'DISPLAY': ':0.0', 'MAKEFLAGS': '', 'SSH_AGENT_PID': '2242', 'LANG': 'en_US.UTF-8', 'SPEECHD_PORT': '7560', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XAUTHORITY': '/var/run/gdm/auth-for-brainfucker-rdxSCA/database', 'SESSION_MANAGER': 'local/brainfucker-laptop:@/tmp/.ICE-unix/1965,unix/brainfucker-laptop:/tmp/.ICE-unix/1965', 'XDG_DATA_DIRS': '/usr/share/gnome:/usr/local/share/:/usr/share/', '_': '/usr/bin/make', 'DESKTOP_AUTOSTART_ID': '105423f5097710b769126618213129088300000019650000', 'MFLAGS': '', 'USERNAME': 'brainfucker', 'MAKELEVEL': '1', 'SSH_AUTH_SOCK': '/tmp/keyring-9OIwAf/socket.ssh', 'GNOME_KEYRING_SOCKET': '/tmp/keyring-9OIwAf/socket', 'GDMSESSION': 'gnome', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-7UX7P2MjSx,guid=a511607030760fe51aa927814b7867f1', 'ORBIT_SOCKETDIR': '/tmp/orbit-brainfucker', 'XDG_SESSION_COOKIE': '8143f1ef8b2173edae5c4ea34aed6323-1266182127.832779-806612176', 'DESKTOP_SESSION': 'gnome', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'GTK_MODULES': 'canberra-gtk-module', 'OLDPWD': '/home/brainfucker', 'GDM_LANG': 'en_US.UTF-8', 'HISTCONTROL': 'ignoreboth', 'SHLVL': '1', 'PWD': '/home/brainfucker/Projects/hashlib', 'GTK_RC_FILES': '/etc/gtk/gtkrc:/home/brainfucker/.gtkrc-1.2-gnome2', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}
files = []
hash = 0
options = {'compile_targets': None, 'force': False, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'destdir': '', 'keep': False, 'zones': '', 'blddir': '', 'prefix': '/usr/local/', 'jobs': 2, 'srcdir': '', 'check_cxx_compiler': 'g++ icpc sunc++', 'check_c_compiler': 'gcc icc suncc'}
View
82 hashlib.cc
@@ -18,9 +18,6 @@ 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"
@@ -97,32 +94,58 @@ sha1(const Arguments& args)
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);
+ HandleScope scope;
+
+ using namespace sha1module;
+ String::Utf8Value data(args[0]->ToString());
+ String::Utf8Value key_input(args[1]->ToString());
+
+ unsigned char digest[40];
+ unsigned char hexdigest[40];
+ unsigned int i;
+
+ const void *key = (unsigned char*) *key_input;
+ size_t keylen = key_input.length();
+
+ char ipad[64], opad[64];
+
+ if(keylen > 64)
+ {
+ char optkeybuf[20];
+ SHAobject *keyhash;
+ keyhash = new SHAobject;
+ sha_init(keyhash);
+ sha_update(keyhash, (unsigned char*) key, keylen);
+ sha_final((unsigned char*) optkeybuf, keyhash);
+ keylen = 20;
+ key = optkeybuf;
+ }
+
+ memcpy(ipad, key, keylen);
+ memcpy(opad, key, keylen);
+ memset(ipad+keylen, 0, 64 - keylen);
+ memset(opad+keylen, 0, 64 - keylen);
+
+ for (i = 0; i < 64; i++)
+ {
+ ipad[i] ^= 0x36;
+ opad[i] ^= 0x5c;
+ }
+
+ SHAobject *context;
+ context = new SHAobject;
+ sha_init(context);
+ sha_update(context, (unsigned char*) ipad, 64);
+ sha_update(context, (unsigned char*)*data, data.length());
+ sha_final(digest, context);
+
+ sha_init(context);
+ sha_update(context, (unsigned char*) opad, 64);
+ sha_update(context, digest, 20);
+ sha_final(digest, context);
+
+ make_digest_ex(hexdigest, digest, 20);
+ return String::New((char*)hexdigest,40);
}
@@ -226,6 +249,7 @@ md6(const Arguments& args)
return String::New((char*)hexdigest,len);
}
+
int read_cb (eio_req *req)
{
file_data *fd=(file_data *)req->data;
View
64 lib/sha/HMAC_SHA1.cpp
@@ -1,64 +0,0 @@
-//******************************************************************************
-//* 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
53 lib/sha/HMAC_SHA1.h
@@ -1,53 +0,0 @@
-/*
- 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__ */
View
1 makefile
@@ -1,6 +1,5 @@
all:
node-waf configure build
- @echo "--------\nMODULE FILE SHOULD BE IN ./build/default/\nUSE 'sudo make install' to install it\nAlso you can use 'make tests' to run tests"
tests:
node ./test.js
install:

0 comments on commit 4aa692c

Please sign in to comment.
Something went wrong with that request. Please try again.