Module: PQCrypto::HybridKEM

Defined in:
lib/pq_crypto/hybrid_kem.rb

Defined Under Namespace

Classes: EncapsulationResult, Keypair, PublicKey, SecretKey

Constant Summary collapse

CANONICAL_ALGORITHM =
:ml_kem_768_x25519_hkdf_sha256
DETAILS =
{
  CANONICAL_ALGORITHM => {
    name: CANONICAL_ALGORITHM,
    family: Serialization.algorithm_to_family(CANONICAL_ALGORITHM),
    oid: Serialization.algorithm_to_oid(CANONICAL_ALGORITHM),
    public_key_bytes: HYBRID_KEM_PUBLIC_KEY_BYTES,
    secret_key_bytes: HYBRID_KEM_SECRET_KEY_BYTES,
    ciphertext_bytes: HYBRID_KEM_CIPHERTEXT_BYTES,
    shared_secret_bytes: HYBRID_KEM_SHARED_SECRET_BYTES,
    description: "Hybrid KEM: ML-KEM-768 + X25519 combined via transcript-bound HKDF-SHA256.",
  }.freeze,
}.freeze

Class Method Summary collapse

Class Method Details

.details(algorithm) ⇒ Object



55
56
57
# File 'lib/pq_crypto/hybrid_kem.rb', line 55

def details(algorithm)
  DETAILS.fetch(resolve_algorithm!(algorithm)).dup
end

.generate(algorithm = CANONICAL_ALGORITHM) ⇒ Object



21
22
23
24
25
# File 'lib/pq_crypto/hybrid_kem.rb', line 21

def generate(algorithm = CANONICAL_ALGORITHM)
  algorithm = resolve_algorithm!(algorithm)
  public_key, secret_key = PQCrypto.__send__(:native_hybrid_kem_keypair)
  Keypair.new(PublicKey.new(algorithm, public_key), SecretKey.new(algorithm, secret_key))
end

.public_key_from_bytes(algorithm, bytes) ⇒ Object



27
28
29
# File 'lib/pq_crypto/hybrid_kem.rb', line 27

def public_key_from_bytes(algorithm, bytes)
  PublicKey.new(resolve_algorithm!(algorithm), bytes)
end

.public_key_from_pqc_container_der(der, algorithm = nil) ⇒ Object



35
36
37
38
# File 'lib/pq_crypto/hybrid_kem.rb', line 35

def public_key_from_pqc_container_der(der, algorithm = nil)
  resolved_algorithm, bytes = Serialization.public_key_from_pqc_container_der(algorithm, der)
  PublicKey.new(resolve_algorithm!(resolved_algorithm), bytes)
end

.public_key_from_pqc_container_pem(pem, algorithm = nil) ⇒ Object



40
41
42
43
# File 'lib/pq_crypto/hybrid_kem.rb', line 40

def public_key_from_pqc_container_pem(pem, algorithm = nil)
  resolved_algorithm, bytes = Serialization.public_key_from_pqc_container_pem(algorithm, pem)
  PublicKey.new(resolve_algorithm!(resolved_algorithm), bytes)
end

.secret_key_from_bytes(algorithm, bytes) ⇒ Object



31
32
33
# File 'lib/pq_crypto/hybrid_kem.rb', line 31

def secret_key_from_bytes(algorithm, bytes)
  SecretKey.new(resolve_algorithm!(algorithm), bytes)
end

.secret_key_from_pqc_container_der(der, algorithm = nil) ⇒ Object



45
46
47
48
# File 'lib/pq_crypto/hybrid_kem.rb', line 45

def secret_key_from_pqc_container_der(der, algorithm = nil)
  resolved_algorithm, bytes = Serialization.secret_key_from_pqc_container_der(algorithm, der)
  SecretKey.new(resolve_algorithm!(resolved_algorithm), bytes)
end

.secret_key_from_pqc_container_pem(pem, algorithm = nil) ⇒ Object



50
51
52
53
# File 'lib/pq_crypto/hybrid_kem.rb', line 50

def secret_key_from_pqc_container_pem(pem, algorithm = nil)
  resolved_algorithm, bytes = Serialization.secret_key_from_pqc_container_pem(algorithm, pem)
  SecretKey.new(resolve_algorithm!(resolved_algorithm), bytes)
end

.supportedObject



59
60
61
# File 'lib/pq_crypto/hybrid_kem.rb', line 59

def supported
  DETAILS.keys.dup
end