Sha256: 0dc522e088a2ae56fce1c23a9cb9413655a29ef587937616f46780ce1f0b896e

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

# encoding: binary
# frozen_string_literal: true

module RbNaCl
  module AEAD
    # This class contains wrappers for the original libsodium implementation of
    # Authenticated Encryption with Additional Data using ChaCha20-Poly1305
    class ChaCha20Poly1305Legacy < RbNaCl::AEAD::Base
      extend Sodium

      sodium_type :aead
      sodium_primitive :chacha20poly1305
      sodium_constant :KEYBYTES
      sodium_constant :NPUBBYTES
      sodium_constant :ABYTES

      sodium_function :aead_chacha20poly1305_encrypt,
                      :crypto_aead_chacha20poly1305_encrypt,
                      [:pointer, :pointer, :pointer, :ulong_long, :pointer, :ulong_long, :pointer, :pointer, :pointer]

      sodium_function :aead_chacha20poly1305_decrypt,
                      :crypto_aead_chacha20poly1305_decrypt,
                      [:pointer, :pointer, :pointer, :pointer, :ulong_long, :pointer, :ulong_long, :pointer, :pointer]

      private

      def do_encrypt(ciphertext, ciphertext_len, nonce, message, additional_data)
        self.class.aead_chacha20poly1305_encrypt(ciphertext, ciphertext_len,
                                                 message, data_len(message),
                                                 additional_data, data_len(additional_data),
                                                 nil, nonce, @key)
      end

      def do_decrypt(message, message_len, nonce, ciphertext, additional_data)
        self.class.aead_chacha20poly1305_decrypt(message, message_len, nil,
                                                 ciphertext, data_len(ciphertext),
                                                 additional_data, data_len(additional_data),
                                                 nonce, @key)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rbnacl-5.0.0 lib/rbnacl/aead/chacha20poly1305_legacy.rb
rbnacl-4.0.2 lib/rbnacl/aead/chacha20poly1305_legacy.rb
rbnacl-4.0.1 lib/rbnacl/aead/chacha20poly1305_legacy.rb