DH private key size was one bit too large#27870
DH private key size was one bit too large#27870bernd-edlinger wants to merge 1 commit intoopenssl:masterfrom
Conversation
|
Note that the rfc also says:
I think the |
|
Actually, the |
58ce39e to
9106593
Compare
9106593 to
bf52c96
Compare
|
okay, @t8m I followed your suggestion, and changed the commit message to: DH private key size was one bit too large In the case when no q parameter was given, EDIT: fixed typo "exeeding" -> "exceeding" |
bf52c96 to
2e96760
Compare
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one.
|
This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago |
|
The patch looks wrong to me. It caps |
| if (dh->length >= l) | ||
| goto err; | ||
| l = dh->length ? dh->length : BN_num_bits(dh->params.p) - 1; | ||
| l -= 2; |
There was a problem hiding this comment.
Please explain/justify the -2 here.
| l -= 2; | |
| l -= 1; |
There was a problem hiding this comment.
Is there a concern that n-bit private key
Looking at SP800-56A, there are two methods (5.6.1.1.3 and 5.6.1.1.4) of private key generation, neither is limiting the private exponent to 1 bit less than
There was a problem hiding this comment.
yes, the concern is that the exponent is equal to q, or very close, so it can be insecure,
however the fips variant is different and what I dislike there is that they care about
explicitly avoiding the exponent 0 but allow very small exponents for no good reason.
There was a problem hiding this comment.
Do we use one of the FIPS methods in the FIPS module? Or does the FIPS module use the code patched in this PR?
If the latter, is that allowed?
Assuming FIPS is not a problem, I'd like to see a comment above l -= 2 that explains that we're ensuring that
There was a problem hiding this comment.
This is whole code section is inside an ifndef FIPS_MODULE section.
The FIPS compliant code using the algorithm in 5.6.1.1.4 is done here:
openssl/crypto/ffc/ffc_key_generate.c
Lines 12 to 23 in 49f8db5
also the RFC 7919 groups are handled there, however while the RFC suggests to choose a
secret exponent in the range
|
Without this patch the random number can be larger than q result after several tries: |
| /* secret exponent length, must satisfy 2^(l-1) <= p */ | ||
| if (dh->length != 0 | ||
| && dh->length >= BN_num_bits(dh->params.p)) | ||
| /* secret exponent length, must satisfy 2^l < (p-1)/2 */ |
There was a problem hiding this comment.
@vdukhovni the comment is already changed, to correctly describe the code below.
There was a problem hiding this comment.
I find it a tad too terse, my request to make it slightly more explicit.
|
This pull request is ready to merge |
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #27870)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #27870) (cherry picked from commit d6510d9)
|
Merged to all the active branches. Thank you for your contribution. |
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given, the function generate_key in dh_key.c did create one bit too much, so the priv_key value was exceeding the DH group size q = (p-1)/2. When the length is used in this case the limit is also one bit too high, but for backward compatibility this limit was left as is, instead we have to silently reduce the value by one. Reviewed-by: Viktor Dukhovni <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#27870) (cherry picked from commit d6510d9)
In the case when no q parameter was given,$2\times 2\times 275$ multiplications by choosing their$[2^{274}, 2^{275}]$ "$2^{274}$ must be the highest bit in the$2^{275}$ as we did previously.
the function generate_key in dh_key.c did create
one bit too much, so the priv_key value was exeeding the DH group size q = (p-1)/2.
This affects also the ffdhe groups, where e.g. the length for ffdhe3072 is given as 275 by RFC 7919,
but the wording in the RFC makes it clear that we
did also use one bit too much, see section 5.2:
"for an ffdhe3072 handshake, each peer can choose
to do
secret exponent from the range
Therefore
secret exponent, not