Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish adding support for AES-CCM mode #569

Closed
wants to merge 1 commit into from

Conversation

louismullie
Copy link

Currently, only the GCM mode of authenticated encryption is supported in Ruby. This patch adds support for the CCM mode of authenticated encryption. It also adds support for explicitly setting IV length, which is required by OpenSSL when dealing with non-standard IV lengths in CCM mode. See https://bugs.ruby-lang.org/issues/9642 for more information.

More details:

  • Add #ossl_is_ccm macro for AES-128-CCM, AES-192-CCM and AES-256-CCM
  • Modify OpenSSL::Cipher#authenticated? to return true for CCM modes
  • Add ossl_ccm_set_auth_tag and ossl_ccm_get_auth_tag methods
  • Modify OpenSSL::Cipher#auth_tag and OpenSSL::Cipher#auth_tag= to
    support CCM
  • Add OpenSSL::Cipher#iv_len= method to support non-standard CCM IV
    lengths
  • Add some documentation on how to use non-standard CCM IV lengths

- Add #ossl_is_ccm macro for AES-128-CCM, AES-192-CCM and AES-256-CCM
- Modify OpenSSL::Cipher#authenticated? to return true for CCM modes
- Add ossl_ccm_set_auth_tag and ossl_ccm_get_auth_tag methods
- Modify OpenSSL::Cipher#auth_tag and OpenSSL::Cipher#auth_tag= to
support CCM
- Add OpenSSL::Cipher#iv_len= method to support non-standard CCM IV
lengths
- Add some documentation on how to use non-standard CCM IV lengths
@louismullie
Copy link
Author

Does anyone have pointers as to what is missing for this PR to be considered for inclusion?

@zzak
Copy link
Member

zzak commented Apr 3, 2014

@louismullie This needs approval of @emboss

@louismullie
Copy link
Author

@zzak @emboss Any updates on this?

@hsbt
Copy link
Member

hsbt commented Jan 2, 2015

@nahi Can you review this?

@zzak
Copy link
Member

zzak commented Nov 13, 2015

I'm not sold on this patch, and releasing "as-is" is taking priority at the moment.

I also think making iv_len public might be a bad decision.

@rhenium
Copy link
Member

rhenium commented Jun 11, 2016

OpenSSL needs to know the plaintext length before setting the AAD or starting encrypting. So if we want support AES-CCM in OpenSSL::Cipher, we need another method #plaintext_len=, and of course this is a very bad idea.

rhenium added a commit to rhenium/ruby-openssl that referenced this pull request Jul 3, 2016
Add OpenSSL::Cipher#iv_len=. For interoperability with other
applications, it is sometimes required. Normally 'IV' is fixed-length,
but in OpenSSL, some ciphers such as aes-128-gcm make use of it as
'nonce', which is variable-length.

Changing the IV length in Cipher#iv= is also an option but I decided not
to choose it. Because in Ruby <= 2.3 Cipher#iv= truncates the input when
the length is longer than the current IV length, changing the behavior
might cause unexpected encryption result.

[Bug #8667] [Bug #10420] [GH ruby/ruby#569]
rhenium added a commit to rhenium/ruby-openssl that referenced this pull request Jul 9, 2016
Add OpenSSL::Cipher#iv_len=. For interoperability with other
applications, it is sometimes required. Normally 'IV' is fixed-length,
but in OpenSSL, some ciphers such as aes-128-gcm make use of it as
'nonce', which is variable-length.

Changing the IV length in Cipher#iv= is also an option but I decided not
to choose it. Because in Ruby <= 2.3 Cipher#iv= truncates the input when
the length is longer than the current IV length, changing the behavior
might cause unexpected encryption result.

[Bug #8667] [Bug #10420] [GH ruby/ruby#569]
nov added a commit to nov/apple_pay that referenced this pull request Oct 5, 2016
ruby openssl itself needs to be updated to support OpenSSL::Cipher#iv_len=
ruby/ruby#569

ApplePay uses 16 as iv_len, not ruby default's 12.
@rhenium
Copy link
Member

rhenium commented Oct 23, 2016

As commented before, CCM does not fit with the interface of OpenSSL::Cipher. Please open a new issue at https://github.com/ruby/openssl if you have ideas about this.

@rhenium rhenium closed this Oct 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants