Skip to content

Rework the partially overlapping handling - #11780

Closed
bernd-edlinger wants to merge 1 commit into
openssl:OpenSSL_1_1_1-stablefrom
bernd-edlinger:rework_partially_overlapping_code_1
Closed

bernd-edlinger wants to merge 1 commit into
openssl:OpenSSL_1_1_1-stablefrom
bernd-edlinger:rework_partially_overlapping_code_1

Conversation

@bernd-edlinger

Copy link
Copy Markdown
Member

The problem here is that in the default case of EVP_EncryptUpdate
the in and out buffers can have different sizes:

Suppose we have a block_size=16 and already buf_len=15.
EVP_EncryptUpdate is called with in==out and inl==2.

In this case, is_partially_overlapping(in+15, in, 2)
returns false, because the intervals are not overlapping at all.
But ctx->cipher->do_cipher(ctx, out, ctx->buf, bl) clobbers the
second byte before it is used.

Make partially overlapping more permissive, i.e.
allow essentially all kinds of overlapping that "work"

Fix error handling in aes_ocb_cipher

Avoid undefined behavior in des_ede3_unwrap

Add a sentence about in-place encryption to the doc
Add a statement about the output buffer size for WRAP mode ciphers
Add a definition for partially overlapping

Add test cases for invalid overlapping
Add test cases for overlapping encryption
Add AES-xxx-CFB1/8 test vectors from NIST SP800-38A
Reuse the second DES-EDE3-CFB1 as BitLen test

Checklist
  • documentation is added or updated
  • tests are added or updated

Backport of #5427 to 1.1.1

@bernd-edlinger bernd-edlinger added the branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) label May 9, 2020
@bernd-edlinger bernd-edlinger reopened this May 9, 2020
@bernd-edlinger
bernd-edlinger force-pushed the rework_partially_overlapping_code_1 branch 3 times, most recently from 49ea0d3 to 76aaba0 Compare May 22, 2020 12:14
@romen

romen commented May 22, 2020

Copy link
Copy Markdown
Member

Backport of #5427 to 1.1.1

This is a bit misleading: #5427 was not merged, so these changes are not being backported from master as we require.

Also there might be a need to discuss if all the changes in here are fixes or if some are new features (which are not allowed in 1.1.1 without a vote to make an exception).

The problem here is that in the default case of EVP_EncryptUpdate
the in and out buffers can have different sizes:

Suppose we have a block_size=16 and already buf_len=15.
EVP_EncryptUpdate is called with in==out and inl==2.

In this case, is_partially_overlapping(in+15, in, 2)
returns false, because the intervals are not overlapping at all.
But ctx->cipher->do_cipher(ctx, out, ctx->buf, bl) clobbers the
second byte before it is used.

Fix error handling in aes_ocb_cipher

Avoid undefined behavior in des_ede3_unwrap

Add a sentence about in-place encryption to the doc
Add a statement about the output buffer size for WRAP mode ciphers
Add a definition for partially overlapping

Add test cases for invalid overlapping
Add test cases for overlapping encryption
Add AES-xxx-CFB1/8 test vectors from NIST SP800-38A
Reuse the second DES-EDE3-CFB1 as BitLen test

[extended tests]
@bernd-edlinger
bernd-edlinger force-pushed the rework_partially_overlapping_code_1 branch from 76aaba0 to e25caaa Compare May 22, 2020 20:35
@t8m t8m added the triaged: feature The issue/pr requests/adds a feature label Aug 4, 2021
@t8m t8m added this to the Post 3.0.0 milestone Sep 24, 2021
@t8m t8m closed this Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) triaged: feature The issue/pr requests/adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants