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

Use as small dh key size as possible to support the security #18480

Closed
wants to merge 10 commits into from

Conversation

t8m
Copy link
Member

@t8m t8m commented Jun 6, 2022

Longer private key sizes unnecessarily raise the cycles needed to
compute the shared secret without any increase of the real security.

This also fixes a regression where we weren't printing the recommended-private-length
in the DH parameters/key text output.

@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 Jun 6, 2022
@t8m
Copy link
Member Author

t8m commented Jun 6, 2022

As this fixes a serious performance regression with ffdhe DH parameters in openssl-3.0 when compared to 1.1.1. I regard it as a bug fix.

@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Jun 6, 2022
crypto/dh/dh_key.c Outdated Show resolved Hide resolved
@kroeckx
Copy link
Member

kroeckx commented Jun 6, 2022

We have 3 callers of ossl_ffc_generate_private_key(), and 2 of them set N to qbits, so still generating a too large key. They call it with a fixed s, I think the callers of ossl_ffc_generate_private_key() should use the ossl_ifc_ffc_compute_security_bits() to set s and probably set N to 0.

@t8m
Copy link
Member Author

t8m commented Jun 7, 2022

We have 3 callers of ossl_ffc_generate_private_key(), and 2 of them set N to qbits, so still generating a too large key. They call it with a fixed s, I think the callers of ossl_ffc_generate_private_key() should use the ossl_ifc_ffc_compute_security_bits() to set s and probably set N to 0.

No! That would be wrong. These other two callers use small q and the call with q bits as N is correct.

@t8m t8m force-pushed the dh-key-bits-default branch 3 times, most recently from ae2f030 to 3141786 Compare June 7, 2022 07:43
@kroeckx
Copy link
Member

kroeckx commented Jun 7, 2022

I'm currently not convinced they only call it with a small q, I guess I need to take a closer look.

Maybe it can be useful to have a function that properly calculates the security strength based on p, q and g. We now pass a security strength of 80 or 112 depending on fips mode. But if we pass an N that's correct, it doesn't matter, s isn't really used.

@t8m
Copy link
Member Author

t8m commented Jun 8, 2022

I'm currently not convinced they only call it with a small q, I guess I need to take a closer look.

Maybe it can be useful to have a function that properly calculates the security strength based on p, q and g. We now pass a security strength of 80 or 112 depending on fips mode. But if we pass an N that's correct, it doesn't matter, s isn't really used.

That can be another PR.

@t8m
Copy link
Member Author

t8m commented Jun 9, 2022

ping for reviews

Copy link
Contributor

@kaduk kaduk left a comment

Choose a reason for hiding this comment

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

Note that RFC 7919 is quite clear that all its named groups use safe primes.
The analogous procedures for SSH in RFC 4419 also restrict the server to picking safe primes, and justify the use of short exponents with a reference to (the conference version of) https://people.scs.carleton.ca/~paulv/papers/Euro96-DH.pdf. The conclusion of that paper seems to pretty clearly state that short exponents are "clearly insecure" when random primes area used.
I think the parts of this change to store the keylength in the named group structure and use the RFC 7919 values is good, but I'm pretty concerned that we're being too aggressive with the switch to 2*security_bits for the general (non-safe-prime) case.

crypto/dh/dh_key.c Outdated Show resolved Hide resolved
@t8m
Copy link
Member Author

t8m commented Jun 10, 2022

I think the parts of this change to store the keylength in the named group structure and use the RFC 7919 values is good, but I'm pretty concerned that we're being too aggressive with the switch to 2*security_bits for the general (non-safe-prime) case.

I've dropped that arbitrary parameters part.

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

One wording update

CHANGES.md Outdated Show resolved Hide resolved
@paulidale paulidale removed the approval: otc review pending This pull request needs review by an OTC member label Jun 14, 2022
crypto/dh/dh_gen.c Show resolved Hide resolved
crypto/ffc/ffc_dh.c Show resolved Hide resolved
@t8m
Copy link
Member Author

t8m commented Jun 16, 2022

@mattcaswell ping for approval, I think your questions were answered.

t8m added 3 commits June 22, 2022 10:14
Longer private key sizes unnecessarily raise the cycles needed to
compute the shared secret without any increase of the real security.

We use minimum key sizes as defined in RFC7919.

For arbitrary parameters we cannot know whether they are safe
primes (we could test but that would be too inefficient) we have
to keep generating large keys.

However we now set a small dh->length when we are generating safe prime
parameters because we know it is safe to use small keys with them.

That means users need to regenerate the parameters if they
want to take the performance advantage of small private key.
@t8m
Copy link
Member Author

t8m commented Jun 22, 2022

Rebased to resolve conflict in CHANGES.md. @paulidale please re-approve.

Ping for second review.

@slontis
Copy link
Member

slontis commented Jul 14, 2022

Just thought of another thing... Does this need to survive the import export dance?
i.e via ossl_dh_params_fromdata and ossl_dh_params_todata

@t8m
Copy link
Member Author

t8m commented Jul 15, 2022

Just thought of another thing... Does this need to survive the import export dance?
i.e via ossl_dh_params_fromdata and ossl_dh_params_todata

The params.keylength will get reinitialized via the ossl_dh_cache_named_group() so IMO this case is covered.

@t8m t8m 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 approval: otc review pending This pull request needs review by an OTC member labels Jul 15, 2022
@openssl-machine openssl-machine removed the approval: done This pull request has the required number of approvals label Jul 16, 2022
@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 Jul 16, 2022
@hlandau
Copy link
Member

hlandau commented Jul 18, 2022

Merged to master. Thank you.

@hlandau hlandau closed this Jul 18, 2022
openssl-machine pushed a commit that referenced this pull request Jul 18, 2022
Longer private key sizes unnecessarily raise the cycles needed to
compute the shared secret without any increase of the real security.

We use minimum key sizes as defined in RFC7919.

For arbitrary parameters we cannot know whether they are safe
primes (we could test but that would be too inefficient) we have
to keep generating large keys.

However we now set a small dh->length when we are generating safe prime
parameters because we know it is safe to use small keys with them.

That means users need to regenerate the parameters if they
want to take the performance advantage of small private key.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)
openssl-machine pushed a commit that referenced this pull request Jul 18, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)
openssl-machine pushed a commit that referenced this pull request Jul 18, 2022
…rint it

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)
openssl-machine pushed a commit that referenced this pull request Jul 18, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)
openssl-machine pushed a commit that referenced this pull request Jul 18, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)
openssl-machine pushed a commit that referenced this pull request Jul 18, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Longer private key sizes unnecessarily raise the cycles needed to
compute the shared secret without any increase of the real security.

We use minimum key sizes as defined in RFC7919.

For arbitrary parameters we cannot know whether they are safe
primes (we could test but that would be too inefficient) we have
to keep generating large keys.

However we now set a small dh->length when we are generating safe prime
parameters because we know it is safe to use small keys with them.

That means users need to regenerate the parameters if they
want to take the performance advantage of small private key.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
…rint it

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)
t8m added a commit to t8m/openssl that referenced this pull request Nov 14, 2022
Longer private key sizes unnecessarily raise the cycles needed to
compute the shared secret without any increase of the real security.

We use minimum key sizes as defined in RFC7919.

For arbitrary parameters we cannot know whether they are safe
primes (we could test but that would be too inefficient) we have
to keep generating large keys.

However we now set a small dh->length when we are generating safe prime
parameters because we know it is safe to use small keys with them.

That means users need to regenerate the parameters if they
want to take the performance advantage of small private key.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)

(cherry picked from commit ddb13b2)
t8m added a commit to t8m/openssl that referenced this pull request Nov 14, 2022
…rint it

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)

(cherry picked from commit 2b11a8e)
t8m added a commit to t8m/openssl that referenced this pull request Nov 14, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18480)

(cherry picked from commit 2885b2c)
openssl-machine pushed a commit that referenced this pull request Nov 21, 2022
Longer private key sizes unnecessarily raise the cycles needed to
compute the shared secret without any increase of the real security.

We use minimum key sizes as defined in RFC7919.

For arbitrary parameters we cannot know whether they are safe
primes (we could test but that would be too inefficient) we have
to keep generating large keys.

However we now set a small dh->length when we are generating safe prime
parameters because we know it is safe to use small keys with them.

That means users need to regenerate the parameters if they
want to take the performance advantage of small private key.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)

(cherry picked from commit ddb13b2)
openssl-machine pushed a commit that referenced this pull request Nov 21, 2022
…rint it

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)

(cherry picked from commit 2b11a8e)
openssl-machine pushed a commit that referenced this pull request Nov 21, 2022
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18480)

(cherry picked from commit 2885b2c)
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 severity: fips change The pull request changes FIPS provider sources triaged: bug The issue/pr is/fixes a bug triaged: feature The issue/pr requests/adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants