mhash 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,7 +30,11 @@ You have to setup rubygems.
30
30
 
31
31
  gem install mhash
32
32
 
33
- or for development:
33
+ or in Gemfile (Bundler):
34
+
35
+ gem 'mhash'
36
+
37
+ ## Development/Debug
34
38
 
35
39
  git clone https://github.com/TibshoOT/ruby-mhash.git
36
40
  cd ruby-mhash/etx/mhash
@@ -39,58 +43,189 @@ or for development:
39
43
  make
40
44
  irb -r ./mhash.so
41
45
  [test it !]
46
+ [pull request]
42
47
 
43
48
 
44
49
  ## Documentation
45
50
 
46
- Just require mhash library and go !
47
-
48
- Mhash's module functions are explicit...
51
+ These are implemented hashes with their methods:
52
+
53
+ <table>
54
+ <tr>
55
+ <th>Cipher (Mhash contanst)</th>
56
+ <th>digest method</th>
57
+ <th>hexdigest method</th>
58
+ </tr>
59
+ <tr>
60
+ <th>CRC32</th>
61
+ <td>Mhash.crc32("a simple test !")</td>
62
+ <td>Mhash.crc32!("a simple test !")</td>
63
+ </tr>
64
+ <tr>
65
+ <th>MD5</th>
66
+ <td>Mhash.md5("a simple test !")</td>
67
+ <td>Mhash.md5!("a simple test !")</td>
68
+ </tr>
69
+ <tr>
70
+ <th>SHA1</th>
71
+ <td>Mhash.sha1("a simple test !")</td>
72
+ <td>Mhash.sha1!("a simple test !")</td>
73
+ </tr>
74
+ <tr>
75
+ <th>HAVAL256</th>
76
+ <td>Mhash.haval256("a simple test !")</td>
77
+ <td>Mhash.haval256!("a simple test !")</td>
78
+ </tr>
79
+ <tr>
80
+ <th>RIPEMD160</th>
81
+ <td>Mhash.ripemd160("a simple test !")</td>
82
+ <td>Mhash.ripemd160!("a simple test !")</td>
83
+ </tr>
84
+ <tr>
85
+ <th>TIGER192</th>
86
+ <td>Mhash.tiger192("a simple test !")</td>
87
+ <td>Mhash.tiger192!("a simple test !")</td>
88
+ </tr>
89
+ <tr>
90
+ <th>GOST</th>
91
+ <td>Mhash.gost("a simple test !")</td>
92
+ <td>Mhash.gost!("a simple test !")</td>
93
+ </tr>
94
+ <tr>
95
+ <th>CRC32B</th>
96
+ <td>Mhash.crc32b("a simple test !")</td>
97
+ <td>Mhash.crc32b!("a simple test !")</td>
98
+ </tr>
99
+ <tr>
100
+ <th>HAVAL224</th>
101
+ <td>Mhash.haval224("a simple test !")</td>
102
+ <td>Mhash.haval224!("a simple test !")</td>
103
+ </tr>
104
+ <tr>
105
+ <th>HAVAL192</th>
106
+ <td>Mhash.haval192("a simple test !")</td>
107
+ <td>Mhash.haval192!("a simple test !")</td>
108
+ </tr>
109
+ <tr>
110
+ <th>HAVAL160</th>
111
+ <td>Mhash.haval160("a simple test !")</td>
112
+ <td>Mhash.haval160!("a simple test !")</td>
113
+ </tr>
114
+ <tr>
115
+ <th>HAVAL128</th>
116
+ <td>Mhash.haval128("a simple test !")</td>
117
+ <td>Mhash.haval128!("a simple test !")</td>
118
+ </tr>
119
+ <tr>
120
+ <th>TIGER128</th>
121
+ <td>Mhash.tiger128("a simple test !")</td>
122
+ <td>Mhash.tiger128!("a simple test !")</td>
123
+ </tr>
124
+ <tr>
125
+ <th>TIGER160</th>
126
+ <td>Mhash.tiger160("a simple test !")</td>
127
+ <td>Mhash.tiger160!("a simple test !")</td>
128
+ </tr>
129
+ <tr>
130
+ <th>SHA256</th>
131
+ <td>Mhash.sha256("a simple test !")</td>
132
+ <td>Mhash.sha256!("a simple test !")</td>
133
+ </tr>
134
+ <tr>
135
+ <th>ADLER32</th>
136
+ <td>Mhash.adler32("a simple test !")</td>
137
+ <td>Mhash.adler32!("a simple test !")</td>
138
+ </tr>
139
+ <tr>
140
+ <th>SHA224</th>
141
+ <td>Mhash.sha224("a simple test !")</td>
142
+ <td>Mhash.sha224!("a simple test !")</td>
143
+ </tr>
144
+ <tr>
145
+ <th>SHA512</th>
146
+ <td>Mhash.sha512("a simple test !")</td>
147
+ <td>Mhash.sha512!("a simple test !")</td>
148
+ </tr>
149
+ <tr>
150
+ <th>SHA384</th>
151
+ <td>Mhash.sha384("a simple test !")</td>
152
+ <td>Mhash.sha384!("a simple test !")</td>
153
+ </tr>
154
+ <tr>
155
+ <th>WHIRLPOOL</th>
156
+ <td>Mhash.whirlpool("a simple test !")</td>
157
+ <td>Mhash.whirlpool!("a simple test !")</td>
158
+ </tr>
159
+ <tr>
160
+ <th>RIPEMD128</th>
161
+ <td>Mhash.ripemd128("a simple test !")</td>
162
+ <td>Mhash.ripemd128!("a simple test !")</td>
163
+ </tr>
164
+ <tr>
165
+ <th>RIPEMD256</th>
166
+ <td>Mhash.ripemd256("a simple test !")</td>
167
+ <td>Mhash.ripemd256!("a simple test !")</td>
168
+ </tr>
169
+ <tr>
170
+ <th>RIPEMD320</th>
171
+ <td>Mhash.ripemd320("a simple test !")</td>
172
+ <td>Mhash.ripemd320!("a simple test !")</td>
173
+ </tr>
174
+ <tr>
175
+ <th>SNEFRU128</th>
176
+ <td>Mhash.snefru128("a simple test !")</td>
177
+ <td>Mhash.snefru128!("a simple test !")</td>
178
+ </tr>
179
+ <tr>
180
+ <th>SNEFRU256</th>
181
+ <td>Mhash.snefru256("a simple test !")</td>
182
+ <td>Mhash.snefru256!("a simple test !")</td>
183
+ </tr>
184
+ </table>
185
+
186
+ ### Examples
187
+
188
+ You can find all available hashes doing this:
49
189
 
50
190
  ```ruby
51
191
 
52
192
  require 'mhash'
53
193
 
54
- Mhash.gost("this is a test !")
55
- Mhash.crc32("this is a test !")
56
- Mhash.md5("this is a test !")
57
- Mhash.sha1("this is a test !")
58
- Mhash.haval256("this is a test !")
59
- Mhash.ripemd160("this is a test !")
60
- Mhash.tiger192("this is a test !")
61
- Mhash.gost("this is a test !")
62
- Mhash.crc32b("this is a test !")
63
- Mhash.haval224("this is a test !")
64
- Mhash.haval192("this is a test !")
65
- Mhash.haval160("this is a test !")
66
- Mhash.haval128("this is a test !")
67
- Mhash.tiger128("this is a test !")
68
- Mhash.tiger160("this is a test !")
69
- Mhash.sha256("this is a test !")
70
- Mhash.adler32("this is a test !")
71
- Mhash.sha224("this is a test !")
72
- Mhash.sha512("this is a test !")
73
- Mhash.sha384("this is a test !")
74
- Mhash.whirlpool("this is a test !")
75
- Mhash.ripemd128("this is a test !")
76
- Mhash.ripemd256("this is a test !")
77
- Mhash.ripemd320("this is a test !")
78
- Mhash.snefru128("this is a test !")
79
- Mhash.snefru256("this is a test !")
80
-
194
+ Mhash.constant
195
+ => [:MHASH_CRC32, :MHASH_MD5, :MHASH_SHA1, :MHASH_HAVAL256, :MHASH_RIPEMD160,
196
+ :MHASH_TIGER192, :MHASH_GOST, :MHASH_CRC32B, :MHASH_HAVAL224, :MHASH_HAVAL192,
197
+ :MHASH_HAVAL160, :MHASH_HAVAL128, :MHASH_TIGER128, :MHASH_TIGER160, :MHASH_SHA256,
198
+ :MHASH_ADLER32, :MHASH_SHA224, :MHASH_SHA512, :MHASH_SHA384, :MHASH_WHIRLPOOL,
199
+ :MHASH_RIPEMD128, :MHASH_RIPEMD256, :MHASH_RIPEMD320, :MHASH_SNEFRU128,
200
+ :MHASH_SNEFRU256, :VERSION]
81
201
  ```
82
202
 
83
- At this time, these functions return byte encoded string but if you want an hexdigest, you can do this:
203
+ If you just want to have a nibble digest:
84
204
 
85
205
  ```ruby
86
206
 
87
207
  require 'mhash'
88
208
 
89
- hash = Mhash.gost("this is a test !").unpack("H*").first
90
-
209
+ hash = Mhash.gost("Hello\n\n")
210
+ puts hash
211
+ => "\x89\r\x02\xF9*\xF7\xD7V\x82\xD4\xC3\x15\xEC\xA2\xF5\x8E~\x9E\xD0\x8D\xFC\xF1\xC0O\xC4\x16\xB0HOE\x1D\x8D"
91
212
  ```
92
213
 
93
- In the next release of mhash gem, you will be able to get hexdigest directly.
214
+ If you want an hexdigest:
215
+
216
+ ```ruby
217
+
218
+ require 'mhash'
219
+
220
+ # Using gost nibble digest as previously:
221
+ hash = Mhash.gost("Hello\n\n").unpack("H*").first
222
+ puts hash
223
+ => "890d02f92af7d75682d4c315eca2f58e7e9ed08dfcf1c04fc416b0484f451d8d"
224
+ # Using ! methods:
225
+ hash = Mhash.gost!("Hello\n\n")
226
+ puts hash
227
+ => "890d02f92af7d75682d4c315eca2f58e7e9ed08dfcf1c04fc416b0484f451d8d"
228
+ ```
94
229
 
95
230
  ## Want a feature ? Problem ?
96
231
 
@@ -18,6 +18,7 @@ void mhash_define_consts(VALUE *m_mhash)
18
18
  rb_define_const(*m_mhash, "MHASH_HAVAL128", INT2NUM(13));
19
19
  rb_define_const(*m_mhash, "MHASH_TIGER128", INT2NUM(14));
20
20
  rb_define_const(*m_mhash, "MHASH_TIGER160", INT2NUM(15));
21
+ rb_define_const(*m_mhash, "MHASH_MD4", INT2NUM(16));
21
22
  rb_define_const(*m_mhash, "MHASH_SHA256", INT2NUM(17));
22
23
  rb_define_const(*m_mhash, "MHASH_ADLER32", INT2NUM(18));
23
24
  rb_define_const(*m_mhash, "MHASH_SHA224", INT2NUM(19));
@@ -29,6 +30,7 @@ void mhash_define_consts(VALUE *m_mhash)
29
30
  rb_define_const(*m_mhash, "MHASH_RIPEMD320", INT2NUM(25));
30
31
  rb_define_const(*m_mhash, "MHASH_SNEFRU128", INT2NUM(26));
31
32
  rb_define_const(*m_mhash, "MHASH_SNEFRU256", INT2NUM(27));
33
+ rb_define_const(*m_mhash, "MHASH_MD2", INT2NUM(28));
32
34
  }
33
35
 
34
36
  void mhash_define_functions(VALUE *m_mhash)
@@ -63,6 +65,8 @@ void mhash_define_functions(VALUE *m_mhash)
63
65
  rb_define_module_function(*m_mhash, "tiger128!", mhash_rb_tiger128_hex, 1);
64
66
  rb_define_module_function(*m_mhash, "tiger160", mhash_rb_tiger160, 1);
65
67
  rb_define_module_function(*m_mhash, "tiger160!", mhash_rb_tiger160_hex, 1);
68
+ rb_define_module_function(*m_mhash, "md4", mhash_rb_md4, 1);
69
+ rb_define_module_function(*m_mhash, "md4!", mhash_rb_md4_hex, 1);
66
70
  rb_define_module_function(*m_mhash, "sha256", mhash_rb_sha256, 1);
67
71
  rb_define_module_function(*m_mhash, "sha256!", mhash_rb_sha256_hex, 1);
68
72
  rb_define_module_function(*m_mhash, "adler32", mhash_rb_adler32, 1);
@@ -85,4 +89,6 @@ void mhash_define_functions(VALUE *m_mhash)
85
89
  rb_define_module_function(*m_mhash, "snefru128!", mhash_rb_snefru128_hex, 1);
86
90
  rb_define_module_function(*m_mhash, "snefru256", mhash_rb_snefru256, 1);
87
91
  rb_define_module_function(*m_mhash, "snefru256!", mhash_rb_snefru256_hex, 1);
92
+ rb_define_module_function(*m_mhash, "md2", mhash_rb_md2, 1);
93
+ rb_define_module_function(*m_mhash, "md2!", mhash_rb_md2_hex, 1);
88
94
  }
@@ -61,7 +61,6 @@ VALUE mhash_rb_crc32_hex(VALUE self, VALUE data_to_hash)
61
61
  return (hash);
62
62
  }
63
63
 
64
-
65
64
  VALUE mhash_rb_md5(VALUE self, VALUE data_to_hash)
66
65
  {
67
66
  return (mhash_rb_digest(self, INT2NUM(1), data_to_hash));
@@ -76,7 +75,6 @@ VALUE mhash_rb_md5_hex(VALUE self, VALUE data_to_hash)
76
75
  return (hash);
77
76
  }
78
77
 
79
-
80
78
  VALUE mhash_rb_sha1(VALUE self, VALUE data_to_hash)
81
79
  {
82
80
  return (mhash_rb_digest(self, INT2NUM(2), data_to_hash));
@@ -161,6 +159,7 @@ VALUE mhash_rb_crc32b_hex(VALUE self, VALUE data_to_hash)
161
159
  data_to_hash));
162
160
  return (hash);
163
161
  }
162
+
164
163
  VALUE mhash_rb_haval224(VALUE self, VALUE data_to_hash)
165
164
  {
166
165
  return (mhash_rb_digest(self, INT2NUM(10), data_to_hash));
@@ -245,6 +244,20 @@ VALUE mhash_rb_tiger160_hex(VALUE self, VALUE data_to_hash)
245
244
  return (hash);
246
245
  }
247
246
 
247
+ VALUE mhash_rb_md4(VALUE self, VALUE data_to_hash)
248
+ {
249
+ return (mhash_rb_digest(self, INT2NUM(16), data_to_hash));
250
+ }
251
+
252
+ VALUE mhash_rb_md4_hex(VALUE self, VALUE data_to_hash)
253
+ {
254
+ VALUE hash;
255
+
256
+ hash = mhash_rb_hexdigest(self, mhash_rb_digest(self, INT2NUM(16),
257
+ data_to_hash));
258
+ return (hash);
259
+ }
260
+
248
261
  VALUE mhash_rb_sha256(VALUE self, VALUE data_to_hash)
249
262
  {
250
263
  return (mhash_rb_digest(self, INT2NUM(17), data_to_hash));
@@ -398,3 +411,17 @@ VALUE mhash_rb_snefru256_hex(VALUE self, VALUE data_to_hash)
398
411
  data_to_hash));
399
412
  return (hash);
400
413
  }
414
+
415
+ VALUE mhash_rb_md2(VALUE self, VALUE data_to_hash)
416
+ {
417
+ return (mhash_rb_digest(self, INT2NUM(28), data_to_hash));
418
+ }
419
+
420
+ VALUE mhash_rb_md2_hex(VALUE self, VALUE data_to_hash)
421
+ {
422
+ VALUE hash;
423
+
424
+ hash = mhash_rb_hexdigest(self, mhash_rb_digest(self, INT2NUM(28),
425
+ data_to_hash));
426
+ return (hash);
427
+ }
@@ -46,6 +46,9 @@
46
46
  VALUE mhash_rb_tiger160(VALUE self, VALUE data_to_hash);
47
47
  VALUE mhash_rb_tiger160_hex(VALUE self, VALUE data_to_hash);
48
48
 
49
+ VALUE mhash_rb_md4(VALUE self, VALUE data_to_hash);
50
+ VALUE mhash_rb_md4_hex(VALUE self, VALUE data_to_hash);
51
+
49
52
  VALUE mhash_rb_sha256(VALUE self, VALUE data_to_hash);
50
53
  VALUE mhash_rb_sha256_hex(VALUE self, VALUE data_to_hash);
51
54
 
@@ -79,4 +82,7 @@
79
82
  VALUE mhash_rb_snefru256(VALUE self, VALUE data_to_hash);
80
83
  VALUE mhash_rb_snefru256_hex(VALUE self, VALUE data_to_hash);
81
84
 
85
+ VALUE mhash_rb_md2(VALUE self, VALUE data_to_hash);
86
+ VALUE mhash_rb_md2_hex(VALUE self, VALUE data_to_hash);
87
+
82
88
  #endif
@@ -1,5 +1,5 @@
1
1
  require 'mhash/mhash'
2
2
 
3
3
  module Mhash
4
- VERSION = "1.1"
4
+ VERSION = "1.2"
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.files = `git ls-files`.split("\n")
11
11
  gem.extensions = ["ext/mhash/extconf.rb"]
12
12
  gem.require_paths = ["lib", "ext"]
13
- gem.version = "1.1"
13
+ gem.version = "1.2"
14
14
  gem.extra_rdoc_files = ["LICENSE.txt"]
15
15
  gem.licenses = ["BSD"]
16
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mhash
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-05 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Mhash library extension for Ruby
15
15
  email:
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 1.8.23
61
+ rubygems_version: 1.8.24
62
62
  signing_key:
63
63
  specification_version: 3
64
64
  summary: Mhash library extension for Ruby