Skip to content

Commit 39232ab

Browse files
authored
ext: rename sha3 to keccak for clarity (#16)
* ext: rename sha3 to keccak for clarity * lib: minor version bump * test: s/sha3/keccak/ on tests * gem: update keccak gemspec
1 parent e698a28 commit 39232ab

File tree

8 files changed

+47
-47
lines changed

8 files changed

+47
-47
lines changed

ext/digest/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ def have_func!(header, *args)
2828

2929
have_func! 'rb_str_set_len'
3030

31-
create_makefile 'digest/sha3' or exit 1
31+
create_makefile 'digest/keccak' or exit 1

ext/digest/sha3.c renamed to ext/digest/keccak.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@
99
#define MAX_DIGEST_SIZE 64
1010
#define DEFAULT_DIGEST_LEN 512
1111

12-
static int sha3_init_func();
13-
static void sha3_update_func(hashState *ctx, unsigned char *str, size_t len);
14-
static int sha3_finish_func(hashState *ctx, unsigned char *digest);
12+
static int keccak_init_func();
13+
static void keccak_update_func(hashState *ctx, unsigned char *str, size_t len);
14+
static int keccak_finish_func(hashState *ctx, unsigned char *digest);
1515

1616
/*
17-
Metadata definition for the SHA3 algorithm.
17+
Metadata definition for the Keccak algorithm.
1818
Defines the Version, sizes for block and digest as well as
1919
the entry points for the algorithms
2020
*/
21-
static rb_digest_metadata_t sha3 = {
21+
static rb_digest_metadata_t keccak = {
2222
RUBY_DIGEST_API_VERSION,
2323
DEFAULT_DIGEST_LEN,
2424
KeccakPermutationSize - (2 * DEFAULT_DIGEST_LEN), //size of blocks
2525
sizeof(hashState), //size of context for the object we'll be passed in below functions.
26-
(rb_digest_hash_init_func_t)sha3_init_func,
27-
(rb_digest_hash_update_func_t)sha3_update_func,
28-
(rb_digest_hash_finish_func_t)sha3_finish_func,
26+
(rb_digest_hash_init_func_t)keccak_init_func,
27+
(rb_digest_hash_update_func_t)keccak_update_func,
28+
(rb_digest_hash_finish_func_t)keccak_finish_func,
2929
};
3030

3131
/* Initialization function for the algorithm,
3232
gets called during allocation of the digest object.
3333
we override initialize to do custom hash size, so we don't care too much here.
3434
*/
3535
static int
36-
sha3_init_func() {
36+
keccak_init_func() {
3737
// Just return a 1 'successful' we override the init function
3838
// so this is not necessary
3939
// the base class alloc calls this to initialize the algorithm
@@ -42,29 +42,29 @@ sha3_init_func() {
4242

4343
/* Update function, take the current context and add str to it */
4444
static void
45-
sha3_update_func(hashState *ctx, unsigned char *str, size_t len) {
45+
keccak_update_func(hashState *ctx, unsigned char *str, size_t len) {
4646
Update(ctx, str, len * 8);
4747
}
4848

4949
/* Finish the hash calculation and return the finished string */
5050
static int
51-
sha3_finish_func(hashState *ctx, unsigned char *digest) {
51+
keccak_finish_func(hashState *ctx, unsigned char *digest) {
5252
Final(ctx, digest);
5353
return 1;
5454
}
5555

56-
/* Ruby method. Digest::SHA3#finish()
56+
/* Ruby method. Digest::Keccak#finish()
5757
* No Arguments
5858
* @returns [String] Encoded Digest String
5959
*/
6060
static VALUE
61-
rb_sha3_finish(VALUE self) {
61+
rb_keccak_finish(VALUE self) {
6262
hashState *ctx;
6363
VALUE digest;
6464

6565
ctx = (hashState *)RTYPEDDATA_DATA(self);
6666
digest = rb_str_new(0, ctx->capacity / 2 / 8);
67-
sha3_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest));
67+
keccak_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest));
6868

6969
return digest;
7070
}
@@ -73,7 +73,7 @@ rb_sha3_finish(VALUE self) {
7373
* initialize the ctx with the bitlength
7474
*/
7575
static void
76-
sha3_init(hashState *ctx, size_t bitlen) {
76+
keccak_init(hashState *ctx, size_t bitlen) {
7777
switch (Init(ctx, bitlen)) {
7878
case SUCCESS:
7979
return;
@@ -86,12 +86,12 @@ sha3_init(hashState *ctx, size_t bitlen) {
8686
}
8787
}
8888

89-
/* Ruby method. Digest::SHA3.new(hashlen)
89+
/* Ruby method. Digest::Keccak.new(hashlen)
9090
* @param hashlen The length of hash, only supports 224, 256, 384 or 512
91-
* @returns [Digest::SHA3] new object.
91+
* @returns [Digest::Keccak] new object.
9292
*/
9393
static VALUE
94-
rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
94+
rb_keccak_initialize(int argc, VALUE *argv, VALUE self) {
9595
hashState *ctx;
9696
VALUE hashlen;
9797
int i_hashlen;
@@ -106,48 +106,48 @@ rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
106106
}
107107

108108
ctx = (hashState *)RTYPEDDATA_DATA(self);
109-
sha3_init(ctx, i_hashlen);
109+
keccak_init(ctx, i_hashlen);
110110

111111
return rb_call_super(0, NULL);
112112
}
113113

114-
/* Ruby method. Digest::SHA3#digest_length
114+
/* Ruby method. Digest::Keccak#digest_length
115115
* @returns [Numeric] Length of the digest.
116116
*/
117117
static VALUE
118-
rb_sha3_digest_length(VALUE self) {
118+
rb_keccak_digest_length(VALUE self) {
119119
hashState *ctx;
120120

121121
ctx = (hashState *)RTYPEDDATA_DATA(self);
122122
return INT2FIX(ctx->capacity / 2 / 8);
123123
}
124124

125-
/* Ruby method. Digest::SHA3#block_length
125+
/* Ruby method. Digest::Keccak#block_length
126126
* @returns [Numeric] Length of blocks in this digest.
127127
*/
128128
static VALUE
129-
rb_sha3_block_length(VALUE self) {
129+
rb_keccak_block_length(VALUE self) {
130130
hashState *ctx;
131131

132132
ctx = (hashState *)RTYPEDDATA_DATA(self);
133133
return INT2FIX(ctx->rate / 8);
134134
}
135135

136136
void __attribute__((visibility("default")))
137-
Init_sha3() {
138-
VALUE mDigest, cDigest_Base, cSHA3;
137+
Init_keccak() {
138+
VALUE mDigest, cDigest_Base, cKeccak;
139139

140140
rb_require("digest");
141141

142142
mDigest = rb_path2class("Digest");
143143
cDigest_Base = rb_path2class("Digest::Base");
144144

145-
cSHA3 = rb_define_class_under(mDigest, "SHA3", cDigest_Base);
145+
cKeccak = rb_define_class_under(mDigest, "Keccak", cDigest_Base);
146146

147-
rb_iv_set(cSHA3, "metadata", Data_Wrap_Struct(0, 0, 0, (void *)&sha3));
147+
rb_iv_set(cKeccak, "metadata", Data_Wrap_Struct(0, 0, 0, (void *)&keccak));
148148

149-
rb_define_method(cSHA3, "initialize", rb_sha3_initialize, -1);
150-
rb_define_method(cSHA3, "digest_length", rb_sha3_digest_length, 0);
151-
rb_define_method(cSHA3, "block_length", rb_sha3_block_length, 0);
152-
rb_define_method(cSHA3, "finish", rb_sha3_finish, 0);
149+
rb_define_method(cKeccak, "initialize", rb_keccak_initialize, -1);
150+
rb_define_method(cKeccak, "digest_length", rb_keccak_digest_length, 0);
151+
rb_define_method(cKeccak, "block_length", rb_keccak_block_length, 0);
152+
rb_define_method(cKeccak, "finish", rb_keccak_finish, 0);
153153
}

keccak.gemspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
lib = File.expand_path('lib', __dir__).freeze
44
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
55

6-
require 'digest/sha3/version'
6+
require 'digest/keccak/version'
77

88
Gem::Specification.new do |spec|
99
spec.name = "keccak"
10-
spec.version = Digest::SHA3::VERSION
11-
spec.summary = "The Keccak (SHA-3) hash used by Ethereum."
12-
spec.description = "The Keccak (SHA-3) hash used by Ethereum. This does not implement the final FIPS202 standard, today known as SHA3 but rather an early version, commonly referred to as Keccak."
10+
spec.version = Digest::Keccak::VERSION
11+
spec.summary = "The Keccak (SHA3) hash used by Ethereum."
12+
spec.description = "The Keccak (SHA3) hash used by Ethereum. This does not implement the final FIPS202 standard, today known as SHA3 but rather an early version, commonly referred to as Keccak."
1313
spec.homepage = "https://github.com/q9f/keccak.rb"
1414
spec.authors = ["Afri Schoedon", "Alex Kotov", "Chris Metcalfe", "Hongli Lai (Phusion)", "Keccak authors"]
1515
spec.email = "%w[[email protected]]"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Digest
4-
class SHA3
5-
VERSION = '1.2.2'
4+
class Keccak
5+
VERSION = '1.3.0'
66
end
77
end

test/generate_tests.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def generate
1919
2020
require 'test/unit'
2121
22-
class SHA3Tests < Test::Unit::TestCase
22+
class KeccakTests < Test::Unit::TestCase
2323
}
2424

2525
FILES.each do |path, hashlen|
@@ -34,7 +34,7 @@ class SHA3Tests < Test::Unit::TestCase
3434
name = File.basename(path).split('.')[0]
3535
puts %Q{
3636
def test_#{name}_#{length}
37-
inst = Digest::SHA3.new(#{hashlen})
37+
inst = Digest::Keccak.new(#{hashlen})
3838
inst.update(#{msg_raw.inspect})
3939
assert_equal #{md.inspect}, inst.hexdigest
4040
end

test/test_all.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$LOAD_PATH.unshift(File.expand_path("lib"))
44
$LOAD_PATH.unshift(File.expand_path("ext"))
5-
require 'digest/sha3'
5+
require 'digest/keccak'
66
require File.expand_path('test/test_usage')
77
require File.expand_path('test/test_vectors')
88
require File.expand_path('test/test_new')

test/test_new.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
require 'test/unit'
44

5-
class SHA3NewTests < Test::Unit::TestCase
5+
class KeccakNewTests < Test::Unit::TestCase
66
def test_singleton_method_hexdigest_256_empty
7-
result = Digest::SHA3.hexdigest '', 256
7+
result = Digest::Keccak.hexdigest '', 256
88
assert_instance_of String, result
99
assert_equal 'c5d2460186f7233c927e7db2dcc703c0' \
1010
'e500b653ca82273b7bfad8045d85a470',
1111
result
1212
end
1313

1414
def test_singleton_method_hexdigest_256_sample
15-
result = Digest::SHA3.hexdigest 'sample', 256
15+
result = Digest::Keccak.hexdigest 'sample', 256
1616
assert_instance_of String, result
1717
assert_equal 'b80204f7e9243e4fca5489740ccd31dc' \
1818
'd0a54619a7f4165cee73c191ef7271a1',

test/test_usage.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
require 'test/unit'
44

5-
class SHA3UsageTest < Test::Unit::TestCase
5+
class KeccakUsageTest < Test::Unit::TestCase
66
def init(hashsize = 512)
7-
@digest = Digest::SHA3.new(hashsize)
7+
@digest = Digest::Keccak.new(hashsize)
88
end
99

1010
def test_copy
@@ -18,7 +18,7 @@ def test_copy
1818

1919
def test_class_methods
2020
assert_equal 'a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802',
21-
Digest::SHA3.hexdigest("\xcc", 224)
21+
Digest::Keccak.hexdigest("\xcc", 224)
2222
end
2323

2424
def test_update

0 commit comments

Comments
 (0)