Class: Bitcoin::BIP324::FSChaCha20

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

Overview

Rekeying wrapper stream cipher around ChaCha20.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_key, rekey_interval = BIP324::REKEY_INTERVAL) ⇒ FSChaCha20

Returns a new instance of FSChaCha20.



80
81
82
83
84
85
86
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 80

def initialize(initial_key, rekey_interval = BIP324::REKEY_INTERVAL)
  @block_counter = 0
  @chunk_counter = 0
  @key = initial_key
  @rekey_interval = rekey_interval
  @key_stream = ''
end

Instance Attribute Details

#block_counterObject

Returns the value of attribute block_counter.



77
78
79
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 77

def block_counter
  @block_counter
end

#chunk_counterObject

Returns the value of attribute chunk_counter.



76
77
78
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 76

def chunk_counter
  @chunk_counter
end

#keyObject

Returns the value of attribute key.



74
75
76
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 74

def key
  @key
end

#key_streamObject

Returns the value of attribute key_stream.



78
79
80
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 78

def key_stream
  @key_stream
end

#rekey_intervalObject (readonly)

Returns the value of attribute rekey_interval.



75
76
77
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 75

def rekey_interval
  @rekey_interval
end

Instance Method Details

#decrypt(chunk) ⇒ String

Decrypt a chunk

Parameters:

  • chunk (String)

    Chunk data with binary format.

Returns:

  • (String)

    Decrypted data with binary format.



98
99
100
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 98

def decrypt(chunk)
  crypt(chunk)
end

#encrypt(chunk) ⇒ String

Encrypt a chunk

Parameters:

  • chunk (String)

    Chunk data with binary format.

Returns:

  • (String)

    Encrypted data with binary format.



91
92
93
# File 'lib/bitcoin/bip324/fs_chacha20.rb', line 91

def encrypt(chunk)
  crypt(chunk)
end