keccak 1.2.1 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +22 -18
- data/ext/digest/extconf.rb +2 -2
- data/ext/digest/{sha3.c → keccak.c} +31 -31
- data/keccak.gemspec +6 -6
- data/lib/digest/{sha3 → keccak}/version.rb +2 -2
- metadata +8 -8
- data/COPYRIGHT +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10fb878fcf308cc1a44942ef197956f830f0d91cc6c258acb8f5913ef6d270ce
|
4
|
+
data.tar.gz: 359c30bf2d466a0d95d714ea82b4281812788e999607bafe917daf7a7b710919
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95a226c317396f99e6fa1fdb15313dac072da683c5aa1345e7a609e7f283081adccf5e60bff0723e99a903a8564fb303c37a5ac9062eac26a14268394119cbd0
|
7
|
+
data.tar.gz: 5ea35b0f285d115dd8226920dacd21a0a51dcb02d6d08aff16985a9a567c85ee397183678bbc26097b36f3242b0d1745c5d081bebbaa4a76efbe9ee0dc4574a4
|
data/LICENSE
CHANGED
@@ -187,7 +187,7 @@
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
188
188
|
identification within third-party archives.
|
189
189
|
|
190
|
-
Copyright
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
191
|
|
192
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
193
193
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
# The Keccak (
|
1
|
+
# The Keccak (SHA3) digest for Ruby
|
2
2
|
|
3
3
|
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/q9f/keccak.rb/Build/main)](https://github.com/q9f/keccak.rb/actions)
|
4
4
|
[![GitHub top language](https://img.shields.io/github/languages/top/q9f/keccak.rb?color=black)](https://github.com/q9f/keccak.rb/pulse)
|
5
|
-
[![GitHub release](https://img.shields.io/github/v/release/q9f/keccak.rb
|
5
|
+
[![GitHub release](https://img.shields.io/github/v/release/q9f/keccak.rb)](https://github.com/q9f/keccak.rb/releases/latest)
|
6
6
|
[![Gem](https://img.shields.io/gem/v/keccak?color=red)](https://rubygems.org/gems/keccak)
|
7
|
+
[![Gem](https://img.shields.io/gem/dt/keccak)](https://rubygems.org/gems/keccak)
|
8
|
+
[![Visitors](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fq9f%2Fkeccak.rb&count_bg=%2379C83D&title_bg=%23555555&icon=rubygems.svg&icon_color=%23FF0000&title=visitors&edge_flat=false)](https://hits.seeyoufarm.com)
|
7
9
|
[![License](https://img.shields.io/github/license/q9f/keccak.rb.svg?color=black)](LICENSE)
|
8
10
|
|
9
|
-
This Ruby extension exposes the [Keccak](http://keccak.noekeon.org/) (
|
11
|
+
This Ruby extension exposes the [Keccak](http://keccak.noekeon.org/) (SHA3) digest `C` bindings in the non-final version used by [Ethereum](https://ethereum.org). It is based on the reference `C` implementation, version 3.2. The exposed interface is almost identical to that of the `digest` standard library. See [#16](https://github.com/q9f/keccak.rb/pull/16).
|
12
|
+
|
13
|
+
:warning: **Note: version `~> 1.3` exposes `digest/keccak` (`Digest::Keccak`) whereas version `~> 1.2` maintains the old `digest/sha3` (`Digest::SHA3`) for backward compatibility.** Only use `~> 1.2` if you want to lazy-patch your library. It works, but it's _not recommended._ Use `~> 1.3` and simply rename SHA3 to Keccak.
|
10
14
|
|
11
15
|
## Installation
|
12
16
|
|
@@ -18,28 +22,28 @@ gem install keccak
|
|
18
22
|
```
|
19
23
|
|
20
24
|
```ruby
|
21
|
-
gem 'keccak', '~> 1.
|
25
|
+
gem 'keccak', '~> 1.3'
|
22
26
|
```
|
23
27
|
|
24
|
-
**Note**: as of version
|
28
|
+
**Note**: as of version `~> v1.1`, `digest-sha3` (historic name, see below) requires Ruby 2.2. The new `keccak` version `~> v1.2` now also supports Ruby 3.0. The last version that worked on older Ruby (1.x) versions was `~> v1.0`. It can be found at the no longer maintained `digest-sha3` [repository from 2015](https://github.com/phusion/digest-sha3-ruby/releases/tag/release-1.0.2).
|
25
29
|
|
26
30
|
## Usage
|
27
31
|
|
28
|
-
This gem extends the `digest/*` module by a `digest/
|
32
|
+
This gem extends the `digest/*` module by a `digest/keccak` class.
|
29
33
|
|
30
34
|
```ruby
|
31
|
-
require 'digest/
|
35
|
+
require 'digest/keccak'
|
32
36
|
|
33
37
|
# Generate 512-bit digest.
|
34
|
-
Digest::
|
35
|
-
Digest::
|
38
|
+
Digest::Keccak.digest("foo") # => "\025\227\204*..."
|
39
|
+
Digest::Keccak.hexdigest("foo") # => "1597842a..."
|
36
40
|
|
37
41
|
# Generate 224-bit digest.
|
38
|
-
Digest::
|
39
|
-
Digest::
|
42
|
+
Digest::Keccak.digest("foo", 224) # => "\332\251M\247..."
|
43
|
+
Digest::Keccak.hexdigest("foo", 224) # => "daa94da7..."
|
40
44
|
|
41
45
|
# Use this interface to feed data in chunks. 512-bit by default.
|
42
|
-
digest = Digest::
|
46
|
+
digest = Digest::Keccak.new
|
43
47
|
digest.update("f")
|
44
48
|
digest.update("o")
|
45
49
|
digest.update("o")
|
@@ -47,7 +51,7 @@ digest.digest # => "\025\227\204*..."
|
|
47
51
|
digest.hexdigest # => "1597842a..."
|
48
52
|
|
49
53
|
# You can pass a hash length to the constructor.
|
50
|
-
digest = Digest::
|
54
|
+
digest = Digest::Keccak.new(224)
|
51
55
|
```
|
52
56
|
|
53
57
|
Keccak supports five hash lengths: 224-bit, 256-bit, 384-bit, 512-bit and variable length. Variable length is not supported by this Ruby extension. Unless the user specifies otherwise, this Ruby extension assumes 512-bit.
|
@@ -63,13 +67,13 @@ make test
|
|
63
67
|
|
64
68
|
A part of the test suite is automatically generated from Keccak's reference test suite.
|
65
69
|
|
66
|
-
## Warning: Keccak vs.
|
70
|
+
## Warning: Keccak vs. SHA3
|
67
71
|
|
68
|
-
**Note:** This gem still uses the `Digest::SHA3` namespace for reasons of
|
72
|
+
**Note:** This gem still uses the `Digest::SHA3` namespace in version `~> 1.2` for reasons of backward compatibility and long-term maintainability. See history section below.
|
69
73
|
|
70
|
-
:warning: This gem does **not** implement the final FIPS202 standard, today known as
|
74
|
+
:warning: This gem does **not** implement the final FIPS202 standard, today known as SHA3 but rather an early version, commonly referred to as Keccak. The reason why this is kept around, is that Ethereum uses this earler version of Keccak. See also: [Ethereum: Difference between keccak256 and sha3](https://ethereum.stackexchange.com/questions/30369/difference-between-keccak256-and-sha3).
|
71
75
|
|
72
|
-
If you are looking for the final
|
76
|
+
If you are looking for the final SHA3 gem, please use the following: https://rubygems.org/gems/sha3
|
73
77
|
|
74
78
|
## History
|
75
79
|
|
@@ -79,5 +83,5 @@ This gem was later patched multiple times:
|
|
79
83
|
|
80
84
|
* https://github.com/teamhedge/digest-sha3-ruby (KECCAK, as `digest-sha3-patched`)
|
81
85
|
* https://github.com/sydneyitguy/digest-sha3-ruby (KECCAK, as `digest-sha3-patched-ruby-3`)
|
82
|
-
* https://github.com/steakknife/digest-sha3-ruby (actual
|
86
|
+
* https://github.com/steakknife/digest-sha3-ruby (actual SHA3, do not use for Ethereum)
|
83
87
|
* https://github.com/kotovalexarian/digest-keccak/ (KECCAK, as `digest-keccak`)
|
data/ext/digest/extconf.rb
CHANGED
@@ -5,7 +5,7 @@ require 'mkmf'
|
|
5
5
|
|
6
6
|
def cflags(*args)
|
7
7
|
args.each do |str|
|
8
|
-
$CFLAGS += " #{str.shellescape} "
|
8
|
+
$CFLAGS += (ENV['OS'] == "Windows_NT") ? " #{str} " : " #{str.shellescape} "
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -28,4 +28,4 @@ have_header! 'string.h'
|
|
28
28
|
|
29
29
|
have_func! 'rb_str_set_len'
|
30
30
|
|
31
|
-
create_makefile 'digest/
|
31
|
+
create_makefile 'digest/keccak' or exit 1
|
@@ -9,23 +9,23 @@
|
|
9
9
|
#define MAX_DIGEST_SIZE 64
|
10
10
|
#define DEFAULT_DIGEST_LEN 512
|
11
11
|
|
12
|
-
static int
|
13
|
-
static void
|
14
|
-
static int
|
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);
|
15
15
|
|
16
16
|
/*
|
17
|
-
Metadata definition for the
|
17
|
+
Metadata definition for the Keccak algorithm.
|
18
18
|
Defines the Version, sizes for block and digest as well as
|
19
19
|
the entry points for the algorithms
|
20
20
|
*/
|
21
|
-
static rb_digest_metadata_t
|
21
|
+
static rb_digest_metadata_t keccak = {
|
22
22
|
RUBY_DIGEST_API_VERSION,
|
23
23
|
DEFAULT_DIGEST_LEN,
|
24
24
|
KeccakPermutationSize - (2 * DEFAULT_DIGEST_LEN), //size of blocks
|
25
25
|
sizeof(hashState), //size of context for the object we'll be passed in below functions.
|
26
|
-
(rb_digest_hash_init_func_t)
|
27
|
-
(rb_digest_hash_update_func_t)
|
28
|
-
(rb_digest_hash_finish_func_t)
|
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,
|
29
29
|
};
|
30
30
|
|
31
31
|
/* Initialization function for the algorithm,
|
@@ -33,7 +33,7 @@ static rb_digest_metadata_t sha3 = {
|
|
33
33
|
we override initialize to do custom hash size, so we don't care too much here.
|
34
34
|
*/
|
35
35
|
static int
|
36
|
-
|
36
|
+
keccak_init_func() {
|
37
37
|
// Just return a 1 'successful' we override the init function
|
38
38
|
// so this is not necessary
|
39
39
|
// the base class alloc calls this to initialize the algorithm
|
@@ -42,29 +42,29 @@ sha3_init_func() {
|
|
42
42
|
|
43
43
|
/* Update function, take the current context and add str to it */
|
44
44
|
static void
|
45
|
-
|
45
|
+
keccak_update_func(hashState *ctx, unsigned char *str, size_t len) {
|
46
46
|
Update(ctx, str, len * 8);
|
47
47
|
}
|
48
48
|
|
49
49
|
/* Finish the hash calculation and return the finished string */
|
50
50
|
static int
|
51
|
-
|
51
|
+
keccak_finish_func(hashState *ctx, unsigned char *digest) {
|
52
52
|
Final(ctx, digest);
|
53
53
|
return 1;
|
54
54
|
}
|
55
55
|
|
56
|
-
/* Ruby method. Digest::
|
56
|
+
/* Ruby method. Digest::Keccak#finish()
|
57
57
|
* No Arguments
|
58
58
|
* @returns [String] Encoded Digest String
|
59
59
|
*/
|
60
60
|
static VALUE
|
61
|
-
|
61
|
+
rb_keccak_finish(VALUE self) {
|
62
62
|
hashState *ctx;
|
63
63
|
VALUE digest;
|
64
64
|
|
65
65
|
ctx = (hashState *)RTYPEDDATA_DATA(self);
|
66
66
|
digest = rb_str_new(0, ctx->capacity / 2 / 8);
|
67
|
-
|
67
|
+
keccak_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest));
|
68
68
|
|
69
69
|
return digest;
|
70
70
|
}
|
@@ -73,7 +73,7 @@ rb_sha3_finish(VALUE self) {
|
|
73
73
|
* initialize the ctx with the bitlength
|
74
74
|
*/
|
75
75
|
static void
|
76
|
-
|
76
|
+
keccak_init(hashState *ctx, size_t bitlen) {
|
77
77
|
switch (Init(ctx, bitlen)) {
|
78
78
|
case SUCCESS:
|
79
79
|
return;
|
@@ -86,12 +86,12 @@ sha3_init(hashState *ctx, size_t bitlen) {
|
|
86
86
|
}
|
87
87
|
}
|
88
88
|
|
89
|
-
/* Ruby method. Digest::
|
89
|
+
/* Ruby method. Digest::Keccak.new(hashlen)
|
90
90
|
* @param hashlen The length of hash, only supports 224, 256, 384 or 512
|
91
|
-
* @returns [Digest::
|
91
|
+
* @returns [Digest::Keccak] new object.
|
92
92
|
*/
|
93
93
|
static VALUE
|
94
|
-
|
94
|
+
rb_keccak_initialize(int argc, VALUE *argv, VALUE self) {
|
95
95
|
hashState *ctx;
|
96
96
|
VALUE hashlen;
|
97
97
|
int i_hashlen;
|
@@ -106,27 +106,27 @@ rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
|
|
106
106
|
}
|
107
107
|
|
108
108
|
ctx = (hashState *)RTYPEDDATA_DATA(self);
|
109
|
-
|
109
|
+
keccak_init(ctx, i_hashlen);
|
110
110
|
|
111
111
|
return rb_call_super(0, NULL);
|
112
112
|
}
|
113
113
|
|
114
|
-
/* Ruby method. Digest::
|
114
|
+
/* Ruby method. Digest::Keccak#digest_length
|
115
115
|
* @returns [Numeric] Length of the digest.
|
116
116
|
*/
|
117
117
|
static VALUE
|
118
|
-
|
118
|
+
rb_keccak_digest_length(VALUE self) {
|
119
119
|
hashState *ctx;
|
120
120
|
|
121
121
|
ctx = (hashState *)RTYPEDDATA_DATA(self);
|
122
122
|
return INT2FIX(ctx->capacity / 2 / 8);
|
123
123
|
}
|
124
124
|
|
125
|
-
/* Ruby method. Digest::
|
125
|
+
/* Ruby method. Digest::Keccak#block_length
|
126
126
|
* @returns [Numeric] Length of blocks in this digest.
|
127
127
|
*/
|
128
128
|
static VALUE
|
129
|
-
|
129
|
+
rb_keccak_block_length(VALUE self) {
|
130
130
|
hashState *ctx;
|
131
131
|
|
132
132
|
ctx = (hashState *)RTYPEDDATA_DATA(self);
|
@@ -134,20 +134,20 @@ rb_sha3_block_length(VALUE self) {
|
|
134
134
|
}
|
135
135
|
|
136
136
|
void __attribute__((visibility("default")))
|
137
|
-
|
138
|
-
VALUE mDigest, cDigest_Base,
|
137
|
+
Init_keccak() {
|
138
|
+
VALUE mDigest, cDigest_Base, cKeccak;
|
139
139
|
|
140
140
|
rb_require("digest");
|
141
141
|
|
142
142
|
mDigest = rb_path2class("Digest");
|
143
143
|
cDigest_Base = rb_path2class("Digest::Base");
|
144
144
|
|
145
|
-
|
145
|
+
cKeccak = rb_define_class_under(mDigest, "Keccak", cDigest_Base);
|
146
146
|
|
147
|
-
rb_iv_set(
|
147
|
+
rb_iv_set(cKeccak, "metadata", Data_Wrap_Struct(0, 0, 0, (void *)&keccak));
|
148
148
|
|
149
|
-
rb_define_method(
|
150
|
-
rb_define_method(
|
151
|
-
rb_define_method(
|
152
|
-
rb_define_method(
|
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);
|
153
153
|
}
|
data/keccak.gemspec
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
lib = File.expand_path('lib', __dir__).freeze
|
4
4
|
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
|
5
5
|
|
6
|
-
require 'digest/
|
6
|
+
require 'digest/keccak/version'
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
spec.name = "keccak"
|
10
|
-
spec.version = Digest::
|
11
|
-
spec.summary = "The Keccak (
|
12
|
-
spec.description = "The 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."
|
13
13
|
spec.homepage = "https://github.com/q9f/keccak.rb"
|
14
14
|
spec.authors = ["Afri Schoedon", "Alex Kotov", "Chris Metcalfe", "Hongli Lai (Phusion)", "Keccak authors"]
|
15
15
|
spec.email = "%w[ruby@q9f.cc]"
|
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.metadata = {
|
21
21
|
'homepage_uri' => 'https://github.com/q9f/keccak.rb',
|
22
22
|
'source_code_uri' => 'https://github.com/q9f/keccak.rb',
|
23
|
-
'
|
24
|
-
|
23
|
+
'github_repo' => 'https://github.com/q9f/keccak.rb',
|
24
|
+
'bug_tracker_uri' => 'https://github.com/q9f/keccak.rb/issues',
|
25
25
|
}.freeze
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
spec.files = Dir[
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keccak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Afri Schoedon
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
- - "~>"
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '3.4'
|
45
|
-
description: The Keccak (
|
45
|
+
description: The Keccak (SHA3) hash used by Ethereum. This does not implement the
|
46
46
|
final FIPS202 standard, today known as SHA3 but rather an early version, commonly
|
47
47
|
referred to as Keccak.
|
48
48
|
email: "%w[ruby@q9f.cc]"
|
@@ -51,7 +51,6 @@ extensions:
|
|
51
51
|
- ext/digest/extconf.rb
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
-
- COPYRIGHT
|
55
54
|
- LICENSE
|
56
55
|
- Makefile
|
57
56
|
- README.md
|
@@ -66,15 +65,16 @@ files:
|
|
66
65
|
- ext/digest/displayIntermediateValues.c
|
67
66
|
- ext/digest/displayIntermediateValues.h
|
68
67
|
- ext/digest/extconf.rb
|
69
|
-
- ext/digest/
|
68
|
+
- ext/digest/keccak.c
|
70
69
|
- keccak.gemspec
|
71
|
-
- lib/digest/
|
70
|
+
- lib/digest/keccak/version.rb
|
72
71
|
homepage: https://github.com/q9f/keccak.rb
|
73
72
|
licenses:
|
74
73
|
- Apache-2.0
|
75
74
|
metadata:
|
76
75
|
homepage_uri: https://github.com/q9f/keccak.rb
|
77
76
|
source_code_uri: https://github.com/q9f/keccak.rb
|
77
|
+
github_repo: https://github.com/q9f/keccak.rb
|
78
78
|
bug_tracker_uri: https://github.com/q9f/keccak.rb/issues
|
79
79
|
post_install_message:
|
80
80
|
rdoc_options: []
|
@@ -94,8 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
|
-
rubygems_version: 3.2.
|
97
|
+
rubygems_version: 3.2.32
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
|
-
summary: The Keccak (
|
100
|
+
summary: The Keccak (SHA3) hash used by Ethereum.
|
101
101
|
test_files: []
|
data/COPYRIGHT
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
This package contains code written by the Keccak authors,
|
2
|
-
which is licensed CC0 (Public Domain).
|
3
|
-
|
4
|
-
Copyright (c) 2012-2015 Phusion B.V.; licensed under MIT License
|
5
|
-
https://github.com/phusion/digest-sha3-ruby
|
6
|
-
|
7
|
-
Copyright (c) 2016-2018 Chris Metcalfe; licensed under MIT License
|
8
|
-
https://github.com/teamhedge/digest-sha3-ruby
|
9
|
-
|
10
|
-
Copyright (c) 2018-2021 Seb's; licensed under MIT License
|
11
|
-
https://github.com/sydneyitguy/digest-sha3-ruby
|
12
|
-
|
13
|
-
Copyright (c) 2019-2021 Alex Kotov; licensed under MIT License
|
14
|
-
https://github.com/kotovalexarian/digest-keccak
|
15
|
-
|
16
|
-
Copyright (c) 2021-2022 Afri Schoedon; re-licensed under Apache 2.0
|
17
|
-
https://github.com/q9f/digest-sha3-ruby
|