class Lightning::Onion::ChaCha20::OpenSSL

Public Class Methods

chacha20_encrypt(key, counter, nonce, plaintext) click to toggle source
# File lib/lightning/onion/chacha20/openssl.rb, line 7
def self.chacha20_encrypt(key, counter, nonce, plaintext)
  cipher = ::OpenSSL::Cipher.new("ChaCha20")
  cipher.encrypt
  cipher.iv = [counter].pack('V*') + nonce
  cipher.key = key
  cipher.update(plaintext) + cipher.final
end