Issue #6980 has been updated by MartinBosslet (Martin Bosslet).


Thanks again, Stephen! I changed the interface a bit to make it possible to support CCM mode as well once it will be available through the EVP interface. Instead of Cipher#gcm_tag, it is now called Cipher#auth_tag. Because of this change, I also made it Cipher#auth_data=, to indicate that both belong together conceptually.

I also omitted the additional Cipher#verify method, since tag verification will be performed during the call to Cipher#final. I didn't want to introduce an additional method - this way the overall Cipher interface stays coherent.
----------------------------------------
Feature #6980: OpenSSL support for AEAD additional authenticated data and tags
https://bugs.ruby-lang.org/issues/6980#change-34887

Author: stouset (Stephen Touset)
Status: Closed
Priority: High
Assignee: MartinBosslet (Martin Bosslet)
Category: ext
Target version: 2.0.0


=begin
I've added support to OpenSSL::Cipher to support AEAD modes of operation. AEAD modes allow for plaintext additional authentication data to be combined with a ciphertext to generate a "tag" (e.g., a MAC). This tag can then be verified during decryption to ensure the secret key, nonce (IV), additional authentication data, ciphertext, and tag have not been changed or manipulated.

Usage can be inferred through documentation and tests.

  
 cipher = OpenSSL::Cipher.new('aes-256-gcm')
 cipher.encrypt
 cipher.key = 'key'
 cipher.iv = 'iv'
 cipher.aad = 'aad'
  
 ct = cipher.update('plain')
 tag = cipher.gcm_tag
 
 cipher.reset
 cipher.decrypt
 cipher.key = 'key'
 cipher.iv = 'iv'
 cipher.gcm_tag = 'tag'
 cipher.aad = 'aad'

 cipher.update(ct) + cipher.verify + cipher.final # => 'plain'

 cipher.reset
 cipher.decrypt
 cipher.key = 'key'
 cipher.iv = 'iv'
 cipher.gcm_tag = 'tag'
 cipher.aad = 'aad'

 cipher.update(ct[0..-2] << ct[-1].succ) + cipher.verify + cipherfinal # => OpenSSL::Cipher::CipherError
=end


-- 
http://bugs.ruby-lang.org/