Class: Bitcoin::BIP324::FSChaCha20Poly1305

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/bip324/fs_chacha_poly1305.rb

Overview

Forward-secure wrapper around AEADChaCha20Poly1305.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_key, rekey_interval = REKEY_INTERVAL) ⇒ FSChaCha20Poly1305

Returns a new instance of FSChaCha20Poly1305.



48
49
50
51
52
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 48

def initialize(initial_key, rekey_interval = REKEY_INTERVAL)
  @packet_counter = 0
  @rekey_interval = rekey_interval
  @key = initial_key
end

Instance Attribute Details

#aeadObject

Returns the value of attribute aead.



43
44
45
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 43

def aead
  @aead
end

#keyObject

Returns the value of attribute key.



46
47
48
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 46

def key
  @key
end

#packet_counterObject

Returns the value of attribute packet_counter.



45
46
47
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 45

def packet_counter
  @packet_counter
end

#rekey_intervalObject (readonly)

Returns the value of attribute rekey_interval.



44
45
46
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 44

def rekey_interval
  @rekey_interval
end

Instance Method Details

#decrypt(aad, ciphertext) ⇒ Array

Decrypt a ciphertext with a specified aad.

Parameters:

  • aad (String)

    AAD

  • ciphertext (String)

    Data to be decrypted with binary format.

Returns:

  • (Array)
    header, plaintext


66
67
68
69
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 66

def decrypt(aad, ciphertext)
  contents = crypt(aad, ciphertext, true)
  [contents[0], contents[1..-1]]
end

#encrypt(aad, plaintext) ⇒ String

Encrypt a plaintext with a specified aad.

Parameters:

  • aad (String)

    AAD

  • plaintext (String)

    Data to be encrypted with binary format.

Returns:



58
59
60
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 58

def encrypt(aad, plaintext)
  crypt(aad, plaintext, false)
end