keccak 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cda9d0be3f1eab051a8a92e9ab5500817f01728cc49b402240e2f01a6546c04f
4
- data.tar.gz: c2482abc3dcb9a76794f9179d7b6532a6199c8cf6d69b9564331040db793db64
3
+ metadata.gz: e1a969197011606b1180df351384087175ffb87884129eb145a0c7997d164a7f
4
+ data.tar.gz: ac8b5a50776439646d75ca24d6f3ee1c48a7a733d8036a1fbd3e3db084746aa9
5
5
  SHA512:
6
- metadata.gz: 3636878a8d2c10f72188485afa5658a9ca7c63cd97aa913e1dd919b15bd670e9095865b82e1e39ee8bd2cacc7a08cccb79d2c738f4a95381677de2eb18d3bc1a
7
- data.tar.gz: ba5450094c95bd85db62a0db1f075a3b5a291f2199b89ee8f87cb69295988d7aa7a5c1ff590a5a9cbfc67d7ecbc20b4ecdfabc9c1d92951afdbec0f2f1b63921
6
+ metadata.gz: d05075ec008a526829a5f6350e862e49a199b462c4be8ac6ac590fdcee2291922c64128983cacee9f786fba18a7a9522bf64840a7b4e75f143d5dca7f3fe3d3d
7
+ data.tar.gz: 2d25d3218b16d50d36d75fde343f7d2c50238398e24b6f3841900c0f53ad74a6e3d4646429d839e0800e799946ac0f42c0b98f29f118e7f83bb1bade2f66728f
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 2019 @q9f
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,4 +1,4 @@
1
- # The Keccak (SHA-3) digest for Ruby
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)
@@ -6,7 +6,9 @@
6
6
  [![Gem](https://img.shields.io/gem/v/keccak?color=red)](https://rubygems.org/gems/keccak)
7
7
  [![License](https://img.shields.io/github/license/q9f/keccak.rb.svg?color=black)](LICENSE)
8
8
 
9
- This Ruby extension exposes the [Keccak](http://keccak.noekeon.org/) (SHA-3) 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.
9
+ 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).
10
+
11
+ :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
12
 
11
13
  ## Installation
12
14
 
@@ -18,28 +20,28 @@ gem install keccak
18
20
  ```
19
21
 
20
22
  ```ruby
21
- gem 'keccak', '~> 1.2'
23
+ gem 'keccak', '~> 1.3'
22
24
  ```
23
25
 
24
- **Note**: as of version `v1.1.0`, `digest-sha3` (historic name, see below) requires Ruby 2.2. The new `keccak` version `v1.2.0` now also supports Ruby 3.0. The last version that worked on older Ruby (1.x) versions was `v1.0.2`. 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).
26
+ **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
27
 
26
28
  ## Usage
27
29
 
28
- This gem extends the `digest/*` module by a `digest/sha3` class (historic reference, see history section below).
30
+ This gem extends the `digest/*` module by a `digest/keccak` class.
29
31
 
30
32
  ```ruby
31
- require 'digest/sha3'
33
+ require 'digest/keccak'
32
34
 
33
35
  # Generate 512-bit digest.
34
- Digest::SHA3.digest("foo") # => "\025\227\204*..."
35
- Digest::SHA3.hexdigest("foo") # => "1597842a..."
36
+ Digest::Keccak.digest("foo") # => "\025\227\204*..."
37
+ Digest::Keccak.hexdigest("foo") # => "1597842a..."
36
38
 
37
39
  # Generate 224-bit digest.
38
- Digest::SHA3.digest("foo", 224) # => "\332\251M\247..."
39
- Digest::SHA3.hexdigest("foo", 224) # => "daa94da7..."
40
+ Digest::Keccak.digest("foo", 224) # => "\332\251M\247..."
41
+ Digest::Keccak.hexdigest("foo", 224) # => "daa94da7..."
40
42
 
41
43
  # Use this interface to feed data in chunks. 512-bit by default.
42
- digest = Digest::SHA3.new
44
+ digest = Digest::Keccak.new
43
45
  digest.update("f")
44
46
  digest.update("o")
45
47
  digest.update("o")
@@ -47,7 +49,7 @@ digest.digest # => "\025\227\204*..."
47
49
  digest.hexdigest # => "1597842a..."
48
50
 
49
51
  # You can pass a hash length to the constructor.
50
- digest = Digest::SHA3.new(224)
52
+ digest = Digest::Keccak.new(224)
51
53
  ```
52
54
 
53
55
  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 +65,13 @@ make test
63
65
 
64
66
  A part of the test suite is automatically generated from Keccak's reference test suite.
65
67
 
66
- ## Warning: Keccak vs. SHA-3
68
+ ## Warning: Keccak vs. SHA3
67
69
 
68
- **Note:** This gem still uses the `Digest::SHA3` namespace for reasons of backwards compatibility and long-term maintainability. See history section below.
70
+ **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
71
 
70
- :warning: This gem does **not** implement the final FIPS202 standard, today known as SHA-3 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)
72
+ :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
73
 
72
- If you are looking for the final SHA-3 gem, please use the following: https://rubygems.org/gems/sha3
74
+ If you are looking for the final SHA3 gem, please use the following: https://rubygems.org/gems/sha3
73
75
 
74
76
  ## History
75
77
 
@@ -79,5 +81,5 @@ This gem was later patched multiple times:
79
81
 
80
82
  * https://github.com/teamhedge/digest-sha3-ruby (KECCAK, as `digest-sha3-patched`)
81
83
  * https://github.com/sydneyitguy/digest-sha3-ruby (KECCAK, as `digest-sha3-patched-ruby-3`)
82
- * https://github.com/steakknife/digest-sha3-ruby (actual SHA-3, do not use for Ethereum)
84
+ * https://github.com/steakknife/digest-sha3-ruby (actual SHA3, do not use for Ethereum)
83
85
  * https://github.com/kotovalexarian/digest-keccak/ (KECCAK, as `digest-keccak`)
@@ -28,4 +28,4 @@ have_header! 'string.h'
28
28
 
29
29
  have_func! 'rb_str_set_len'
30
30
 
31
- create_makefile 'digest/sha3' or exit 1
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 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);
15
15
 
16
16
  /*
17
- Metadata definition for the SHA3 algorithm.
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 sha3 = {
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)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,
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
- sha3_init_func() {
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
- sha3_update_func(hashState *ctx, unsigned char *str, size_t len) {
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
- sha3_finish_func(hashState *ctx, unsigned char *digest) {
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::SHA3#finish()
56
+ /* Ruby method. Digest::Keccak#finish()
57
57
  * No Arguments
58
58
  * @returns [String] Encoded Digest String
59
59
  */
60
60
  static VALUE
61
- rb_sha3_finish(VALUE self) {
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
- sha3_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest));
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
- sha3_init(hashState *ctx, size_t bitlen) {
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::SHA3.new(hashlen)
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::SHA3] new object.
91
+ * @returns [Digest::Keccak] new object.
92
92
  */
93
93
  static VALUE
94
- rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
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
- sha3_init(ctx, i_hashlen);
109
+ keccak_init(ctx, i_hashlen);
110
110
 
111
111
  return rb_call_super(0, NULL);
112
112
  }
113
113
 
114
- /* Ruby method. Digest::SHA3#digest_length
114
+ /* Ruby method. Digest::Keccak#digest_length
115
115
  * @returns [Numeric] Length of the digest.
116
116
  */
117
117
  static VALUE
118
- rb_sha3_digest_length(VALUE self) {
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::SHA3#block_length
125
+ /* Ruby method. Digest::Keccak#block_length
126
126
  * @returns [Numeric] Length of blocks in this digest.
127
127
  */
128
128
  static VALUE
129
- rb_sha3_block_length(VALUE self) {
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
- Init_sha3() {
138
- VALUE mDigest, cDigest_Base, cSHA3;
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
- cSHA3 = rb_define_class_under(mDigest, "SHA3", cDigest_Base);
145
+ cKeccak = rb_define_class_under(mDigest, "Keccak", cDigest_Base);
146
146
 
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));
148
148
 
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);
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/sha3/version'
6
+ require 'digest/keccak/version'
7
7
 
8
8
  Gem::Specification.new do |spec|
9
9
  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."
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]"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Digest
4
- class SHA3
5
- VERSION = '1.2.2'
4
+ class Keccak
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
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.2.2
4
+ version: 1.3.0
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: 2021-10-07 00:00:00.000000000 Z
15
+ date: 2021-12-01 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 (SHA-3) hash used by Ethereum. This does not implement the
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,9 +65,9 @@ files:
66
65
  - ext/digest/displayIntermediateValues.c
67
66
  - ext/digest/displayIntermediateValues.h
68
67
  - ext/digest/extconf.rb
69
- - ext/digest/sha3.c
68
+ - ext/digest/keccak.c
70
69
  - keccak.gemspec
71
- - lib/digest/sha3/version.rb
70
+ - lib/digest/keccak/version.rb
72
71
  homepage: https://github.com/q9f/keccak.rb
73
72
  licenses:
74
73
  - Apache-2.0
@@ -95,8 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
96
  requirements: []
98
- rubygems_version: 3.2.28
97
+ rubygems_version: 3.2.31
99
98
  signing_key:
100
99
  specification_version: 4
101
- summary: The Keccak (SHA-3) hash used by Ethereum.
100
+ summary: The Keccak (SHA3) hash used by Ethereum.
102
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