digest-kangarootwelve 0.0.1

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.
@@ -0,0 +1,2 @@
1
+ require 'mkmf'
2
+ create_makefile('digest/kangarootwelve')
@@ -0,0 +1,5 @@
1
+ module Digest
2
+ class KangarooTwelve
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/test/test.rb ADDED
@@ -0,0 +1,102 @@
1
+ require 'minitest/autorun'
2
+ require 'yaml'
3
+
4
+ TEST_DIR = File.dirname(__FILE__)
5
+ require File.join(TEST_DIR, %w{ .. lib digest kangarootwelve })
6
+
7
+ def get_repeated_0x00_to_0xfa(length)
8
+ hex = (0..0xfa).to_a.map{ |e| sprintf "%2x", e }.join
9
+ str = [hex].pack('H*')
10
+ cycles = (Float(length) / str.size).ceil
11
+ [str].cycle(cycles).to_a.join[0...length]
12
+ end
13
+
14
+ def get_repeated_0xff(length)
15
+ str = ["ffffffffffffffffffff"].pack('H*')
16
+ cycles = (Float(length) / str.size).ceil
17
+ [str].cycle(cycles).to_a.join[0...length]
18
+ end
19
+
20
+ describe Digest::KangarooTwelve do
21
+ it "produces implementation classes" do
22
+ Digest::KangarooTwelve[32].superclass.must_equal Digest::KangarooTwelve::Impl
23
+ Digest::KangarooTwelve[32].digest_length.must_equal 32
24
+ Digest::KangarooTwelve[32].must_equal Digest::KangarooTwelve_32
25
+ Digest::KangarooTwelve.implement(digest_length: 64).superclass.must_equal Digest::KangarooTwelve::Impl
26
+ Digest::KangarooTwelve.implement(digest_length: 64).digest_length.must_equal 64
27
+ Digest::KangarooTwelve.implement(digest_length: 64).must_equal Digest::KangarooTwelve_64
28
+ end
29
+
30
+ it "produces a default implemention with a digest length of 64" do
31
+ Digest::KangarooTwelve.implement.must_equal Digest::KangarooTwelve_64
32
+ Digest::KangarooTwelve_64.digest_length.must_equal 64
33
+ end
34
+
35
+ it "produces instances that are consistent with produced implementation classes" do
36
+ Digest::KangarooTwelve[32].new.class.must_equal Digest::KangarooTwelve_32
37
+ Digest::KangarooTwelve.implement(digest_length: 48).must_equal Digest::KangarooTwelve_48
38
+ end
39
+
40
+ it "produces classes with equal digest length as its instances" do
41
+ Digest::KangarooTwelve[32].new.digest_length.must_equal Digest::KangarooTwelve_32.digest_length
42
+ Digest::KangarooTwelve.implement(digest_length: 48).new.digest_length.must_equal Digest::KangarooTwelve_48.digest_length
43
+ end
44
+
45
+ it "produces a hash" do
46
+ Digest::KangarooTwelve.default.new.digest("")
47
+ end
48
+
49
+ it "works with customization strings" do
50
+ Digest::KangarooTwelve.implement(customization: "abc").new.digest("")
51
+ end
52
+
53
+ it "produces implementations with small and long option names" do
54
+ a = Digest::KangarooTwelve.implement(n: "KangarooTwelveTestA", d: 48, b: 512, c: "abc")
55
+ b = Digest::KangarooTwelve.implement(name: "KangarooTwelveTestB", digest_length: 48, block_length: 512, customization: "abc")
56
+ a.name.must_equal "Digest::KangarooTwelveTestA"
57
+ b.name.must_equal "Digest::KangarooTwelveTestB"
58
+ a.digest_length.must_equal 48
59
+ a.digest_length.must_equal b.digest_length
60
+ a.block_length.must_equal 512
61
+ a.block_length.must_equal b.block_length
62
+ a.customization.must_equal "abc"
63
+ a.customization.must_equal b.customization
64
+ end
65
+
66
+ it "produces valid hashes" do
67
+ # KangarooTwelve(M=empty, C=empty, 32 bytes):
68
+ Digest::KangarooTwelve[32].new.hexdigest("").must_equal "1ac2d450fc3b4205d19da7bfca1b37513c0803577ac7167f06fe2ce1f0ef39e5"
69
+ # KangarooTwelve(M=empty, C=empty, 64 bytes):
70
+ Digest::KangarooTwelve[64].new.hexdigest("").must_equal "1ac2d450fc3b4205d19da7bfca1b37513c0803577ac7167f06fe2ce1f0ef39e54269c056b8c82e48276038b6d292966cc07a3d4645272e31ff38508139eb0a71"
71
+ # KangarooTwelve(M=empty, C=empty, 10032 bytes), last 32 bytes:
72
+ Digest::KangarooTwelve[10032].new.hexdigest("")[-64..-1].must_equal "e8dc563642f7228c84684c898405d3a834799158c079b12880277a1d28e2ff6d"
73
+
74
+ # KangarooTwelve(M=pattern 0x00 to 0xFA for 17^i bytes, C=empty, 32 bytes):
75
+ [
76
+ [0, "2bda92450e8b147f8a7cb629e784a058efca7cf7d8218e02d345dfaa65244a1f"],
77
+ [1, "6bf75fa2239198db4772e36478f8e19b0f371205f6a9a93a273f51df37122888"],
78
+ [2, "0c315ebcdedbf61426de7dcf8fb725d1e74675d7f5327a5067f367b108ecb67c"],
79
+ [3, "cb552e2ec77d9910701d578b457ddf772c12e322e4ee7fe417f92c758f0d59d0"],
80
+ [4, "8701045e22205345ff4dda05555cbb5c3af1a771c2b89baef37db43d9998b9fe"],
81
+ [5, "844d610933b1b9963cbdeb5ae3b6b05cc7cbd67ceedf883eb678a0a8e0371682"],
82
+ [6, "3c390782a8a4e89fa6367f72feaaf13255c8d95878481d3cd8ce85f58e880af8"]
83
+ ].each do |i, hash|
84
+ m = get_repeated_0x00_to_0xfa(17 ** i)
85
+ Digest::KangarooTwelve[32].new.hexdigest(m).must_equal hash
86
+ end
87
+ end
88
+
89
+ it "produces valid hashes with customization strings" do
90
+ # KangarooTwelve(M=i times byte 0xFF, C=pattern 0x00 to 0xFA for 41^j bytes, 32 bytes):
91
+ [
92
+ [0, 0, "fab658db63e94a246188bf7af69a133045f46ee984c56e3c3328caaf1aa1a583"],
93
+ [1, 1, "d848c5068ced736f4462159b9867fd4c20b808acc3d5bc48e0b06ba0a3762ec4"],
94
+ [3, 2, "c389e5009ae57120854c2e8c64670ac01358cf4c1baf89447a724234dc7ced74"],
95
+ [7, 3, "75d2f86a2e644566726b4fbcfc5657b9dbcf070c7b0dca06450ab291d7443bcf"]
96
+ ].each do |i, j, hash|
97
+ m = get_repeated_0xff(i)
98
+ c = get_repeated_0x00_to_0xfa(41 ** j)
99
+ Digest::KangarooTwelve.implement(digest_length: 32, customization: c).new.hexdigest(m).must_equal hash
100
+ end
101
+ end
102
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digest-kangarootwelve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - konsolebox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ description: An implementation of KangarooTwelve for Ruby that works on top of Digest::Base.
56
+ email:
57
+ - konsolebox@gmail.com
58
+ executables: []
59
+ extensions:
60
+ - ext/digest/kangarootwelve/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - digest-kangarootwelve.gemspec
68
+ - ext/digest/kangarootwelve/KangarooTwelve.c
69
+ - ext/digest/kangarootwelve/KangarooTwelve.h
70
+ - ext/digest/kangarootwelve/KeccakP-1600-SnP.h
71
+ - ext/digest/kangarootwelve/KeccakP-1600-compact64.c
72
+ - ext/digest/kangarootwelve/KeccakP-1600-times2-SnP.h
73
+ - ext/digest/kangarootwelve/KeccakP-1600-times2-on1.c
74
+ - ext/digest/kangarootwelve/KeccakP-1600-times4-SnP.h
75
+ - ext/digest/kangarootwelve/KeccakP-1600-times4-on1.c
76
+ - ext/digest/kangarootwelve/KeccakP-1600-times8-SnP.h
77
+ - ext/digest/kangarootwelve/KeccakP-1600-times8-on1.c
78
+ - ext/digest/kangarootwelve/KeccakSponge-common.h
79
+ - ext/digest/kangarootwelve/KeccakSponge.inc
80
+ - ext/digest/kangarootwelve/KeccakSpongeWidth1600.c
81
+ - ext/digest/kangarootwelve/KeccakSpongeWidth1600.h
82
+ - ext/digest/kangarootwelve/Phases.h
83
+ - ext/digest/kangarootwelve/PlSnP-Fallback.inc
84
+ - ext/digest/kangarootwelve/SnP-Relaned.h
85
+ - ext/digest/kangarootwelve/align.h
86
+ - ext/digest/kangarootwelve/brg_endian.h
87
+ - ext/digest/kangarootwelve/ext.c
88
+ - ext/digest/kangarootwelve/extconf.rb
89
+ - lib/digest/kangarootwelve/version.rb
90
+ - test/test.rb
91
+ homepage: https://github.com/konsolebox/digest-kangaootwelve-ruby
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '2.2'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.8
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: KangarooTwelve for Ruby
115
+ test_files:
116
+ - test/test.rb