Class: Miscreant::STREAM::Decryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/miscreant/stream.rb

Overview

A STREAM decryptor

This corresponds to the ???? stream decryptor object as defined in the paper Online Authenticated-Encryption and its Nonce-Reuse Misuse-Resistance

Instance Method Summary collapse

Constructor Details

#initialize(alg, key, nonce) ⇒ Decryptor

Create a new STREAM decryptor.

Parameters:

  • alg ("AES-SIV", "AES-PMAC-SIV")

    cryptographic algorithm to use

  • key (String)

    32-byte or 64-byte random Encoding::BINARY secret key

  • nonce (String)

    8-byte nonce

Raises:

  • (TypeError)

    nonce is not a String

  • (ArgumentError)

    nonce is wrong length or not Encoding::BINARY



73
74
75
76
# File 'lib/miscreant/stream.rb', line 73

def initialize(alg, key, nonce)
  @aead = AEAD.new(alg, key)
  @nonce_encoder = NonceEncoder.new(nonce)
end

Instance Method Details

#inspectString

Inspect this STREAM encryptor instance

Returns:

  • (String)

    description of this instance



93
94
95
# File 'lib/miscreant/stream.rb', line 93

def inspect
  to_s
end

#open(ciphertext, ad: "", last_block: false) ⇒ String

Decrypt the next message in the stream

Parameters:

  • ciphertext (String)

    cipher message to encrypt

  • ad (String) (defaults to: "")

    (optional) associated data to authenticate

  • last_block (true, false) (defaults to: false)

    is this the last block in the STREAM?

Returns:

  • (String)

    plaintext message

Raises:



86
87
88
# File 'lib/miscreant/stream.rb', line 86

def open(ciphertext, ad: "", last_block: false)
  @aead.open(ciphertext, nonce: @nonce_encoder.next(last_block), ad: ad)
end