Skip to content

Conversation

@tniessen
Copy link
Contributor

This change allows to pass the authentication tag after specifying the AAD in CCM mode. This is already true for the other two supported AEAD modes (GCM and OCB) and it seems appropriate to match the behavior.

GCM and OCB also support to set the tag at any point before the call to EVP_*Final, but this won't work for CCM due to a restriction imposed by section 2.6 of RFC3610: The tag must be set before actually decrypting data.

This commit also adds a test case for setting the tag after supplying plaintext length and AAD.

Checklist
  • tests are added or updated

@mspncp
Copy link
Contributor

mspncp commented Feb 19, 2019

ping

Hello everyone,

in GCM and OCB mode, it is possible to set the authentication tag after
supplying AAD, but the CCM implementation does not allow that. This
isn't a problem for most applications, but in Node.js, we expose similar
APIs to interact with AEAD ciphers and these differences between cipher
modes within OpenSSL propagate to our users. Unless there is a reason
for the current behavior, I would prefer to change it.

I opened a PR about this five months ago
(#7243). It has received zero
attention and I am hoping the mailing list is a good way to change that.

Kind regards,
Tobias

(see https://mta.openssl.org/pipermail/openssl-users/2019-February/009881.html)

@mattcaswell mattcaswell added branch: master Applies to master branch branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) labels Feb 19, 2019
Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the EVP_EncryptInit man page could do with some update as part of this PR to clarify when exactly the tag can be set.

Copy link

@blaufish blaufish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1/ I don't follow the comment in the commit message,

GCM and OCB also support to set the tag at any point before the call
to `EVP_*Final`, but this won't work for CCM due to a restriction
imposed by section 2.6 of RFC3610: The tag must be set before
actually decrypting data.

Does RFC3610 2.6 say anything specific on this subject?

Are you referring to this advice?

The recipient MUST verify the CBC-MAC before releasing any
information such as the plaintext.  If the CBC-MAC verification
fails, the receiver MUST destroy all information, except for the fact
that the CBC-MAC verification failed.

It seems like good advice for any AEAD mode, and doesn't explicitly talk about in which order tag,aad,ciphertext is provided to aead-decrypt operations?

As per 2.2, before decryption can start:

  • length(nonce)
  • length(AAD)
  • length(message)

These are needed due to CBC.MAC operations needs first block B_0 calculations.

As far as I know, there's nothing in the RFC about when tag needs to be provided, except that tag length must be known prior to decrypt finalising (releasing plaintext to caller).

2/ openssl behaviour is documented here:

It seems documented, at least on the wiki, that SET_TAG behaviour differs from GCM and CCM.

As far as I am concerned, there is no reason CCM couldn't have relax SET_TAG behaviour in the future, but it would be good if someone with more experience of this implementation could comment.

@tniessen tniessen force-pushed the crypto-evp-aes-ccm-relax-tag-requirement branch from 1c7b44c to 2c4d8ec Compare February 19, 2019 19:17
@tniessen
Copy link
Contributor Author

tniessen commented Feb 19, 2019

@mattcaswell Thank you for reviewing! I fixed the indentation issue, but I'll have to take a look at the documentation.

@blaufish Thank you for reviewing as well!

GCM and OCB also support to set the tag at any point before the call
to `EVP_*Final`, but this won't work for CCM due to a restriction
imposed by section 2.6 of RFC3610: The tag must be set before
actually decrypting data.

Does RFC3610 2.6 say anything specific on this subject?

Are you referring to this advice?

The recipient MUST verify the CBC-MAC before releasing any
information such as the plaintext.  If the CBC-MAC verification
fails, the receiver MUST destroy all information, except for the fact
that the CBC-MAC verification failed.

Yes, I am. I agree that the commit message might be a bit inaccurate there, I meant "releasing any information such as the plaintext" when I wrote "decrypting data".

It seems like good advice for any AEAD mode, and doesn't explicitly talk about in which order tag,aad,ciphertext is provided to aead-decrypt operations?

As per 2.2, before decryption can start:

* length(nonce)

* length(AAD)

* length(message)

These are needed due to CBC.MAC operations needs first block B_0 calculations.

As far as I know, there's nothing in the RFC about when tag needs to be provided, except that tag length must be known prior to decrypt finalising (releasing plaintext to caller).

That is correct, but the tag is required before providing the plaintext to the user, meaning it needs to be provided before decrypting data using EVP_CipherUpdate. And that should be exactly what this commit does, instead of unnecessarily requring it before AAD is passed.

This change allows to pass the authentication tag after specifying
the AAD in CCM mode. This is already true for the other two supported
AEAD modes (GCM and OCB) and it seems appropriate to match the
behavior.

GCM and OCB also support to set the tag at any point before the call
to `EVP_*Final`, but this won't work for CCM due to a restriction
imposed by section 2.6 of RFC3610: The tag must be set before
actually decrypting data.

This commit also adds a test case for setting the tag after supplying
plaintext length and AAD.
@tniessen tniessen force-pushed the crypto-evp-aes-ccm-relax-tag-requirement branch from 2c4d8ec to 30c1de8 Compare May 5, 2019 14:51
@tniessen
Copy link
Contributor Author

tniessen commented May 5, 2019

I think the EVP_EncryptInit man page could do with some update as part of this PR to clarify when exactly the tag can be set.

@mattcaswell I added a few lines to the documentation, I assume that's what this has been waiting for. Please take another look.

@mattcaswell mattcaswell added the approval: review pending This pull request needs review by a committer label May 7, 2019
@mattcaswell
Copy link
Member

Ping @openssl for second review.

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels May 8, 2019
levitte pushed a commit that referenced this pull request May 8, 2019
This change allows to pass the authentication tag after specifying
the AAD in CCM mode. This is already true for the other two supported
AEAD modes (GCM and OCB) and it seems appropriate to match the
behavior.

GCM and OCB also support to set the tag at any point before the call
to `EVP_*Final`, but this won't work for CCM due to a restriction
imposed by section 2.6 of RFC3610: The tag must be set before
actually decrypting data.

This commit also adds a test case for setting the tag after supplying
plaintext length and AAD.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
(Merged from #7243)

(cherry picked from commit 67c81ec)
levitte pushed a commit that referenced this pull request May 8, 2019
This change allows to pass the authentication tag after specifying
the AAD in CCM mode. This is already true for the other two supported
AEAD modes (GCM and OCB) and it seems appropriate to match the
behavior.

GCM and OCB also support to set the tag at any point before the call
to `EVP_*Final`, but this won't work for CCM due to a restriction
imposed by section 2.6 of RFC3610: The tag must be set before
actually decrypting data.

This commit also adds a test case for setting the tag after supplying
plaintext length and AAD.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Matt Caswell <[email protected]>
(Merged from #7243)
@mattcaswell
Copy link
Member

Pushed. Thanks.

@mattcaswell mattcaswell closed this May 8, 2019
tniessen added a commit to tniessen/node that referenced this pull request Jul 10, 2019
This was fixed in OpenSSL 1.1.1c (openssl/openssl@b48e3be947). The
authentication tag can now be specified after setAAD was called,
matching the behavior of the other supported AEAD modes (GCM, OCB).

Refs: openssl/openssl#7243
Trott pushed a commit to Trott/io.js that referenced this pull request Jul 12, 2019
This was fixed in OpenSSL 1.1.1c (openssl/openssl@b48e3be947). The
authentication tag can now be specified after setAAD was called,
matching the behavior of the other supported AEAD modes (GCM, OCB).

Refs: openssl/openssl#7243

PR-URL: nodejs#28624
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit to nodejs/node that referenced this pull request Jul 20, 2019
This was fixed in OpenSSL 1.1.1c (openssl/openssl@b48e3be947). The
authentication tag can now be specified after setAAD was called,
matching the behavior of the other supported AEAD modes (GCM, OCB).

Refs: openssl/openssl#7243

PR-URL: #28624
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: done This pull request has the required number of approvals branch: master Applies to master branch branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants