Skip to content

Comments

Fix s390x AES OFB/CFB cipher implementation on updating IV (1.1.1)#16292

Closed
ifranzki wants to merge 2 commits intoopenssl:OpenSSL_1_1_1-stablefrom
ifranzki:aes-ofb-cfb-s390x-fix-1.1.1
Closed

Fix s390x AES OFB/CFB cipher implementation on updating IV (1.1.1)#16292
ifranzki wants to merge 2 commits intoopenssl:OpenSSL_1_1_1-stablefrom
ifranzki:aes-ofb-cfb-s390x-fix-1.1.1

Conversation

@ifranzki
Copy link
Contributor

@ifranzki ifranzki commented Aug 11, 2021

This is a backport of the the same fix as in #16291

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.

I have added a testcase in test/evp_extra_test.c to reproduce this error.

  • 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.

Signed-off-by: Ingo Franzki <[email protected]>
@ifranzki ifranzki changed the title Fix s390x AES OFB/CFB cipher implementation on updating IV Fix s390x AES OFB/CFB cipher implementation on updating IV (1.1.1) Aug 11, 2021
@ifranzki
Copy link
Contributor Author

Please add @p-steuer @juergenchrist as reviewer.

@juergenchrist
Copy link
Contributor

Isn't this fixed with PR #14900?

@ifranzki
Copy link
Contributor Author

Isn't this fixed with PR #14900?

No it is not. PR #14900 only cares about context initialization.

@t8m t8m added approval: review pending This pull request needs review by a committer branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) triaged: bug The issue/pr is/fixes a bug labels Aug 11, 2021
t8m
t8m previously approved these changes Aug 11, 2021
@t8m t8m requested a review from p-steuer August 11, 2021 13:59
@ifranzki
Copy link
Contributor Author

The tests I added shows

../test/recipes/30-test_evp_extra.t ................ 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests 

What does that mean? Isn't a return code of 1 expected when the test succeeds?

@mattcaswell
Copy link
Member

Try running evp_extra_test directly from the command line:

$ util/shlib_wrap.sh test/evp_extra_test

Also try evp_extra_test -context.

$ util/shlib_wrap.sh test/evp_extra_test -context

@mattcaswell
Copy link
Member

Oh...sorry. the "-context" variant is only relevant to master. This PR is targeting 1.1.1

@richsalz
Copy link
Contributor

"0" is exit-success status. That wstat has 256 (0x80 in hex) means that the test program crashed.

@t8m t8m dismissed their stale review August 11, 2021 15:01

Too early

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 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-1.1.1 branch from f4953c6 to 0383863 Compare August 11, 2021 15:12
@ifranzki
Copy link
Contributor Author

it does not crash on my system (i.e. with make test).... Made a small modification to the test, lets see if this makes a difference.

@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 removed the approval: done This pull request has the required number of approvals label Aug 14, 2021
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@openssl-machine openssl-machine added the approval: ready to merge The 24 hour grace period has passed, ready to merge label Aug 14, 2021
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.

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

Reviewed-by: Patrick Steuer <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #16292)
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 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 #16292)
@t8m
Copy link
Member

t8m commented Aug 16, 2021

Merged to 1.1.1 branch. Thank you for your contribution.

@t8m t8m closed this Aug 16, 2021
@ifranzki ifranzki deleted the aes-ofb-cfb-s390x-fix-1.1.1 branch August 16, 2021 15:09