Class: MLKEM::Crypto::HashFunctions
- Inherits:
-
Object
- Object
- MLKEM::Crypto::HashFunctions
- Defined in:
- lib/ml_kem/crypto/hash_functions.rb
Overview
Provides cryptographic hash functions used in ML-KEM (Kyber), including SHAKE128, SHAKE256, SHA3-256, and SHA3-512.
Class Method Summary collapse
-
.sha3_256(data) ⇒ String
Computes the SHA3-256 hash of the given data.
-
.sha3_512(data) ⇒ String
Computes the SHA3-512 hash of the given data.
-
.shake128(data, length) ⇒ String
Computes the SHAKE128 extendable-output function (XOF).
-
.shake256(data, length) ⇒ String
Computes the SHAKE256 extendable-output function (XOF).
Class Method Details
.sha3_256(data) ⇒ String
Computes the SHA3-256 hash of the given data.
53 54 55 56 57 |
# File 'lib/ml_kem/crypto/hash_functions.rb', line 53 def sha3_256(data) digest = SHA3::Digest.new(:sha3_256) digest.update(data) digest.digest end |
.sha3_512(data) ⇒ String
Computes the SHA3-512 hash of the given data.
66 67 68 69 70 |
# File 'lib/ml_kem/crypto/hash_functions.rb', line 66 def sha3_512(data) digest = SHA3::Digest.new(:sha3_512) digest.update(data) digest.digest end |
.shake128(data, length) ⇒ String
Computes the SHAKE128 extendable-output function (XOF).
26 27 28 29 30 |
# File 'lib/ml_kem/crypto/hash_functions.rb', line 26 def shake128(data, length) shake = SHA3::Digest::SHAKE_128.new shake << data shake.squeeze(length) end |
.shake256(data, length) ⇒ String
Computes the SHAKE256 extendable-output function (XOF).
40 41 42 43 44 |
# File 'lib/ml_kem/crypto/hash_functions.rb', line 40 def shake256(data, length) shake = SHA3::Digest::SHAKE_256.new shake << data shake.squeeze(length) end |