Skip to content

Comments

Fix s390x AES OFB/CFB cipher implementation on updating IV#16291

Closed
ifranzki wants to merge 2 commits intoopenssl:masterfrom
ifranzki:aes-ofb-cfb-s390x-fix
Closed

Fix s390x AES OFB/CFB cipher implementation on updating IV#16291
ifranzki wants to merge 2 commits intoopenssl:masterfrom
ifranzki:aes-ofb-cfb-s390x-fix

Conversation

@ifranzki
Copy link
Contributor

@ifranzki ifranzki commented Aug 11, 2021

The s390x specific implementation in crypto/evp/e_aes.c does not update the cipher context's IV field during an operation for AES OFB and CFB.

An application that uses EVP_CIPHER_CTX_iv() to get the updated IV would thus always get the original IV value on s390x. Other platforms are not affected as far as I can tell.

Please note that the provider based implementation in providers/implementations/ciphers/cipher_aes_hw_s390x.inc does it correctly already. The fix in e_aes.c aligns the code to the code in cipher_aes_hw_s390x.inc.

Because the provider based implementation is correct, an application using OpenSSL 3.0 will not see the error. However, the same error is in the OpenSSL 1.1.1 branch, and with OpenSSL 1.1.1 the error can be seen by an application (on s390x). I would suggest to fix this anyway in the master branch, since the code in e_aes.c is wrong, too.

I have added a testcase in test/evp_extra_test.c to reproduce this error. Of course, it won't fail with OpenSSL 3.0, because the code goes the provider path. I don't know how the code in e_aes.c could be tested in OpenSSL 3.0....

I will submit another PR for the same fix in the OpenSSL 1.1.1 branch.

  • tests are added or updated

Copy the current IV from the cipher context into the kmo/kmf param before
the operation, and copy the modified IV back to the context afterwards.
Without this, an application that obtains the running IV from the context
would still get the original IV, but not the updated one.

This implementation in e_aes.c now matches the code in cipher_aes_hw_s390x.inc
that is used for the provider implementation.

Signed-off-by: Ingo Franzki <[email protected]>
@ifranzki
Copy link
Contributor Author

Please add @p-steuer @juergenchrist as reviewer.

@ifranzki
Copy link
Contributor Author

PR for OpenSSL 1.1.1: #16292

@juergenchrist
Copy link
Contributor

When fixing the provider we could not figure out how to use these implementations. So we just did not fix them. But in principle I agree with you about fixing them. Either that or removing them if they really are no longer needed.

@mattcaswell
Copy link
Member

When fixing the provider we could not figure out how to use these implementations. So we just did not fix them. But in principle I agree with you about fixing them. Either that or removing them if they really are no longer needed.

In theory then can be reached by using the EVP_CIPHER_meth_get_*() functions. It is possible to create a custom EVP_CIPHER_METHOD that just wraps a built-in one. In that case these old codepaths can be hit.

t8m
t8m previously approved these changes Aug 11, 2021
@t8m t8m added branch: master Applies to master branch triaged: bug The issue/pr is/fixes a bug approval: review pending This pull request needs review by a committer labels Aug 11, 2021
@ifranzki
Copy link
Contributor Author

Looks like the test I added fails because it does not find the cipher it uses in amny cases. Could it be that aes-128-cfb/ofb/etc. are not available in the default provider? Should I change it to aes-256 instead?

@t8m t8m dismissed their stale review August 11, 2021 14:55

Too early.

@t8m
Copy link
Member

t8m commented Aug 11, 2021

Looks like the test I added fails because it does not find the cipher it uses in amny cases. Could it be that aes-128-cfb/ofb/etc. are not available in the default provider? Should I change it to aes-256 instead?

This is not the cause, please look at other tests in the evp_extra_test.c - you have to use EVP_CIPHER_fetch() instead of EVP_get_cipherbyname() as the later uses the default context which might not have any provider set for some invocations of the evp_extra_test.

@ifranzki ifranzki force-pushed the aes-ofb-cfb-s390x-fix branch from d1fe78c to 8a37b85 Compare August 11, 2021 15:37
@ifranzki
Copy link
Contributor Author

you have to use EVP_CIPHER_fetch()

Ah yes, sure. Changed.

Ensure that an EVP_CipherUpdate operation updates the context's
IV for AES CBC, CFB, OFB, and CTR. An application can get the
updated IV via EVP_CIPHER_CTX_iv().

The s390x implementation of the CFB and OFB ciphers in e_aes.c did not
update the IV in the context, but only within its s390x specific
context data.

Signed-off-by: Ingo Franzki <[email protected]>
@ifranzki ifranzki force-pushed the aes-ofb-cfb-s390x-fix branch from 8a37b85 to e1470e5 Compare August 12, 2021 08:20
@ifranzki
Copy link
Contributor Author

Can someone please approve the workflows, so that the checks can run again?

@t8m t8m requested a review from p-steuer August 13, 2021 09:00
@p-steuer p-steuer 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 Aug 13, 2021
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Aug 14, 2021
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Aug 16, 2021
Copy the current IV from the cipher context into the kmo/kmf param before
the operation, and copy the modified IV back to the context afterwards.
Without this, an application that obtains the running IV from the context
would still get the original IV, but not the updated one.

This implementation in e_aes.c now matches the code in cipher_aes_hw_s390x.inc
that is used for the provider implementation.

Signed-off-by: Ingo Franzki <[email protected]>

Reviewed-by: Patrick Steuer <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #16291)
openssl-machine pushed a commit that referenced this pull request Aug 16, 2021
Ensure that an EVP_CipherUpdate operation updates the context's
IV for AES CBC, CFB, OFB, and CTR. An application can get the
updated IV via EVP_CIPHER_CTX_iv().

The s390x implementation of the CFB and OFB ciphers in e_aes.c did not
update the IV in the context, but only within its s390x specific
context data.

Signed-off-by: Ingo Franzki <[email protected]>

Reviewed-by: Patrick Steuer <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #16291)
@t8m
Copy link
Member

t8m commented Aug 16, 2021

Merged to master. Thank you for your contribution.

@t8m t8m closed this Aug 16, 2021
@ifranzki ifranzki deleted the aes-ofb-cfb-s390x-fix branch August 16, 2021 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants