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

Avoid undefined behavior of provided macs on EVP_MAC reinitialization #18100

Closed
wants to merge 5 commits into from

Conversation

t8m
Copy link
Member

@t8m t8m commented Apr 12, 2022

When the context is reinitialized, i.e. the same key should be used
we must properly reinitialize the underlying implementation.

However in POLY1305 case it does not make sense as this special MAC
should not reuse keys. We fail with this provided implementation
when reinitialization happens.

Fixes #17811

Checklist
  • tests are added or updated

t8m added 2 commits April 12, 2022 17:58
When the context is reinitialized, i.e. the same key should be used
we must properly reinitialize the underlying implementation.

However in POLY1305 case it does not make sense as this special MAC
should not reuse keys. We fail with this provided implementation
when reinitialization happens.

Fixes openssl#17811
@t8m t8m added branch: master Merge to master branch approval: review pending This pull request needs review by a committer approval: otc review pending This pull request needs review by an OTC member triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch labels Apr 12, 2022
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Apr 12, 2022
@t8m
Copy link
Member Author

t8m commented Apr 12, 2022

Aargh, we apparently depend on EVP_MAC_init() not failing even for the POLY1305 mac.

@paulidale
Copy link
Contributor

Yeah, here:

openssl/apps/mac.c

Lines 183 to 186 in 801c638

if (!EVP_MAC_init(ctx, NULL, 0, NULL)) {
BIO_printf(bio_err, "EVP_MAC_Init failed\n");
goto err;
}

The key is passed as a param not via this call. I prefer the way you are heading but it means an API break :(

@t8m
Copy link
Member Author

t8m commented Apr 13, 2022

The key is passed as a param not via this call. I prefer the way you are heading but it means an API break :(

I think it can be avoided - done in the fixup.

@t8m
Copy link
Member Author

t8m commented Apr 13, 2022

CI is green

@mattcaswell mattcaswell removed the approval: otc review pending This pull request needs review by an OTC member label Apr 13, 2022
@paulidale paulidale removed the approval: review pending This pull request needs review by a committer label Apr 13, 2022
@t8m t8m added the approval: done This pull request has the required number of approvals label Apr 14, 2022
@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 Apr 15, 2022
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@t8m
Copy link
Member Author

t8m commented Apr 19, 2022

Merged to master and 3.0 branches. Thank you for the reviews.

@t8m t8m closed this Apr 19, 2022
openssl-machine pushed a commit that referenced this pull request Apr 19, 2022
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #18100)
openssl-machine pushed a commit that referenced this pull request Apr 19, 2022
When the context is reinitialized, i.e. the same key should be used
we must properly reinitialize the underlying implementation.

However in POLY1305 case it does not make sense as this special MAC
should not reuse keys. We fail with this provided implementation
when reinitialization happens.

Fixes #17811

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #18100)
openssl-machine pushed a commit that referenced this pull request Apr 19, 2022
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #18100)

(cherry picked from commit e58ba18)
openssl-machine pushed a commit that referenced this pull request Apr 19, 2022
When the context is reinitialized, i.e. the same key should be used
we must properly reinitialize the underlying implementation.

However in POLY1305 case it does not make sense as this special MAC
should not reuse keys. We fail with this provided implementation
when reinitialization happens.

Fixes #17811

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #18100)

(cherry picked from commit c9ddc5a)
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 Merge to master branch branch: 3.0 Merge to openssl-3.0 branch severity: fips change The pull request changes FIPS provider sources triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reusing existing HMAC key not possible via EVP_MAC_init()
4 participants