Permalink
Browse files

Adding sha1, sha256, sha512 and md6 hashes

  • Loading branch information...
brainfucker committed Jan 14, 2010
1 parent 4f02645 commit d79aad2ecc052d1b6a85cb09b18b495854eef618
View
@@ -0,0 +1,9 @@
+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', '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', 'HOME': '/home/brainfucker', 'DISPLAY': ':0.0', 'SSH_AGENT_PID': '2165', 'LANG': 'en_US.UTF-8', 'SPEECHD_PORT': '7560', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XDG_SESSION_COOKIE': '8143f1ef8b2173edae5c4ea34aed6323-1263460248.734008-24927218', 'SESSION_MANAGER': 'local/brainfucker-laptop:@/tmp/.ICE-unix/1990,unix/brainfucker-laptop:/tmp/.ICE-unix/1990', 'SHLVL': '1', '_': '/usr/local/bin/node-waf', 'DESKTOP_AUTOSTART_ID': '107978dae8fb34ab126346025650407300000019900000', 'USERNAME': 'brainfucker', 'SSH_AUTH_SOCK': '/tmp/keyring-jtkWgy/socket.ssh', 'GNOME_KEYRING_SOCKET': '/tmp/keyring-jtkWgy/socket', 'GDMSESSION': 'gnome', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-jBVVX0EYEA,guid=d3f01e347305d102686b68af4b4edf9b', 'ORBIT_SOCKETDIR': '/tmp/orbit-brainfucker', 'XAUTHORITY': '/var/run/gdm/auth-for-brainfucker-9Sn1Pn/database', 'DESKTOP_SESSION': 'gnome', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'GTK_MODULES': 'canberra-gtk-module', 'OLDPWD': '/home/brainfucker/Projects/hashlib', 'GDM_LANG': 'en_US.UTF-8', 'HISTCONTROL': 'ignoreboth', 'XDG_DATA_DIRS': '/usr/share/gnome:/usr/local/share/:/usr/share/', '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++'}
+srcdir = '/home/brainfucker/Projects/hashlib'
View
21 README
@@ -1,7 +1,18 @@
+# Hashlib
Its an library for making hashes
-===========
- install:
- 1) go to the directory whith this library
- 2) make: node-waf configure build
-
+## Install:
+ 1) go to the directory whith this library
+ 2) make: node-waf configure build
+ 3) module will be here ./build/default/hashlib.node
+
+## Functions:
+ md5([sting] str); // Returns md5 hash from sting
+ sha1([sting] str); // Returns sha1 hash from sting
+ sha256([sting] str); // Returns sha256 hash from sting
+ sha512([sting] str); // Returns sha512 hash from sting
+ md6([sting] str, [int] length); // Returns md6 hash from sting, second parametr is optional
+
+## Using:
+ var hashlib = require("__path_to_hashlib_module__/hashlib");
+ hashlib.md5('text');
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': 'node_addon', 'tooldir': None, 'funs': None}]
@@ -0,0 +1,43 @@
+AR = '/usr/bin/ar'
+ARFLAGS = 'rcs'
+CCFLAGS_MACBUNDLE = ['-fPIC']
+CC_VERSION = ('4', '4', '1')
+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_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_CXXFLAGS = ['-fPIC', '-DPIC']
+shlib_LINKFLAGS = ['-shared']
+shlib_PATTERN = 'lib%s.so'
+staticlib_LINKFLAGS = ['-Wl,-Bstatic']
+staticlib_PATTERN = 'lib%s.a'
View
@@ -0,0 +1,24 @@
+# project configured on Thu Jan 14 13:43:34 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 node prefix
+
View
Binary file not shown.
View
Binary file not shown.
View
@@ -1,47 +1,171 @@
#include <v8.h>
-//#include "lib/md5/md5.cpp"
-//#include "lib/md5/arc4.h"
+
#include "lib/md5/md5.c"
+#include "lib/sha/shamodule.c"
+#include "lib/sha/sha256module.c"
+#include "lib/sha/sha512module.c"
+
+#include "lib/md6/md6.h"
+#include "lib/md6/md6_compress.c"
+#include "lib/md6/md6_mode.c"
+
+//
+
#include <iostream>
-#include <string>
using namespace v8;
+Handle<Value>
+sha1(const Arguments& args)
+{
+ HandleScope scope;
+ using namespace sha1module;
+ String::Utf8Value data(args[0]->ToString());
+ unsigned char digest[40];
+ unsigned char hexdigest[40];
+ SHAobject *sha;
+ sha=new SHAobject;
+ sha_init(sha);
+ sha_update(sha, (unsigned char*) *data, data.length());
+ sha_final(digest, sha);
+ char chr;
+ int i, j;
+ for(i=j=0; i<20; i++) {
+ chr = (digest[i] >> 4) & 0xf;
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ chr = (digest[i] & 0xf);
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ }
+
+ return String::New((char*)hexdigest,40);
+}
+
Handle<Value>
-md5(const Arguments& args)
+sha256(const Arguments& args)
+{
+ HandleScope scope;
+ using namespace sha256module;
+ String::Utf8Value data(args[0]->ToString());
+ unsigned char digest[64];
+ unsigned char hexdigest[64];
+ SHAobject *sha;
+ sha=new SHAobject;
+ sha_init(sha);
+ sha_update(sha, (unsigned char*) *data, data.length());
+ sha_final(digest, sha);
+ char chr;
+ int i, j;
+ for(i=j=0; i<32; i++) {
+ chr = (digest[i] >> 4) & 0xf;
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ chr = (digest[i] & 0xf);
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ }
+
+ return String::New((char*)hexdigest,64);
+}
+
+Handle<Value>
+sha512(const Arguments& args)
+{
+ HandleScope scope;
+ using namespace sha512module;
+ String::Utf8Value data(args[0]->ToString());
+ unsigned char digest[128];
+ unsigned char hexdigest[128];
+ SHAobject *sha;
+ sha=new SHAobject;
+ sha512_init(sha);
+ sha512_update(sha, (unsigned char*) *data, data.length());
+ sha512_final(digest, sha);
+ char chr;
+ int i, j;
+ for(i=j=0; i<64; i++) {
+ chr = (digest[i] >> 4) & 0xf;
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ chr = (digest[i] & 0xf);
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ }
+
+ return String::New((char*)hexdigest,128);
+}
+
+
+Handle<Value>
+md6(const Arguments& args)
{
HandleScope scope;
String::Utf8Value data(args[0]->ToString());
+
+ int len(32);
+ if (!args[1]->IsUndefined()) {
+ len=args[1]->ToInteger()->Value();
+ }
+ unsigned char digest[len];
+ unsigned char hexdigest[len];
+ md6_hash(len*8, (unsigned char*) *data, data.length(), digest);
+ char chr;
+ int i, j;
+ int half_len=len/2;
+ if (len%2!=0) half_len++;
+
+ for(i=j=0; i<half_len; i++) {
+ chr = (digest[i] >> 4) & 0xf;
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ chr = (digest[i] & 0xf);
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ }
+
+ return String::New((char*)hexdigest,len);
+}
+
+Handle<Value>
+md5(const Arguments& args)
+{
+ HandleScope scope;
+
+ String::Utf8Value data(args[0]->ToString());
md5_state_t mdContext;
unsigned char digest[16];
unsigned char hexdigest[32];
- int i, j;
/* make an hash */
md5_init(&mdContext);
- md5_append(&mdContext,(unsigned char*) *data,data.length());
+ md5_append(&mdContext,(unsigned char*)*data,data.length());
md5_finish(&mdContext, digest);
-
- /* Make hex version of the digest */
+
+ int i, j;
for(i=j=0; i<16; i++) {
- char c;
- c = (digest[i] >> 4) & 0xf;
- c = (c>9) ? c+'a'-10 : c + '0';
- hexdigest[j++] = c;
- c = (digest[i] & 0xf);
- c = (c>9) ? c+'a'-10 : c + '0';
- hexdigest[j++] = c;
+ char chr;
+ chr = (digest[i] >> 4) & 0xf;
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
+ chr = (digest[i] & 0xf);
+ chr = (chr>9) ? chr+'a'-10 : chr + '0';
+ hexdigest[j++] = chr;
}
return String::New((char*)hexdigest,32);
}
-
extern "C" void init (Handle<Object> target)
{
HandleScope scope;
target->Set(String::New("md5"), FunctionTemplate::New(md5)->GetFunction());
+ target->Set(String::New("md6"), FunctionTemplate::New(md6)->GetFunction());
+ target->Set(String::New("sha"), FunctionTemplate::New(sha1)->GetFunction());
+ target->Set(String::New("sha1"), FunctionTemplate::New(sha1)->GetFunction());
+ target->Set(String::New("sha256"), FunctionTemplate::New(sha256)->GetFunction());
+ target->Set(String::New("sha512"), FunctionTemplate::New(sha512)->GetFunction());
}
@@ -0,0 +1,16 @@
+Filename: README_Reference.txt
+Author: Ronald L. Rivest
+Date: 8/31/08
+
+This directory (Reference_Implementation) contains the
+required reference implementation for our NIST SHA-3
+submission, "MD6".
+
+The files included here are:
+ md6.h
+ md6_compress.c
+ md6_mode.c
+ md6_nist.h
+ md6_nist.c
+ inttypes.h
+ stdint.h
Oops, something went wrong.

0 comments on commit d79aad2

Please sign in to comment.