sha3 2.0.0 → 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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.clang-format +1 -1
- data/.document +1 -2
- data/.rdoc_options +1 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +1 -0
- data/README.md +37 -4
- data/Rakefile +4 -2
- data/doc/sha3.rb +2 -0
- data/ext/sha3/config.h +2 -2
- data/ext/sha3/digest.c +296 -211
- data/ext/sha3/digest.h +1 -66
- data/ext/sha3/extconf.rb +3 -3
- data/ext/sha3/kmac.c +504 -0
- data/ext/sha3/kmac.h +14 -0
- data/ext/sha3/sha3.c +31 -0
- data/ext/sha3/sha3.h +17 -0
- data/lib/constants.rb +5 -0
- data/lib/sha3.rb +28 -24
- data.tar.gz.sig +0 -0
- metadata +15 -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: de8b62510dacd92d85961808033747000eaed0b5866ed33e1d51599a9ce03b17
|
4
|
+
data.tar.gz: dc36181bd1095ab54c2574fba9fde0c37fd011d256067325abadb3bbb734b1da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8f86426fd9b7ecb187eb3b75cbf0b9d574cfc6e6bda0370c25e4b9d8b1ccf33a45427b7c5a0e16b7f7e6ff0c9c5b8d2b556fa409d9890ed5c67c261c734c770
|
7
|
+
data.tar.gz: 8c670be3e5adadc174a164a757aec0e326b26633737c52a8c1f8e41dc3f69f9dc44be9ad077dc22e7ce6742a0313f89151d5ec7135958cde0ccc2a59173f2cea
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.clang-format
CHANGED
@@ -20,7 +20,7 @@ BinPackArguments: true
|
|
20
20
|
BinPackParameters: true
|
21
21
|
BreakBeforeBraces: Attach
|
22
22
|
BreakBeforeTernaryOperators: true
|
23
|
-
ColumnLimit:
|
23
|
+
ColumnLimit: 120
|
24
24
|
CompactNamespaces: false
|
25
25
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
26
26
|
Cpp11BracedListStyle: true
|
data/.document
CHANGED
data/.rdoc_options
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,13 +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) 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
|
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.
|
12
14
|
> If you need the previous behavior, lock your Gemfile to version '~> 1.0'.
|
13
15
|
|
14
16
|
## Table of Contents
|
@@ -19,6 +21,7 @@ A high-performance native binding to the SHA3 (FIPS 202) cryptographic hashing a
|
|
19
21
|
- [Usage](#usage)
|
20
22
|
- [SHA-3 Fixed Hash Functions](#sha-3-fixed-hash-functions)
|
21
23
|
- [SHAKE128/256 Functions](#shake128256-functions)
|
24
|
+
- [KMAC Functions](#kmac-functions)
|
22
25
|
- [Alternate Class Syntax](#alternate-class-syntax)
|
23
26
|
- [Hashing a File](#hashing-a-file)
|
24
27
|
- [Development](#development)
|
@@ -38,8 +41,9 @@ 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 KMAC (Keccak Message Authentication Code)
|
43
47
|
- Native C implementation for high performance
|
44
48
|
- Simple, Ruby-friendly API that follows Ruby's standard Digest interface
|
45
49
|
- Comprehensive test suite with official NIST test vectors
|
@@ -119,6 +123,31 @@ second_part = shake.squeeze(64) # Get 64 bytes
|
|
119
123
|
third_part = shake.hex_squeeze(128) # Get 128 bytes as hex
|
120
124
|
```
|
121
125
|
|
126
|
+
### KMAC Functions
|
127
|
+
|
128
|
+
KMAC (Keccak Message Authentication Code) is a message authentication code algorithm based on the SHAKE extendable-output functions:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
require 'sha3'
|
132
|
+
|
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")
|
136
|
+
|
137
|
+
# Add data to be authenticated
|
138
|
+
kmac.update("Authenticate this message")
|
139
|
+
|
140
|
+
# Get the result as a hex string
|
141
|
+
result = kmac.hexdigest
|
142
|
+
# => "a8982c..."
|
143
|
+
|
144
|
+
# Or as binary
|
145
|
+
binary_result = kmac.digest
|
146
|
+
|
147
|
+
# One-shot operation
|
148
|
+
result = SHA3::KMAC.hexdigest(:kmac_256, "message", 64, "key", "customization")
|
149
|
+
```
|
150
|
+
|
122
151
|
### Alternate Class Syntax
|
123
152
|
|
124
153
|
For convenience, you can also use dedicated classes for each algorithm:
|
@@ -150,6 +179,9 @@ digest.hexdigest
|
|
150
179
|
# Compute the hash value for a given file, and return the result as hex
|
151
180
|
hash = SHA3::Digest::SHA3_256.file("my_file.bin").hexdigest
|
152
181
|
|
182
|
+
# Using SHAKE function to squeeze an arbitrary number of bytes
|
183
|
+
shake = SHA3::Digest::SHAKE_128.file("my_file.bin").hexdigest(320)
|
184
|
+
|
153
185
|
# Calling SHA3::Digest.file(...) defaults to SHA3_256
|
154
186
|
hash = SHA3::Digest.file("my_file.bin").hexdigest
|
155
187
|
# => "a9801db49389339..."
|
@@ -187,7 +219,8 @@ The test vectors are downloaded only once and cached in the `spec/data` director
|
|
187
219
|
|
188
220
|
- [X] Add support for SHA-3 variants (224, 256, 384, and 512 bit)
|
189
221
|
- [X] Add support for SHAKE128 and SHAKE256 extendable-output functions (XOFs)
|
190
|
-
- [
|
222
|
+
- [X] Add support for KMAC
|
223
|
+
- [ ] Add support for cSHAKE
|
191
224
|
|
192
225
|
## Contributing
|
193
226
|
|
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
|