Sha256: a4f8ed69fa38aeaf6ec412c216ca201956632139ca1a086ccf44471c5d40a2a6

Contents?: true

Size: 714 Bytes

Versions: 10

Compression:

Stored size: 714 Bytes

Contents

require 'aead/cipher'
require 'aead/cipher/aes_hmac'

require 'securerandom'

#
# Encrypt plaintext using the CTR mode of AES and authenticate the
# result with HMAC-SHA-256.
#
class AEAD::Cipher::AES_256_CTR_HMAC_SHA_256 < AEAD::Cipher
  include AEAD::Cipher::AES_HMAC

  def self.key_len;   64; end
  def self.iv_len;    16; end
  def self.nonce_len; 16; end
  def self.tag_len;   32; end

  def self.encryption_key_len; 32; end
  def self.signing_key_len;    32; end

  def self.cipher_mode; 'aes-256-ctr'; end
  def self.digest_mode; 'SHA256'; end

  #
  # CBC requires non-range-overlapped IVs, and random numbers suffice.
  #
  def self.generate_nonce
    SecureRandom.random_bytes(self.nonce_len)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
aead-1.8.1 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.8.0 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.7.1 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.7.0 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.6.2 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.6.1 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.5.1 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.5.0 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.3.1 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb
aead-1.3.0 lib/aead/cipher/aes_256_ctr_hmac_sha_256.rb