Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

shitch to make_digest from PHP

  • Loading branch information...
commit 98580afb13112d3423450d22a3d88f7cf37741ae 1 parent 24cd540
@brainfucker authored
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', '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:'}
+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-another', '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++'}
View
BIN  build/.wafpickle-7
Binary file not shown
View
2  build/c4che/build.config.py
@@ -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}]
View
43 build/c4che/default.cache.py
@@ -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
24 build/config.log
@@ -0,0 +1,24 @@
+# project configured on Thu Jan 14 23:21:13 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
BIN  build/default/hashlib.node
Binary file not shown
View
BIN  build/default/hashlib_1.o
Binary file not shown
View
75 hashlib.cc
@@ -10,11 +10,23 @@
#include "lib/md6/md6_compress.c"
#include "lib/md6/md6_mode.c"
-//
-
#include <iostream>
using namespace v8;
+// make digest from php
+static void
+make_digest_ex(unsigned char *md5str, unsigned char *digest, int len)
+{
+ static const char hexits[17] = "0123456789abcdef";
+ int i;
+
+ for (i = 0; i < len; i++) {
+ md5str[i * 2] = hexits[digest[i] >> 4];
+ md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F];
+ }
+ md5str[len * 2] = '\0';
+}
+
Handle<Value>
sha1(const Arguments& args)
{
@@ -28,16 +40,8 @@ sha1(const Arguments& args)
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;
- }
+
+ make_digest_ex(hexdigest, digest, 20);
return String::New((char*)hexdigest,40);
}
@@ -56,16 +60,8 @@ sha256(const Arguments& args)
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;
- }
+
+ make_digest_ex(hexdigest, digest, 32);
return String::New((char*)hexdigest,64);
}
@@ -83,16 +79,8 @@ sha512(const Arguments& args)
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;
- }
+
+ make_digest_ex(hexdigest, digest, 64);
return String::New((char*)hexdigest,128);
}
@@ -112,19 +100,11 @@ md6(const Arguments& args)
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;
- }
+ make_digest_ex(hexdigest, digest, half_len);
return String::New((char*)hexdigest,len);
}
@@ -145,16 +125,7 @@ md5(const Arguments& args)
md5_append(&mdContext,(unsigned char*)*data,data.length());
md5_finish(&mdContext, digest);
- int i, j;
- for(i=j=0; i<16; i++) {
- 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;
- }
+ make_digest_ex(hexdigest, digest, 16);
return String::New((char*)hexdigest,32);
}
View
1  test.js
@@ -1,7 +1,6 @@
var hashlib = require("./build/default/hashlib");
var sys = require("sys");
var md5 = require("./test/md5");
-
if (hashlib.md5('test')=='098f6bcd4621d373cade4e832627b4f6')
sys.puts('test 1 PASSED');
else
Please sign in to comment.
Something went wrong with that request. Please try again.