Sha256: c2fe9ea4f225636d05086a1b4998448a880502350b720bd834c3ea0b43e63bb4

Contents?: true

Size: 618 Bytes

Versions: 6

Compression:

Stored size: 618 Bytes

Contents

# frozen_string_literal: true

require 'aead'

module Noise
  module Functions
    module Cipher
      class AesGcm
        def encrypt(k, n, ad, plaintext)
          mode = AEAD::Cipher.new('AES-256-GCM')
          cipher = mode.new(k)
          cipher.encrypt(nonce_to_bytes(n), ad, plaintext)
        end

        def decrypt(k, n, ad, ciphertext)
          mode = AEAD::Cipher.new('AES-256-GCM')
          cipher = mode.new(k)
          cipher.decrypt(nonce_to_bytes(n), ad, ciphertext)
        end

        def nonce_to_bytes(n)
          "\00" * 4 + format('%16x', n).htb
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
noise-ruby-0.5.3 lib/noise/functions/cipher/aes_gcm.rb
noise-ruby-0.5.2 lib/noise/functions/cipher/aes_gcm.rb
noise-ruby-0.5.1 lib/noise/functions/cipher/aes_gcm.rb
noise-ruby-0.5.0 lib/noise/functions/cipher/aes_gcm.rb
noise-ruby-0.3.0 lib/noise/functions/cipher/aes_gcm.rb
noise-ruby-0.2.0 lib/noise/functions/cipher/aes_gcm.rb