sha3 1.0.5 → 2.1.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 (54) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.clang-format +54 -0
  4. data/.document +3 -3
  5. data/.rdoc_options +11 -0
  6. data/.rspec +2 -2
  7. data/.rubocop.yml +8 -1
  8. data/CHANGELOG.md +23 -0
  9. data/Gemfile +12 -0
  10. data/LICENSE.txt +1 -1
  11. data/README.md +185 -65
  12. data/Rakefile +12 -4
  13. data/certs/io+sha3@jsg.io.pem +26 -0
  14. data/doc/sha3.rb +83 -0
  15. data/ext/sha3/config.h +2 -2
  16. data/ext/sha3/digest.c +726 -169
  17. data/ext/sha3/digest.h +6 -35
  18. data/ext/sha3/extconf.rb +42 -38
  19. data/ext/sha3/kmac.c +504 -0
  20. data/ext/sha3/kmac.h +14 -0
  21. data/ext/sha3/lib/high/Keccak/KeccakDuplex.c +81 -0
  22. data/ext/sha3/lib/high/Keccak/KeccakDuplex.h +73 -0
  23. data/ext/sha3/lib/high/Keccak/KeccakDuplex.inc +201 -0
  24. data/ext/sha3/lib/high/Keccak/KeccakSponge.c +2 -18
  25. data/ext/sha3/lib/high/Keccak/KeccakSponge.h +4 -10
  26. data/ext/sha3/lib/high/Keccak/KeccakSponge.inc +27 -31
  27. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.c +61 -0
  28. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.h +67 -0
  29. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.inc +128 -0
  30. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.c +93 -0
  31. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.h +599 -0
  32. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.inc +573 -0
  33. data/ext/sha3/lib/high/common/Phases.h +25 -0
  34. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +19 -9
  35. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +18 -12
  36. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +28 -36
  37. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +18 -12
  38. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +28 -59
  39. data/ext/sha3/lib/low/common/PlSnP-Fallback.inc +291 -0
  40. data/ext/sha3/lib/low/common/SnP-Relaned.h +145 -0
  41. data/ext/sha3/sha3.c +28 -59
  42. data/ext/sha3/sha3.h +4 -13
  43. data/lib/constants.rb +5 -0
  44. data/lib/sha3.rb +25 -24
  45. data.tar.gz.sig +0 -0
  46. metadata +61 -127
  47. metadata.gz.sig +0 -0
  48. data/.yardopts +0 -1
  49. data/ChangeLog.rdoc +0 -27
  50. data/certs/johanns.pem +0 -25
  51. data/lib/sha3/doc.rb +0 -121
  52. data/lib/sha3/version.rb +0 -9
  53. data/sha3.gemspec +0 -54
  54. data/tests.sh +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16edba407e859ee7afacc8a405666ec66cab0052cd7788e79089bd3f0d295844
4
- data.tar.gz: 5552886038bbec790d086599cbbe6ad09a0c3561b58a9a2dfff2b9c9834b7154
3
+ metadata.gz: de8b62510dacd92d85961808033747000eaed0b5866ed33e1d51599a9ce03b17
4
+ data.tar.gz: dc36181bd1095ab54c2574fba9fde0c37fd011d256067325abadb3bbb734b1da
5
5
  SHA512:
6
- metadata.gz: a8e36ae984df177684d4b1a70689a80824e9d9ee70fd07812eaa50c8f0cd90a90f292dca435764842b737fb268084d09fa5f47450bdc9cf93316253c70484945
7
- data.tar.gz: a643ded4e2f9828d732f428eba1757c6cc383797f32b52ba7427dae8234ac9bc0e158712ccf64d7be77f2538b80904efaf26a0e455ce9515f9a76679929054c0
6
+ metadata.gz: d8f86426fd9b7ecb187eb3b75cbf0b9d574cfc6e6bda0370c25e4b9d8b1ccf33a45427b7c5a0e16b7f7e6ff0c9c5b8d2b556fa409d9890ed5c67c261c734c770
7
+ data.tar.gz: 8c670be3e5adadc174a164a757aec0e326b26633737c52a8c1f8e41dc3f69f9dc44be9ad077dc22e7ce6742a0313f89151d5ec7135958cde0ccc2a59173f2cea
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: 120
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,4 @@
1
- -
2
- README.rdoc
3
- ChangeLog.rdoc
1
+ README.md
4
2
  LICENSE.txt
3
+ doc/**/*.rb
4
+ ext/sha3/*.c
data/.rdoc_options ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ main_page: README.md
3
+ title: SHA3
4
+
5
+ charset: UTF-8
6
+ encoding: UTF-8
7
+ force_update: true
8
+ line_numbers: true
9
+ markup: rdoc
10
+ op_dir: html
11
+ 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,13 @@
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
11
+
12
+ Naming/VariableNumber:
13
+ Enabled: false
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,15 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+
7
+ group :development, :test do
8
+ gem 'irb'
9
+ gem 'rdoc', '~> 6'
10
+
11
+ gem 'rake', '~> 13'
12
+ gem 'rake-compiler', '~> 1'
13
+ gem 'rspec', '~> 3'
14
+ gem 'rubocop', '~> 1'
15
+ gem 'rubocop-rake', '~> 0.7'
16
+ gem 'rubocop-rspec', '~> 3'
17
+ 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,123 +1,243 @@
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 XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing algorithm.
5
+ A high-performance native binding to the SHA3 (FIPS 202) cryptographic hashing algorithms, based on the [XKCP - eXtended Keccak Code Package](https://github.com/XKCP/XKCP).
6
+
7
+ This gem provides support for the standard SHA-3 fixed-length functions (224, 256, 384, and 512 bits), as well as the SHAKE128/SHAKE256 extendable-output functions (XOFs) and KMAC (Keccak Message Authentication Code) as specified in NIST SP 800-185.
8
+
9
+ > [!CAUTION]
10
+ > **Security Notice**: Do not use SHA-3 for hashing passwords. Instead, use a slow hashing function such as PBKDF2, Argon2, bcrypt, or scrypt.
11
+
12
+ > [!IMPORTANT]
13
+ > **Breaking Changes**: SHA3 version 2.0 introduces breaking changes in the API to support new features and functionality. Please review the changelog and ensure compatibility with your application.
14
+ > If you need the previous behavior, lock your Gemfile to version '~> 1.0'.
15
+
16
+ ## Table of Contents
17
+
18
+ - [Documentation](#documentation)
19
+ - [Features](#features)
20
+ - [Installation](#installation)
21
+ - [Usage](#usage)
22
+ - [SHA-3 Fixed Hash Functions](#sha-3-fixed-hash-functions)
23
+ - [SHAKE128/256 Functions](#shake128256-functions)
24
+ - [KMAC Functions](#kmac-functions)
25
+ - [Alternate Class Syntax](#alternate-class-syntax)
26
+ - [Hashing a File](#hashing-a-file)
27
+ - [Development](#development)
28
+ - [Dependencies](#dependencies)
29
+ - [Testing](#testing)
30
+ - [Supported Ruby Versions](#supported-ruby-versions)
31
+ - [Contributing](#contributing)
32
+ - [Roadmap](#roadmap)
33
+ - [License](#license)
34
+ - [Credits](#credits)
35
+
36
+ ## Documentation
37
+
38
+ - [API Documentation](https://docs.jsg.io/sha3/html/index.html)
39
+ - [GitHub Repository](https://github.com/johanns/sha3#readme)
40
+ - [Issue Tracker](https://github.com/johanns/sha3/issues)
41
+
42
+ ## Features
43
+
44
+ - Full support for all SHA-3 variants (224, 256, 384, and 512 bits)
45
+ - Support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
46
+ - Support for KMAC (Keccak Message Authentication Code)
47
+ - Native C implementation for high performance
48
+ - Simple, Ruby-friendly API that follows Ruby's standard Digest interface
49
+ - Comprehensive test suite with official NIST test vectors
50
+ - Thread-safe implementation
6
51
 
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
- - [XKCP - eXtended Keccak Code Package](https://github.com/XKCP/XKCP)
11
-
12
- ## Warning
52
+ ## Installation
13
53
 
14
- - Please do NOT use SHA3 to hash passwords -- use a slow hashing function instead (e.g.: `pbkdf2`, `argon2`, `bcrypt` or `scrypt`)
15
- - Version 1.0 introduces new API and is incompatible with previous versions (0.x).
54
+ Add this line to your application's Gemfile:
16
55
 
17
- ## Module details
56
+ ```ruby
57
+ gem 'sha3', '~> 2.0'
58
+ ```
18
59
 
19
- **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**).
60
+ And then execute:
20
61
 
21
- See [documentation for Ruby's **Digest** class for additional details](http://www.ruby-doc.org/stdlib-2.2.3/libdoc/digest/rdoc/Digest.html).
62
+ ```sh
63
+ bundle install
64
+ ```
22
65
 
23
- ## Installation
66
+ Or install it yourself as:
24
67
 
25
- ```shell
68
+ ```sh
26
69
  gem install sha3
27
70
  ```
28
71
 
29
72
  ## Usage
30
73
 
74
+ ### SHA-3 Fixed Hash Functions
75
+
31
76
  ```ruby
32
77
  require 'sha3'
33
- ```
34
78
 
35
- Valid hash bit-lengths are: *224*, *256*, *384*, *512*.
79
+ # Create a new digest instance
80
+ digest = SHA3::Digest.new(:sha3_224, 'Start here')
36
81
 
37
- ```ruby
38
- :sha224 :sha256 :sha384 :sha512
82
+ # Add more data to be hashed
83
+ digest << "Compute Me"
84
+ digest.update("Me too")
85
+
86
+ # Get the final hash value as a hex string
87
+ digest.hexdigest
88
+ # => "d6d38021d60857..."
39
89
 
40
- # SHA3::Digest.new(224) is SHA3::Digest.new(:sha224)
90
+ # Or as a binary string
91
+ digest.digest
41
92
  ```
42
93
 
43
- Alternatively, you can instantiate using one of four sub-classes:
94
+ Valid algorithm symbols are:
95
+
96
+ - `:sha3_224` - SHA-3 224 bits
97
+ - `:sha3_256` - SHA-3 256 bits
98
+ - `:sha3_384` - SHA-3 384 bits
99
+ - `:sha3_512` - SHA-3 512 bits
100
+ - `:shake_128` - SHAKE128 extendable-output function
101
+ - `:shake_256` - SHAKE256 extendable-output function
102
+
103
+ ### SHAKE128/256 Functions
104
+
105
+ SHAKE128 and SHAKE256 are extendable-output functions (XOFs) that allow you to "squeeze" an arbitrary number of bytes from the hash state:
44
106
 
45
107
  ```ruby
46
- SHA3::Digest::SHA224.new() # 224 bits
47
- SHA3::Digest::SHA256.new() # 256 bits
48
- SHA3::Digest::SHA384.new() # 384 bits
49
- SHA3::Digest::SHA512.new() # 512 bits
108
+ # Create a new SHAKE128 instance
109
+ shake = SHA3::Digest.new(:shake_128)
110
+
111
+ # Add data to be hashed
112
+ shake << 'Squeeze this data...'
113
+
114
+ # Squeeze 120 bytes (240 hex characters) from the hash state
115
+ result = shake.hex_squeeze(120)
116
+
117
+ # Or get binary output
118
+ binary_result = shake.squeeze(1024)
119
+
120
+ # You can call squeeze functions multiple times with arbitrary output lengths
121
+ first_part = shake.squeeze(32) # Get 32 bytes
122
+ second_part = shake.squeeze(64) # Get 64 bytes
123
+ third_part = shake.hex_squeeze(128) # Get 128 bytes as hex
50
124
  ```
51
125
 
52
- ### Basics
126
+ ### KMAC Functions
127
+
128
+ KMAC (Keccak Message Authentication Code) is a message authentication code algorithm based on the SHAKE extendable-output functions:
53
129
 
54
130
  ```ruby
55
- # Instantiate a new SHA3::Digest class with 256 bit length
56
- s = SHA3::Digest.new(:sha256)
131
+ require 'sha3'
57
132
 
58
- # OR #
133
+ # Create a new KMAC instance
134
+ # Parameters: algorithm, output_length (in bytes), key, [customization]
135
+ kmac = SHA3::KMAC.new(:kmac_128, 32, "my secret key", "app-specific customization")
59
136
 
60
- s = SHA3::Digest::SHA256.new()
137
+ # Add data to be authenticated
138
+ kmac.update("Authenticate this message")
61
139
 
62
- # Update hash state, and compute new value
63
- s.update "Compute Me"
140
+ # Get the result as a hex string
141
+ result = kmac.hexdigest
142
+ # => "a8982c..."
64
143
 
65
- # << is an .update() alias
66
- s << "Me too"
144
+ # Or as binary
145
+ binary_result = kmac.digest
67
146
 
68
- # Returns digest value in bytes
69
- s.digest
70
- # => "\xBE\xDF\r\xD9\xA1..."
147
+ # One-shot operation
148
+ result = SHA3::KMAC.hexdigest(:kmac_256, "message", 64, "key", "customization")
149
+ ```
71
150
 
72
- # Returns digest value as hex string
73
- s.hexdigest
74
- # => "bedf0dd9a15b647..."
151
+ ### Alternate Class Syntax
152
+
153
+ For convenience, you can also use dedicated classes for each algorithm:
154
+
155
+ ```ruby
156
+ # Available classes
157
+ SHA3::Digest::SHA3_224.new([data])
158
+ SHA3::Digest::SHA3_256.new([data])
159
+ SHA3::Digest::SHA3_384.new([data])
160
+ SHA3::Digest::SHA3_512.new([data])
161
+ SHA3::Digest::SHAKE_128.new([data])
162
+ SHA3::Digest::SHAKE_256.new([data])
163
+ ```
75
164
 
76
- ### Digest class-methods: ###
165
+ ```ruby
166
+ # Example usage
167
+ digest = SHA3::Digest::SHA3_256.new('Start here')
77
168
 
78
- SHA3::Digest.hexdigest(:sha224, "Hash me, please")
79
- # => "200e7bc18cd613..."
169
+ digest << "Compute Me"
170
+ digest.update("Me too")
80
171
 
81
- SHA3::Digest::SHA384.digest("Hash me, please")
82
- # => "\xF5\xCEpC\xB0eV..."
172
+ digest.hexdigest
173
+ # => "bedf0dd9a15b647..."
83
174
  ```
84
175
 
85
- ### Hashing a file
176
+ ### Hashing a File
86
177
 
87
178
  ```ruby
88
- # Compute the hash value for given file, and return the result as hex
89
- s = SHA3::Digest::SHA224.file("my_fantastical_file.bin").hexdigest
179
+ # Compute the hash value for a given file, and return the result as hex
180
+ hash = SHA3::Digest::SHA3_256.file("my_file.bin").hexdigest
90
181
 
91
- # Calling SHA3::Digest.file(...) defaults to SHA256
92
- s = SHA3::Digest.file("tests.sh")
93
- # => #<SHA3::Digest: a9801db49389339...>
182
+ # Using SHAKE function to squeeze an arbitrary number of bytes
183
+ shake = SHA3::Digest::SHAKE_128.file("my_file.bin").hexdigest(320)
184
+
185
+ # Calling SHA3::Digest.file(...) defaults to SHA3_256
186
+ hash = SHA3::Digest.file("my_file.bin").hexdigest
187
+ # => "a9801db49389339..."
94
188
  ```
95
189
 
96
- ### Development Dependencies
190
+ ## Development
191
+
192
+ ### Dependencies
97
193
 
98
- * Native build tools (e.g., Clang/LLVM, GCC, Minigw, etc.)
99
- * Gems: rubygems-tasks, rake, rspec, yard
194
+ - **C/C++** compiler and native build tools (e.g., Clang/LLVM, GCC, MinGW, etc.)
195
+ - **Gems**: rake, rake-compiler, rspec, yard
100
196
 
101
197
  ### Testing
102
198
 
103
- Call ```rake``` to run the included RSpec tests.
199
+ Run `rake` to build and run the (RSpec) tests.
104
200
 
105
- 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.
201
+ To run the tests manually:
106
202
 
107
- ```sh tests.sh```
203
+ ```bash
204
+ bundle exec rspec
205
+ ```
108
206
 
109
- ### Rubies
207
+ The test suite includes a special `sha3_vectors_spec.rb` file that automatically:
208
+ 1. Downloads the official SHA3 test vectors from the XKCP repository
209
+ 2. Parses the test vectors
210
+ 3. Runs tests against all SHA3 variants (224, 256, 384, and 512 bit)
110
211
 
111
- Supported Ruby versions:
212
+ The test vectors are downloaded only once and cached in the `spec/data` directory for future test runs.
112
213
 
113
- - MRI Ruby 2.6 - 3.1
214
+ ### Supported Ruby Versions
114
215
 
115
- ## Credits
216
+ - MRI Ruby 2.7 - 3.1
217
+
218
+ ## Roadmap
219
+
220
+ - [X] Add support for SHA-3 variants (224, 256, 384, and 512 bit)
221
+ - [X] Add support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
222
+ - [X] Add support for KMAC
223
+ - [ ] Add support for cSHAKE
224
+
225
+ ## Contributing
116
226
 
117
- XKCP by Keccak team: [https://keccak.team/index.html]()
227
+ 1. Fork it
228
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
229
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
230
+ 4. Push to the branch (`git push origin my-new-feature`)
231
+ 5. Create new Pull Request
118
232
 
119
- ## Copyright
233
+ ## License
234
+
235
+ Copyright (c) 2012 - 2025 Johanns Gregorian (https://github.com/johanns)
236
+
237
+ Released under the MIT License. See [LICENSE.txt](LICENSE.txt) for details.
238
+
239
+ ## Credits
120
240
 
121
- Copyright (c) 2012 - 2022 Johanns Gregorian (https://github.com/johanns)
241
+ - [XKCP - eXtended Keccak Code Package](https://github.com/XKCP/XKCP) by the Keccak team: [https://keccak.team/index.html](https://keccak.team/index.html)
242
+ - All contributors to the SHA3 for Ruby project
122
243
 
123
- **See LICENSE.txt for details.**
data/Rakefile CHANGED
@@ -1,22 +1,22 @@
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_ext'
16
+
17
17
  ext.ext_dir = 'ext/sha3'
18
- ext.tmp_dir = 'tmp'
19
18
  ext.source_pattern = '*.{c}'
19
+ ext.tmp_dir = 'tmp'
20
20
  end
21
21
  rescue LoadError
22
22
  task :compile do
@@ -24,4 +24,12 @@ rescue LoadError
24
24
  end
25
25
  end
26
26
 
27
+ require 'rdoc/task'
28
+
29
+ RDoc::Task.new do |rdoc|
30
+ rdoc.rdoc_dir = '../docs/sha3'
31
+ rdoc.options << '--force-update'
32
+ rdoc.options << '-V'
33
+ end
34
+
27
35
  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,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SHA3
4
+ module Digest
5
+ # SHA3_224 is a cryptographic hash function that produces a 224-bit (28-byte) hash value.
6
+ #
7
+ # Usage:
8
+ # digest = SHA3::Digest::SHA3_224.new
9
+ # digest.update("message")
10
+ # hash = digest.hexdigest
11
+ #
12
+ # # Or more simply:
13
+ # hash = SHA3::Digest::SHA3_224.hexdigest("message")
14
+ #
15
+ # See SHA3::Digest for complete API list and additional documentation.
16
+ class SHA3_224 < ::Digest::Class; end
17
+
18
+ # SHA3_256 is a cryptographic hash function that produces a 256-bit (32-byte) hash value.
19
+ #
20
+ # Usage:
21
+ # digest = SHA3::Digest::SHA3_256.new
22
+ # digest.update("message")
23
+ # hash = digest.hexdigest
24
+ #
25
+ # # Or more simply:
26
+ # hash = SHA3::Digest::SHA3_256.hexdigest("message")
27
+ #
28
+ # See SHA3::Digest for complete API list and additional documentation.
29
+ class SHA3_256 < ::Digest::Class; end
30
+
31
+ # SHA3_384 is a cryptographic hash function that produces a 384-bit (48-byte) hash value.
32
+ #
33
+ # Usage:
34
+ # digest = SHA3::Digest::SHA3_384.new
35
+ # digest.update("message")
36
+ # hash = digest.hexdigest
37
+ #
38
+ # # Or more simply:
39
+ # hash = SHA3::Digest::SHA3_384.hexdigest("message")
40
+ #
41
+ # See SHA3::Digest for complete API list and additional documentation.
42
+ class SHA3_384 < ::Digest::Class; end
43
+
44
+ # SHA3_512 is a cryptographic hash function that produces a 512-bit (64-byte) hash value.
45
+ #
46
+ # Usage:
47
+ # digest = SHA3::Digest::SHA3_512.new
48
+ # digest.update("message")
49
+ # hash = digest.hexdigest
50
+ #
51
+ # # Or more simply:
52
+ # hash = SHA3::Digest::SHA3_512.hexdigest("message")
53
+ #
54
+ # See SHA3::Digest for complete API list and additional documentation.
55
+ class SHA3_512 < ::Digest::Class; end
56
+
57
+ # SHAKE_128 is an extendable-output function (XOF) that can produce hash values of any desired length.
58
+ #
59
+ # Usage:
60
+ # digest = SHA3::Digest::SHAKE_128.new
61
+ # digest.update("message")
62
+ # hash = digest.hexdigest(32) # Get 32 bytes (64 hex chars) of output
63
+ #
64
+ # # Or more simply:
65
+ # hash = SHA3::Digest::SHAKE_128.hexdigest("message", 32)
66
+ #
67
+ # See SHA3::Digest for complete API list and additional documentation.
68
+ class SHAKE_128 < ::Digest::Class; end
69
+
70
+ # SHAKE_256 is an extendable-output function (XOF) that can produce hash values of any desired length.
71
+ #
72
+ # Usage:
73
+ # digest = SHA3::Digest::SHAKE_256.new
74
+ # digest.update("message")
75
+ # hash = digest.hexdigest(32) # Get 32 bytes (64 hex chars) of output
76
+ #
77
+ # # Or more simply:
78
+ # hash = SHA3::Digest::SHAKE_256.hexdigest("message", 32)
79
+ #
80
+ # See SHA3::Digest for complete API list and additional documentation.
81
+ class SHAKE_256 < ::Digest::Class; end
82
+ end
83
+ end
data/ext/sha3/config.h CHANGED
@@ -1,10 +1,10 @@
1
1
  /* File generated by ToTargetConfigFile.xsl */
2
2
 
3
- #define XKCP_has_Sponge_Keccak
4
3
  #define XKCP_has_FIPS202
5
4
  #define XKCP_has_KeccakP1600
5
+ #define XKCP_has_Sponge_Keccak
6
+ #define XKCP_has_SP800_185
6
7
 
7
- // #define XKCP_has_SP800_185
8
8
  // #define XKCP_has_Duplex_Keccak
9
9
  // #define XKCP_has_PRG_Keccak
10
10
  // #define XKCP_has_Ketje