sha3 2.1.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 +4 -51
- data/.rubocop.yml +1 -1
- data/.vscode/launch.json +15 -0
- data/.vscode/settings.json +9 -0
- data/.vscode/tasks.json +29 -0
- data/CHANGELOG.md +15 -0
- data/README.md +103 -53
- data/ext/sha3/cshake.c +391 -0
- data/ext/sha3/cshake.h +17 -0
- data/ext/sha3/digest.c +90 -86
- data/ext/sha3/digest.h +2 -5
- data/ext/sha3/extconf.rb +11 -5
- data/ext/sha3/kmac.c +188 -218
- data/ext/sha3/kmac.h +3 -3
- data/ext/sha3/sha3.c +6 -2
- data/ext/sha3/sp800_185.c +311 -0
- data/ext/sha3/sp800_185.h +94 -0
- data/lib/constants.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +12 -5
- 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
|
-
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
|
1
|
+
BasedOnStyle: Google
|
2
|
+
|
23
3
|
ColumnLimit: 120
|
24
|
-
|
25
|
-
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
26
|
-
Cpp11BracedListStyle: true
|
27
|
-
DerivePointerAlignment: false
|
28
|
-
FixNamespaceComments: true
|
29
|
-
IncludeBlocks: Regroup
|
30
|
-
IndentCaseLabels: true
|
31
|
-
IndentPPDirectives: None
|
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/.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/README.md
CHANGED
@@ -4,14 +4,13 @@
|
|
4
4
|
|
5
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
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.
|
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.
|
8
8
|
|
9
9
|
> [!CAUTION]
|
10
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
11
|
|
12
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'.
|
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'.
|
15
14
|
|
16
15
|
## Table of Contents
|
17
16
|
|
@@ -20,10 +19,11 @@ This gem provides support for the standard SHA-3 fixed-length functions (224, 25
|
|
20
19
|
- [Installation](#installation)
|
21
20
|
- [Usage](#usage)
|
22
21
|
- [SHA-3 Fixed Hash Functions](#sha-3-fixed-hash-functions)
|
23
|
-
- [SHAKE128/256 Functions](#shake128256-functions)
|
24
|
-
- [KMAC Functions](#kmac-functions)
|
25
22
|
- [Alternate Class Syntax](#alternate-class-syntax)
|
26
23
|
- [Hashing a File](#hashing-a-file)
|
24
|
+
- [SHAKE128/256 Functions](#shake128256-functions)
|
25
|
+
- [cSHAKE128/256 Functions](#cshake128256-functions)
|
26
|
+
- [KMAC Functions](#kmac-functions)
|
27
27
|
- [Development](#development)
|
28
28
|
- [Dependencies](#dependencies)
|
29
29
|
- [Testing](#testing)
|
@@ -43,6 +43,7 @@ This gem provides support for the standard SHA-3 fixed-length functions (224, 25
|
|
43
43
|
|
44
44
|
- Full support for all SHA-3 variants (224, 256, 384, and 512 bits)
|
45
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
|
46
47
|
- Support for KMAC (Keccak Message Authentication Code)
|
47
48
|
- Native C implementation for high performance
|
48
49
|
- Simple, Ruby-friendly API that follows Ruby's standard Digest interface
|
@@ -54,7 +55,7 @@ This gem provides support for the standard SHA-3 fixed-length functions (224, 25
|
|
54
55
|
Add this line to your application's Gemfile:
|
55
56
|
|
56
57
|
```ruby
|
57
|
-
gem 'sha3', '~> 2.
|
58
|
+
gem 'sha3', '~> 2.2'
|
58
59
|
```
|
59
60
|
|
60
61
|
And then execute:
|
@@ -100,15 +101,54 @@ Valid algorithm symbols are:
|
|
100
101
|
- `:shake_128` - SHAKE128 extendable-output function
|
101
102
|
- `:shake_256` - SHAKE256 extendable-output function
|
102
103
|
|
104
|
+
### Alternate Class Syntax
|
105
|
+
|
106
|
+
For convenience, you can also use dedicated classes for each algorithm:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
# Available classes
|
110
|
+
SHA3::Digest::SHA3_224.new([data])
|
111
|
+
SHA3::Digest::SHA3_256.new([data])
|
112
|
+
SHA3::Digest::SHA3_384.new([data])
|
113
|
+
SHA3::Digest::SHA3_512.new([data])
|
114
|
+
SHA3::Digest::SHAKE_128.new([data])
|
115
|
+
SHA3::Digest::SHAKE_256.new([data])
|
116
|
+
```
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
# Example usage
|
120
|
+
digest = SHA3::Digest::SHA3_256.new('Start here')
|
121
|
+
|
122
|
+
digest << "Compute Me"
|
123
|
+
digest.update("Me too")
|
124
|
+
|
125
|
+
digest.hexdigest
|
126
|
+
# => "bedf0dd9a15b647..."
|
127
|
+
```
|
128
|
+
|
129
|
+
### Hashing a File
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
# Compute the hash value for a given file, and return the result as hex
|
133
|
+
hash = SHA3::Digest::SHA3_256.file("my_file.bin").hexdigest
|
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
|
+
|
138
|
+
# Calling SHA3::Digest.file(...) defaults to SHA3_256
|
139
|
+
hash = SHA3::Digest.file("my_file.bin").hexdigest
|
140
|
+
# => "a9801db49389339..."
|
141
|
+
```
|
142
|
+
|
103
143
|
### SHAKE128/256 Functions
|
104
144
|
|
105
145
|
SHAKE128 and SHAKE256 are extendable-output functions (XOFs) that allow you to "squeeze" an arbitrary number of bytes from the hash state:
|
106
146
|
|
107
147
|
```ruby
|
108
148
|
# Create a new SHAKE128 instance
|
109
|
-
shake = SHA3::Digest.new
|
149
|
+
shake = SHA3::Digest::SHAKE_128.new
|
110
150
|
|
111
|
-
# Add data to
|
151
|
+
# Add data to hash
|
112
152
|
shake << 'Squeeze this data...'
|
113
153
|
|
114
154
|
# Squeeze 120 bytes (240 hex characters) from the hash state
|
@@ -123,6 +163,36 @@ second_part = shake.squeeze(64) # Get 64 bytes
|
|
123
163
|
third_part = shake.hex_squeeze(128) # Get 128 bytes as hex
|
124
164
|
```
|
125
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
|
+
|
126
196
|
### KMAC Functions
|
127
197
|
|
128
198
|
KMAC (Keccak Message Authentication Code) is a message authentication code algorithm based on the SHAKE extendable-output functions:
|
@@ -130,12 +200,14 @@ KMAC (Keccak Message Authentication Code) is a message authentication code algor
|
|
130
200
|
```ruby
|
131
201
|
require 'sha3'
|
132
202
|
|
133
|
-
# Create a new KMAC instance
|
134
|
-
# Parameters: algorithm, output_length (in bytes), key, [customization]
|
203
|
+
# Create a new KMAC instance with a fixed output length
|
204
|
+
# Parameters: algorithm, output_length (in bytes), key, [customization] optional
|
135
205
|
kmac = SHA3::KMAC.new(:kmac_128, 32, "my secret key", "app-specific customization")
|
136
206
|
|
137
|
-
# Add data to be authenticated
|
207
|
+
# Add data to be authenticated (update can be called multiple times)
|
138
208
|
kmac.update("Authenticate this message")
|
209
|
+
# or use the << operator
|
210
|
+
kmac << "And this too"
|
139
211
|
|
140
212
|
# Get the result as a hex string
|
141
213
|
result = kmac.hexdigest
|
@@ -144,47 +216,23 @@ result = kmac.hexdigest
|
|
144
216
|
# Or as binary
|
145
217
|
binary_result = kmac.digest
|
146
218
|
|
147
|
-
#
|
148
|
-
|
149
|
-
```
|
150
|
-
|
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
|
-
```
|
164
|
-
|
165
|
-
```ruby
|
166
|
-
# Example usage
|
167
|
-
digest = SHA3::Digest::SHA3_256.new('Start here')
|
168
|
-
|
169
|
-
digest << "Compute Me"
|
170
|
-
digest.update("Me too")
|
171
|
-
|
172
|
-
digest.hexdigest
|
173
|
-
# => "bedf0dd9a15b647..."
|
174
|
-
```
|
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")
|
175
221
|
|
176
|
-
|
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"
|
177
226
|
|
178
|
-
|
179
|
-
|
180
|
-
hash = SHA3::Digest::SHA3_256.file("my_file.bin").hexdigest
|
227
|
+
# Get the result as a hex string
|
228
|
+
result = kmac.hex_squeeze(128)
|
181
229
|
|
182
|
-
#
|
183
|
-
|
230
|
+
# Or as binary
|
231
|
+
binary_result = kmac.squeeze(128)
|
184
232
|
|
185
|
-
#
|
186
|
-
|
187
|
-
|
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")
|
188
236
|
```
|
189
237
|
|
190
238
|
## Development
|
@@ -213,14 +261,16 @@ The test vectors are downloaded only once and cached in the `spec/data` director
|
|
213
261
|
|
214
262
|
### Supported Ruby Versions
|
215
263
|
|
216
|
-
- MRI Ruby 2.7 - 3.
|
264
|
+
- MRI Ruby 2.7 - 3.4
|
217
265
|
|
218
266
|
## Roadmap
|
219
267
|
|
220
|
-
|
221
|
-
|
222
|
-
- [X] Add support for
|
223
|
-
- [
|
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
|
224
274
|
|
225
275
|
## Contributing
|
226
276
|
|