mhash 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/Rakefile +6 -0
- data/ext/mhash/Makefile +187 -0
- data/ext/mhash/extconf.rb +4 -0
- data/ext/mhash/mhash.c +16 -0
- data/ext/mhash/module_definitions.c +62 -0
- data/ext/mhash/module_definitions.h +7 -0
- data/ext/mhash/module_functions.c +150 -0
- data/ext/mhash/module_functions.h +32 -0
- data/lib/mhash.rb +5 -0
- data/mhash.gemspec +16 -0
- data/test/test_mhash.rb +70 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
* Copyright (c) 2013, Thibaut Deloffre
|
2
|
+
* All rights reserved.
|
3
|
+
* Redistribution and use in source and binary forms, with or without
|
4
|
+
* modification, are permitted provided that the following conditions are met:
|
5
|
+
*
|
6
|
+
* * Redistributions of source code must retain the above copyright
|
7
|
+
* notice, this list of conditions and the following disclaimer.
|
8
|
+
* * Redistributions in binary form must reproduce the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer in the
|
10
|
+
* documentation and/or other materials provided with the distribution.
|
11
|
+
* * Neither the name of RocknRoot nor the names of its contributors may
|
12
|
+
* be used to endorse or promote products derived from this software
|
13
|
+
* without specific prior written permission.
|
14
|
+
*
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
|
16
|
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
|
19
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Rakefile
ADDED
data/ext/mhash/Makefile
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /home/tibshoot/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1
|
8
|
+
hdrdir = /home/tibshoot/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1
|
9
|
+
arch_hdrdir = /home/tibshoot/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/$(arch)
|
10
|
+
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
11
|
+
prefix = $(DESTDIR)/home/tibshoot/.rvm/rubies/ruby-1.9.2-p320
|
12
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
13
|
+
exec_prefix = $(prefix)
|
14
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
15
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
16
|
+
rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
|
17
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
18
|
+
sitedir = $(rubylibprefix)/site_ruby
|
19
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
20
|
+
mandir = $(datarootdir)/man
|
21
|
+
localedir = $(datarootdir)/locale
|
22
|
+
libdir = $(exec_prefix)/lib
|
23
|
+
psdir = $(docdir)
|
24
|
+
pdfdir = $(docdir)
|
25
|
+
dvidir = $(docdir)
|
26
|
+
htmldir = $(docdir)
|
27
|
+
infodir = $(datarootdir)/info
|
28
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
29
|
+
oldincludedir = $(DESTDIR)/usr/include
|
30
|
+
includedir = $(prefix)/include
|
31
|
+
localstatedir = $(prefix)/var
|
32
|
+
sharedstatedir = $(prefix)/com
|
33
|
+
sysconfdir = $(prefix)/etc
|
34
|
+
datadir = $(datarootdir)
|
35
|
+
datarootdir = $(prefix)/share
|
36
|
+
libexecdir = $(exec_prefix)/libexec
|
37
|
+
sbindir = $(exec_prefix)/sbin
|
38
|
+
bindir = $(exec_prefix)/bin
|
39
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
40
|
+
archdir = $(rubylibdir)/$(arch)
|
41
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
42
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
43
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
44
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
45
|
+
|
46
|
+
CC = gcc
|
47
|
+
CXX = g++
|
48
|
+
LIBRUBY = $(LIBRUBY_SO)
|
49
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
50
|
+
LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
|
51
|
+
LIBRUBYARG_STATIC = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static
|
52
|
+
OUTFLAG = -o
|
53
|
+
COUTFLAG = -o
|
54
|
+
|
55
|
+
RUBY_EXTCONF_H =
|
56
|
+
cflags = $(optflags) $(debugflags) $(warnflags)
|
57
|
+
optflags = -O3
|
58
|
+
debugflags = -ggdb
|
59
|
+
warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long
|
60
|
+
CFLAGS = -fPIC $(cflags) -fPIC
|
61
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
62
|
+
DEFS =
|
63
|
+
CPPFLAGS = -I/home/tibshoot/.rvm/usr/include $(DEFS) $(cppflags)
|
64
|
+
CXXFLAGS = $(CFLAGS) $(cxxflags)
|
65
|
+
ldflags = -L. -rdynamic -Wl,-export-dynamic
|
66
|
+
dldflags =
|
67
|
+
ARCH_FLAG =
|
68
|
+
DLDFLAGS = $(ldflags) $(dldflags)
|
69
|
+
LDSHARED = $(CC) -shared
|
70
|
+
LDSHAREDXX = $(CXX) -shared
|
71
|
+
AR = ar
|
72
|
+
EXEEXT =
|
73
|
+
|
74
|
+
RUBY_BASE_NAME = ruby
|
75
|
+
RUBY_INSTALL_NAME = ruby
|
76
|
+
RUBY_SO_NAME = ruby
|
77
|
+
arch = x86_64-linux
|
78
|
+
sitearch = $(arch)
|
79
|
+
ruby_version = 1.9.1
|
80
|
+
ruby = /home/tibshoot/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
|
81
|
+
RUBY = $(ruby)
|
82
|
+
RM = rm -f
|
83
|
+
RM_RF = $(RUBY) -run -e rm -- -rf
|
84
|
+
RMDIRS = $(RUBY) -run -e rmdir -- -p
|
85
|
+
MAKEDIRS = /bin/mkdir -p
|
86
|
+
INSTALL = /usr/bin/install -c
|
87
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
88
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
89
|
+
COPY = cp
|
90
|
+
|
91
|
+
#### End of system configuration section. ####
|
92
|
+
|
93
|
+
preload =
|
94
|
+
|
95
|
+
libpath = . $(libdir) /home/tibshoot/.rvm/usr/lib
|
96
|
+
LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir) -L/home/tibshoot/.rvm/usr/lib -Wl,-R/home/tibshoot/.rvm/usr/lib
|
97
|
+
DEFFILE =
|
98
|
+
|
99
|
+
CLEANFILES = mkmf.log
|
100
|
+
DISTCLEANFILES =
|
101
|
+
DISTCLEANDIRS =
|
102
|
+
|
103
|
+
extout =
|
104
|
+
extout_prefix =
|
105
|
+
target_prefix = /mhash
|
106
|
+
LOCAL_LIBS =
|
107
|
+
LIBS = $(LIBRUBYARG_SHARED) -lmhash -lpthread -lrt -ldl -lcrypt -lm -lc
|
108
|
+
SRCS = mhash.c module_definitions.c module_functions.c
|
109
|
+
OBJS = mhash.o module_definitions.o module_functions.o
|
110
|
+
TARGET = mhash
|
111
|
+
DLLIB = $(TARGET).so
|
112
|
+
EXTSTATIC =
|
113
|
+
STATIC_LIB =
|
114
|
+
|
115
|
+
BINDIR = $(bindir)
|
116
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
117
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
118
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
119
|
+
HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
|
120
|
+
ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
|
121
|
+
|
122
|
+
TARGET_SO = $(DLLIB)
|
123
|
+
CLEANLIBS = $(TARGET).so
|
124
|
+
CLEANOBJS = *.o *.bak
|
125
|
+
|
126
|
+
all: $(DLLIB)
|
127
|
+
static: $(STATIC_LIB)
|
128
|
+
.PHONY: all install static install-so install-rb
|
129
|
+
.PHONY: clean clean-so clean-rb
|
130
|
+
|
131
|
+
clean-rb-default::
|
132
|
+
clean-rb::
|
133
|
+
clean-so::
|
134
|
+
clean: clean-so clean-rb-default clean-rb
|
135
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
136
|
+
|
137
|
+
distclean-rb-default::
|
138
|
+
distclean-rb::
|
139
|
+
distclean-so::
|
140
|
+
distclean: clean distclean-so distclean-rb-default distclean-rb
|
141
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
142
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
143
|
+
@-$(RMDIRS) $(DISTCLEANDIRS)
|
144
|
+
|
145
|
+
realclean: distclean
|
146
|
+
install: install-so install-rb
|
147
|
+
|
148
|
+
install-so: $(RUBYARCHDIR)
|
149
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
150
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
151
|
+
@-$(MAKEDIRS) $(@D)
|
152
|
+
$(INSTALL_PROG) $(DLLIB) $(@D)
|
153
|
+
install-rb: pre-install-rb install-rb-default
|
154
|
+
install-rb-default: pre-install-rb-default
|
155
|
+
pre-install-rb: Makefile
|
156
|
+
pre-install-rb-default: Makefile
|
157
|
+
$(RUBYARCHDIR):
|
158
|
+
$(MAKEDIRS) $@
|
159
|
+
|
160
|
+
site-install: site-install-so site-install-rb
|
161
|
+
site-install-so: install-so
|
162
|
+
site-install-rb: install-rb
|
163
|
+
|
164
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
165
|
+
|
166
|
+
.cc.o:
|
167
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
168
|
+
|
169
|
+
.cxx.o:
|
170
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
171
|
+
|
172
|
+
.cpp.o:
|
173
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
174
|
+
|
175
|
+
.C.o:
|
176
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
|
177
|
+
|
178
|
+
.c.o:
|
179
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
|
180
|
+
|
181
|
+
$(DLLIB): $(OBJS) Makefile
|
182
|
+
@-$(RM) $(@)
|
183
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
$(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
|
data/ext/mhash/mhash.c
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <mhash.h>
|
3
|
+
#include "module_definitions.h"
|
4
|
+
|
5
|
+
void Init_mhash();
|
6
|
+
static VALUE m_mhash;
|
7
|
+
|
8
|
+
void Init_mhash()
|
9
|
+
{
|
10
|
+
static VALUE m_hash;
|
11
|
+
|
12
|
+
m_mhash = rb_define_module("Mhash");
|
13
|
+
|
14
|
+
mhash_define_consts(&m_mhash);
|
15
|
+
mhash_define_functions(&m_mhash);
|
16
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "module_definitions.h"
|
3
|
+
#include "module_functions.h"
|
4
|
+
|
5
|
+
void mhash_define_consts(VALUE *m_mhash)
|
6
|
+
{
|
7
|
+
rb_define_const(*m_mhash, "MHASH_CRC32", INT2NUM(0));
|
8
|
+
rb_define_const(*m_mhash, "MHASH_MD5", INT2NUM(1));
|
9
|
+
rb_define_const(*m_mhash, "MHASH_SHA1", INT2NUM(2));
|
10
|
+
rb_define_const(*m_mhash, "MHASH_HAVAL256", INT2NUM(3));
|
11
|
+
rb_define_const(*m_mhash, "MHASH_RIPEMD160", INT2NUM(5));
|
12
|
+
rb_define_const(*m_mhash, "MHASH_TIGER192", INT2NUM(7));
|
13
|
+
rb_define_const(*m_mhash, "MHASH_GOST", INT2NUM(8));
|
14
|
+
rb_define_const(*m_mhash, "MHASH_CRC32B", INT2NUM(9));
|
15
|
+
rb_define_const(*m_mhash, "MHASH_HAVAL224", INT2NUM(10));
|
16
|
+
rb_define_const(*m_mhash, "MHASH_HAVAL192", INT2NUM(11));
|
17
|
+
rb_define_const(*m_mhash, "MHASH_HAVAL160", INT2NUM(12));
|
18
|
+
rb_define_const(*m_mhash, "MHASH_HAVAL128", INT2NUM(13));
|
19
|
+
rb_define_const(*m_mhash, "MHASH_TIGER128", INT2NUM(14));
|
20
|
+
rb_define_const(*m_mhash, "MHASH_TIGER160", INT2NUM(15));
|
21
|
+
rb_define_const(*m_mhash, "MHASH_SHA256", INT2NUM(17));
|
22
|
+
rb_define_const(*m_mhash, "MHASH_ADLER32", INT2NUM(18));
|
23
|
+
rb_define_const(*m_mhash, "MHASH_SHA224", INT2NUM(19));
|
24
|
+
rb_define_const(*m_mhash, "MHASH_SHA512", INT2NUM(20));
|
25
|
+
rb_define_const(*m_mhash, "MHASH_SHA384", INT2NUM(21));
|
26
|
+
rb_define_const(*m_mhash, "MHASH_WHIRLPOOL", INT2NUM(22));
|
27
|
+
rb_define_const(*m_mhash, "MHASH_RIPEMD128", INT2NUM(23));
|
28
|
+
rb_define_const(*m_mhash, "MHASH_RIPEMD256", INT2NUM(24));
|
29
|
+
rb_define_const(*m_mhash, "MHASH_RIPEMD320", INT2NUM(25));
|
30
|
+
rb_define_const(*m_mhash, "MHASH_SNEFRU128", INT2NUM(26));
|
31
|
+
rb_define_const(*m_mhash, "MHASH_SNEFRU256", INT2NUM(27));
|
32
|
+
}
|
33
|
+
|
34
|
+
void mhash_define_functions(VALUE *m_mhash)
|
35
|
+
{
|
36
|
+
rb_define_module_function(*m_mhash, "digest", mhash_rb_digest, 2);
|
37
|
+
rb_define_module_function(*m_mhash, "crc32", mhash_rb_crc32, 1);
|
38
|
+
rb_define_module_function(*m_mhash, "md5", mhash_rb_md5, 1);
|
39
|
+
rb_define_module_function(*m_mhash, "sha1", mhash_rb_sha1, 1);
|
40
|
+
rb_define_module_function(*m_mhash, "haval256", mhash_rb_haval256, 1);
|
41
|
+
rb_define_module_function(*m_mhash, "ripemd160", mhash_rb_ripemd160, 1);
|
42
|
+
rb_define_module_function(*m_mhash, "tiger192", mhash_rb_tiger192, 1);
|
43
|
+
rb_define_module_function(*m_mhash, "gost", mhash_rb_gost, 1);
|
44
|
+
rb_define_module_function(*m_mhash, "crc32b", mhash_rb_crc32b, 1);
|
45
|
+
rb_define_module_function(*m_mhash, "haval224", mhash_rb_haval224, 1);
|
46
|
+
rb_define_module_function(*m_mhash, "haval192", mhash_rb_haval192, 1);
|
47
|
+
rb_define_module_function(*m_mhash, "haval160", mhash_rb_haval160, 1);
|
48
|
+
rb_define_module_function(*m_mhash, "haval128", mhash_rb_haval128, 1);
|
49
|
+
rb_define_module_function(*m_mhash, "tiger128", mhash_rb_tiger128, 1);
|
50
|
+
rb_define_module_function(*m_mhash, "tiger160", mhash_rb_tiger160, 1);
|
51
|
+
rb_define_module_function(*m_mhash, "sha256", mhash_rb_sha256, 1);
|
52
|
+
rb_define_module_function(*m_mhash, "adler32", mhash_rb_adler32, 1);
|
53
|
+
rb_define_module_function(*m_mhash, "sha224", mhash_rb_sha224, 1);
|
54
|
+
rb_define_module_function(*m_mhash, "sha512", mhash_rb_sha512, 1);
|
55
|
+
rb_define_module_function(*m_mhash, "sha384", mhash_rb_sha384, 1);
|
56
|
+
rb_define_module_function(*m_mhash, "whirlpool", mhash_rb_whirlpool, 1);
|
57
|
+
rb_define_module_function(*m_mhash, "ripemd128", mhash_rb_ripemd128, 1);
|
58
|
+
rb_define_module_function(*m_mhash, "ripemd256", mhash_rb_ripemd256, 1);
|
59
|
+
rb_define_module_function(*m_mhash, "ripemd320", mhash_rb_ripemd320, 1);
|
60
|
+
rb_define_module_function(*m_mhash, "snefru128", mhash_rb_snefru128, 1);
|
61
|
+
rb_define_module_function(*m_mhash, "snefru256", mhash_rb_snefru256, 1);
|
62
|
+
}
|
@@ -0,0 +1,150 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <mhash.h>
|
3
|
+
#include "module_functions.h"
|
4
|
+
|
5
|
+
VALUE mhash_rb_digest(VALUE self, VALUE hash_type, VALUE data_to_hash)
|
6
|
+
{
|
7
|
+
MHASH td;
|
8
|
+
VALUE rb_str_hash;
|
9
|
+
unsigned int i;
|
10
|
+
unsigned int size_of_hash;
|
11
|
+
char *hash;
|
12
|
+
|
13
|
+
td = mhash_init(FIX2INT(hash_type));
|
14
|
+
if (td == MHASH_FAILED)
|
15
|
+
rb_raise(rb_eException, "Unable to init mhash - MHASH_FAILED");
|
16
|
+
mhash(td, RSTRING_PTR(data_to_hash), RSTRING_LEN(data_to_hash));
|
17
|
+
hash = mhash_end(td);
|
18
|
+
size_of_hash = mhash_get_block_size(FIX2INT(hash_type));
|
19
|
+
rb_str_hash = rb_str_new2("");
|
20
|
+
for (i = 0; i < size_of_hash; i++) {
|
21
|
+
rb_str_hash = rb_str_cat(rb_str_hash, (const char *) &hash[i], 1);
|
22
|
+
}
|
23
|
+
free(hash);
|
24
|
+
return (rb_str_hash);
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE mhash_rb_crc32(VALUE self, VALUE data_to_hash)
|
28
|
+
{
|
29
|
+
return (mhash_rb_digest(self, INT2NUM(0), data_to_hash));
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE mhash_rb_md5(VALUE self, VALUE data_to_hash)
|
33
|
+
{
|
34
|
+
return (mhash_rb_digest(self, INT2NUM(1), data_to_hash));
|
35
|
+
}
|
36
|
+
|
37
|
+
VALUE mhash_rb_sha1(VALUE self, VALUE data_to_hash)
|
38
|
+
{
|
39
|
+
return (mhash_rb_digest(self, INT2NUM(2), data_to_hash));
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE mhash_rb_haval256(VALUE self, VALUE data_to_hash)
|
43
|
+
{
|
44
|
+
return (mhash_rb_digest(self, INT2NUM(3), data_to_hash));
|
45
|
+
}
|
46
|
+
|
47
|
+
VALUE mhash_rb_ripemd160(VALUE self, VALUE data_to_hash)
|
48
|
+
{
|
49
|
+
return (mhash_rb_digest(self, INT2NUM(5), data_to_hash));
|
50
|
+
}
|
51
|
+
|
52
|
+
VALUE mhash_rb_tiger192(VALUE self, VALUE data_to_hash)
|
53
|
+
{
|
54
|
+
return (mhash_rb_digest(self, INT2NUM(7), data_to_hash));
|
55
|
+
}
|
56
|
+
|
57
|
+
VALUE mhash_rb_gost(VALUE self, VALUE data_to_hash)
|
58
|
+
{
|
59
|
+
return (mhash_rb_digest(self, INT2NUM(8), data_to_hash));
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE mhash_rb_crc32b(VALUE self, VALUE data_to_hash)
|
63
|
+
{
|
64
|
+
return (mhash_rb_digest(self, INT2NUM(9), data_to_hash));
|
65
|
+
}
|
66
|
+
|
67
|
+
VALUE mhash_rb_haval224(VALUE self, VALUE data_to_hash)
|
68
|
+
{
|
69
|
+
return (mhash_rb_digest(self, INT2NUM(10), data_to_hash));
|
70
|
+
}
|
71
|
+
|
72
|
+
VALUE mhash_rb_haval192(VALUE self, VALUE data_to_hash)
|
73
|
+
{
|
74
|
+
return (mhash_rb_digest(self, INT2NUM(11), data_to_hash));
|
75
|
+
}
|
76
|
+
|
77
|
+
VALUE mhash_rb_haval160(VALUE self, VALUE data_to_hash)
|
78
|
+
{
|
79
|
+
return (mhash_rb_digest(self, INT2NUM(12), data_to_hash));
|
80
|
+
}
|
81
|
+
|
82
|
+
VALUE mhash_rb_haval128(VALUE self, VALUE data_to_hash)
|
83
|
+
{
|
84
|
+
return (mhash_rb_digest(self, INT2NUM(13), data_to_hash));
|
85
|
+
}
|
86
|
+
|
87
|
+
VALUE mhash_rb_tiger128(VALUE self, VALUE data_to_hash)
|
88
|
+
{
|
89
|
+
return (mhash_rb_digest(self, INT2NUM(14), data_to_hash));
|
90
|
+
}
|
91
|
+
|
92
|
+
VALUE mhash_rb_tiger160(VALUE self, VALUE data_to_hash)
|
93
|
+
{
|
94
|
+
return (mhash_rb_digest(self, INT2NUM(15), data_to_hash));
|
95
|
+
}
|
96
|
+
|
97
|
+
VALUE mhash_rb_sha256(VALUE self, VALUE data_to_hash)
|
98
|
+
{
|
99
|
+
return (mhash_rb_digest(self, INT2NUM(17), data_to_hash));
|
100
|
+
}
|
101
|
+
|
102
|
+
VALUE mhash_rb_adler32(VALUE self, VALUE data_to_hash)
|
103
|
+
{
|
104
|
+
return (mhash_rb_digest(self, INT2NUM(18), data_to_hash));
|
105
|
+
}
|
106
|
+
|
107
|
+
VALUE mhash_rb_sha224(VALUE self, VALUE data_to_hash)
|
108
|
+
{
|
109
|
+
return (mhash_rb_digest(self, INT2NUM(19), data_to_hash));
|
110
|
+
}
|
111
|
+
|
112
|
+
VALUE mhash_rb_sha512(VALUE self, VALUE data_to_hash)
|
113
|
+
{
|
114
|
+
return (mhash_rb_digest(self, INT2NUM(20), data_to_hash));
|
115
|
+
}
|
116
|
+
|
117
|
+
VALUE mhash_rb_sha384(VALUE self, VALUE data_to_hash)
|
118
|
+
{
|
119
|
+
return (mhash_rb_digest(self, INT2NUM(21), data_to_hash));
|
120
|
+
}
|
121
|
+
|
122
|
+
VALUE mhash_rb_whirlpool(VALUE self, VALUE data_to_hash)
|
123
|
+
{
|
124
|
+
return (mhash_rb_digest(self, INT2NUM(22), data_to_hash));
|
125
|
+
}
|
126
|
+
|
127
|
+
VALUE mhash_rb_ripemd128(VALUE self, VALUE data_to_hash)
|
128
|
+
{
|
129
|
+
return (mhash_rb_digest(self, INT2NUM(23), data_to_hash));
|
130
|
+
}
|
131
|
+
|
132
|
+
VALUE mhash_rb_ripemd256(VALUE self, VALUE data_to_hash)
|
133
|
+
{
|
134
|
+
return (mhash_rb_digest(self, INT2NUM(24), data_to_hash));
|
135
|
+
}
|
136
|
+
|
137
|
+
VALUE mhash_rb_ripemd320(VALUE self, VALUE data_to_hash)
|
138
|
+
{
|
139
|
+
return (mhash_rb_digest(self, INT2NUM(25), data_to_hash));
|
140
|
+
}
|
141
|
+
|
142
|
+
VALUE mhash_rb_snefru128(VALUE self, VALUE data_to_hash)
|
143
|
+
{
|
144
|
+
return (mhash_rb_digest(self, INT2NUM(26), data_to_hash));
|
145
|
+
}
|
146
|
+
|
147
|
+
VALUE mhash_rb_snefru256(VALUE self, VALUE data_to_hash)
|
148
|
+
{
|
149
|
+
return (mhash_rb_digest(self, INT2NUM(27), data_to_hash));
|
150
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef __MHASH_FUNCTIONS__
|
2
|
+
#define __MHASH_FUNCTIONS__
|
3
|
+
|
4
|
+
VALUE mhash_rb_digest(VALUE self, VALUE hash_type, VALUE data_to_hash);
|
5
|
+
|
6
|
+
VALUE mhash_rb_crc32(VALUE self, VALUE data_to_hash);
|
7
|
+
VALUE mhash_rb_md5(VALUE self, VALUE data_to_hash);
|
8
|
+
VALUE mhash_rb_sha1(VALUE self, VALUE data_to_hash);
|
9
|
+
VALUE mhash_rb_haval256(VALUE self, VALUE data_to_hash);
|
10
|
+
VALUE mhash_rb_ripemd160(VALUE self, VALUE data_to_hash);
|
11
|
+
VALUE mhash_rb_tiger192(VALUE self, VALUE data_to_hash);
|
12
|
+
VALUE mhash_rb_gost(VALUE self, VALUE data_to_hash);
|
13
|
+
VALUE mhash_rb_crc32b(VALUE self, VALUE data_to_hash);
|
14
|
+
VALUE mhash_rb_haval224(VALUE self, VALUE data_to_hash);
|
15
|
+
VALUE mhash_rb_haval192(VALUE self, VALUE data_to_hash);
|
16
|
+
VALUE mhash_rb_haval160(VALUE self, VALUE data_to_hash);
|
17
|
+
VALUE mhash_rb_haval128(VALUE self, VALUE data_to_hash);
|
18
|
+
VALUE mhash_rb_tiger128(VALUE self, VALUE data_to_hash);
|
19
|
+
VALUE mhash_rb_tiger160(VALUE self, VALUE data_to_hash);
|
20
|
+
VALUE mhash_rb_sha256(VALUE self, VALUE data_to_hash);
|
21
|
+
VALUE mhash_rb_adler32(VALUE self, VALUE data_to_hash);
|
22
|
+
VALUE mhash_rb_sha224(VALUE self, VALUE data_to_hash);
|
23
|
+
VALUE mhash_rb_sha512(VALUE self, VALUE data_to_hash);
|
24
|
+
VALUE mhash_rb_sha384(VALUE self, VALUE data_to_hash);
|
25
|
+
VALUE mhash_rb_whirlpool(VALUE self, VALUE data_to_hash);
|
26
|
+
VALUE mhash_rb_ripemd128(VALUE self, VALUE data_to_hash);
|
27
|
+
VALUE mhash_rb_ripemd256(VALUE self, VALUE data_to_hash);
|
28
|
+
VALUE mhash_rb_ripemd320(VALUE self, VALUE data_to_hash);
|
29
|
+
VALUE mhash_rb_snefru128(VALUE self, VALUE data_to_hash);
|
30
|
+
VALUE mhash_rb_snefru256(VALUE self, VALUE data_to_hash);
|
31
|
+
|
32
|
+
#endif
|
data/lib/mhash.rb
ADDED
data/mhash.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
t = Time.now
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.authors = ["Thibaut Deloffre"]
|
4
|
+
gem.email = ["tib@rocknroot.org"]
|
5
|
+
gem.summary = "Mhash library extension for Ruby"
|
6
|
+
gem.description = "Mhash library extension for Ruby"
|
7
|
+
gem.homepage = "http://github.com/TibshoOT/ruby-mhash"
|
8
|
+
gem.date = t.strftime("%Y-%m-%d")
|
9
|
+
gem.name = "mhash"
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.extensions = ["ext/mhash/extconf.rb"]
|
12
|
+
gem.require_paths = ["lib", "ext"]
|
13
|
+
gem.version = "1.0"
|
14
|
+
gem.extra_rdoc_files = ["LICENSE.txt"]
|
15
|
+
gem.licenses = ["BSD"]
|
16
|
+
end
|
data/test/test_mhash.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'mhash'
|
3
|
+
|
4
|
+
class TestMhash < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@data = "hello\n\n"
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_gost_hash
|
11
|
+
hash = Mhash.ghost(@data)
|
12
|
+
valid_digest = 'a2c0810ccbb997eb2e029e7e4186535ef4efae43fdcb49afb4933303f649f8db'
|
13
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_tiger192_hash
|
17
|
+
hash = Mhash.tiger192(@data)
|
18
|
+
valid_digest = '3655e96f537401e1c5ac4197ac22594e6d0a740c664e7263'
|
19
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_sha1_hash
|
23
|
+
hash = Mhash.sha1(@data)
|
24
|
+
valid_digest = '4588019fd3d2567f303815db6adfe489b2ee5f92'
|
25
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_sha256_hash
|
29
|
+
hash = Mhash.sha256(@data)
|
30
|
+
valid_digest = '50adea61fa4e77ab111b814716097abfd05f83a207b47eb4529bbd4f54e111e0'
|
31
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_md5_hash
|
35
|
+
hash = Mhash.md5(@data)
|
36
|
+
valid_digest = '14e273e6f416c4b90a071f59ac01206a'
|
37
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_whirlpool_hash
|
41
|
+
hash = Mhash.whirlpool(@data)
|
42
|
+
valid_digest = 'adc277e898e7164962c1674c0c3984169534630428364dd43fc7e4e3e7222b6ccf7b7c4656f972f392d5580797b70125780ac860cb84de6f55ed043277d545d3'
|
43
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_ripemd160_hash
|
47
|
+
hash = Mhash.ripemd160(@data)
|
48
|
+
valid_digest = '52985141506d19e443281ad5c6e058871bb2f765'
|
49
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_haval256_hash
|
53
|
+
hash = Mhash.haval256(@data)
|
54
|
+
valid_digest = '1b3aa948d5d867964d72b9320a648050725e2daac5898c2d9f09512b99e5f72f'
|
55
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_adler32_hash
|
59
|
+
hash = Mhash.adler32(@data)
|
60
|
+
valid_digest = '2902740a'
|
61
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_snefru256_hash
|
65
|
+
hash = Mhash.snefru256(@data)
|
66
|
+
valid_digest = 'f33eb2a3152af27e719474e8888da43c53b1ea7a629796eb7a67ecc539fc29a8'
|
67
|
+
assert_equal(valid_digest, hash.unpack("H*").first)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mhash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thibaut Deloffre
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Mhash library extension for Ruby
|
15
|
+
email:
|
16
|
+
- tib@rocknroot.org
|
17
|
+
executables: []
|
18
|
+
extensions:
|
19
|
+
- ext/mhash/extconf.rb
|
20
|
+
extra_rdoc_files:
|
21
|
+
- LICENSE.txt
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- .travis.yml
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE.txt
|
27
|
+
- Rakefile
|
28
|
+
- ext/mhash/Makefile
|
29
|
+
- ext/mhash/extconf.rb
|
30
|
+
- ext/mhash/mhash.c
|
31
|
+
- ext/mhash/module_definitions.c
|
32
|
+
- ext/mhash/module_definitions.h
|
33
|
+
- ext/mhash/module_functions.c
|
34
|
+
- ext/mhash/module_functions.h
|
35
|
+
- lib/mhash.rb
|
36
|
+
- mhash.gemspec
|
37
|
+
- test/test_mhash.rb
|
38
|
+
homepage: http://github.com/TibshoOT/ruby-mhash
|
39
|
+
licenses:
|
40
|
+
- BSD
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
- ext
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.24
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Mhash library extension for Ruby
|
64
|
+
test_files: []
|