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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c29bcfb557e028701b34ce0d2be3cdbec41882e45cedcb2f129e874bbb3867e5
4
- data.tar.gz: 12c260b599a433def09b389d0cd39e72ebe2dae4e495979235aece99f2684e25
3
+ metadata.gz: de8b62510dacd92d85961808033747000eaed0b5866ed33e1d51599a9ce03b17
4
+ data.tar.gz: dc36181bd1095ab54c2574fba9fde0c37fd011d256067325abadb3bbb734b1da
5
5
  SHA512:
6
- metadata.gz: 1be97184feef60e8340b6dd009f5c8eabcc6b2b72b050d2a3f08ef93d9c11184c7a9c1246f2cf241ef62d47fc13b96a62bab8b61002001b04942162dc9a7dd82
7
- data.tar.gz: ca4d24baf5cda13fb0f071640875a16182aa234dca43b85d5d81e05ec80a9d3d1ea89b98b0f7f6a621d6395e6647472ef131c9dd2979f942556137108079ca80
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: 100
23
+ ColumnLimit: 120
24
24
  CompactNamespaces: false
25
25
  ConstructorInitializerAllOnOneLineOrOnePerLine: true
26
26
  Cpp11BracedListStyle: true
data/.document CHANGED
@@ -1,5 +1,4 @@
1
1
  README.md
2
2
  LICENSE.txt
3
- lib/**/*.rb
4
- ext/sha3/digest.{c,h}
5
3
  doc/**/*.rb
4
+ ext/sha3/*.c
data/.rdoc_options CHANGED
@@ -5,6 +5,7 @@ title: SHA3
5
5
  charset: UTF-8
6
6
  encoding: UTF-8
7
7
  force_update: true
8
+ line_numbers: true
8
9
  markup: rdoc
9
10
  op_dir: html
10
11
  visibility: :private
data/.rubocop.yml CHANGED
@@ -8,3 +8,6 @@ AllCops:
8
8
 
9
9
  Layout/LineLength:
10
10
  Max: 120
11
+
12
+ Naming/VariableNumber:
13
+ Enabled: false
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gemspec
6
6
 
7
7
  group :development, :test do
8
8
  gem 'irb'
9
+ gem 'rdoc', '~> 6'
9
10
 
10
11
  gem 'rake', '~> 13'
11
12
  gem 'rake-compiler', '~> 1'
data/README.md CHANGED
@@ -2,13 +2,15 @@
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
- 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).
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 to the API. Please review the changelog and ensure compatibility with your application.
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 bit)
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
- - [ ] Add support for cSHAKE, TurboSHANKE, and KMAC
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 = 'sha3_digest'
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SHA3
2
4
  module Digest
3
5
  # SHA3_224 is a cryptographic hash function that produces a 224-bit (28-byte) hash value.
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