Class: Bitcoin::BIP324::FSChaCha20Poly1305
- Inherits:
-
Object
- Object
- Bitcoin::BIP324::FSChaCha20Poly1305
- Defined in:
- lib/bitcoin/bip324/fs_chacha_poly1305.rb
Overview
Forward-secure wrapper around AEADChaCha20Poly1305.
Instance Attribute Summary collapse
-
#aead ⇒ Object
Returns the value of attribute aead.
-
#key ⇒ Object
Returns the value of attribute key.
-
#packet_counter ⇒ Object
Returns the value of attribute packet_counter.
-
#rekey_interval ⇒ Object
readonly
Returns the value of attribute rekey_interval.
Instance Method Summary collapse
-
#decrypt(aad, ciphertext) ⇒ Array
Decrypt a ciphertext with a specified
aad
. -
#encrypt(aad, plaintext) ⇒ String
Encrypt a
plaintext
with a specifiedaad
. -
#initialize(initial_key, rekey_interval = REKEY_INTERVAL) ⇒ FSChaCha20Poly1305
constructor
A new instance of FSChaCha20Poly1305.
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
#aead ⇒ Object
Returns the value of attribute aead.
43 44 45 |
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 43 def aead @aead end |
#key ⇒ Object
Returns the value of attribute key.
46 47 48 |
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 46 def key @key end |
#packet_counter ⇒ Object
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_interval ⇒ Object (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
.
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
.
58 59 60 |
# File 'lib/bitcoin/bip324/fs_chacha_poly1305.rb', line 58 def encrypt(aad, plaintext) crypt(aad, plaintext, false) end |