Class: XStream::X25519HKDF::Decryptor

Inherits:
Miscreant::STREAM::Decryptor
  • Object
show all
Defined in:
lib/xstream/x25519hkdf.rb

Overview

XSTREAM decryptor class with X25519+HKDF key derivation

Instance Method Summary collapse

Constructor Details

#initialize(private_key, ephemeral_public, encryption_alg: "AES-PMAC-SIV", digest_alg: "SHA-256", salt: nil) ⇒ Decryptor

Create an XSTREAM decryptor object using our private key and an ephemeral public key

Parameters:

  • private_key (String)

    32-byte X25519 private key (i.e. private scalar)

  • ephemeral_public (String)

    32-byte X25519 ephemeral public key from XSTREAM encryption

  • encryption_alg (String) (defaults to: "AES-PMAC-SIV")

    symmetric encryption algorithm to use with STREAM (default '"AES-PMAC-SIV"`)

  • digest_alg (String) (defaults to: "SHA-256")

    digest algorithm to use with HKDF (default '"SHA256"`)

  • salt (String) (defaults to: nil)

    (optional) salt value to pass to HKDF



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/xstream/x25519hkdf.rb', line 56

def initialize(
    private_key,
    ephemeral_public,
    encryption_alg: "AES-PMAC-SIV",
    digest_alg: "SHA-256",
    salt: nil
)
  # Perform an X25519 elliptic curve Diffie-Hellman operation and use
  # the resulting shared secret to derive a symmetric key (using HKDF)
  symmetric_key = X25519HKDF.kdf(
    private_key,
    ephemeral_public,
    salt: salt,
    digest_alg: digest_alg,
    output_size: SYMMETRIC_KEY_SIZE
  )

  super(encryption_alg, symmetric_key, XStream::NONCE)
end