Sha256: 336901753c3eac31fd4984ff8707e8615af16c197a8d737262dffce41c5f6039

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

# encoding: binary
# frozen_string_literal: true

module RbNaCl
  module AEAD
    # This class contains wrappers for the IETF implementation of
    # Authenticated Encryption with Additional Data using ChaCha20-Poly1305
    class ChaCha20Poly1305IETF < RbNaCl::AEAD::Base
      extend Sodium
      if Sodium::Version.supported_version?("1.0.9")
        sodium_type :aead
        sodium_primitive :chacha20poly1305_ietf

        sodium_constant :KEYBYTES
        sodium_constant :NPUBBYTES
        sodium_constant :ABYTES

        sodium_function :aead_chacha20poly1305_ietf_encrypt,
                        :crypto_aead_chacha20poly1305_ietf_encrypt,
                        [:pointer, :pointer, :pointer, :ulong_long, :pointer, :ulong_long, :pointer, :pointer, :pointer]

        sodium_function :aead_chacha20poly1305_ietf_decrypt,
                        :crypto_aead_chacha20poly1305_ietf_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_ietf_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_ietf_decrypt(message, message_len, nil,
                                                        ciphertext, data_len(ciphertext),
                                                        additional_data, data_len(additional_data),
                                                        nonce, @key)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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