sha3 0.2.5 → 1.0.3
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.
Potentially problematic release.
This version of sha3 might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +232 -20
- data/.travis.yml +18 -12
- data/Gemfile +1 -1
- data/Gemfile.ci +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +120 -0
- data/Rakefile +15 -18
- data/ext/sha3/KeccakF-1600-interface.h +28 -34
- data/ext/sha3/KeccakHash.c +80 -0
- data/ext/sha3/KeccakHash.h +110 -0
- data/ext/sha3/KeccakSponge.c +127 -201
- data/ext/sha3/KeccakSponge.h +74 -37
- data/ext/sha3/Optimized64/KeccakF-1600-64.macros +2199 -0
- data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +3 -0
- data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +508 -0
- data/ext/sha3/{KeccakF-1600-unrolling.macros → Optimized64/KeccakF-1600-unrolling.macros} +16 -14
- data/ext/sha3/Optimized64/SnP-interface.h +47 -0
- data/ext/sha3/Reference/KeccakF-1600-reference.c +311 -0
- data/ext/sha3/Reference/KeccakF-reference.h +26 -0
- data/ext/sha3/Reference/SnP-FBWL-default.c +96 -0
- data/ext/sha3/Reference/SnP-FBWL-default.h +26 -0
- data/ext/sha3/Reference/SnP-interface.h +42 -0
- data/ext/sha3/{displayIntermediateValues.c → Reference/displayIntermediateValues.c} +52 -11
- data/ext/sha3/{displayIntermediateValues.h → Reference/displayIntermediateValues.h} +11 -6
- data/ext/sha3/SnP-Relaned.h +249 -0
- data/ext/sha3/brg_endian.h +0 -0
- data/ext/sha3/digest.c +182 -167
- data/ext/sha3/digest.h +37 -29
- data/ext/sha3/extconf.rb +13 -13
- data/ext/sha3/sha3.c +46 -30
- data/ext/sha3/sha3.h +10 -9
- data/lib/sha3/doc.rb +26 -39
- data/lib/sha3/version.rb +2 -3
- data/sha3.gemspec +13 -15
- data/spec/generate_tests.rb +22 -57
- data/spec/sha3_core_spec.rb +111 -133
- data/spec/spec_helper.rb +2 -2
- data/tests.sh +11 -9
- metadata +46 -51
- data/README.rdoc +0 -132
- data/ext/sha3/KeccakF-1600-32-rvk.macros +0 -555
- data/ext/sha3/KeccakF-1600-32-s1.macros +0 -1187
- data/ext/sha3/KeccakF-1600-32-s2.macros +0 -1187
- data/ext/sha3/KeccakF-1600-32.macros +0 -26
- data/ext/sha3/KeccakF-1600-64.macros +0 -728
- data/ext/sha3/KeccakF-1600-int-set.h +0 -6
- data/ext/sha3/KeccakF-1600-opt.c +0 -504
- data/ext/sha3/KeccakF-1600-opt32-settings.h +0 -4
- data/ext/sha3/KeccakF-1600-opt32.c-arch +0 -524
- data/ext/sha3/KeccakF-1600-opt64-settings.h +0 -7
- data/ext/sha3/KeccakF-1600-opt64.c-arch +0 -504
- data/ext/sha3/KeccakF-1600-reference.c-arch +0 -300
- data/ext/sha3/KeccakF-1600-x86-64-gas.s +0 -766
- data/ext/sha3/KeccakF-1600-x86-64-shld-gas.s +0 -766
- data/ext/sha3/KeccakNISTInterface.c +0 -81
- data/ext/sha3/KeccakNISTInterface.h +0 -70
data/lib/sha3/doc.rb
CHANGED
@@ -2,10 +2,10 @@ require 'digest'
|
|
2
2
|
|
3
3
|
module SHA3
|
4
4
|
# A sub-class of (MRI Ruby based) Digest::Class, it implements SHA3 (Keccak) digest algorithm.
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# @note SHA3::Digest class provides a four sub-classes for the available hash bit lengths (types).
|
7
7
|
# You can instantiate a new instance of Digest sub-class for a given type using the following sub-classes:
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# SHA3::Digest::SHA224([data])
|
10
10
|
# SHA3::Digest::SHA256([data])
|
11
11
|
# SHA3::Digest::SHA384([data])
|
@@ -14,18 +14,18 @@ module SHA3
|
|
14
14
|
# The [data] parameter is optional.
|
15
15
|
class Digest < Digest::Class
|
16
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
|
-
#
|
17
|
+
#
|
18
|
+
# @param type [Number, Symbol] optional parameter used to set hash bit length (type).
|
19
|
+
# Valid options are:
|
20
|
+
#
|
21
21
|
# Number: 224, 256, 384, or 512
|
22
22
|
# Symobols: :sha224, :sha256, :sha384, or :sha512
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# Default value: 256 (bits)
|
25
25
|
# @param data [String] optional parameter used to update initial instance state.
|
26
|
-
# #
|
26
|
+
# #
|
27
27
|
# @return [Digest] self
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# @example
|
30
30
|
# digest = SHA3::Digest.new # => Defaults to 256 bits
|
31
31
|
# digest = SHA3::Digest.new(224) # => Initialize a new 224 bit digest instance
|
@@ -34,15 +34,15 @@ module SHA3
|
|
34
34
|
# See function: c_digest_init(...) in ext/sha3/_digest.c
|
35
35
|
end
|
36
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
|
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
39
|
# to the Digest instance.
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# @param data [String] data to compute
|
42
|
-
#
|
42
|
+
#
|
43
43
|
# @return [Digest] self
|
44
|
-
#
|
45
|
-
# @example
|
44
|
+
#
|
45
|
+
# @example
|
46
46
|
# digest = SHA3::Digest::SHA256.new
|
47
47
|
# digest.update('hash me')
|
48
48
|
# digest.update('me too')
|
@@ -61,9 +61,9 @@ module SHA3
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# Returns message digest length in bytes.
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# @return [Number] message length in bytes.
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# @example
|
68
68
|
# digest = SHA3::Digest::SHA256.new
|
69
69
|
# digest.length # Result => 32 (or 256 bits)
|
@@ -72,9 +72,9 @@ module SHA3
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Returns digest block length in bytes.
|
75
|
-
#
|
75
|
+
#
|
76
76
|
# @return [Number] digest block length in bytes.
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# @example
|
79
79
|
# digest = SHA3::Digest::SHA384.new
|
80
80
|
# digest.block_length # Result => 104
|
@@ -83,19 +83,19 @@ module SHA3
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# Returns name of initialized digest
|
86
|
-
#
|
86
|
+
#
|
87
87
|
# @return [String] name
|
88
88
|
def name
|
89
89
|
# See function: c_digest_name(...) in ext/sha3/_digest.c
|
90
90
|
end
|
91
91
|
|
92
92
|
# Returns computed hash value for given hash type, and data in hex (string).
|
93
|
-
#
|
93
|
+
#
|
94
94
|
# @param type [Number, Symbol] See {#initialize} for valid type values.
|
95
95
|
# @param data [String] data to compute hash value
|
96
|
-
#
|
96
|
+
#
|
97
97
|
# @return (String) computed hash as hex-encoded string
|
98
|
-
#
|
98
|
+
#
|
99
99
|
# @example
|
100
100
|
# SHA3::Digest.hexdigest(256, 'compute me, please')
|
101
101
|
# SHA3::Digest::SHA256.hexdigest('compute me, please') # => Alternate syntax
|
@@ -103,30 +103,17 @@ module SHA3
|
|
103
103
|
end
|
104
104
|
|
105
105
|
# Returns computed hash value for given hash type, and data in bytes.
|
106
|
-
#
|
106
|
+
#
|
107
107
|
# @param type [Number, Symbol] See {#initialize} for valid type values.
|
108
108
|
# @param data [String] data to compute hash value
|
109
|
-
#
|
109
|
+
#
|
110
110
|
# @return [String] computed hash in bytes
|
111
|
-
#
|
111
|
+
#
|
112
112
|
# @example
|
113
113
|
# SHA3::Digest.digest(256, 'compute me, please')
|
114
114
|
# SHA3::Digest::SHA256.digest('compute me, please') # => Alternate syntax
|
115
115
|
def self.digest(type, data)
|
116
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
117
|
end
|
131
118
|
|
132
119
|
class DigestError < StandardError
|
data/lib/sha3/version.rb
CHANGED
data/sha3.gemspec
CHANGED
@@ -1,25 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path('../lib/sha3/version', __FILE__)
|
1
|
+
require File.expand_path('lib/sha3/version', __dir__)
|
4
2
|
|
5
3
|
Gem::Specification.new do |gem|
|
6
|
-
gem.name =
|
4
|
+
gem.name = 'sha3'
|
7
5
|
gem.version = SHA3::VERSION
|
8
|
-
gem.summary =
|
9
|
-
gem.description =
|
10
|
-
gem.license =
|
11
|
-
gem.authors = [
|
12
|
-
gem.email =
|
13
|
-
gem.homepage =
|
6
|
+
gem.summary = 'SHA3 for Ruby'
|
7
|
+
gem.description = 'SHA3 for Ruby is a native (C) FIPS 202 compliant implementation of SHA3 (Keccak) cryptographic hashing algorithm.'
|
8
|
+
gem.license = 'MIT'
|
9
|
+
gem.authors = ['Johanns Gregorian']
|
10
|
+
gem.email = 'io+sha3@jsg.io'
|
11
|
+
gem.homepage = 'https://github.com/johanns/sha3#readme'
|
14
12
|
|
15
13
|
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
15
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
16
|
gem.require_paths = ['lib']
|
19
17
|
gem.extensions = ['ext/sha3/extconf.rb']
|
20
|
-
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency 'rspec', '~>
|
18
|
+
|
19
|
+
gem.add_development_dependency 'rake-compiler', '~> 1.1'
|
20
|
+
gem.add_development_dependency 'rspec', '~> 3.3'
|
23
21
|
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
24
|
-
gem.add_development_dependency 'yard', '~> 0.
|
22
|
+
gem.add_development_dependency 'yard', '~> 0.9'
|
25
23
|
end
|
data/spec/generate_tests.rb
CHANGED
@@ -1,84 +1,49 @@
|
|
1
1
|
# Based on python-sha3's / digest-sha3 test generator.
|
2
2
|
|
3
3
|
FILES = [
|
4
|
-
['data/
|
5
|
-
['data/
|
6
|
-
['data/
|
7
|
-
['data/
|
8
|
-
|
9
|
-
]
|
4
|
+
['data/ShortMsgKAT_SHA3-224.txt', 224],
|
5
|
+
['data/ShortMsgKAT_SHA3-256.txt', 256],
|
6
|
+
['data/ShortMsgKAT_SHA3-384.txt', 384],
|
7
|
+
['data/ShortMsgKAT_SHA3-512.txt', 512]
|
8
|
+
].freeze
|
10
9
|
|
11
10
|
def gen_digest_byte_tests
|
12
11
|
FILES.each do |path, hashlen|
|
13
12
|
name = File.basename(path).split('.')[0]
|
14
13
|
|
15
|
-
f = File.new("sha3_digest_#{name}_spec.rb",
|
14
|
+
f = File.new("sha3_digest_#{name}_spec.rb", 'w')
|
16
15
|
f.puts(
|
17
|
-
%
|
16
|
+
%{require 'spec_helper'
|
18
17
|
require 'sha3'
|
19
18
|
|
20
19
|
describe "SHA3::Digest.new(#{hashlen})" do
|
21
20
|
it "should match byte-length test vectors (#{name})." do
|
22
|
-
}
|
21
|
+
}
|
22
|
+
)
|
23
23
|
contents = File.read(path).split('Len = ')
|
24
24
|
contents.each do |test|
|
25
25
|
lines = test.split("\n")
|
26
|
-
|
27
|
-
length = lines[0].to_i
|
28
|
-
if length % 8 == 0 && length != 0
|
29
|
-
msg_raw = [lines[1].split(' = ').last].pack("H*")
|
30
|
-
md = lines[2].split(' = ').last.downcase
|
31
|
-
f.puts(
|
32
|
-
%Q{ SHA3::Digest.new(#{hashlen}, #{msg_raw.inspect}).hexdigest.should(eq("#{md}"))
|
33
|
-
})
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
f.puts(
|
38
|
-
%Q{ end
|
39
|
-
end
|
40
|
-
})
|
41
|
-
f.close
|
42
|
-
end
|
43
|
-
end
|
26
|
+
next unless !lines.empty? && lines[0] !~ /^#/
|
44
27
|
|
45
|
-
|
46
|
-
|
47
|
-
name = File.basename(path).split('.')[0]
|
28
|
+
length = lines[0].to_i
|
29
|
+
next unless (length % 8).zero? && length != 0
|
48
30
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
it "should match bit-length test vectors (#{name})." do
|
56
|
-
})
|
57
|
-
contents = File.read(path).split('Len = ')
|
58
|
-
contents.each do |test|
|
59
|
-
lines = test.split("\n")
|
60
|
-
if !lines.empty? && lines[0] !~ /^#/
|
61
|
-
length = lines[0].to_i
|
62
|
-
if length != 0
|
63
|
-
msg_raw = [lines[1].split(' = ').last].pack("H*")
|
64
|
-
md = lines[2].split(' = ').last.downcase
|
65
|
-
f.puts(
|
66
|
-
%Q{ SHA3::Digest.compute(#{hashlen}, #{msg_raw.inspect}, #{length}).unpack("H*").first.should(eq("#{md}"))
|
67
|
-
})
|
68
|
-
end
|
69
|
-
end
|
31
|
+
msg_raw = [lines[1].split(' = ').last].pack('H*')
|
32
|
+
md = lines[2].split(' = ').last.downcase
|
33
|
+
f.puts(
|
34
|
+
%{ expect(SHA3::Digest.new(#{hashlen}, #{msg_raw.inspect}).hexdigest).to eq("#{md}")
|
35
|
+
}
|
36
|
+
)
|
70
37
|
end
|
71
38
|
f.puts(
|
72
|
-
%
|
39
|
+
%( end
|
73
40
|
end
|
74
|
-
|
41
|
+
)
|
42
|
+
)
|
75
43
|
f.close
|
76
44
|
end
|
77
45
|
end
|
78
46
|
|
79
|
-
def setup
|
80
|
-
|
81
|
-
end
|
47
|
+
def setup; end
|
82
48
|
|
83
49
|
gen_digest_byte_tests
|
84
|
-
gen_compute_bit_tests
|
data/spec/sha3_core_spec.rb
CHANGED
@@ -1,170 +1,148 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'sha3'
|
3
3
|
|
4
|
-
describe SHA3 do
|
5
|
-
it
|
6
|
-
subject.const_get('VERSION').
|
4
|
+
RSpec.describe SHA3 do
|
5
|
+
it 'should have a VERSION constant' do
|
6
|
+
expect(subject.const_get('VERSION')).not_to be_empty
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
10
|
-
subject.const_get('KECCAK_VERSION').
|
9
|
+
it 'should have a KECCAK_VERSION constant' do
|
10
|
+
expect(subject.const_get('KECCAK_VERSION')).not_to be_empty
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
subject.const_get('Digest').is_a?(Class).
|
15
|
-
end
|
13
|
+
it 'should have Digest class' do
|
14
|
+
expect(subject.const_get('Digest').is_a?(Class)).to be_truthy
|
15
|
+
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe SHA3::Digest do
|
19
|
-
it
|
18
|
+
RSpec.describe SHA3::Digest do
|
19
|
+
it 'should pass Digest.new() (default: :sha256) usage test' do
|
20
20
|
sha = SHA3::Digest.new()
|
21
|
-
|
22
|
-
sha.
|
23
|
-
sha.
|
24
|
-
sha
|
25
|
-
|
26
|
-
sha.
|
27
|
-
|
21
|
+
|
22
|
+
expect(sha.hexdigest).to eq('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a')
|
23
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('677035391cd3701293d385f037ba32796252bb7ce180b00b582dd9b20aaad7f0')
|
24
|
+
expect(sha.reset).to eq('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a')
|
25
|
+
|
26
|
+
sha << (['6172f1971a6e1e4e6170afbad95d5fec99bf69b24b674bc17dd78011615e502de6f56b86b1a71d3f4348087218ac7b7d09302993be272e4a591968aef18a1262d665610d1070ee91cc8da36e1f841a69a7a682c580e836941d21d909a3afc1f0b963e1ca5ab193e124a1a53df1c587470e5881fb54dae1b0d840f0c8f9d1b04c645ba1041c7d8dbf22030a623aa15638b3d99a2c400ff76f3252079af88d2b37f35ee66c1ad7801a28d3d388ac450b97d5f0f79e4541755356b3b1a5696b023f39ab7ab5f28df4202936bc97393b93bc915cb159ea1bd7a0a414cb4b7a1ac3af68f50d79f0c9c7314e750f7d02faa58bfa'].pack('H*'))
|
27
|
+
|
28
|
+
expect(sha.hexdigest).to eq('f60c53ba2132293b881f0513e7ab47fe9746ed4a6ac9cade61e6d802d5872372')
|
29
|
+
expect(sha.digest_length).to eq(32)
|
30
|
+
expect(sha.block_length).to eq(136)
|
28
31
|
end
|
29
32
|
|
30
|
-
it
|
33
|
+
it 'should pass Digest.new(:sha224) usage test' do
|
31
34
|
sha = SHA3::Digest.new(:sha224)
|
32
|
-
|
33
|
-
sha.
|
34
|
-
sha.
|
35
|
-
sha
|
36
|
-
|
37
|
-
sha.
|
38
|
-
|
35
|
+
|
36
|
+
expect(sha.hexdigest).to eq('6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7')
|
37
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('df70adc49b2e76eee3a6931b93fa41841c3af2cdf5b32a18b5478c39')
|
38
|
+
expect(sha.reset).to eq('6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7')
|
39
|
+
|
40
|
+
sha << (['5fce8109a358570e40983e1184e541833bb9091e280f258cfb144387b05d190e431cb19baa67273ba0c58abe91308e1844dcd0b3678baa42f335f2fa05267a0240b3c718a5942b3b3e3bfa98a55c25a1466e8d7a603722cb2bbf03afa54cd769a99f310735ee5a05dae2c22d397bd95635f58c48a67f90e1b73aafcd3f82117f0166657838691005b18da6f341d6e90fc1cdb352b30fae45d348294e501b63252de14740f2b85ae5299ddec3172de8b6d0ba219a20a23bb5e10ff434d39db3f583305e9f5c039d98569e377b75a70ab837d1df269b8a4b566f40bb91b577455fd3c356c914fa06b9a7ce24c7317a172d'].pack('H*'))
|
41
|
+
|
42
|
+
expect(sha.hexdigest).to eq('2ebe13f12ec43e3f6b0506d7ab216e1c311394f7c89d69a920cd00c0')
|
43
|
+
expect(sha.digest_length).to eq(28)
|
44
|
+
expect(sha.block_length).to eq(144)
|
39
45
|
end
|
40
46
|
|
41
|
-
it
|
47
|
+
it 'should pass Digest.new(:sha256) usage test' do
|
42
48
|
sha = SHA3::Digest.new(:sha256)
|
43
|
-
|
44
|
-
sha.
|
45
|
-
sha.
|
46
|
-
sha
|
47
|
-
|
48
|
-
sha.
|
49
|
-
|
49
|
+
|
50
|
+
expect(sha.hexdigest).to eq('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a')
|
51
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('677035391cd3701293d385f037ba32796252bb7ce180b00b582dd9b20aaad7f0')
|
52
|
+
expect(sha.reset).to eq('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a')
|
53
|
+
|
54
|
+
sha << (['6172f1971a6e1e4e6170afbad95d5fec99bf69b24b674bc17dd78011615e502de6f56b86b1a71d3f4348087218ac7b7d09302993be272e4a591968aef18a1262d665610d1070ee91cc8da36e1f841a69a7a682c580e836941d21d909a3afc1f0b963e1ca5ab193e124a1a53df1c587470e5881fb54dae1b0d840f0c8f9d1b04c645ba1041c7d8dbf22030a623aa15638b3d99a2c400ff76f3252079af88d2b37f35ee66c1ad7801a28d3d388ac450b97d5f0f79e4541755356b3b1a5696b023f39ab7ab5f28df4202936bc97393b93bc915cb159ea1bd7a0a414cb4b7a1ac3af68f50d79f0c9c7314e750f7d02faa58bfa'].pack('H*'))
|
55
|
+
|
56
|
+
expect(sha.hexdigest).to eq('f60c53ba2132293b881f0513e7ab47fe9746ed4a6ac9cade61e6d802d5872372')
|
57
|
+
expect(sha.digest_length).to eq(32)
|
58
|
+
expect(sha.block_length).to eq(136)
|
50
59
|
end
|
51
|
-
|
52
|
-
it
|
60
|
+
|
61
|
+
it 'should pass Digest.new(:sha384) usage test' do
|
53
62
|
sha = SHA3::Digest.new(:sha384)
|
54
|
-
|
55
|
-
sha.
|
56
|
-
|
57
|
-
sha
|
58
|
-
sha.
|
59
|
-
|
60
|
-
sha.
|
63
|
+
|
64
|
+
expect(sha.hexdigest).to eq('0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004')
|
65
|
+
|
66
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('5ee7f374973cd4bb3dc41e3081346798497ff6e36cb9352281dfe07d07fc530ca9ad8ef7aad56ef5d41be83d5e543807')
|
67
|
+
expect(sha.reset).to eq('0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004')
|
68
|
+
|
69
|
+
sha << (['3b8e97c5ffc2d6a40fa7de7fcefc90f3b12c940e7ab415321e29ee692dfac799b009c99dcddb708fce5a178c5c35ee2b8617143edc4c40b4d313661f49abdd93cea79d117518805496fe6acf292c4c2a1f76b403a97d7c399daf85b46ad84e16246c67d6836757bde336c290d5d401e6c1386ab32797af6bb251e9b2d8fe754c47482b72e0b394eab76916126fd68ea7d65eb93d59f5b4c5ac40f7c3b37e7f3694f29424c24af8c8f0ef59cd9dbf1d28e0e10f799a6f78cad1d45b9db3d7dee4a7059abe99182714983b9c9d44d7f5643596d4f3'].pack('H*'))
|
70
|
+
|
71
|
+
expect(sha.hexdigest).to eq('9b809198dcce24175e33098331d3a402a821ae9326e72775aae34d1a9bb53d2b57863905cfd60543bbc42b454007c315')
|
72
|
+
expect(sha.digest_length).to eq(48)
|
73
|
+
expect(sha.block_length).to eq(104)
|
61
74
|
end
|
62
75
|
|
63
|
-
it
|
76
|
+
it 'should pass Digest.new(:sha512) usage test' do
|
64
77
|
sha = SHA3::Digest.new(:sha512)
|
65
|
-
|
66
|
-
sha.
|
67
|
-
sha.
|
68
|
-
sha
|
69
|
-
|
70
|
-
sha.
|
71
|
-
|
78
|
+
|
79
|
+
expect(sha.hexdigest).to eq('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26')
|
80
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('3939fcc8b57b63612542da31a834e5dcc36e2ee0f652ac72e02624fa2e5adeecc7dd6bb3580224b4d6138706fc6e80597b528051230b00621cc2b22999eaa205')
|
81
|
+
expect(sha.reset).to eq('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26')
|
82
|
+
|
83
|
+
sha << (['03d625488354df30e3f875a68edfcf340e8366a8e1ab67f9d5c5486a96829dfac0578289082b2a62117e1cf418b43b90e0adc881fc6ae8105c888e9ecd21aea1c9ae1a4038dfd17378fed71d02ae492087d7cdcd98f746855227967cb1ab4714261ee3bead3f4db118329d3ebef4bc48a875c19ba763966da0ebea800e01b2f50b00e9dd4caca6dcb314d00184ef71ea2391d760c950710db4a70f9212ffc54861f9dc752ce18867b8ad0c48df8466ef7231e7ac567f0eb55099e622ebb86cb237520190a61c66ad34f1f4e289cb3282ae3eaac6152ed24d2c92bae5a7658252a53c49b7b02dfe54fdb2e90074b6cf310ac661'].pack('H*'))
|
84
|
+
|
85
|
+
expect(sha.hexdigest).to eq('1fcd1e38ab03c750366cf86dd72ec3bf22f5bbf7fea0149d31b6a67b68b537b59ba37917fd88ced9aa8d2941a65f552b7928b3785c66d640f3b74af039ed18ce')
|
86
|
+
expect(sha.digest_length).to eq(64)
|
87
|
+
expect(sha.block_length).to eq(72)
|
72
88
|
end
|
73
89
|
end
|
74
90
|
|
75
|
-
describe
|
76
|
-
it
|
91
|
+
RSpec.describe 'SHA3::Digest::SHAxyz' do
|
92
|
+
it 'should pass Digest.SHA224() usage test' do
|
77
93
|
sha = SHA3::Digest::SHA224.new()
|
78
|
-
|
79
|
-
sha.
|
80
|
-
sha.
|
81
|
-
sha
|
82
|
-
|
83
|
-
sha.
|
84
|
-
|
94
|
+
|
95
|
+
expect(sha.hexdigest).to eq('6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7')
|
96
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('df70adc49b2e76eee3a6931b93fa41841c3af2cdf5b32a18b5478c39')
|
97
|
+
expect(sha.reset).to eq('6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7')
|
98
|
+
|
99
|
+
sha << (['5fce8109a358570e40983e1184e541833bb9091e280f258cfb144387b05d190e431cb19baa67273ba0c58abe91308e1844dcd0b3678baa42f335f2fa05267a0240b3c718a5942b3b3e3bfa98a55c25a1466e8d7a603722cb2bbf03afa54cd769a99f310735ee5a05dae2c22d397bd95635f58c48a67f90e1b73aafcd3f82117f0166657838691005b18da6f341d6e90fc1cdb352b30fae45d348294e501b63252de14740f2b85ae5299ddec3172de8b6d0ba219a20a23bb5e10ff434d39db3f583305e9f5c039d98569e377b75a70ab837d1df269b8a4b566f40bb91b577455fd3c356c914fa06b9a7ce24c7317a172d'].pack("H*"))
|
100
|
+
|
101
|
+
expect(sha.hexdigest).to eq('2ebe13f12ec43e3f6b0506d7ab216e1c311394f7c89d69a920cd00c0')
|
102
|
+
expect(sha.digest_length).to eq(28)
|
103
|
+
expect(sha.block_length).to eq(144)
|
85
104
|
end
|
86
105
|
|
87
|
-
it
|
106
|
+
it 'should pass Digest.SHA256() usage test' do
|
88
107
|
sha = SHA3::Digest::SHA256.new()
|
89
|
-
|
90
|
-
sha.
|
91
|
-
sha.
|
92
|
-
sha
|
93
|
-
|
94
|
-
sha.
|
95
|
-
|
108
|
+
|
109
|
+
expect(sha.hexdigest).to eq('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a')
|
110
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('677035391cd3701293d385f037ba32796252bb7ce180b00b582dd9b20aaad7f0')
|
111
|
+
expect(sha.reset).to eq('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a')
|
112
|
+
|
113
|
+
sha << (['6172f1971a6e1e4e6170afbad95d5fec99bf69b24b674bc17dd78011615e502de6f56b86b1a71d3f4348087218ac7b7d09302993be272e4a591968aef18a1262d665610d1070ee91cc8da36e1f841a69a7a682c580e836941d21d909a3afc1f0b963e1ca5ab193e124a1a53df1c587470e5881fb54dae1b0d840f0c8f9d1b04c645ba1041c7d8dbf22030a623aa15638b3d99a2c400ff76f3252079af88d2b37f35ee66c1ad7801a28d3d388ac450b97d5f0f79e4541755356b3b1a5696b023f39ab7ab5f28df4202936bc97393b93bc915cb159ea1bd7a0a414cb4b7a1ac3af68f50d79f0c9c7314e750f7d02faa58bfa'].pack("H*"))
|
114
|
+
|
115
|
+
expect(sha.hexdigest).to eq('f60c53ba2132293b881f0513e7ab47fe9746ed4a6ac9cade61e6d802d5872372')
|
116
|
+
expect(sha.digest_length).to eq(32)
|
117
|
+
expect(sha.block_length).to eq(136)
|
96
118
|
end
|
97
|
-
|
98
|
-
it
|
119
|
+
|
120
|
+
it 'should pass Digest.SHA384() usage test' do
|
99
121
|
sha = SHA3::Digest::SHA384.new()
|
100
|
-
sha.hexdigest.should eq("2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff")
|
101
|
-
sha.update(["cc"].pack("H*")).hexdigest.should eq("1b84e62a46e5a201861754af5dc95c4a1a69caf4a796ae405680161e29572641f5fa1e8641d7958336ee7b11c58f73e9")
|
102
|
-
sha.reset.hexdigest.should eq("2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff")
|
103
|
-
sha << (["3b8e97c5ffc2d6a40fa7de7fcefc90f3b12c940e7ab415321e29ee692dfac799b009c99dcddb708fce5a178c5c35ee2b8617143edc4c40b4d313661f49abdd93cea79d117518805496fe6acf292c4c2a1f76b403a97d7c399daf85b46ad84e16246c67d6836757bde336c290d5d401e6c1386ab32797af6bb251e9b2d8fe754c47482b72e0b394eab76916126fd68ea7d65eb93d59f5b4c5ac40f7c3b37e7f3694f29424c24af8c8f0ef59cd9dbf1d28e0e10f799a6f78cad1d45b9db3d7dee4a7059abe99182714983b9c9d44d7f5643596d4f3"].pack("H*"))
|
104
|
-
sha.hexdigest.should(eq("9172aad6c15b4dcd79bbd84fad0601119d8b4e3afed17b594ff38424157985ee27b65826b9905486e767e85aa031e07b"))
|
105
|
-
sha.digest_length.should(eq(48))
|
106
|
-
sha.block_length.should(eq(104))
|
107
|
-
end
|
108
122
|
|
109
|
-
|
110
|
-
sha = SHA3::Digest::SHA512.new()
|
111
|
-
sha.hexdigest.should eq("0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e")
|
112
|
-
sha.update(["cc"].pack("H*")).hexdigest.should eq("8630c13cbd066ea74bbe7fe468fec1dee10edc1254fb4c1b7c5fd69b646e44160b8ce01d05a0908ca790dfb080f4b513bc3b6225ece7a810371441a5ac666eb9")
|
113
|
-
sha.reset.hexdigest.should eq("0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e")
|
114
|
-
sha << (["03d625488354df30e3f875a68edfcf340e8366a8e1ab67f9d5c5486a96829dfac0578289082b2a62117e1cf418b43b90e0adc881fc6ae8105c888e9ecd21aea1c9ae1a4038dfd17378fed71d02ae492087d7cdcd98f746855227967cb1ab4714261ee3bead3f4db118329d3ebef4bc48a875c19ba763966da0ebea800e01b2f50b00e9dd4caca6dcb314d00184ef71ea2391d760c950710db4a70f9212ffc54861f9dc752ce18867b8ad0c48df8466ef7231e7ac567f0eb55099e622ebb86cb237520190a61c66ad34f1f4e289cb3282ae3eaac6152ed24d2c92bae5a7658252a53c49b7b02dfe54fdb2e90074b6cf310ac661"].pack("H*"))
|
115
|
-
sha.hexdigest.should(eq("13a592b73ede487036c8816bd6fc6cdc04dc6133409a6ee990584160518f9ef573264cf04d38a3ba75d150f4f026f6df8936e13c8f4f3ecc9ecbc43fdfc488a4"))
|
116
|
-
sha.digest_length.should(eq(64))
|
117
|
-
sha.block_length.should(eq(72))
|
118
|
-
end
|
123
|
+
expect(sha.hexdigest).to eq('0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004')
|
119
124
|
|
120
|
-
|
125
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('5ee7f374973cd4bb3dc41e3081346798497ff6e36cb9352281dfe07d07fc530ca9ad8ef7aad56ef5d41be83d5e543807')
|
126
|
+
expect(sha.reset).to eq('0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004')
|
121
127
|
|
122
|
-
|
123
|
-
it "should match SHA3-224 test vectors (subset)" do
|
124
|
-
SHA3::Digest.compute(:sha224, ["00"].pack("H*"), 0).unpack("H*").first.should(eq("f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd"))
|
125
|
-
SHA3::Digest.compute(:sha224, ["00"].pack("H*"), 1).unpack("H*").first.should(eq("860e3ec314c5cbf19c1a4314e9ea8cb85cecd18bd850b42f5c6f2a07"))
|
126
|
-
SHA3::Digest.compute(:sha224, ["c0"].pack("H*"), 2).unpack("H*").first.should(eq("6b22cddbd1366f7b8db2026aee8a0afa86b323aed7aa270ad928d1c5"))
|
127
|
-
SHA3::Digest.compute(:sha224, ["c0"].pack("H*"), 3).unpack("H*").first.should(eq("2b695a6fd92a2b3f3ce9cfca617d22c9bb52815dd59a9719b01bad25"))
|
128
|
-
SHA3::Digest.compute(:sha224, ["80"].pack("H*"), 4).unpack("H*").first.should(eq("bfa0740d2f2edcdee2db3f66f04fb8179967d3fb5981644d9d084bd7"))
|
129
|
-
SHA3::Digest.compute(:sha224, ["48"].pack("H*"), 5).unpack("H*").first.should(eq("e4384016d64610d75e0a5d73821a02d524f847a25a571b5940cd6450"))
|
130
|
-
SHA3::Digest.compute(:sha224, ["50"].pack("H*"), 6).unpack("H*").first.should(eq("a0fb02f1d41bc09cc4b3e85b15be85e3b3c2d43eb36dd616c640d7ca"))
|
131
|
-
SHA3::Digest.compute(:sha224, ["98"].pack("H*"), 7).unpack("H*").first.should(eq("c00ecd3072762c82d08f8f76fecf38be23075f9c5663d06a9184bd0b"))
|
132
|
-
SHA3::Digest.compute(:sha224, ["cc"].pack("H*"), 8).unpack("H*").first.should(eq("a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802"))
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should match SHA3-256 test vectors (subset)" do
|
136
|
-
SHA3::Digest.compute(:sha256, ["00"].pack("H*"), 0).unpack("H*").first.should(eq("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"))
|
137
|
-
SHA3::Digest.compute(:sha256, ["00"].pack("H*"), 1).unpack("H*").first.should(eq("c3e5cb55999eeff4e07b7effec77582d0a5a11a94fc268a872493099273992e1"))
|
138
|
-
SHA3::Digest.compute(:sha256, ["c0"].pack("H*"), 2).unpack("H*").first.should(eq("3a1108d4a90a31b85a10bdce77f4bfbdcc5b1d70dd405686f8bbde834aa1a410"))
|
139
|
-
SHA3::Digest.compute(:sha256, ["c0"].pack("H*"), 3).unpack("H*").first.should(eq("7384d12118da4ad51a519806e2529fb2548b5dce2a87122b8507f71a28a35deb"))
|
140
|
-
SHA3::Digest.compute(:sha256, ["80"].pack("H*"), 4).unpack("H*").first.should(eq("53e5e48805ae70306bf9ddc26e9ee2db87afe95ef0bfb9f9c44211be11a4c810"))
|
141
|
-
SHA3::Digest.compute(:sha256, ["48"].pack("H*"), 5).unpack("H*").first.should(eq("c341f676da4d10d32d9dad5140d497fecfe9565c79f4f5aa7f1d3c36b290fe3b"))
|
142
|
-
SHA3::Digest.compute(:sha256, ["50"].pack("H*"), 6).unpack("H*").first.should(eq("80b7ed96c53f37ebd0a0f2f7c63b0b35480f57215ab8c5fdf9f5f6e989a53366"))
|
143
|
-
SHA3::Digest.compute(:sha256, ["98"].pack("H*"), 7).unpack("H*").first.should(eq("aca86ee608e0a6e31c0173f2eedee26c527f108f7f11a19a2e4327116485414c"))
|
144
|
-
SHA3::Digest.compute(:sha256, ["cc"].pack("H*"), 8).unpack("H*").first.should(eq("eead6dbfc7340a56caedc044696a168870549a6a7f6f56961e84a54bd9970b8a"))
|
145
|
-
end
|
128
|
+
sha << (['3b8e97c5ffc2d6a40fa7de7fcefc90f3b12c940e7ab415321e29ee692dfac799b009c99dcddb708fce5a178c5c35ee2b8617143edc4c40b4d313661f49abdd93cea79d117518805496fe6acf292c4c2a1f76b403a97d7c399daf85b46ad84e16246c67d6836757bde336c290d5d401e6c1386ab32797af6bb251e9b2d8fe754c47482b72e0b394eab76916126fd68ea7d65eb93d59f5b4c5ac40f7c3b37e7f3694f29424c24af8c8f0ef59cd9dbf1d28e0e10f799a6f78cad1d45b9db3d7dee4a7059abe99182714983b9c9d44d7f5643596d4f3'].pack("H*"))
|
146
129
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
SHA3::Digest.compute(:sha384, ["c0"].pack("H*"), 2).unpack("H*").first.should(eq("c7058511440be5d4f5688ef721000e91244ad6d10fee477dccb84e8b84db897f51db533e49964b18e5e362e5fd569e19"))
|
151
|
-
SHA3::Digest.compute(:sha384, ["c0"].pack("H*"), 3).unpack("H*").first.should(eq("3c297324d6f43be6a5b784c25b559910b6f79ef3c74db21575325cc9c917d935d8c3d6a9aa34f9fc65f1e9c39abc83ab"))
|
152
|
-
SHA3::Digest.compute(:sha384, ["80"].pack("H*"), 4).unpack("H*").first.should(eq("b43af6ccf78fc5cab63eb7cda68fd89e95c506eea63c131a82f9d9a1798002bb40d3b78473c3a66456034720ba8142e2"))
|
153
|
-
SHA3::Digest.compute(:sha384, ["48"].pack("H*"), 5).unpack("H*").first.should(eq("6877f31b109ebc6ddab14087739d7702f7e2aa2dd9d54b3b9c04749cb1adea194a52496dc78adcee84e705621f0564cc"))
|
154
|
-
SHA3::Digest.compute(:sha384, ["50"].pack("H*"), 6).unpack("H*").first.should(eq("b7136d3ef3112a47c1c59c5fab6a40c6ecd7cc89e400dc2efae388dec1028985e138a2b2f54683a8814ef3c1ba28ea9c"))
|
155
|
-
SHA3::Digest.compute(:sha384, ["98"].pack("H*"), 7).unpack("H*").first.should(eq("748de17dccb6b3fbaa1c938f5a3167244c83683105d45d429f0b40b31d9317860529ea54bfde1521423ceda9debd9d73"))
|
156
|
-
SHA3::Digest.compute(:sha384, ["cc"].pack("H*"), 8).unpack("H*").first.should(eq("1b84e62a46e5a201861754af5dc95c4a1a69caf4a796ae405680161e29572641f5fa1e8641d7958336ee7b11c58f73e9"))
|
130
|
+
expect(sha.hexdigest).to eq('9b809198dcce24175e33098331d3a402a821ae9326e72775aae34d1a9bb53d2b57863905cfd60543bbc42b454007c315')
|
131
|
+
expect(sha.digest_length).to eq(48)
|
132
|
+
expect(sha.block_length).to eq(104)
|
157
133
|
end
|
158
134
|
|
159
|
-
it
|
160
|
-
SHA3::Digest.
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
135
|
+
it 'should pass Digest.SHA512() usage test' do
|
136
|
+
sha = SHA3::Digest::SHA512.new()
|
137
|
+
|
138
|
+
expect(sha.hexdigest).to eq('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26')
|
139
|
+
expect(sha.update(['cc'].pack('H*'))).to eq('3939fcc8b57b63612542da31a834e5dcc36e2ee0f652ac72e02624fa2e5adeecc7dd6bb3580224b4d6138706fc6e80597b528051230b00621cc2b22999eaa205')
|
140
|
+
expect(sha.reset).to eq('a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26')
|
141
|
+
|
142
|
+
sha << (['03d625488354df30e3f875a68edfcf340e8366a8e1ab67f9d5c5486a96829dfac0578289082b2a62117e1cf418b43b90e0adc881fc6ae8105c888e9ecd21aea1c9ae1a4038dfd17378fed71d02ae492087d7cdcd98f746855227967cb1ab4714261ee3bead3f4db118329d3ebef4bc48a875c19ba763966da0ebea800e01b2f50b00e9dd4caca6dcb314d00184ef71ea2391d760c950710db4a70f9212ffc54861f9dc752ce18867b8ad0c48df8466ef7231e7ac567f0eb55099e622ebb86cb237520190a61c66ad34f1f4e289cb3282ae3eaac6152ed24d2c92bae5a7658252a53c49b7b02dfe54fdb2e90074b6cf310ac661'].pack("H*"))
|
143
|
+
|
144
|
+
expect(sha.hexdigest).to eq('1fcd1e38ab03c750366cf86dd72ec3bf22f5bbf7fea0149d31b6a67b68b537b59ba37917fd88ced9aa8d2941a65f552b7928b3785c66d640f3b74af039ed18ce')
|
145
|
+
expect(sha.digest_length).to eq(64)
|
146
|
+
expect(sha.block_length).to eq(72)
|
169
147
|
end
|
170
|
-
end
|
148
|
+
end
|
data/spec/spec_helper.rb
CHANGED