sha3 2.0.0 → 2.2.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.clang-format +5 -52
- data/.document +1 -2
- data/.rdoc_options +1 -0
- data/.rubocop.yml +3 -0
- data/.vscode/launch.json +15 -0
- data/.vscode/settings.json +9 -0
- data/.vscode/tasks.json +29 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -0
- data/README.md +116 -33
- data/Rakefile +4 -2
- data/doc/sha3.rb +2 -0
- data/ext/sha3/config.h +2 -2
- data/ext/sha3/cshake.c +391 -0
- data/ext/sha3/cshake.h +17 -0
- data/ext/sha3/digest.c +320 -231
- data/ext/sha3/digest.h +3 -71
- data/ext/sha3/extconf.rb +14 -8
- data/ext/sha3/kmac.c +474 -0
- data/ext/sha3/kmac.h +14 -0
- data/ext/sha3/sha3.c +35 -0
- data/ext/sha3/sha3.h +17 -0
- data/ext/sha3/sp800_185.c +311 -0
- data/ext/sha3/sp800_185.h +94 -0
- data/lib/constants.rb +5 -0
- data/lib/sha3.rb +28 -24
- data.tar.gz.sig +0 -0
- metadata +22 -21
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0352e31c9fba5b6e692cca78be1860cccf6a008717738ecbea414d83d195b588
|
4
|
+
data.tar.gz: 24f543cfcb6b2d477182912a65b54a09cce5209dcfe6c8dbeec22c3992296cec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a947dc104fa08b9199ed307fd43b3bee24143561aaa9665b4c6dd6a0d20ddbf69194b4eb96b845fd0974dc68d2133d024157c754f5e2835ec6161958df343caa
|
7
|
+
data.tar.gz: 4dd184e53262a9ec71eaf56bf80a295e8d3b691b736333834e5ae9e416df65bbea4ca10c20cc4c22e429bb6ffc97debda126b59bd50f23d732b079c3418b2653
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.clang-format
CHANGED
@@ -1,54 +1,7 @@
|
|
1
|
-
BasedOnStyle: Google
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
1
|
+
BasedOnStyle: Google
|
2
|
+
|
3
|
+
ColumnLimit: 120
|
4
|
+
|
32
5
|
IndentWidth: 4
|
33
|
-
|
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
|
6
|
+
TabWidth: 4
|
54
7
|
UseTab: Never
|
data/.document
CHANGED
data/.rdoc_options
CHANGED
data/.rubocop.yml
CHANGED
data/.vscode/launch.json
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
3
|
+
// Hover to view descriptions of existing attributes.
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
+
"version": "0.2.0",
|
6
|
+
"configurations": [
|
7
|
+
{
|
8
|
+
"name": "(lldb) Attach",
|
9
|
+
"type": "cppdbg",
|
10
|
+
"request": "attach",
|
11
|
+
"program": "/Users/johannsg/.rubies/ruby-3.4.2/bin/ruby",
|
12
|
+
"MIMode": "lldb"
|
13
|
+
},
|
14
|
+
]
|
15
|
+
}
|
data/.vscode/tasks.json
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"tasks": [
|
3
|
+
{
|
4
|
+
"type": "cppbuild",
|
5
|
+
"label": "C/C++: clang build active file",
|
6
|
+
"command": "/usr/bin/clang",
|
7
|
+
"args": [
|
8
|
+
"-fcolor-diagnostics",
|
9
|
+
"-fansi-escape-codes",
|
10
|
+
"-g",
|
11
|
+
"${file}",
|
12
|
+
"-o",
|
13
|
+
"${fileDirname}/${fileBasenameNoExtension}"
|
14
|
+
],
|
15
|
+
"options": {
|
16
|
+
"cwd": "${fileDirname}"
|
17
|
+
},
|
18
|
+
"problemMatcher": [
|
19
|
+
"$gcc"
|
20
|
+
],
|
21
|
+
"group": {
|
22
|
+
"kind": "build",
|
23
|
+
"isDefault": true
|
24
|
+
},
|
25
|
+
"detail": "Task generated by Debugger."
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"version": "2.0.0"
|
29
|
+
}
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# SHA3 Ruby Gem Changelog
|
2
2
|
|
3
|
+
## v2.2.0 (2025-03-15)
|
4
|
+
|
5
|
+
### Features
|
6
|
+
- Added support for cSHAKE
|
7
|
+
|
8
|
+
## v2.1.0 (2025-03-15)
|
9
|
+
|
10
|
+
### Features
|
11
|
+
- Added support for KMAC
|
12
|
+
|
13
|
+
## v2.0.0 (2025-03-15)
|
14
|
+
|
15
|
+
### Features
|
16
|
+
- Added support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
|
17
|
+
|
3
18
|
## v1.0.5 (2022-10-23)
|
4
19
|
|
5
20
|
### Security
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/sha3) [](https://github.com/johanns/sha3/actions/workflows/main.yml)
|
4
4
|
|
5
|
-
A high-performance native binding to the SHA3 (FIPS 202) cryptographic hashing
|
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), cSHAKE128/cSHAKE256, and KMAC (Keccak Message Authentication Code) as specified in NIST SP 800-185.
|
6
8
|
|
7
9
|
> [!CAUTION]
|
8
10
|
> **Security Notice**: Do not use SHA-3 for hashing passwords. Instead, use a slow hashing function such as PBKDF2, Argon2, bcrypt, or scrypt.
|
9
11
|
|
10
12
|
> [!IMPORTANT]
|
11
|
-
> **Breaking Changes**: SHA3 version 2.0 introduces breaking changes
|
12
|
-
> If you need the previous behavior, lock your Gemfile to version '~> 1.0'.
|
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. If you need the previous behavior, lock your Gemfile to version '~> 1.0'.
|
13
14
|
|
14
15
|
## Table of Contents
|
15
16
|
|
@@ -18,9 +19,11 @@ A high-performance native binding to the SHA3 (FIPS 202) cryptographic hashing a
|
|
18
19
|
- [Installation](#installation)
|
19
20
|
- [Usage](#usage)
|
20
21
|
- [SHA-3 Fixed Hash Functions](#sha-3-fixed-hash-functions)
|
21
|
-
- [SHAKE128/256 Functions](#shake128256-functions)
|
22
22
|
- [Alternate Class Syntax](#alternate-class-syntax)
|
23
23
|
- [Hashing a File](#hashing-a-file)
|
24
|
+
- [SHAKE128/256 Functions](#shake128256-functions)
|
25
|
+
- [cSHAKE128/256 Functions](#cshake128256-functions)
|
26
|
+
- [KMAC Functions](#kmac-functions)
|
24
27
|
- [Development](#development)
|
25
28
|
- [Dependencies](#dependencies)
|
26
29
|
- [Testing](#testing)
|
@@ -38,8 +41,10 @@ A high-performance native binding to the SHA3 (FIPS 202) cryptographic hashing a
|
|
38
41
|
|
39
42
|
## Features
|
40
43
|
|
41
|
-
- Full support for all SHA-3 variants (224, 256, 384, and 512
|
44
|
+
- Full support for all SHA-3 variants (224, 256, 384, and 512 bits)
|
42
45
|
- Support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
|
46
|
+
- Support for cSHAKE128 and cSHAKE256 extendable-output functions (XOFs) with domain separation and personalization
|
47
|
+
- Support for KMAC (Keccak Message Authentication Code)
|
43
48
|
- Native C implementation for high performance
|
44
49
|
- Simple, Ruby-friendly API that follows Ruby's standard Digest interface
|
45
50
|
- Comprehensive test suite with official NIST test vectors
|
@@ -50,7 +55,7 @@ A high-performance native binding to the SHA3 (FIPS 202) cryptographic hashing a
|
|
50
55
|
Add this line to your application's Gemfile:
|
51
56
|
|
52
57
|
```ruby
|
53
|
-
gem 'sha3', '~> 2.
|
58
|
+
gem 'sha3', '~> 2.2'
|
54
59
|
```
|
55
60
|
|
56
61
|
And then execute:
|
@@ -96,29 +101,6 @@ Valid algorithm symbols are:
|
|
96
101
|
- `:shake_128` - SHAKE128 extendable-output function
|
97
102
|
- `:shake_256` - SHAKE256 extendable-output function
|
98
103
|
|
99
|
-
### SHAKE128/256 Functions
|
100
|
-
|
101
|
-
SHAKE128 and SHAKE256 are extendable-output functions (XOFs) that allow you to "squeeze" an arbitrary number of bytes from the hash state:
|
102
|
-
|
103
|
-
```ruby
|
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...'
|
109
|
-
|
110
|
-
# Squeeze 120 bytes (240 hex characters) from the hash state
|
111
|
-
result = shake.hex_squeeze(120)
|
112
|
-
|
113
|
-
# Or get binary output
|
114
|
-
binary_result = shake.squeeze(1024)
|
115
|
-
|
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
|
-
```
|
121
|
-
|
122
104
|
### Alternate Class Syntax
|
123
105
|
|
124
106
|
For convenience, you can also use dedicated classes for each algorithm:
|
@@ -150,11 +132,109 @@ digest.hexdigest
|
|
150
132
|
# Compute the hash value for a given file, and return the result as hex
|
151
133
|
hash = SHA3::Digest::SHA3_256.file("my_file.bin").hexdigest
|
152
134
|
|
135
|
+
# Using SHAKE function to generate an arbitrary-length hash output
|
136
|
+
shake = SHA3::Digest::SHAKE_128.file("my_file.bin").hexdigest(320)
|
137
|
+
|
153
138
|
# Calling SHA3::Digest.file(...) defaults to SHA3_256
|
154
139
|
hash = SHA3::Digest.file("my_file.bin").hexdigest
|
155
140
|
# => "a9801db49389339..."
|
156
141
|
```
|
157
142
|
|
143
|
+
### SHAKE128/256 Functions
|
144
|
+
|
145
|
+
SHAKE128 and SHAKE256 are extendable-output functions (XOFs) that allow you to "squeeze" an arbitrary number of bytes from the hash state:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
# Create a new SHAKE128 instance
|
149
|
+
shake = SHA3::Digest::SHAKE_128.new
|
150
|
+
|
151
|
+
# Add data to hash
|
152
|
+
shake << 'Squeeze this data...'
|
153
|
+
|
154
|
+
# Squeeze 120 bytes (240 hex characters) from the hash state
|
155
|
+
result = shake.hex_squeeze(120)
|
156
|
+
|
157
|
+
# Or get binary output
|
158
|
+
binary_result = shake.squeeze(1024)
|
159
|
+
|
160
|
+
# You can call squeeze functions multiple times with arbitrary output lengths
|
161
|
+
first_part = shake.squeeze(32) # Get 32 bytes
|
162
|
+
second_part = shake.squeeze(64) # Get 64 bytes
|
163
|
+
third_part = shake.hex_squeeze(128) # Get 128 bytes as hex
|
164
|
+
```
|
165
|
+
|
166
|
+
### cSHAKE128/256 Functions
|
167
|
+
|
168
|
+
cSHAKE128 and cSHAKE256 are customizable versions of SHAKE128 and SHAKE256, allowing for domain separation and personalization through a customization string.
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
# Create a new cSHAKE instance with a fixed output length
|
172
|
+
cshake = SHA3::CSHAKE.new(:cshake_128, 32, name: 'my-app', customization: 'Email Signature')
|
173
|
+
|
174
|
+
# Add data to hash
|
175
|
+
cshake.update('Hello')
|
176
|
+
# Or use the << operator
|
177
|
+
cshake << 'Compute me...'
|
178
|
+
|
179
|
+
# Get the final hash value as a hex string
|
180
|
+
cshake.hexdigest
|
181
|
+
# => "d6d38021d60857..."
|
182
|
+
|
183
|
+
# Or as a binary string
|
184
|
+
cshake.digest
|
185
|
+
|
186
|
+
# Create a new cSHAKE instance for an arbitrarily-long (XOF) operation
|
187
|
+
cshake = SHA3::CSHAKE.new(:cshake_256, 0, customization: 'Signature')
|
188
|
+
|
189
|
+
# Add data to hash
|
190
|
+
cshake.update('Beep Beep')
|
191
|
+
|
192
|
+
# Squeeze 64-bytes of data from state
|
193
|
+
cshake.squeeze(64)
|
194
|
+
```
|
195
|
+
|
196
|
+
### KMAC Functions
|
197
|
+
|
198
|
+
KMAC (Keccak Message Authentication Code) is a message authentication code algorithm based on the SHAKE extendable-output functions:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
require 'sha3'
|
202
|
+
|
203
|
+
# Create a new KMAC instance with a fixed output length
|
204
|
+
# Parameters: algorithm, output_length (in bytes), key, [customization] optional
|
205
|
+
kmac = SHA3::KMAC.new(:kmac_128, 32, "my secret key", "app-specific customization")
|
206
|
+
|
207
|
+
# Add data to be authenticated (update can be called multiple times)
|
208
|
+
kmac.update("Authenticate this message")
|
209
|
+
# or use the << operator
|
210
|
+
kmac << "And this too"
|
211
|
+
|
212
|
+
# Get the result as a hex string
|
213
|
+
result = kmac.hexdigest
|
214
|
+
# => "a8982c..."
|
215
|
+
|
216
|
+
# Or as binary
|
217
|
+
binary_result = kmac.digest
|
218
|
+
|
219
|
+
# Create a new KMAC instance with an arbitrary-length (XOF) operation
|
220
|
+
kmac = SHA3::KMAC.new(:kmac_256, 0, "my secret key", "app-specific customization")
|
221
|
+
|
222
|
+
# Add data to be authenticated (update can be called multiple times)
|
223
|
+
kmac.update("Authenticate this message")
|
224
|
+
# or use the << operator
|
225
|
+
kmac << "And this too"
|
226
|
+
|
227
|
+
# Get the result as a hex string
|
228
|
+
result = kmac.hex_squeeze(128)
|
229
|
+
|
230
|
+
# Or as binary
|
231
|
+
binary_result = kmac.squeeze(128)
|
232
|
+
|
233
|
+
# One-shot operation (customization is optional)
|
234
|
+
# Parameters: algorithm, data, data, output_length (in bytes),key, [customization] optional
|
235
|
+
result = SHA3::KMAC.hexdigest(:kmac_256, "message", 64, "key", "customization")
|
236
|
+
```
|
237
|
+
|
158
238
|
## Development
|
159
239
|
|
160
240
|
### Dependencies
|
@@ -181,13 +261,16 @@ The test vectors are downloaded only once and cached in the `spec/data` director
|
|
181
261
|
|
182
262
|
### Supported Ruby Versions
|
183
263
|
|
184
|
-
- MRI Ruby 2.7 - 3.
|
264
|
+
- MRI Ruby 2.7 - 3.4
|
185
265
|
|
186
266
|
## Roadmap
|
187
267
|
|
188
|
-
|
189
|
-
|
190
|
-
- [
|
268
|
+
As of version 2.2.0 (2025), this gem is feature complete with a stable API—future updates will focus exclusively on performance improvements, security enhancements, and bug fixes.
|
269
|
+
|
270
|
+
- [X] 0.1.0: Add support for SHA-3 variants (224, 256, 384, and 512 bit)
|
271
|
+
- [X] 2.0.0: Add support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
|
272
|
+
- [X] 2.1.0: Add support for KMAC
|
273
|
+
- [X] 2.2.0: Add support for cSHAKE
|
191
274
|
|
192
275
|
## Contributing
|
193
276
|
|
data/Rakefile
CHANGED
@@ -12,10 +12,11 @@ require 'rake/extensiontask'
|
|
12
12
|
|
13
13
|
begin
|
14
14
|
Rake::ExtensionTask.new :compile do |ext|
|
15
|
-
ext.name = '
|
15
|
+
ext.name = 'sha3_ext'
|
16
|
+
|
16
17
|
ext.ext_dir = 'ext/sha3'
|
17
|
-
ext.tmp_dir = 'tmp'
|
18
18
|
ext.source_pattern = '*.{c}'
|
19
|
+
ext.tmp_dir = 'tmp'
|
19
20
|
end
|
20
21
|
rescue LoadError
|
21
22
|
task :compile do
|
@@ -28,6 +29,7 @@ require 'rdoc/task'
|
|
28
29
|
RDoc::Task.new do |rdoc|
|
29
30
|
rdoc.rdoc_dir = '../docs/sha3'
|
30
31
|
rdoc.options << '--force-update'
|
32
|
+
rdoc.options << '-V'
|
31
33
|
end
|
32
34
|
|
33
35
|
task default: %i[compile spec]
|
data/doc/sha3.rb
CHANGED
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
|