sha3 1.0.1 → 1.0.2
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.
- checksums.yaml +5 -5
- data/.gitignore +232 -22
- data/.travis.yml +16 -15
- data/Gemfile +1 -1
- data/Gemfile.ci +3 -9
- data/README.md +10 -35
- data/Rakefile +12 -14
- data/ext/sha3/digest.c +149 -131
- data/ext/sha3/digest.h +36 -28
- data/ext/sha3/extconf.rb +1 -1
- data/ext/sha3/sha3.c +46 -30
- data/ext/sha3/sha3.h +8 -7
- data/lib/sha3/version.rb +2 -3
- data/sha3.gemspec +12 -14
- data/spec/generate_tests.rb +21 -20
- data/tests.sh +7 -7
- metadata +18 -20
data/ext/sha3/extconf.rb
CHANGED
data/ext/sha3/sha3.c
CHANGED
@@ -7,40 +7,56 @@ VALUE eSHA3Error;
|
|
7
7
|
|
8
8
|
int get_hlen(VALUE obj)
|
9
9
|
{
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
int hlen;
|
11
|
+
|
12
|
+
if (TYPE(obj) == T_SYMBOL)
|
13
|
+
{
|
14
|
+
ID symid;
|
15
|
+
|
16
|
+
symid = SYM2ID(obj);
|
17
|
+
|
18
|
+
if (rb_intern("sha224") == symid)
|
19
|
+
{
|
20
|
+
hlen = 224;
|
21
|
+
}
|
22
|
+
else if (rb_intern("sha256") == symid)
|
23
|
+
{
|
24
|
+
hlen = 256;
|
25
|
+
}
|
26
|
+
else if (rb_intern("sha384") == symid)
|
27
|
+
{
|
28
|
+
hlen = 384;
|
29
|
+
}
|
30
|
+
else if (rb_intern("sha512") == symid)
|
31
|
+
{
|
32
|
+
hlen = 512;
|
33
|
+
}
|
34
|
+
else
|
35
|
+
{
|
36
|
+
rb_raise(eSHA3Error, "invalid hash bit symbol (should be: :sha224, :sha256, :sha384, or :sha512");
|
37
|
+
}
|
38
|
+
}
|
39
|
+
else if (TYPE(obj) == T_FIXNUM)
|
40
|
+
{
|
41
|
+
hlen = NUM2INT(obj);
|
42
|
+
|
43
|
+
if ((hlen != 224) && (hlen != 256) && (hlen != 384) && (hlen != 512))
|
44
|
+
{
|
45
|
+
rb_raise(rb_eArgError, "invalid hash bit length (should be: 224, 256, 384, or 512)");
|
46
|
+
}
|
47
|
+
}
|
25
48
|
else
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if ((hlen != 224) && (hlen != 256) && (hlen != 384) && (hlen != 512))
|
32
|
-
rb_raise(rb_eArgError, "invalid hash bit length (should be: 224, 256, 384, or 512)");
|
33
|
-
}
|
34
|
-
else
|
35
|
-
rb_raise(eSHA3Error, "unknown type value");
|
36
|
-
|
37
|
-
return hlen;
|
49
|
+
{
|
50
|
+
rb_raise(eSHA3Error, "unknown type value");
|
51
|
+
}
|
52
|
+
|
53
|
+
return hlen;
|
38
54
|
}
|
39
55
|
|
40
56
|
void Init_sha3_n()
|
41
57
|
{
|
42
|
-
|
43
|
-
|
58
|
+
mSHA3 = rb_define_module("SHA3");
|
59
|
+
eSHA3Error = rb_define_class_under(mSHA3, "SHA3Error", rb_eStandardError);
|
44
60
|
|
45
|
-
|
61
|
+
Init_sha3_n_digest();
|
46
62
|
}
|
data/ext/sha3/sha3.h
CHANGED
@@ -8,17 +8,18 @@
|
|
8
8
|
#include "KeccakHash.h"
|
9
9
|
#include "digest.h"
|
10
10
|
|
11
|
-
#ifdef
|
12
|
-
extern "C"
|
11
|
+
#ifdef __cplusplus
|
12
|
+
extern "C"
|
13
|
+
{
|
13
14
|
#endif
|
14
15
|
|
15
|
-
extern VALUE mSHA3;
|
16
|
-
extern VALUE eSHA3Error;
|
16
|
+
extern VALUE mSHA3;
|
17
|
+
extern VALUE eSHA3Error;
|
17
18
|
|
18
|
-
int get_hlen(VALUE);
|
19
|
-
void Init_sha3_n(void);
|
19
|
+
int get_hlen(VALUE);
|
20
|
+
void Init_sha3_n(void);
|
20
21
|
|
21
|
-
#ifdef
|
22
|
+
#ifdef __cplusplus
|
22
23
|
}
|
23
24
|
#endif
|
24
25
|
|
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
18
|
|
21
|
-
gem.add_development_dependency
|
19
|
+
gem.add_development_dependency 'rake-compiler', '~> 1.1'
|
22
20
|
gem.add_development_dependency 'rspec', '~> 3.3'
|
23
|
-
gem.add_development_dependency 'rubygems-tasks'
|
24
|
-
gem.add_development_dependency 'yard'
|
21
|
+
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
22
|
+
gem.add_development_dependency 'yard', '~> 0.9'
|
25
23
|
end
|
data/spec/generate_tests.rb
CHANGED
@@ -4,46 +4,47 @@ FILES = [
|
|
4
4
|
['data/ShortMsgKAT_SHA3-224.txt', 224],
|
5
5
|
['data/ShortMsgKAT_SHA3-256.txt', 256],
|
6
6
|
['data/ShortMsgKAT_SHA3-384.txt', 384],
|
7
|
-
['data/ShortMsgKAT_SHA3-512.txt', 512]
|
8
|
-
]
|
7
|
+
['data/ShortMsgKAT_SHA3-512.txt', 512]
|
8
|
+
].freeze
|
9
9
|
|
10
10
|
def gen_digest_byte_tests
|
11
11
|
FILES.each do |path, hashlen|
|
12
12
|
name = File.basename(path).split('.')[0]
|
13
13
|
|
14
|
-
f = File.new("sha3_digest_#{name}_spec.rb",
|
14
|
+
f = File.new("sha3_digest_#{name}_spec.rb", 'w')
|
15
15
|
f.puts(
|
16
|
-
%
|
16
|
+
%{require 'spec_helper'
|
17
17
|
require 'sha3'
|
18
18
|
|
19
19
|
describe "SHA3::Digest.new(#{hashlen})" do
|
20
20
|
it "should match byte-length test vectors (#{name})." do
|
21
|
-
}
|
21
|
+
}
|
22
|
+
)
|
22
23
|
contents = File.read(path).split('Len = ')
|
23
24
|
contents.each do |test|
|
24
25
|
lines = test.split("\n")
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
next unless !lines.empty? && lines[0] !~ /^#/
|
27
|
+
|
28
|
+
length = lines[0].to_i
|
29
|
+
next unless (length % 8).zero? && length != 0
|
30
|
+
|
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
|
+
)
|
35
37
|
end
|
36
38
|
f.puts(
|
37
|
-
%
|
39
|
+
%( end
|
38
40
|
end
|
39
|
-
|
41
|
+
)
|
42
|
+
)
|
40
43
|
f.close
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
|
-
def setup
|
45
|
-
|
46
|
-
end
|
47
|
+
def setup; end
|
47
48
|
|
48
49
|
gen_digest_byte_tests
|
49
50
|
gen_compute_bit_tests
|
data/tests.sh
CHANGED
@@ -5,22 +5,22 @@ rm -fv spec/sha3_digest*.rb
|
|
5
5
|
|
6
6
|
if [ -d "spec/data" ]
|
7
7
|
then
|
8
|
-
|
8
|
+
rm -rfv spec/data/*
|
9
9
|
else
|
10
|
-
|
10
|
+
mkdir "spec/data"
|
11
11
|
fi
|
12
12
|
|
13
13
|
pushd "spec/data"
|
14
14
|
|
15
15
|
if [ -f "*.txt" ]
|
16
16
|
then
|
17
|
-
|
17
|
+
rm -v *.txt
|
18
18
|
fi
|
19
19
|
|
20
|
-
wget "https://raw.githubusercontent.com/
|
21
|
-
wget "https://raw.githubusercontent.com/
|
22
|
-
wget "https://raw.githubusercontent.com/
|
23
|
-
wget "https://raw.githubusercontent.com/
|
20
|
+
wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-224.txt"
|
21
|
+
wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-256.txt"
|
22
|
+
wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-384.txt"
|
23
|
+
wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-512.txt"
|
24
24
|
|
25
25
|
cd ".."
|
26
26
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sha3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johanns Gregorian
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,30 +42,30 @@ dependencies:
|
|
42
42
|
name: rubygems-tasks
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.9'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '0.9'
|
69
69
|
description: SHA3 for Ruby is a native (C) FIPS 202 compliant implementation of SHA3
|
70
70
|
(Keccak) cryptographic hashing algorithm.
|
71
71
|
email: io+sha3@jsg.io
|
@@ -121,7 +121,7 @@ homepage: https://github.com/johanns/sha3#readme
|
|
121
121
|
licenses:
|
122
122
|
- MIT
|
123
123
|
metadata: {}
|
124
|
-
post_install_message:
|
124
|
+
post_install_message:
|
125
125
|
rdoc_options: []
|
126
126
|
require_paths:
|
127
127
|
- lib
|
@@ -136,13 +136,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
|
-
|
140
|
-
|
141
|
-
signing_key:
|
139
|
+
rubygems_version: 3.1.4
|
140
|
+
signing_key:
|
142
141
|
specification_version: 4
|
143
142
|
summary: SHA3 for Ruby
|
144
143
|
test_files:
|
145
144
|
- spec/generate_tests.rb
|
146
145
|
- spec/sha3_core_spec.rb
|
147
146
|
- spec/spec_helper.rb
|
148
|
-
has_rdoc:
|