-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alex Kotov <[email protected]>
- Loading branch information
1 parent
ef9da53
commit 42ecf94
Showing
12 changed files
with
149 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,43 @@ | ||
*.DS_Store | ||
|
||
/test/test_vectors.rb | ||
/ext/digest/Makefile | ||
/ext/digest/keccak.so | ||
/ext/digest/mkmf.log | ||
|
||
*.o | ||
*.bundle | ||
Makefile | ||
test/test_vectors.rb | ||
*.so | ||
*.gem | ||
*.log | ||
*.so | ||
*.rbc | ||
/.config | ||
/.rake_tasks~ | ||
/coverage/ | ||
/InstalledFiles | ||
/pkg/ | ||
/tmp/ | ||
|
||
# RSpec configuration and generated files: | ||
/.rspec | ||
/spec/examples.txt | ||
|
||
# Documentation cache and generated files: | ||
/.yardoc/ | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
# Environment normalization: | ||
/.bundle/ | ||
/vendor/bundle/* | ||
!/vendor/bundle/.keep | ||
/lib/bundler/man/ | ||
|
||
# For a library or gem, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
/Gemfile.lock | ||
/.ruby-version | ||
/.ruby-gemset | ||
|
||
# Unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in keccak.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'mkmf' | ||
|
||
have_header('ruby/digest.h') | ||
have_func('rb_str_set_len') | ||
def cflags(*args) | ||
args.each do |str| | ||
$CFLAGS += " #{str.shellescape} " | ||
end | ||
end | ||
|
||
def have_header!(*args) | ||
exit 1 unless have_header(*args) | ||
end | ||
|
||
def have_func!(header, *args) | ||
exit 1 unless have_func(*args, header) | ||
end | ||
|
||
cflags '-std=c11' | ||
cflags '-Wall' | ||
cflags '-Wextra' | ||
cflags '-fvisibility=hidden' | ||
|
||
have_header! 'ruby/digest.h' | ||
have_header! 'stdio.h' | ||
have_header! 'string.h' | ||
|
||
have_func! 'rb_str_set_len' | ||
|
||
$CFLAGS << " -fvisibility=hidden" | ||
create_makefile('digest/sha3') | ||
create_makefile 'digest/sha3' or exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
require File.expand_path('lib/digest/sha3/version') | ||
# frozen_string_literal: true | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "keccak" | ||
s.version = Digest::SHA3::Version::STRING | ||
s.summary = "The Keccak (SHA-3) hash used by Ethereum." | ||
s.email = "[email protected]" | ||
s.homepage = "https://github.com/q9f/keccak.rb" | ||
s.description = "The Keccak (SHA-3) hash use by Ethereum. This does not implement the final FIPS202 standard, today known as SHA3 but rather an early version, commonly referred to as Keccak." | ||
s.authors = ["Afri Schoedon", "Chris Metcalfe", "Hongli Lai (Phusion)", "Keccak authors"] | ||
s.extensions << "ext/digest/extconf.rb" | ||
s.required_ruby_version = ">= 2.2" | ||
s.license = "Apache-2.0" | ||
lib = File.expand_path('lib', __dir__).freeze | ||
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib | ||
|
||
s.files = Dir[ | ||
require 'digest/sha3' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "keccak" | ||
spec.version = Digest::SHA3::VERSION | ||
spec.summary = "The Keccak (SHA-3) hash used by Ethereum." | ||
spec.description = "The Keccak (SHA-3) hash use by Ethereum. This does not implement the final FIPS202 standard, today known as SHA3 but rather an early version, commonly referred to as Keccak." | ||
spec.homepage = "https://github.com/q9f/keccak.rb" | ||
spec.authors = ["Afri Schoedon", "Alex Kotov", "Chris Metcalfe", "Hongli Lai (Phusion)", "Keccak authors"] | ||
spec.email = "%w[[email protected]]" | ||
spec.extensions << "ext/digest/extconf.rb" | ||
spec.platform = Gem::Platform::RUBY | ||
spec.required_ruby_version = ">= 2.2", "< 4.0" | ||
spec.license = "Apache-2.0" | ||
spec.metadata = { | ||
'homepage_uri' => 'https://github.com/q9f/keccak.rb', | ||
'source_code_uri' => 'https://github.com/q9f/keccak.rb', | ||
'bug_tracker_uri' => | ||
'https://github.com/q9f/keccak.rb/issues', | ||
}.freeze | ||
spec.require_paths = ['lib'] | ||
spec.files = Dir[ | ||
"README.md", | ||
"COPYRIGHT", | ||
"LICENSE", | ||
|
@@ -21,4 +33,7 @@ Gem::Specification.new do |s| | |
"ext/**/*.{c,h,rb}", | ||
"lib/**/*" | ||
] | ||
spec.test_files = spec.files.grep %r{^(test|spec|features)/} | ||
spec.add_development_dependency 'bundler', '~> 2.2' | ||
spec.add_development_dependency 'test-unit', '~> 3.4' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Digest | ||
class SHA3 | ||
module Version | ||
STRING = "1.2.0" | ||
end | ||
VERSION = '1.2.1' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
$LOAD_PATH.unshift(File.expand_path("lib")) | ||
$LOAD_PATH.unshift(File.expand_path("ext")) | ||
require 'digest/sha3' | ||
require File.expand_path('test/test_usage') | ||
require File.expand_path('test/test_vectors') | ||
require File.expand_path('test/test_new') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test/unit' | ||
|
||
class SHA3NewTests < Test::Unit::TestCase | ||
def test_singleton_method_hexdigest_256_empty | ||
result = Digest::SHA3.hexdigest '', 256 | ||
assert_instance_of String, result | ||
assert_equal 'c5d2460186f7233c927e7db2dcc703c0' \ | ||
'e500b653ca82273b7bfad8045d85a470', | ||
result | ||
end | ||
|
||
def test_singleton_method_hexdigest_256_sample | ||
result = Digest::SHA3.hexdigest 'sample', 256 | ||
assert_instance_of String, result | ||
assert_equal 'b80204f7e9243e4fca5489740ccd31dc' \ | ||
'd0a54619a7f4165cee73c191ef7271a1', | ||
result | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test/unit' | ||
|
||
class SHA3UsageTest < Test::Unit::TestCase | ||
|