From e7e8940b335b1367314788933533afd51c06c35a Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 8 Jun 2019 16:53:04 +0500 Subject: [PATCH] Rename gem --- README.md | 14 ++--- digest-sha3.gemspec => digest-keccak.gemspec | 8 +-- ext/digest/extconf.rb | 2 +- ext/digest/{sha3.c => keccak.c} | 62 ++++++++++---------- lib/digest/{sha3 => keccak}/version.rb | 2 +- test/generate_tests.rb | 4 +- test/test_all.rb | 2 +- test/test_usage.rb | 6 +- 8 files changed, 50 insertions(+), 50 deletions(-) rename digest-sha3.gemspec => digest-keccak.gemspec (89%) rename ext/digest/{sha3.c => keccak.c} (62%) rename lib/digest/{sha3 => keccak}/version.rb (83%) diff --git a/README.md b/README.md index 2137157..0f4c4ad 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,18 @@ and variable length. Variable length is not supported by this Ruby extension. Unless the user specifies otherwise, this Ruby extension assumes 512-bit. ```ruby - require 'digest/sha3' + require 'digest/keccak' # Generate 512-bit digest. - Digest::SHA3.digest("foo") # => "\025\227\204*..." - Digest::SHA3.hexdigest("foo") # => "1597842a..." + Digest::Keccak.digest("foo") # => "\025\227\204*..." + Digest::Keccak.hexdigest("foo") # => "1597842a..." # Generate 224-bit digest. - Digest::SHA3.digest("foo", 224) # => "\332\251M\247..." - Digest::SHA3.hexdigest("foo", 224) # => "daa94da7..." + Digest::Keccak.digest("foo", 224) # => "\332\251M\247..." + Digest::Keccak.hexdigest("foo", 224) # => "daa94da7..." # Use this interface to feed data in chunks. 512-bit by default. - digest = Digest::SHA3.new + digest = Digest::Keccak.new digest.update("f") digest.update("o") digest.update("o") @@ -37,7 +37,7 @@ Unless the user specifies otherwise, this Ruby extension assumes 512-bit. digest.hexdigest # => "1597842a..." # You can pass a hash length to the constructor. - digest = Digest::SHA3.new(224) + digest = Digest::Keccak.new(224) ``` diff --git a/digest-sha3.gemspec b/digest-keccak.gemspec similarity index 89% rename from digest-sha3.gemspec rename to digest-keccak.gemspec index 3691d15..7f036a3 100644 --- a/digest-sha3.gemspec +++ b/digest-keccak.gemspec @@ -3,11 +3,11 @@ lib = File.expand_path('lib', __dir__).freeze $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib -require 'digest/sha3/version' +require 'digest/keccak/version' Gem::Specification.new do |spec| - spec.name = 'digest-sha3' - spec.version = Digest::SHA3::Version::STRING + spec.name = 'digest-keccak' + spec.version = Digest::Keccak::Version::STRING spec.license = 'MIT' spec.homepage = 'https://github.com/kotovalexarian/digest-keccak.rb' spec.summary = 'The Keccak cryptographic hash function.' @@ -35,7 +35,7 @@ Gem::Specification.new do |spec| 'README.md', 'LICENSE', 'Makefile', - 'digest-sha3.gemspec', + 'digest-keccak.gemspec', 'ext/**/*.{c,h,rb}', 'lib/**/*', ] diff --git a/ext/digest/extconf.rb b/ext/digest/extconf.rb index bb3f7f2..4e7bba6 100644 --- a/ext/digest/extconf.rb +++ b/ext/digest/extconf.rb @@ -4,4 +4,4 @@ have_header('ruby/digest.h') have_func('rb_str_set_len') $CFLAGS << " -fvisibility=hidden" -create_makefile('digest/sha3') +create_makefile('digest/keccak') diff --git a/ext/digest/sha3.c b/ext/digest/keccak.c similarity index 62% rename from ext/digest/sha3.c rename to ext/digest/keccak.c index a3cbc9e..683a371 100644 --- a/ext/digest/sha3.c +++ b/ext/digest/keccak.c @@ -9,23 +9,23 @@ #define MAX_DIGEST_SIZE 64 #define DEFAULT_DIGEST_LEN 512 -static int sha3_init_func(hashState *ctx); -static void sha3_update_func(hashState *ctx, unsigned char *str, size_t len); -static int sha3_finish_func(hashState *ctx, unsigned char *digest); +static int keccak_init_func(hashState *ctx); +static void keccak_update_func(hashState *ctx, unsigned char *str, size_t len)keccak +static int keccak_finish_func(hashState *ctx, unsigned char *digest); /* - Metadata definition for the SHA3 algorithm. + Metadata definition for the Keccak algorithm. Defines the Version, sizes for block and digest as well as the entry points for the algorithms */ -static rb_digest_metadata_t sha3 = { +static rb_digest_metadata_t keccak = { RUBY_DIGEST_API_VERSION, DEFAULT_DIGEST_LEN, KeccakPermutationSize - (2 * DEFAULT_DIGEST_LEN), //size of blocks sizeof(hashState), //size of context for the object we'll be passed in below functions. - (rb_digest_hash_init_func_t)sha3_init_func, - (rb_digest_hash_update_func_t)sha3_update_func, - (rb_digest_hash_finish_func_t)sha3_finish_func, + (rb_digest_hash_init_func_t)keccak_init_func, + (rb_digest_hash_update_func_t)keccak_update_func, + (rb_digest_hash_finish_func_t)keccak_finish_func, }; /* Initialization function for the algorithm, @@ -33,7 +33,7 @@ static rb_digest_metadata_t sha3 = { we override initialize to do custom hash size, so we don't care too much here. */ static int -sha3_init_func(hashState *ctx) { +keccak_init_func(hashState *ctx) { // Just return a 1 ' successful' we override the init function // so this is not necessary // the base class alloc calls this to initialize the algorithm @@ -42,29 +42,29 @@ sha3_init_func(hashState *ctx) { /* Update function, take the current context and add str to it */ static void -sha3_update_func(hashState *ctx, unsigned char *str, size_t len) { +keccak_update_func(hashState *ctx, unsigned char *str, size_t len) { Update(ctx, str, len * 8); } /* Finish the hash calculation and return the finished string */ static int -sha3_finish_func(hashState *ctx, unsigned char *digest) { +keccak_finish_func(hashState *ctx, unsigned char *digest) { Final(ctx, digest); return 1; } -/* Ruby method. Digest::SHA3#finish() +/* Ruby method. Digest::Keccak#finish() * No Arguments * @returns [String] Encoded Digest String */ static VALUE -rb_sha3_finish(VALUE self) { +rb_keccak_finish(VALUE self) { hashState *ctx; VALUE digest; ctx = (hashState *)RTYPEDDATA_DATA(self); digest = rb_str_new(0, ctx->capacity / 2 / 8); - sha3_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest)); + keccak_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest)); return digest; } @@ -73,7 +73,7 @@ rb_sha3_finish(VALUE self) { * initialize the ctx with the bitlength */ static void -sha3_init(hashState *ctx, size_t bitlen) { +keccak_init(hashState *ctx, size_t bitlen) { switch (Init(ctx, bitlen)) { case SUCCESS: return; @@ -86,12 +86,12 @@ sha3_init(hashState *ctx, size_t bitlen) { } } -/* Ruby method. Digest::SHA3.new(hashlen) +/* Ruby method. Digest::Keccak.new(hashlen) * @param hashlen The length of hash, only supports 224, 256, 384 or 512 - * @returns [Digest::SHA3] new object. + * @returns [Digest::Keccak] new object. */ static VALUE -rb_sha3_initialize(int argc, VALUE *argv, VALUE self) { +rb_keccak_initialize(int argc, VALUE *argv, VALUE self) { hashState *ctx; VALUE hashlen; int i_hashlen; @@ -106,27 +106,27 @@ rb_sha3_initialize(int argc, VALUE *argv, VALUE self) { } ctx = (hashState *)RTYPEDDATA_DATA(self); - sha3_init(ctx, i_hashlen); + keccak_init(ctx, i_hashlen); return rb_call_super(0, NULL); } -/* Ruby method. Digest::SHA3#digest_length +/* Ruby method. Digest::Keccak#digest_length * @returns [Numeric] Length of the digest. */ static VALUE -rb_sha3_digest_length(VALUE self) { +rb_keccak_digest_length(VALUE self) { hashState *ctx; ctx = (hashState *)RTYPEDDATA_DATA(self); return INT2FIX(ctx->capacity / 2 / 8); } -/* Ruby method. Digest::SHA3#block_length +/* Ruby method. Digest::Keccak#block_length * @returns [Numeric] Length of blocks in this digest. */ static VALUE -rb_sha3_block_length(VALUE self) { +rb_keccak_block_length(VALUE self) { hashState *ctx; ctx = (hashState *)RTYPEDDATA_DATA(self); @@ -134,20 +134,20 @@ rb_sha3_block_length(VALUE self) { } void __attribute__((visibility("default"))) -Init_sha3() { - VALUE mDigest, cDigest_Base, cSHA3; +Init_keccak() { + VALUE mDigest, cDigest_Base, cKeccak; rb_require("digest"); mDigest = rb_path2class("Digest"); cDigest_Base = rb_path2class("Digest::Base"); - cSHA3 = rb_define_class_under(mDigest, "SHA3", cDigest_Base); + cKeccak = rb_define_class_under(mDigest, "Keccak", cDigest_Base); - rb_iv_set(cSHA3, "metadata", Data_Wrap_Struct(0, 0, 0, (void *)&sha3)); + rb_iv_set(cKeccak, "metadata", Data_Wrap_Struct(0, 0, 0, (void *)&keccak)); - rb_define_method(cSHA3, "initialize", rb_sha3_initialize, -1); - rb_define_method(cSHA3, "digest_length", rb_sha3_digest_length, 0); - rb_define_method(cSHA3, "block_length", rb_sha3_block_length, 0); - rb_define_method(cSHA3, "finish", rb_sha3_finish, 0); + rb_define_method(cKeccak, "initialize", rb_keccak_initialize, -1); + rb_define_method(cKeccak, "digest_length", rb_keccak_digest_length, 0); + rb_define_method(cKeccak, "block_length", rb_keccak_block_length, 0); + rb_define_method(cKeccak, "finish", rb_keccak_finish, 0); } diff --git a/lib/digest/sha3/version.rb b/lib/digest/keccak/version.rb similarity index 83% rename from lib/digest/sha3/version.rb rename to lib/digest/keccak/version.rb index b55dcab..c44ebac 100644 --- a/lib/digest/sha3/version.rb +++ b/lib/digest/keccak/version.rb @@ -1,5 +1,5 @@ module Digest - class SHA3 + class Keccak module Version STRING = "1.1.0" end diff --git a/test/generate_tests.rb b/test/generate_tests.rb index e76d9ad..35db2c6 100644 --- a/test/generate_tests.rb +++ b/test/generate_tests.rb @@ -18,7 +18,7 @@ def generate require 'test/unit' - class SHA3Tests < Test::Unit::TestCase + class KeccakTests < Test::Unit::TestCase } FILES.each do |path, hashlen| @@ -33,7 +33,7 @@ def generate name = File.basename(path).split('.')[0] puts %Q{ def test_#{name}_#{length} - inst = Digest::SHA3.new(#{hashlen}) + inst = Digest::Keccak.new(#{hashlen}) inst.update(#{msg_raw.inspect}) assert_equal #{md.inspect}, inst.hexdigest end diff --git a/test/test_all.rb b/test/test_all.rb index 0b5ef32..715c85d 100644 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -1,5 +1,5 @@ $LOAD_PATH.unshift(File.expand_path("lib")) $LOAD_PATH.unshift(File.expand_path("ext")) -require 'digest/sha3' +require 'digest/keccak' require File.expand_path('test/test_usage') require File.expand_path('test/test_vectors') diff --git a/test/test_usage.rb b/test/test_usage.rb index e195d79..fddf52d 100644 --- a/test/test_usage.rb +++ b/test/test_usage.rb @@ -1,8 +1,8 @@ require 'test/unit' -class SHA3UsageTest < Test::Unit::TestCase +class KeccakUsageTest < Test::Unit::TestCase def init(hashsize = 512) - @digest = Digest::SHA3.new(hashsize) + @digest = Digest::Keccak.new(hashsize) end def test_copy @@ -16,7 +16,7 @@ class SHA3UsageTest < Test::Unit::TestCase def test_class_methods assert_equal 'a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802', - Digest::SHA3.hexdigest("\xcc", 224) + Digest::Keccak.hexdigest("\xcc", 224) end def test_update