keccak-pure-ruby 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 73764214b42066133a8ea89fbf28d64156527b2d5ae9d71520757c2d434d39fc
4
+ data.tar.gz: 852efe6a69cd1cc3df61ac8fee3b7c01f91e25ccf6eb25665b88220aa6031191
5
+ SHA512:
6
+ metadata.gz: 0dda2f15b0ff43f043afbd41e6940997288fc7ec59801cb91e831398e9a6c3ae3724b3e09453a5d1375cc8b9755c03cde23946d95864bc7d33a102127c3910f7
7
+ data.tar.gz: 868c9bec64fb0a3c0dbb55c6541aaf619d9eaab922312479dde53c222dfa2389d201e4082690d5ab96d05d8ec5c2e95d8ed6e9899af2411c049f3f5876cfc161
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-19mode
7
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ keccak-pure-ruby (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.11.3)
10
+ rake (12.3.1)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ keccak-pure-ruby!
17
+ minitest
18
+ rake
19
+
20
+ BUNDLED WITH
21
+ 1.16.1
@@ -0,0 +1,44 @@
1
+ # Pure Ruby SHA3 Gem
2
+ [![Build Status](https://travis-ci.org/havenwood/sha3-pure-ruby.png?branch=master)](https://travis-ci.org/havenwood/sha3-pure-ruby)
3
+
4
+ A pure Ruby implementation of SHA3.
5
+
6
+ ## Installation
7
+
8
+ Install it from the command line:
9
+
10
+ ```bash
11
+ gem install keccak-pure-ruby
12
+ ```
13
+
14
+ Or execute `bundle` after adding this line to your app's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'sha3-pure-ruby'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ Digest::SHA3.new.hexdigest 'default 512-bit'
24
+ #=> "26dce8c3ea8e5ffbfbf684070ca59f9635487942bfc220b9fe94bf9b2f8a7dfa2e4e85059ead3c92f14e5d2e06076eb6643adf50481976bd52f737f89b185ae2"
25
+
26
+ Digest::SHA3.new(224).hexdigest 'example 224-bit'
27
+ #=> "d6e8cef46de550a1b50ca920c4600a6e1512af055034c45a33849133"
28
+ ```
29
+
30
+ ## Compatibility
31
+
32
+ - Ruby 2.0.0
33
+ - Ruby 1.9.3
34
+ - Ruby 1.9.2
35
+ - JRuby
36
+ - Rubinius
37
+
38
+ ## License
39
+
40
+ Creative Commons
41
+
42
+ To the extent possible under law, Christian Neukirchen has waived all copyright and related or neighboring rights to the source code of the original Ruby implementation. Performance enhancements added by Clemens Gruber. Refactored, tests added, and cut into a gem by Shannon Skipper. You can copy, modify, distribute and perform this work, even for commercial purposes, all without asking permission:
43
+
44
+ [https://creativecommons.org/publicdomain/zero/1.0/](https://creativecommons.org/publicdomain/zero/1.0/)
@@ -0,0 +1,5 @@
1
+ task default: [:test]
2
+
3
+ task :test do
4
+ ruby 'test/test_sha3-pure-ruby.rb'
5
+ end
@@ -0,0 +1,103 @@
1
+ require 'digest'
2
+ require_relative 'sha3-pure-ruby/version'
3
+
4
+ module Digest
5
+ class SHA3 < Digest::Class
6
+ PILN = [10, 7, 11, 17, 18, 3, 5, 16,
7
+ 8, 21, 24, 4, 15, 23, 19, 13,
8
+ 12, 2, 20, 14, 22, 9, 6, 1]
9
+
10
+ ROTC = [ 1, 3, 6, 10, 15, 21, 28, 36,
11
+ 45, 55, 2, 14, 27, 41, 56, 8,
12
+ 25, 43, 62, 18, 39, 61, 20, 44]
13
+
14
+ RNDC = [0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
15
+ 0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
16
+ 0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
17
+ 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
18
+ 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
19
+ 0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
20
+ 0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
21
+ 0x8000000000008080, 0x0000000080000001, 0x8000000080008008]
22
+
23
+ def initialize hash_size = 512
24
+ @size = hash_size / 8
25
+ @buffer = ''
26
+ end
27
+
28
+ def << s
29
+ @buffer << s
30
+ self
31
+ end
32
+ alias update <<
33
+
34
+ def reset
35
+ @buffer.clear
36
+ self
37
+ end
38
+
39
+ def finish
40
+ s = Array.new 25, 0
41
+ width = 200 - @size * 2
42
+
43
+ buffer = @buffer
44
+ buffer << "\x01" << "\0" * (width - buffer.size % width)
45
+ buffer[-1] = (buffer[-1].ord | 0x80).chr
46
+
47
+ 0.step buffer.size - 1, width do |j|
48
+ quads = buffer[j, width].unpack 'Q*'
49
+ (width / 8).times do |i|
50
+ s[i] ^= quads[i]
51
+ end
52
+
53
+ keccak s
54
+ end
55
+
56
+ s.pack('Q*')[0, @size]
57
+ end
58
+
59
+ private
60
+ def keccak s
61
+ 24.times.each_with_object [] do |round, a|
62
+ # Theta
63
+ 5.times do |i|
64
+ a[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20]
65
+ end
66
+
67
+ 5.times do |i|
68
+ t = a[(i + 4) % 5] ^ rotate(a[(i + 1) % 5], 1)
69
+ 0.step 24, 5 do |j|
70
+ s[j + i] ^= t
71
+ end
72
+ end
73
+
74
+ # Rho Pi
75
+ t = s[1]
76
+ 24.times do |i|
77
+ j = PILN[i]
78
+ a[0] = s[j]
79
+ s[j] = rotate t, ROTC[i]
80
+ t = a[0]
81
+ end
82
+
83
+ # Chi
84
+ 0.step 24, 5 do |j|
85
+ 5.times do |i|
86
+ a[i] = s[j + i]
87
+ end
88
+
89
+ 5.times do |i|
90
+ s[j + i] ^= ~a[(i + 1) % 5] & a[(i + 2) % 5]
91
+ end
92
+ end
93
+
94
+ # Iota
95
+ s[0] ^= RNDC[round]
96
+ end
97
+ end
98
+
99
+ def rotate x, y
100
+ (x << y | x >> 64 - y) & (1 << 64) - 1
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,3 @@
1
+ class SHA3
2
+ VERSION = '0.2.1'
3
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path '../lib', __FILE__
3
+ $:.unshift lib unless $:.include? lib
4
+ require 'sha3-pure-ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'keccak-pure-ruby'
8
+ spec.version = SHA3::VERSION
9
+ spec.authors = ['havenwood']
10
+ spec.email = ['shannonskipper@gmail.com']
11
+ spec.description = 'An implementation of SHA3 in pure Ruby.'
12
+ spec.summary = 'Pure Ruby SHA3.'
13
+ spec.homepage = 'https://github.com/havenwood/sha3-pure-ruby'
14
+ spec.license = 'https://creativecommons.org/publicdomain/zero/1.0/'
15
+ spec.files = `git ls-files`.split $/
16
+ # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename f }
17
+ spec.test_files = spec.files.grep %r{^(test)/}
18
+ spec.require_paths = ['lib']
19
+ spec.add_development_dependency 'rake'
20
+ spec.add_development_dependency 'minitest'
21
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path '../../lib/sha3-pure-ruby', __FILE__
2
+ require 'minitest/autorun'
3
+ require 'minitest/pride'
4
+
5
+ describe Digest::SHA3 do
6
+ describe 'default 512-bit' do
7
+ it 'should work when empty' do
8
+ empty_string_sha3 = '0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e'
9
+ assert_equal Digest::SHA3.new.hexdigest(''), empty_string_sha3
10
+ end
11
+
12
+ it 'should work with content' do
13
+ cat_sha3 = "b2faf80c85bd36029dc3f804cbf439888fd1ca195ab0e3decb872f8aa9ef767e4866186ebb8b5ecfa1237147a94775f8302648be0fd0ae3a6ebbdf931f423360"
14
+ assert_equal Digest::SHA3.new.hexdigest('cat'), cat_sha3
15
+ end
16
+ end
17
+
18
+ describe '384-bit' do
19
+ it 'should work when empty' do
20
+ empty_string_sha3 = '2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff'
21
+ assert_equal Digest::SHA3.new(384).hexdigest(''), empty_string_sha3
22
+ end
23
+
24
+ it 'should work with content' do
25
+ cat_sha3 = 'fbcae9b945da6967b622e93e5712dcd0b4df2f522a89b0a20b485684c02efcf9efafb699499b2328172cbf654b7721c5'
26
+ assert_equal Digest::SHA3.new(384).hexdigest('cat'), cat_sha3
27
+ end
28
+ end
29
+
30
+ describe '256-bit' do
31
+ it 'should work when empty' do
32
+ empty_string_sha3 = 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
33
+ assert_equal Digest::SHA3.new(256).hexdigest(''), empty_string_sha3
34
+ end
35
+
36
+ it 'should work with content' do
37
+ cat_sha3 = '52763589e772702fa7977a28b3cfb6ca534f0208a2b2d55f7558af664eac478a'
38
+ assert_equal Digest::SHA3.new(256).hexdigest('cat'), cat_sha3
39
+ end
40
+ end
41
+
42
+ describe '224-bit' do
43
+ it 'should work when empty' do
44
+ empty_string_sha3 = 'f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd'
45
+ assert_equal Digest::SHA3.new(224).hexdigest(''), empty_string_sha3
46
+ end
47
+
48
+ it 'should work with content' do
49
+ cat_sha3 = "c3e4d225cefd1d01166d801f856907492b3bf8909a8a3a5bc922580f"
50
+ assert_equal Digest::SHA3.new(224).hexdigest('cat'), cat_sha3
51
+ end
52
+ end
53
+ end
54
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keccak-pure-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - havenwood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-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: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: An implementation of SHA3 in pure Ruby.
42
+ email:
43
+ - shannonskipper@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - README.md
53
+ - Rakefile
54
+ - lib/sha3-pure-ruby.rb
55
+ - lib/sha3-pure-ruby/version.rb
56
+ - sha3-pure-ruby.gemspec
57
+ - test/test_sha3-pure-ruby.rb
58
+ homepage: https://github.com/havenwood/sha3-pure-ruby
59
+ licenses:
60
+ - https://creativecommons.org/publicdomain/zero/1.0/
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.7.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Pure Ruby SHA3.
82
+ test_files:
83
+ - test/test_sha3-pure-ruby.rb