Class: MLKEM::Crypto::SymmetricPrimitives
- Inherits:
-
Object
- Object
- MLKEM::Crypto::SymmetricPrimitives
- Defined in:
- lib/ml_kem/crypto/symmetric_primitives.rb
Overview
Provides symmetric cryptographic primitives as defined by ML-KEM (Kyber), including hash functions h, g, j and a pseudorandom function (PRF).
These are used for key derivation, random generation, and message hashing.
Class Method Summary collapse
-
.g(x) ⇒ Array<String>
Hash function g: SHA3-512, split into two 32-byte outputs.
-
.h(x) ⇒ String
Hash function h: SHA3-256.
-
.j(s) ⇒ String
Hash function j: SHAKE256 with 32-byte output.
-
.prf(eta, s, b) ⇒ String
Pseudorandom Function (PRF).
Class Method Details
.g(x) ⇒ Array<String>
Hash function g: SHA3-512, split into two 32-byte outputs.
33 34 35 36 |
# File 'lib/ml_kem/crypto/symmetric_primitives.rb', line 33 def g(x) hash = HashFunctions.sha3_512(x) [hash[0...32], hash[32...64]] end |
.h(x) ⇒ String
Hash function h: SHA3-256
22 23 24 |
# File 'lib/ml_kem/crypto/symmetric_primitives.rb', line 22 def h(x) HashFunctions.sha3_256(x) end |
.j(s) ⇒ String
Hash function j: SHAKE256 with 32-byte output.
45 46 47 |
# File 'lib/ml_kem/crypto/symmetric_primitives.rb', line 45 def j(s) HashFunctions.shake256(s, 32) end |
.prf(eta, s, b) ⇒ String
Pseudorandom Function (PRF)
Uses SHAKE256 to expand ‘s || b` into `eta * 64` bytes of pseudorandom data.
60 61 62 63 |
# File 'lib/ml_kem/crypto/symmetric_primitives.rb', line 60 def prf(eta, s, b) input = s + [b].pack('C*') HashFunctions.shake256(input, eta * 64) end |