sha3 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.clang-format +54 -0
  4. data/.document +4 -3
  5. data/.rdoc_options +10 -0
  6. data/.rspec +2 -2
  7. data/.rubocop.yml +5 -1
  8. data/CHANGELOG.md +23 -0
  9. data/Gemfile +11 -0
  10. data/LICENSE.txt +1 -1
  11. data/README.md +153 -63
  12. data/Rakefile +9 -3
  13. data/certs/io+sha3@jsg.io.pem +26 -0
  14. data/doc/sha3.rb +81 -0
  15. data/ext/sha3/config.h +26 -0
  16. data/ext/sha3/digest.c +636 -164
  17. data/ext/sha3/digest.h +71 -35
  18. data/ext/sha3/extconf.rb +47 -13
  19. data/ext/sha3/lib/common/align.h +33 -0
  20. data/ext/sha3/{brg_endian.h → lib/common/brg_endian.h} +8 -7
  21. data/ext/sha3/{KeccakHash.c → lib/high/Keccak/FIPS202/KeccakHash.c} +26 -25
  22. data/ext/sha3/{KeccakHash.h → lib/high/Keccak/FIPS202/KeccakHash.h} +34 -19
  23. data/ext/sha3/lib/high/Keccak/KeccakDuplex.c +81 -0
  24. data/ext/sha3/lib/high/Keccak/KeccakDuplex.h +73 -0
  25. data/ext/sha3/lib/high/Keccak/KeccakDuplex.inc +201 -0
  26. data/ext/sha3/lib/high/Keccak/KeccakSponge.c +95 -0
  27. data/ext/sha3/lib/high/Keccak/KeccakSponge.h +70 -0
  28. data/ext/sha3/lib/high/Keccak/KeccakSponge.inc +312 -0
  29. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.c +61 -0
  30. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.h +67 -0
  31. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.inc +128 -0
  32. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.c +93 -0
  33. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.h +599 -0
  34. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.inc +573 -0
  35. data/ext/sha3/lib/high/common/Phases.h +25 -0
  36. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +758 -0
  37. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-unrolling.macros +305 -0
  38. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +50 -0
  39. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference.h +23 -0
  40. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +617 -0
  41. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +50 -0
  42. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +413 -0
  43. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.h +23 -0
  44. data/ext/sha3/lib/low/common/PlSnP-Fallback.inc +291 -0
  45. data/ext/sha3/lib/low/common/SnP-Relaned.h +145 -0
  46. data/lib/sha3.rb +25 -28
  47. data.tar.gz.sig +0 -0
  48. metadata +73 -149
  49. metadata.gz.sig +0 -0
  50. data/.yardopts +0 -1
  51. data/ChangeLog.rdoc +0 -27
  52. data/certs/johanns.pem +0 -24
  53. data/ext/sha3/KeccakF-1600-interface.h +0 -40
  54. data/ext/sha3/KeccakSponge.c +0 -192
  55. data/ext/sha3/KeccakSponge.h +0 -113
  56. data/ext/sha3/Optimized64/KeccakF-1600-64.macros +0 -2199
  57. data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +0 -3
  58. data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +0 -508
  59. data/ext/sha3/Optimized64/KeccakF-1600-unrolling.macros +0 -126
  60. data/ext/sha3/Optimized64/SnP-interface.h +0 -47
  61. data/ext/sha3/Reference/KeccakF-1600-reference.c +0 -311
  62. data/ext/sha3/Reference/KeccakF-reference.h +0 -26
  63. data/ext/sha3/Reference/SnP-FBWL-default.c +0 -96
  64. data/ext/sha3/Reference/SnP-FBWL-default.h +0 -26
  65. data/ext/sha3/Reference/SnP-interface.h +0 -42
  66. data/ext/sha3/Reference/displayIntermediateValues.c +0 -158
  67. data/ext/sha3/Reference/displayIntermediateValues.h +0 -34
  68. data/ext/sha3/SnP-Relaned.h +0 -249
  69. data/ext/sha3/sha3.c +0 -62
  70. data/ext/sha3/sha3.h +0 -26
  71. data/lib/sha3/doc.rb +0 -121
  72. data/lib/sha3/version.rb +0 -9
  73. data/sha3.gemspec +0 -53
  74. data/tests.sh +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae66a849bd5438b3b6d3fa4f5d33505a75e6f64556bfacc21d0efcf03a7d41d8
4
- data.tar.gz: dea6beac49eeaeb12829af4e87b36dfc19ac1b66bb7872a7c6884441a70cf814
3
+ metadata.gz: c29bcfb557e028701b34ce0d2be3cdbec41882e45cedcb2f129e874bbb3867e5
4
+ data.tar.gz: 12c260b599a433def09b389d0cd39e72ebe2dae4e495979235aece99f2684e25
5
5
  SHA512:
6
- metadata.gz: d374e5f716056d6d888d862f97bc07d433c74f4d721d2342cc09f7865571e47eec50f7b1ecd9b284aedb1c908393b0da249e0c474f5792e215097263928d9195
7
- data.tar.gz: 6ea6442adf3c90ca8849576f8539835630d968a032b385447a9c95e2f4be97861910f510ba528dbe398990c2eb71fac6b3966816807571855b855afa8c6af15b
6
+ metadata.gz: 1be97184feef60e8340b6dd009f5c8eabcc6b2b72b050d2a3f08ef93d9c11184c7a9c1246f2cf241ef62d47fc13b96a62bab8b61002001b04942162dc9a7dd82
7
+ data.tar.gz: ca4d24baf5cda13fb0f071640875a16182aa234dca43b85d5d81e05ec80a9d3d1ea89b98b0f7f6a621d6395e6647472ef131c9dd2979f942556137108079ca80
checksums.yaml.gz.sig CHANGED
Binary file
data/.clang-format ADDED
@@ -0,0 +1,54 @@
1
+ BasedOnStyle: Google # Use Google's style as a foundation
2
+ AccessModifierOffset: -1
3
+ AlignAfterOpenBracket: Align
4
+ AlignConsecutiveAssignments: false
5
+ AlignConsecutiveDeclarations: false
6
+ AlignEscapedNewlines: Left
7
+ AlignOperands: true
8
+ AlignTrailingComments: true
9
+ AllowAllParametersOfDeclarationOnNextLine: true
10
+ AllowShortBlocksOnASingleLine: false
11
+ AllowShortCaseLabelsOnASingleLine: false
12
+ AllowShortFunctionsOnASingleLine: Empty
13
+ AllowShortIfStatementsOnASingleLine: false
14
+ AllowShortLoopsOnASingleLine: false
15
+ AlwaysBreakAfterDefinitionReturnType: None
16
+ AlwaysBreakAfterReturnType: None
17
+ AlwaysBreakBeforeMultilineStrings: true
18
+ AlwaysBreakTemplateDeclarations: Yes
19
+ BinPackArguments: true
20
+ BinPackParameters: true
21
+ BreakBeforeBraces: Attach
22
+ BreakBeforeTernaryOperators: true
23
+ ColumnLimit: 100
24
+ CompactNamespaces: false
25
+ ConstructorInitializerAllOnOneLineOrOnePerLine: true
26
+ Cpp11BracedListStyle: true
27
+ DerivePointerAlignment: false
28
+ FixNamespaceComments: true
29
+ IncludeBlocks: Regroup
30
+ IndentCaseLabels: true
31
+ IndentPPDirectives: None
32
+ IndentWidth: 4
33
+ KeepEmptyLinesAtTheStartOfBlocks: false
34
+ Language: Cpp
35
+ MaxEmptyLinesToKeep: 1
36
+ NamespaceIndentation: None
37
+ PointerAlignment: Left
38
+ ReflowComments: true
39
+ SortIncludes: true
40
+ SortUsingDeclarations: true
41
+ SpaceAfterCStyleCast: false
42
+ SpaceAfterTemplateKeyword: true
43
+ SpaceBeforeAssignmentOperators: true
44
+ SpaceBeforeParens: ControlStatements
45
+ SpaceInEmptyParentheses: false
46
+ SpacesBeforeTrailingComments: 2
47
+ SpacesInAngles: false
48
+ SpacesInContainerLiterals: false
49
+ SpacesInCStyleCastParentheses: false
50
+ SpacesInParentheses: false
51
+ SpacesInSquareBrackets: false
52
+ Standard: Auto
53
+ TabWidth: 2
54
+ UseTab: Never
data/.document CHANGED
@@ -1,4 +1,5 @@
1
- -
2
- README.rdoc
3
- ChangeLog.rdoc
1
+ README.md
4
2
  LICENSE.txt
3
+ lib/**/*.rb
4
+ ext/sha3/digest.{c,h}
5
+ doc/**/*.rb
data/.rdoc_options ADDED
@@ -0,0 +1,10 @@
1
+ ---
2
+ main_page: README.md
3
+ title: SHA3
4
+
5
+ charset: UTF-8
6
+ encoding: UTF-8
7
+ force_update: true
8
+ markup: rdoc
9
+ op_dir: html
10
+ visibility: :private
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --require spec_helper
2
2
  --color
3
- --require ./spec/spec_helper
3
+ --format documentation
data/.rubocop.yml CHANGED
@@ -1,6 +1,10 @@
1
+ plugins:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
6
  NewCops: enable
3
- TargetRubyVersion: 2.6
7
+ TargetRubyVersion: 2.7
4
8
 
5
9
  Layout/LineLength:
6
10
  Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # SHA3 Ruby Gem Changelog
2
+
3
+ ## v1.0.5 (2022-10-23)
4
+
5
+ ### Security
6
+ - Fixed buffer overflow vulnerability in Keccak implementation by updating to latest XKCP library
7
+ - Added test to verify fix for buffer overflow vulnerability
8
+
9
+ ### Improvements
10
+ - Updated XKCP library with improved directory structure
11
+ - Refactored byte-length test vector generator
12
+
13
+ ### Documentation
14
+ - Updated README with current supported Ruby versions
15
+ - Added credits section to README
16
+ - Fixed typo in README
17
+ - Updated gem description
18
+
19
+ ### Maintenance
20
+ - Updated development dependencies
21
+ - Removed bundler from development dependencies list
22
+ - Updated signing certificate
23
+ - Added macOS file types to .gitignore
data/Gemfile CHANGED
@@ -3,3 +3,14 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+
7
+ group :development, :test do
8
+ gem 'irb'
9
+
10
+ gem 'rake', '~> 13'
11
+ gem 'rake-compiler', '~> 1'
12
+ gem 'rspec', '~> 3'
13
+ gem 'rubocop', '~> 1'
14
+ gem 'rubocop-rake', '~> 0.7'
15
+ gem 'rubocop-rspec', '~> 3'
16
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Johanns Gregorian
1
+ Copyright (c) 2025 Johanns Gregorian
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,120 +1,210 @@
1
- # sha3
1
+ # SHA3 for Ruby
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/sha3.svg)](https://badge.fury.io/rb/sha3) [![Ruby](https://github.com/johanns/sha3/actions/workflows/main.yml/badge.svg)](https://github.com/johanns/sha3/actions/workflows/main.yml)
4
4
 
5
- **SHA3 for Ruby** is a native (C) binding to SHA3 (Keccak FIPS 202) cryptographic hashing algorithm.
5
+ A high-performance native binding to the SHA3 (FIPS 202) cryptographic hashing algorithm, based on the [XKCP - eXtended Keccak Code Package](https://github.com/XKCP/XKCP).
6
+
7
+ > [!CAUTION]
8
+ > **Security Notice**: Do not use SHA-3 for hashing passwords. Instead, use a slow hashing function such as PBKDF2, Argon2, bcrypt, or scrypt.
9
+
10
+ > [!IMPORTANT]
11
+ > **Breaking Changes**: SHA3 version 2.0 introduces breaking changes to the API. Please review the changelog and ensure compatibility with your application.
12
+ > If you need the previous behavior, lock your Gemfile to version '~> 1.0'.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Documentation](#documentation)
17
+ - [Features](#features)
18
+ - [Installation](#installation)
19
+ - [Usage](#usage)
20
+ - [SHA-3 Fixed Hash Functions](#sha-3-fixed-hash-functions)
21
+ - [SHAKE128/256 Functions](#shake128256-functions)
22
+ - [Alternate Class Syntax](#alternate-class-syntax)
23
+ - [Hashing a File](#hashing-a-file)
24
+ - [Development](#development)
25
+ - [Dependencies](#dependencies)
26
+ - [Testing](#testing)
27
+ - [Supported Ruby Versions](#supported-ruby-versions)
28
+ - [Contributing](#contributing)
29
+ - [Roadmap](#roadmap)
30
+ - [License](#license)
31
+ - [Credits](#credits)
32
+
33
+ ## Documentation
34
+
35
+ - [API Documentation](https://docs.jsg.io/sha3/html/index.html)
36
+ - [GitHub Repository](https://github.com/johanns/sha3#readme)
37
+ - [Issue Tracker](https://github.com/johanns/sha3/issues)
38
+
39
+ ## Features
40
+
41
+ - Full support for all SHA-3 variants (224, 256, 384, and 512 bit)
42
+ - Support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
43
+ - Native C implementation for high performance
44
+ - Simple, Ruby-friendly API that follows Ruby's standard Digest interface
45
+ - Comprehensive test suite with official NIST test vectors
46
+ - Thread-safe implementation
6
47
 
7
- - [Home](https://github.com/johanns/sha3#readme)
8
- - [Issues](https://github.com/johanns/sha3/issues)
9
- - [Documentation](http://rubydoc.info/gems/sha3/frames)
10
-
11
- ## Warnings
48
+ ## Installation
12
49
 
13
- - Please do NOT use SHA3 to hash passwords -- use a slow hashing function instead (e.g.: `pbkdf2`, `argon2`, `bcrypt` or `scrypt`)
14
- - Version 1.0 introduces new API and is incompatible with previous versions (0.x).
50
+ Add this line to your application's Gemfile:
15
51
 
16
- ## Module details
52
+ ```ruby
53
+ gem 'sha3', '~> 2.0'
54
+ ```
17
55
 
18
- **SHA3::Digest**: A standard *Digest* _subclass_. The interface, and operation of this class are parallel to digest classes bundled with MRI-based Rubies (e.g.: **Digest::SHA2**, and **OpenSSL::Digest**).
56
+ And then execute:
19
57
 
20
- See [documentation for Ruby's **Digest** class for additional details](http://www.ruby-doc.org/stdlib-2.2.3/libdoc/digest/rdoc/Digest.html).
58
+ ```sh
59
+ bundle install
60
+ ```
21
61
 
22
- ## Installation
62
+ Or install it yourself as:
23
63
 
24
- ```shell
64
+ ```sh
25
65
  gem install sha3
26
66
  ```
27
67
 
28
68
  ## Usage
29
69
 
70
+ ### SHA-3 Fixed Hash Functions
71
+
30
72
  ```ruby
31
73
  require 'sha3'
32
- ```
33
74
 
34
- Valid hash bit-lengths are: *224*, *256*, *384*, *512*.
75
+ # Create a new digest instance
76
+ digest = SHA3::Digest.new(:sha3_224, 'Start here')
35
77
 
36
- ```ruby
37
- :sha224 :sha256 :sha384 :sha512
78
+ # Add more data to be hashed
79
+ digest << "Compute Me"
80
+ digest.update("Me too")
38
81
 
39
- # SHA3::Digest.new(224) is SHA3::Digest.new(:sha224)
82
+ # Get the final hash value as a hex string
83
+ digest.hexdigest
84
+ # => "d6d38021d60857..."
85
+
86
+ # Or as a binary string
87
+ digest.digest
40
88
  ```
41
89
 
42
- Alternatively, you can instantiate using one of four sub-classes:
90
+ Valid algorithm symbols are:
43
91
 
44
- ```ruby
45
- SHA3::Digest::SHA224.new() # 224 bits
46
- SHA3::Digest::SHA256.new() # 256 bits
47
- SHA3::Digest::SHA384.new() # 384 bits
48
- SHA3::Digest::SHA512.new() # 512 bits
49
- ```
92
+ - `:sha3_224` - SHA-3 224 bits
93
+ - `:sha3_256` - SHA-3 256 bits
94
+ - `:sha3_384` - SHA-3 384 bits
95
+ - `:sha3_512` - SHA-3 512 bits
96
+ - `:shake_128` - SHAKE128 extendable-output function
97
+ - `:shake_256` - SHAKE256 extendable-output function
98
+
99
+ ### SHAKE128/256 Functions
50
100
 
51
- ### Basics
101
+ SHAKE128 and SHAKE256 are extendable-output functions (XOFs) that allow you to "squeeze" an arbitrary number of bytes from the hash state:
52
102
 
53
103
  ```ruby
54
- # Instantiate a new SHA3::Digest class with 256 bit length
55
- s = SHA3::Digest.new(:sha256)
104
+ # Create a new SHAKE128 instance
105
+ shake = SHA3::Digest.new(:shake_128)
106
+
107
+ # Add data to be hashed
108
+ shake << 'Squeeze this data...'
56
109
 
57
- # OR #
110
+ # Squeeze 120 bytes (240 hex characters) from the hash state
111
+ result = shake.hex_squeeze(120)
58
112
 
59
- s = SHA3::Digest::SHA256.new()
113
+ # Or get binary output
114
+ binary_result = shake.squeeze(1024)
60
115
 
61
- # Update hash state, and compute new value
62
- s.update "Compute Me"
116
+ # You can call squeeze functions multiple times with arbitrary output lengths
117
+ first_part = shake.squeeze(32) # Get 32 bytes
118
+ second_part = shake.squeeze(64) # Get 64 bytes
119
+ third_part = shake.hex_squeeze(128) # Get 128 bytes as hex
120
+ ```
63
121
 
64
- # << is an .update() alias
65
- s << "Me too"
122
+ ### Alternate Class Syntax
66
123
 
67
- # Returns digest value in bytes
68
- s.digest
69
- # => "\xBE\xDF\r\xD9\xA1..."
124
+ For convenience, you can also use dedicated classes for each algorithm:
70
125
 
71
- # Returns digest value as hex string
72
- s.hexdigest
73
- # => "bedf0dd9a15b647..."
126
+ ```ruby
127
+ # Available classes
128
+ SHA3::Digest::SHA3_224.new([data])
129
+ SHA3::Digest::SHA3_256.new([data])
130
+ SHA3::Digest::SHA3_384.new([data])
131
+ SHA3::Digest::SHA3_512.new([data])
132
+ SHA3::Digest::SHAKE_128.new([data])
133
+ SHA3::Digest::SHAKE_256.new([data])
134
+ ```
74
135
 
75
- ### Digest class-methods: ###
136
+ ```ruby
137
+ # Example usage
138
+ digest = SHA3::Digest::SHA3_256.new('Start here')
76
139
 
77
- SHA3::Digest.hexdigest(:sha224, "Hash me, please")
78
- # => "200e7bc18cd613..."
140
+ digest << "Compute Me"
141
+ digest.update("Me too")
79
142
 
80
- SHA3::Digest::SHA384.digest("Hash me, please")
81
- # => "\xF5\xCEpC\xB0eV..."
143
+ digest.hexdigest
144
+ # => "bedf0dd9a15b647..."
82
145
  ```
83
146
 
84
- ### Hashing a file
147
+ ### Hashing a File
85
148
 
86
149
  ```ruby
87
- # Compute the hash value for given file, and return the result as hex
88
- s = SHA3::Digest::SHA224.file("my_fantastical_file.bin").hexdigest
150
+ # Compute the hash value for a given file, and return the result as hex
151
+ hash = SHA3::Digest::SHA3_256.file("my_file.bin").hexdigest
89
152
 
90
- # Calling SHA3::Digest.file(...) defaults to SHA256
91
- s = SHA3::Digest.file("tests.sh")
92
- # => #<SHA3::Digest: a9801db49389339...>
153
+ # Calling SHA3::Digest.file(...) defaults to SHA3_256
154
+ hash = SHA3::Digest.file("my_file.bin").hexdigest
155
+ # => "a9801db49389339..."
93
156
  ```
94
157
 
95
158
  ## Development
96
159
 
97
- * Native build tools (e.g., GCC, Minigw, etc.)
98
- * Gems: rubygems-tasks, rake, rspec, yard
160
+ ### Dependencies
161
+
162
+ - **C/C++** compiler and native build tools (e.g., Clang/LLVM, GCC, MinGW, etc.)
163
+ - **Gems**: rake, rake-compiler, rspec, yard
99
164
 
100
165
  ### Testing
101
166
 
102
- Call ```rake``` to run the included RSpec tests.
167
+ Run `rake` to build and run the (RSpec) tests.
168
+
169
+ To run the tests manually:
170
+
171
+ ```bash
172
+ bundle exec rspec
173
+ ```
174
+
175
+ The test suite includes a special `sha3_vectors_spec.rb` file that automatically:
176
+ 1. Downloads the official SHA3 test vectors from the XKCP repository
177
+ 2. Parses the test vectors
178
+ 3. Runs tests against all SHA3 variants (224, 256, 384, and 512 bit)
179
+
180
+ The test vectors are downloaded only once and cached in the `spec/data` directory for future test runs.
181
+
182
+ ### Supported Ruby Versions
183
+
184
+ - MRI Ruby 2.7 - 3.1
103
185
 
104
- Only a small subset of test vectors are included in the source repository; however, the complete test vectors suite is available for download. Simply run the ```tests.sh``` shell script (available in the root of source directory) to generate full byte-length RSpec test files.
186
+ ## Roadmap
105
187
 
106
- ```sh tests.sh```
188
+ - [X] Add support for SHA-3 variants (224, 256, 384, and 512 bit)
189
+ - [X] Add support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
190
+ - [ ] Add support for cSHAKE, TurboSHANKE, and KMAC
107
191
 
108
- ### Rubies
192
+ ## Contributing
109
193
 
110
- Supported Ruby versions:
194
+ 1. Fork it
195
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
196
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
197
+ 4. Push to the branch (`git push origin my-new-feature`)
198
+ 5. Create new Pull Request
111
199
 
112
- - MRI Ruby 2.4 - 3.1
200
+ ## License
113
201
 
202
+ Copyright (c) 2012 - 2025 Johanns Gregorian (https://github.com/johanns)
114
203
 
204
+ Released under the MIT License. See [LICENSE.txt](LICENSE.txt) for details.
115
205
 
116
- ## Copyright
206
+ ## Credits
117
207
 
118
- Copyright (c) 2012 - 2022 Johanns Gregorian (https://github.com/johanns)
208
+ - [XKCP - eXtended Keccak Code Package](https://github.com/XKCP/XKCP) by the Keccak team: [https://keccak.team/index.html](https://keccak.team/index.html)
209
+ - All contributors to the SHA3 for Ruby project
119
210
 
120
- **See LICENSE.txt for details.**
data/Rakefile CHANGED
@@ -1,19 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
4
 
5
+ require 'rspec/core/rake_task'
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  require 'rubocop/rake_task'
9
-
10
9
  RuboCop::RakeTask.new
11
10
 
12
11
  require 'rake/extensiontask'
13
12
 
14
13
  begin
15
14
  Rake::ExtensionTask.new :compile do |ext|
16
- ext.name = 'sha3_n'
15
+ ext.name = 'sha3_digest'
17
16
  ext.ext_dir = 'ext/sha3'
18
17
  ext.tmp_dir = 'tmp'
19
18
  ext.source_pattern = '*.{c}'
@@ -24,4 +23,11 @@ rescue LoadError
24
23
  end
25
24
  end
26
25
 
26
+ require 'rdoc/task'
27
+
28
+ RDoc::Task.new do |rdoc|
29
+ rdoc.rdoc_dir = '../docs/sha3'
30
+ rdoc.options << '--force-update'
31
+ end
32
+
27
33
  task default: %i[compile spec]
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEYDCCAsigAwIBAgIBATANBgkqhkiG9w0BAQsFADA7MRAwDgYDVQQDDAdpb19z
3
+ aGEzMRMwEQYKCZImiZPyLGQBGRYDanNnMRIwEAYKCZImiZPyLGQBGRYCaW8wHhcN
4
+ MjUwMzAxMDYxMTE1WhcNMjYwMzAxMDYxMTE1WjA7MRAwDgYDVQQDDAdpb19zaGEz
5
+ MRMwEQYKCZImiZPyLGQBGRYDanNnMRIwEAYKCZImiZPyLGQBGRYCaW8wggGiMA0G
6
+ CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDMdO1oUQ9FzXYtfFktOXDx6oIf9uSk
7
+ mg+yfo7uvcyNSa4gsF4+CY/TOYNBtwlD25AlgDqpxVCHFwUaBD+MHKyd8p6Eto1Q
8
+ Bwb7YrjPOXlmCKQYr5sFfbjeUfQRKBUTAhzM0W/5Zh9C4gkOyZ/7SaU6mI/M/LgQ
9
+ dZsw2y6l2bAl4aZaXgbnO7B1rPTPr6yQRZTveacmeTGHav1WACdE36Txqyv2QA7+
10
+ +VdYx04fOe2FEipan7d4TA4XKW+0Z+VWyoWFNyyxJtiT53PB10lztPiycBqZ+A3L
11
+ aA2VjZekn3NFbsXMOa4fbSTMddb784IWEeySmTMu6W/yYpo1B1PbgRaD/z2Zg0Qj
12
+ SZ2ldqqk68nvFVWqUlRbT8ZY6McKC1VEbNLLk7jNvdbgr/VPo4Zu5TP3FXjsPlpz
13
+ 1duXTtAGtHjPnS+tdkSinKv4OmbTHid9gnoDcRjlNpWxoULs9iSNb6lOCUeBxvF6
14
+ 4Eh7nyIPmaTDwPQtg5/RTvjZMqprS8D3tKsCAwEAAaNvMG0wCQYDVR0TBAIwADAL
15
+ BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFLCWxOjmn5qTuhjFG7fwiPXzSIlFMBkGA1Ud
16
+ EQQSMBCBDmlvK3NoYTNAanNnLmlvMBkGA1UdEgQSMBCBDmlvK3NoYTNAanNnLmlv
17
+ MA0GCSqGSIb3DQEBCwUAA4IBgQC4Y5pXxtopzHiSBsg6fuozv7zHXXuYXOL2Bq2x
18
+ l8C8lYjC2pN/Fh+FlgrJkqAoJ0wBlh3+wkhYPhSehkUy/2HaUYYTd1Zv4Odw+C/Q
19
+ rQnN5+nIv+gMrLwoBXH9sFjAp/iYKd4cDz5aUVNrPqibj8zivcSqFJ9lsyOvIZO6
20
+ tajU2HVxXOkpTtLzMgPEGdwlFEd2tB7VCGFbrTskxrpv243b0HdpeEVh2e9dNkl4
21
+ XobOvUPXHzFTDucYe8jpCn7e7Cj43PpTZFnxIRJnO8cVpX6n7UG8+JgBSqvwuv5C
22
+ YwFBqP6G2+0e0EdIIMdbCDBTmJbFyBr6y4pzED/FvEFzhAmCKOcZ6RJ8H7hkX5rh
23
+ +L4c9pHTemc2sQl7kH+mrntu7pt6D4EM4FD5eyWujQN1ME7xvLIFm5SczqCzFDfe
24
+ UjZtrp/rHLfHln46RvB+a1NlMRWxtJ7mQc/CMEbT+cpHlzuYa9qGakA4TmMpK10h
25
+ uYUv/V6CD4iTEMby0dopwHt5NqE=
26
+ -----END CERTIFICATE-----
data/doc/sha3.rb ADDED
@@ -0,0 +1,81 @@
1
+ module SHA3
2
+ module Digest
3
+ # SHA3_224 is a cryptographic hash function that produces a 224-bit (28-byte) hash value.
4
+ #
5
+ # Usage:
6
+ # digest = SHA3::Digest::SHA3_224.new
7
+ # digest.update("message")
8
+ # hash = digest.hexdigest
9
+ #
10
+ # # Or more simply:
11
+ # hash = SHA3::Digest::SHA3_224.hexdigest("message")
12
+ #
13
+ # See SHA3::Digest for complete API list and additional documentation.
14
+ class SHA3_224 < ::Digest::Class; end
15
+
16
+ # SHA3_256 is a cryptographic hash function that produces a 256-bit (32-byte) hash value.
17
+ #
18
+ # Usage:
19
+ # digest = SHA3::Digest::SHA3_256.new
20
+ # digest.update("message")
21
+ # hash = digest.hexdigest
22
+ #
23
+ # # Or more simply:
24
+ # hash = SHA3::Digest::SHA3_256.hexdigest("message")
25
+ #
26
+ # See SHA3::Digest for complete API list and additional documentation.
27
+ class SHA3_256 < ::Digest::Class; end
28
+
29
+ # SHA3_384 is a cryptographic hash function that produces a 384-bit (48-byte) hash value.
30
+ #
31
+ # Usage:
32
+ # digest = SHA3::Digest::SHA3_384.new
33
+ # digest.update("message")
34
+ # hash = digest.hexdigest
35
+ #
36
+ # # Or more simply:
37
+ # hash = SHA3::Digest::SHA3_384.hexdigest("message")
38
+ #
39
+ # See SHA3::Digest for complete API list and additional documentation.
40
+ class SHA3_384 < ::Digest::Class; end
41
+
42
+ # SHA3_512 is a cryptographic hash function that produces a 512-bit (64-byte) hash value.
43
+ #
44
+ # Usage:
45
+ # digest = SHA3::Digest::SHA3_512.new
46
+ # digest.update("message")
47
+ # hash = digest.hexdigest
48
+ #
49
+ # # Or more simply:
50
+ # hash = SHA3::Digest::SHA3_512.hexdigest("message")
51
+ #
52
+ # See SHA3::Digest for complete API list and additional documentation.
53
+ class SHA3_512 < ::Digest::Class; end
54
+
55
+ # SHAKE_128 is an extendable-output function (XOF) that can produce hash values of any desired length.
56
+ #
57
+ # Usage:
58
+ # digest = SHA3::Digest::SHAKE_128.new
59
+ # digest.update("message")
60
+ # hash = digest.hexdigest(32) # Get 32 bytes (64 hex chars) of output
61
+ #
62
+ # # Or more simply:
63
+ # hash = SHA3::Digest::SHAKE_128.hexdigest("message", 32)
64
+ #
65
+ # See SHA3::Digest for complete API list and additional documentation.
66
+ class SHAKE_128 < ::Digest::Class; end
67
+
68
+ # SHAKE_256 is an extendable-output function (XOF) that can produce hash values of any desired length.
69
+ #
70
+ # Usage:
71
+ # digest = SHA3::Digest::SHAKE_256.new
72
+ # digest.update("message")
73
+ # hash = digest.hexdigest(32) # Get 32 bytes (64 hex chars) of output
74
+ #
75
+ # # Or more simply:
76
+ # hash = SHA3::Digest::SHAKE_256.hexdigest("message", 32)
77
+ #
78
+ # See SHA3::Digest for complete API list and additional documentation.
79
+ class SHAKE_256 < ::Digest::Class; end
80
+ end
81
+ end
data/ext/sha3/config.h ADDED
@@ -0,0 +1,26 @@
1
+ /* File generated by ToTargetConfigFile.xsl */
2
+
3
+ #define XKCP_has_Sponge_Keccak
4
+ #define XKCP_has_FIPS202
5
+ #define XKCP_has_KeccakP1600
6
+
7
+ // #define XKCP_has_SP800_185
8
+ // #define XKCP_has_Duplex_Keccak
9
+ // #define XKCP_has_PRG_Keccak
10
+ // #define XKCP_has_Ketje
11
+ // #define XKCP_has_Keyak
12
+ // #define XKCP_has_KangarooTwelve
13
+ // #define XKCP_has_Kravatte
14
+ // #define XKCP_has_Xoofff
15
+ // #define XKCP_has_Xoodyak
16
+ // #define XKCP_has_KeccakP200
17
+ // #define XKCP_has_KeccakP400
18
+ // #define XKCP_has_KeccakP800
19
+ // #define XKCP_has_KeccakP1600
20
+ // #define XKCP_has_KeccakP1600times2
21
+ // #define XKCP_has_KeccakP1600times4
22
+ // #define XKCP_has_KeccakP1600times8
23
+ // #define XKCP_has_Xoodoo
24
+ // #define XKCP_has_Xoodootimes4
25
+ // #define XKCP_has_Xoodootimes8
26
+ // #define XKCP_has_Xoodootimes16