sha3 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sha3 might be problematic. Click here for more details.
- data/.gitignore +3 -1
- data/.yardopts +1 -1
- data/ChangeLog.rdoc +8 -0
- data/README.rdoc +22 -26
- data/ext/sha3/{_sha3.c → digest.c} +11 -84
- data/ext/sha3/{_sha3.h → digest.h} +6 -8
- data/ext/sha3/sha3.c +44 -0
- data/ext/sha3/sha3.h +15 -0
- data/lib/sha3.rb +1 -1
- data/lib/sha3/doc.rb +134 -0
- data/lib/sha3/version.rb +4 -2
- data/spec/sha3_core_spec.rb +3 -1
- metadata +7 -4
data/.gitignore
CHANGED
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
lib
|
1
|
+
lib/**/doc.rb lib/**/version.rb --markup rdoc --title "sha3 Documentation" --protected
|
data/ChangeLog.rdoc
CHANGED
@@ -9,3 +9,11 @@
|
|
9
9
|
=== 0.2.0 / 2012-11-1
|
10
10
|
|
11
11
|
* SHA3::Digest: A proper ::Digest subclass.
|
12
|
+
|
13
|
+
=== 0.2.2 / 2012-12-14
|
14
|
+
|
15
|
+
* Added sub-class for each SHA3 supported bit-lengths (example: SHA3::Digest::SHA256). Minor bug fix.
|
16
|
+
|
17
|
+
=== 0.2.3 / 2013-1-28
|
18
|
+
|
19
|
+
* Added documentation file (decoupled form C source); refactored C source.
|
data/README.rdoc
CHANGED
@@ -1,23 +1,16 @@
|
|
1
|
-
= sha3
|
1
|
+
= sha3 {<img src="https://secure.travis-ci.org/johanns/sha3.png" alt="Build Status" />}[http://travis-ci.org/johanns/sha3] {<img src="https://gemnasium.com/johanns/sha3.png" alt="Dependency Status" />}[https://gemnasium.com/johanns/sha3]
|
2
|
+
|
3
|
+
<em>SHA3 for Ruby</em> is a native (C) implementation of Keccak (SHA3) cryptographic hashing algorithm. Platform optimized reference is used, wherever possible.
|
2
4
|
|
3
|
-
{<img src="https://secure.travis-ci.org/johanns/sha3.png" alt="Build Status" />}[http://travis-ci.org/johanns/sha3]
|
4
5
|
Home :: https://github.com/johanns/sha3#readme
|
5
6
|
Issues :: https://github.com/johanns/sha3/issues
|
6
7
|
Documentation :: http://rubydoc.info/gems/sha3/frames
|
7
8
|
|
8
|
-
==
|
9
|
-
|
10
|
-
<em>SHA3 for Ruby</em> is a native (C) implementation of Keccak (SHA3) cryptographic hashing algorithm.
|
9
|
+
== Module details
|
11
10
|
|
12
|
-
|
11
|
+
<em>SHA3::Digest</em>: A standard *Digest* _subclass_. The interface, and operation of this class are parallel to digest classes bundled with MRI-based Rubies (e.g.: <em>Digest::SHA2</em>, and <em>OpenSSL::Digest</em>). See *Digest* documentation for additional details (http://www.ruby-doc.org/stdlib-1.9.3/libdoc/digest/rdoc/Digest.html).
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
== Releases
|
17
|
-
|
18
|
-
*0.1.x* :: Alpha code, and not suitable for production.
|
19
|
-
*0.2.0* :: Production worthy, but breaks API compatibility with 0.1.x. Backward-compatibility will be maintained henceforth.
|
20
|
-
*0.2.1* :: Added sub-class for each SHA3 supported bit-lengths (example: SHA3::Digest::SHA256). Minor bug fix.
|
13
|
+
<em>SHA3::Digest.compute()</em>: A class-method with data bit-length hashing support.
|
21
14
|
|
22
15
|
== Installation
|
23
16
|
|
@@ -27,15 +20,12 @@ Documentation :: http://rubydoc.info/gems/sha3/frames
|
|
27
20
|
|
28
21
|
require 'sha3'
|
29
22
|
|
30
|
-
Valid hash bit-lengths are: *224*, *256*, *384*, *512*. You may also use corresponding symbols when instantiating a new instance or calling the
|
23
|
+
Valid hash bit-lengths are: *224*, *256*, *384*, *512*. You may also use corresponding symbols when instantiating a new instance or calling the <em>SHA3::Digest.compute()</em> method:
|
31
24
|
|
32
|
-
:sha224
|
33
|
-
:sha256
|
34
|
-
:sha384
|
35
|
-
:sha512
|
36
|
-
|
37
|
-
# Example: SHA3::Digest.new(224) = SHA3::Digest.new(:sha224)
|
25
|
+
:sha224 :sha256 :sha384 :sha512
|
38
26
|
|
27
|
+
# SHA3::Digest.new(224) is SHA3::Digest.new(:sha224)
|
28
|
+
|
39
29
|
Alternatively, you can instantiate using one of four sub-classes:
|
40
30
|
|
41
31
|
SHA3::Digest::SHA224.new() # 224 bits
|
@@ -66,7 +56,7 @@ Alternatively, you can instantiate using one of four sub-classes:
|
|
66
56
|
s.hexdigest
|
67
57
|
# => "bedf0dd9a15b6474208b624c4e8a1e672ce0f06498e3abd7cc37f0ae69759259"
|
68
58
|
|
69
|
-
|
59
|
+
### Digest class-methods: ###
|
70
60
|
|
71
61
|
SHA3::Digest.hexdigest("Hash me, please", :sha224)
|
72
62
|
# => "200e7bc18cd6132689eb8fa3f7c3a978d73215384a626c23e4508f33"
|
@@ -81,13 +71,13 @@ Alternatively, you can instantiate using one of four sub-classes:
|
|
81
71
|
|
82
72
|
# Calling SHA3::Digest.file(...) defaults to SHA256
|
83
73
|
s = SHA3::Digest.file("tests.sh")
|
84
|
-
|
74
|
+
# => #<SHA3::Digest: a9801db49389339bd8a62817f229f0f9394ca73b34fd7dbc7ec5ed7a99bc49f1>
|
85
75
|
|
86
76
|
=== Bit-length hashing
|
87
77
|
|
88
78
|
# Compute hash of "011"
|
89
79
|
SHA3::Digest.compute(:sha224, "\xC0", 3).unpack("H*")
|
90
|
-
|
80
|
+
# => ["2b695a6fd92a2b3f3ce9cfca617d22c9bb52815dd59a9719b01bad25"]
|
91
81
|
|
92
82
|
== Development
|
93
83
|
|
@@ -98,7 +88,7 @@ Alternatively, you can instantiate using one of four sub-classes:
|
|
98
88
|
|
99
89
|
Call +rake+ to run the included RSpec tests.
|
100
90
|
|
101
|
-
Only a small subset of test vectors are included in the source repository; however, the complete test vectors suite is available for download. Simply run the +
|
91
|
+
Only a small subset of test vectors are included in the source repository; however, the complete test vectors suite is available for download. Simply run the +tests.sh+ shell script (available in the root of source directory) to generate full bit-length RSpec test files.
|
102
92
|
|
103
93
|
sh tests.sh
|
104
94
|
|
@@ -120,14 +110,20 @@ On:
|
|
120
110
|
- Windows 7, 8
|
121
111
|
- Mac OS X 10.8
|
122
112
|
|
113
|
+
== Releases
|
114
|
+
|
115
|
+
*0.1.x* :: Alpha code, and not suitable for production.
|
116
|
+
*0.2.0* :: Production worthy, but breaks API compatibility with 0.1.x. Backward-compatibility will be maintained henceforth.
|
117
|
+
*0.2.2* :: Added sub-class for each SHA3 supported bit-lengths (example: SHA3::Digest::SHA256). Minor bug fix.
|
118
|
+
*0.2.3* :: Added documentation file (decoupled form C source); refactored C source.
|
119
|
+
|
123
120
|
== TO DO:
|
124
121
|
|
125
|
-
* Documentation (resolve order issue with Yard)!
|
126
122
|
* Add support for arbitrary length hashes.
|
127
123
|
* Add hex output support to compute method.
|
128
124
|
|
129
125
|
== Copyright
|
130
126
|
|
131
|
-
Copyright (c) 2012 Johanns Gregorian
|
127
|
+
Copyright (c) 2012 Johanns Gregorian (https://github.com/johanns)
|
132
128
|
|
133
129
|
See LICENSE.txt for details.
|
@@ -1,49 +1,9 @@
|
|
1
|
-
#include "
|
1
|
+
#include "sha3.h"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
*/
|
3
|
+
VALUE cDigest;
|
4
|
+
VALUE eDigestError;
|
6
5
|
|
7
|
-
/*
|
8
|
-
* SHA3::Digest allows you to compute message digests
|
9
|
-
* (interchangeably called "hashes") of arbitrary data that are
|
10
|
-
* cryptographically secure using SHA3 (Keccak) algorithm.
|
11
|
-
*
|
12
|
-
* == Usage
|
13
|
-
*
|
14
|
-
* require 'sha3'
|
15
|
-
*
|
16
|
-
* === Basics
|
17
|
-
*
|
18
|
-
* # Instantiate a new SHA3::Digest class with 256 bit length
|
19
|
-
* s = SHA3::Digest.new(:sha256)
|
20
|
-
* # => #<SHA3::Digest: c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470>
|
21
|
-
*
|
22
|
-
* # Update hash state, and compute new value
|
23
|
-
* s.update "Compute Me"
|
24
|
-
* # => #<SHA3::Digest: c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470>
|
25
|
-
*
|
26
|
-
* # << is an .update() alias
|
27
|
-
* s << "Me too"
|
28
|
-
* # => #<SHA3::Digest: e26f539eee3a05c52eb1f9439652d23343adea9764f011da232d24cd6d19924a>
|
29
|
-
*
|
30
|
-
* # Print digest bytes string
|
31
|
-
* puts s.digest
|
32
|
-
*
|
33
|
-
* # Print digest hex string
|
34
|
-
* puts s.hexdigest
|
35
|
-
*
|
36
|
-
* === Hashing a file
|
37
|
-
*
|
38
|
-
* # Compute the hash value for given file, and return the result as hex
|
39
|
-
* s = SHA3::Digest.new(224).file("my_awesome_file.bin").hexdigest
|
40
|
-
*
|
41
|
-
* === Bit operation
|
42
|
-
*
|
43
|
-
* # Compute hash of "011"
|
44
|
-
* SHA3::Digest.compute(:sha224, "\xC0", 3).unpack("H*")
|
45
|
-
* # => ["2b695a6fd92a2b3f3ce9cfca617d22c9bb52815dd59a9719b01bad25"]
|
46
|
-
*
|
6
|
+
/*
|
47
7
|
* == Notes
|
48
8
|
*
|
49
9
|
* ::Digest::Class call sequence ->
|
@@ -57,38 +17,6 @@
|
|
57
17
|
*
|
58
18
|
*/
|
59
19
|
|
60
|
-
static int get_hlen(VALUE obj)
|
61
|
-
{
|
62
|
-
int hlen;
|
63
|
-
|
64
|
-
if (TYPE(obj) == T_SYMBOL) {
|
65
|
-
ID symid;
|
66
|
-
|
67
|
-
symid = SYM2ID(obj);
|
68
|
-
|
69
|
-
if (rb_intern("sha224") == symid)
|
70
|
-
hlen = 224;
|
71
|
-
else if (rb_intern("sha256") == symid)
|
72
|
-
hlen = 256;
|
73
|
-
else if (rb_intern("sha384") == symid)
|
74
|
-
hlen = 384;
|
75
|
-
else if (rb_intern("sha512") == symid)
|
76
|
-
hlen = 512;
|
77
|
-
else
|
78
|
-
rb_raise(eDigestError, "invalid hash bit symbol (should be: :sha224, :sha256, :sha384, or :sha512");
|
79
|
-
}
|
80
|
-
else if (TYPE(obj) == T_FIXNUM) {
|
81
|
-
hlen = NUM2INT(obj);
|
82
|
-
|
83
|
-
if ((hlen != 224) && (hlen != 256) && (hlen != 384) && (hlen != 512))
|
84
|
-
rb_raise(rb_eArgError, "invalid hash bit length (should be: 224, 256, 384, or 512)");
|
85
|
-
}
|
86
|
-
else
|
87
|
-
rb_raise(eDigestError, "unknown type value");
|
88
|
-
|
89
|
-
return hlen;
|
90
|
-
}
|
91
|
-
|
92
20
|
static void free_allox(MDX *mdx)
|
93
21
|
{
|
94
22
|
if (mdx) {
|
@@ -102,15 +30,15 @@ static void free_allox(MDX *mdx)
|
|
102
30
|
}
|
103
31
|
|
104
32
|
static VALUE c_digest_alloc(VALUE klass)
|
105
|
-
{
|
33
|
+
{
|
106
34
|
MDX *mdx;
|
107
35
|
VALUE obj;
|
108
36
|
|
109
|
-
mdx = (MDX *) malloc(sizeof(
|
37
|
+
mdx = (MDX *) malloc(sizeof(MDX));
|
110
38
|
if (!mdx)
|
111
39
|
rb_raise(eDigestError, "failed to allocate object memory");
|
112
40
|
|
113
|
-
mdx->state = (hashState *) malloc(sizeof(
|
41
|
+
mdx->state = (hashState *) malloc(sizeof(hashState));
|
114
42
|
if (!mdx->state) {
|
115
43
|
free_allox(mdx);
|
116
44
|
rb_raise(eDigestError, "failed to allocate state memory");
|
@@ -118,7 +46,7 @@ static VALUE c_digest_alloc(VALUE klass)
|
|
118
46
|
|
119
47
|
obj = Data_Wrap_Struct(klass, 0, free_allox, mdx);
|
120
48
|
|
121
|
-
memset(mdx->state, 0, sizeof(
|
49
|
+
memset(mdx->state, 0, sizeof(hashState));
|
122
50
|
mdx->hashbitlen = 0;
|
123
51
|
|
124
52
|
return obj;
|
@@ -173,7 +101,7 @@ static VALUE c_digest_reset(VALUE self)
|
|
173
101
|
|
174
102
|
GETMDX(self, mdx);
|
175
103
|
|
176
|
-
memset(mdx->state, 0, sizeof(
|
104
|
+
memset(mdx->state, 0, sizeof(hashState));
|
177
105
|
|
178
106
|
if (Init(mdx->state, mdx->hashbitlen) != SUCCESS)
|
179
107
|
rb_raise(eDigestError, "failed to reset internal state");
|
@@ -254,7 +182,7 @@ static VALUE c_digest_finish(int argc, VALUE *argv, VALUE self)
|
|
254
182
|
|
255
183
|
// SHA3::Digest.compute(type, data, [datalen]) -> String (bytes)
|
256
184
|
// TO-DO: styled output (hex)
|
257
|
-
VALUE c_digest_compute(int argc, VALUE *argv, VALUE self)
|
185
|
+
static VALUE c_digest_compute(int argc, VALUE *argv, VALUE self)
|
258
186
|
{
|
259
187
|
VALUE hlen, data, dlen, str;
|
260
188
|
int hashbitlen;
|
@@ -279,11 +207,10 @@ VALUE c_digest_compute(int argc, VALUE *argv, VALUE self)
|
|
279
207
|
return str;
|
280
208
|
}
|
281
209
|
|
282
|
-
void
|
210
|
+
void Init_sha3_n_digest()
|
283
211
|
{
|
284
212
|
rb_require("digest");
|
285
213
|
|
286
|
-
mSHA3 = rb_define_module("SHA3");
|
287
214
|
/* SHA3::Digest (class) */
|
288
215
|
cDigest = rb_define_class_under(mSHA3, "Digest", rb_path2class("Digest::Class"));
|
289
216
|
/* SHA3::Digest::DigestError (class) */
|
@@ -1,8 +1,5 @@
|
|
1
|
-
#ifndef
|
2
|
-
#define
|
3
|
-
|
4
|
-
#include <ruby.h>
|
5
|
-
#include "KeccakNISTInterface.h"
|
1
|
+
#ifndef _DIGEST_H_
|
2
|
+
#define _DIGEST_H_
|
6
3
|
|
7
4
|
// From ruby/ext/openssl/ossl_digest.c
|
8
5
|
#define GETMDX(obj, mdx) do { \
|
@@ -20,13 +17,14 @@
|
|
20
17
|
GETMDX(obj, mdx); \
|
21
18
|
} while(0)
|
22
19
|
|
23
|
-
VALUE
|
24
|
-
VALUE
|
25
|
-
VALUE eDigestError;
|
20
|
+
extern VALUE cDigest;
|
21
|
+
extern VALUE eDigestError;
|
26
22
|
|
27
23
|
typedef struct {
|
28
24
|
hashState *state;
|
29
25
|
int hashbitlen;
|
30
26
|
} MDX;
|
31
27
|
|
28
|
+
void Init_sha3_n_digest(void);
|
29
|
+
|
32
30
|
#endif
|
data/ext/sha3/sha3.c
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#include "sha3.h"
|
2
|
+
|
3
|
+
VALUE mSHA3;
|
4
|
+
VALUE eSHA3Error;
|
5
|
+
|
6
|
+
int get_hlen(VALUE obj)
|
7
|
+
{
|
8
|
+
int hlen;
|
9
|
+
|
10
|
+
if (TYPE(obj) == T_SYMBOL) {
|
11
|
+
ID symid;
|
12
|
+
|
13
|
+
symid = SYM2ID(obj);
|
14
|
+
|
15
|
+
if (rb_intern("sha224") == symid)
|
16
|
+
hlen = 224;
|
17
|
+
else if (rb_intern("sha256") == symid)
|
18
|
+
hlen = 256;
|
19
|
+
else if (rb_intern("sha384") == symid)
|
20
|
+
hlen = 384;
|
21
|
+
else if (rb_intern("sha512") == symid)
|
22
|
+
hlen = 512;
|
23
|
+
else
|
24
|
+
rb_raise(eSHA3Error, "invalid hash bit symbol (should be: :sha224, :sha256, :sha384, or :sha512");
|
25
|
+
}
|
26
|
+
else if (TYPE(obj) == T_FIXNUM) {
|
27
|
+
hlen = NUM2INT(obj);
|
28
|
+
|
29
|
+
if ((hlen != 224) && (hlen != 256) && (hlen != 384) && (hlen != 512))
|
30
|
+
rb_raise(rb_eArgError, "invalid hash bit length (should be: 224, 256, 384, or 512)");
|
31
|
+
}
|
32
|
+
else
|
33
|
+
rb_raise(eSHA3Error, "unknown type value");
|
34
|
+
|
35
|
+
return hlen;
|
36
|
+
}
|
37
|
+
|
38
|
+
void Init_sha3_n()
|
39
|
+
{
|
40
|
+
mSHA3 = rb_define_module("SHA3");
|
41
|
+
eSHA3Error = rb_define_class_under(mSHA3, "SHA3Error", rb_eStandardError);
|
42
|
+
|
43
|
+
Init_sha3_n_digest();
|
44
|
+
}
|
data/ext/sha3/sha3.h
ADDED
data/lib/sha3.rb
CHANGED
data/lib/sha3/doc.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module SHA3
|
4
|
+
# A sub-class of (MRI Ruby based) Digest::Class, it implements SHA3 (Keccak) digest algorithm.
|
5
|
+
#
|
6
|
+
# @note SHA3::Digest class provides a four sub-classes for the available hash bit lengths (types).
|
7
|
+
# You can instantiate a new instance of Digest sub-class for a given type using the following sub-classes:
|
8
|
+
#
|
9
|
+
# SHA3::Digest::SHA224([data])
|
10
|
+
# SHA3::Digest::SHA256([data])
|
11
|
+
# SHA3::Digest::SHA384([data])
|
12
|
+
# SHA3::Digest::SHA512([data])
|
13
|
+
#
|
14
|
+
# The [data] parameter is optional.
|
15
|
+
class Digest < Digest::Class
|
16
|
+
# Creates a Digest instance based on given hash bit length (type).
|
17
|
+
#
|
18
|
+
# @param type [Number, Symbol] optional parameter used to set hash bit length (type).
|
19
|
+
# Valid options are:
|
20
|
+
#
|
21
|
+
# Number: 224, 256, 384, or 512
|
22
|
+
# Symobols: :sha224, :sha256, :sha384, or :sha512
|
23
|
+
#
|
24
|
+
# Default value: 256 (bits)
|
25
|
+
# @param data [String] optional parameter used to update initial instance state.
|
26
|
+
# #
|
27
|
+
# @return [Digest] self
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# digest = SHA3::Digest.new # => Defaults to 256 bits
|
31
|
+
# digest = SHA3::Digest.new(224) # => Initialize a new 224 bit digest instance
|
32
|
+
# digest = SHA3::Digest::SHA224 # => An alternate method for creating a digest class with 224 bit hash bit length
|
33
|
+
def initialize(type, data)
|
34
|
+
# See function: c_digest_init(...) in ext/sha3/_digest.c
|
35
|
+
end
|
36
|
+
|
37
|
+
# Updates, and recalculates Message Digest (state) with given data. If a message digest
|
38
|
+
# is to be computed from several subsequent sources, then each may be passed individually
|
39
|
+
# to the Digest instance.
|
40
|
+
#
|
41
|
+
# @param data [String] data to compute
|
42
|
+
#
|
43
|
+
# @return [Digest] self
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# digest = SHA3::Digest::SHA256.new
|
47
|
+
# digest.update('hash me')
|
48
|
+
# digest.update('me too')
|
49
|
+
def update(data)
|
50
|
+
# See function: c_digest_update(...) in ext/sha3/_digest.c
|
51
|
+
end
|
52
|
+
|
53
|
+
# Alias for update method
|
54
|
+
alias << :update
|
55
|
+
|
56
|
+
# Resets the Digest object to initial state, abandoning computed data.
|
57
|
+
#
|
58
|
+
# @return [Digest] self
|
59
|
+
def reset
|
60
|
+
# See function: c_digest_reset(...) in ext/sha3/_digest.c
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns message digest length in bytes.
|
64
|
+
#
|
65
|
+
# @return [Number] message length in bytes.
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# digest = SHA3::Digest::SHA256.new
|
69
|
+
# digest.length # Result => 32 (or 256 bits)
|
70
|
+
def length
|
71
|
+
# See function: c_digest_length(...) in ext/sha3/_digest.c
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns digest block length in bytes.
|
75
|
+
#
|
76
|
+
# @return [Number] digest block length in bytes.
|
77
|
+
#
|
78
|
+
# @example
|
79
|
+
# digest = SHA3::Digest::SHA384.new
|
80
|
+
# digest.block_length # Result => 104
|
81
|
+
def block_length
|
82
|
+
# See function: c_digest_block_length(...) in ext/sha3/_digest.c
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns name of initialized digest
|
86
|
+
#
|
87
|
+
# @return [String] name
|
88
|
+
def name
|
89
|
+
# See function: c_digest_name(...) in ext/sha3/_digest.c
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns computed hash value for given hash type, and data in hex (string).
|
93
|
+
#
|
94
|
+
# @param type [Number, Symbol] See {#initialize} for valid type values.
|
95
|
+
# @param data [String] data to compute hash value
|
96
|
+
#
|
97
|
+
# @return (String) computed hash as hex-encoded string
|
98
|
+
#
|
99
|
+
# @example
|
100
|
+
# SHA3::Digest.hexdigest(256, 'compute me, please')
|
101
|
+
# SHA3::Digest::SHA256.hexdigest('compute me, please') # => Alternate syntax
|
102
|
+
def self.hexdigest(type, data)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns computed hash value for given hash type, and data in bytes.
|
106
|
+
#
|
107
|
+
# @param type [Number, Symbol] See {#initialize} for valid type values.
|
108
|
+
# @param data [String] data to compute hash value
|
109
|
+
#
|
110
|
+
# @return [String] computed hash in bytes
|
111
|
+
#
|
112
|
+
# @example
|
113
|
+
# SHA3::Digest.digest(256, 'compute me, please')
|
114
|
+
# SHA3::Digest::SHA256.digest('compute me, please') # => Alternate syntax
|
115
|
+
def self.digest(type, data)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns computed hash value of bit-length data.
|
119
|
+
#
|
120
|
+
# @param type [Number, Symbol] See {#initialize} for valid type values.
|
121
|
+
# @param data [String] data to compute hash value
|
122
|
+
# @param data_length [Number] data bit length
|
123
|
+
#
|
124
|
+
# @return [String] computed hash in bytes
|
125
|
+
#
|
126
|
+
# @example
|
127
|
+
# SHA3::Digest.compute(:sha384, '\0C', 2)
|
128
|
+
def self.compute(type, data, data_length)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class DigestError < StandardError
|
133
|
+
end
|
134
|
+
end
|
data/lib/sha3/version.rb
CHANGED
data/spec/sha3_core_spec.rb
CHANGED
@@ -70,7 +70,9 @@ describe SHA3::Digest do
|
|
70
70
|
sha.digest_length.should(eq(64))
|
71
71
|
sha.block_length.should(eq(72))
|
72
72
|
end
|
73
|
-
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "SHA3::Digest::SHAxyz" do
|
74
76
|
it "should pass Digest.SHA224() usage test" do
|
75
77
|
sha = SHA3::Digest::SHA224.new()
|
76
78
|
sha.hexdigest.should eq("f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sha3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
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:
|
12
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
@@ -114,13 +114,16 @@ files:
|
|
114
114
|
- ext/sha3/KeccakNISTInterface.h
|
115
115
|
- ext/sha3/KeccakSponge.c
|
116
116
|
- ext/sha3/KeccakSponge.h
|
117
|
-
- ext/sha3/_sha3.c
|
118
|
-
- ext/sha3/_sha3.h
|
119
117
|
- ext/sha3/brg_endian.h
|
118
|
+
- ext/sha3/digest.c
|
119
|
+
- ext/sha3/digest.h
|
120
120
|
- ext/sha3/displayIntermediateValues.c
|
121
121
|
- ext/sha3/displayIntermediateValues.h
|
122
122
|
- ext/sha3/extconf.rb
|
123
|
+
- ext/sha3/sha3.c
|
124
|
+
- ext/sha3/sha3.h
|
123
125
|
- lib/sha3.rb
|
126
|
+
- lib/sha3/doc.rb
|
124
127
|
- lib/sha3/version.rb
|
125
128
|
- sha3.gemspec
|
126
129
|
- spec/generate_tests.rb
|