Class: MLKEM::Crypto::HashFunctions

Inherits:
Object
  • Object
show all
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.

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.sha3_256(data) ⇒ String

Computes the SHA3-256 hash of the given data.

Examples:

digest = HashFunctions.sha3_256("message")

Parameters:

  • data (String)

    Input byte string.

Returns:

  • (String)

    32-byte hash digest.

Since:

  • 0.1.0



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.

Examples:

digest = HashFunctions.sha3_512("message")

Parameters:

  • data (String)

    Input byte string.

Returns:

  • (String)

    64-byte hash digest.

Since:

  • 0.1.0



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).

Examples:

out = HashFunctions.shake128("seed", 32)

Parameters:

  • data (String)

    Input byte string.

  • length (Integer)

    Number of output bytes to produce.

Returns:

  • (String)

    XOF output of the specified length.

Since:

  • 0.1.0



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).

Examples:

out = HashFunctions.shake256("key", 64)

Parameters:

  • data (String)

    Input byte string.

  • length (Integer)

    Number of output bytes to produce.

Returns:

  • (String)

    XOF output of the specified length.

Since:

  • 0.1.0



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