Skip to content

Conversation

@t8m
Copy link
Member

@t8m t8m commented Apr 11, 2024

It will work only if OSSL_DIGEST_PARAM_XOFLEN is set.

Also add new SHAKE-128/128, SHAKE-256/256, SHAKE-128/256 and SHAKE-256/512 algorithms which have explicit default XOFLEN set.

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

@t8m t8m added branch: master Applies to master branch approval: review pending This pull request needs review by a committer approval: otc review pending triaged: feature The issue/pr requests/adds a feature tests: present The PR has suitable tests present labels Apr 11, 2024
@t8m t8m requested review from a team and slontis April 11, 2024 08:30
@t8m t8m removed approval: review pending This pull request needs review by a committer approval: otc review pending labels Apr 11, 2024
@t8m
Copy link
Member Author

t8m commented Apr 11, 2024

This is my alternative proposal to #23877

@t8m t8m added the hold: discussion The community needs to establish a consensus how to move forward with the issue or PR label Apr 11, 2024
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Apr 11, 2024
@t8m t8m force-pushed the shake-mishap-fix branch from a5b3a1f to 91b3565 Compare April 11, 2024 08:41
@levitte
Copy link
Member

levitte commented Apr 11, 2024

Apart from my review comment, those looks good to me

@beldmit
Copy link
Member

beldmit commented Apr 11, 2024

I wonder whether we have a (potential) regression with PKCS#12

@t8m
Copy link
Member Author

t8m commented Apr 12, 2024

I wonder whether we have a (potential) regression with PKCS#12

How so? I do not see SHAKE being used in PKCS#12. It would make no sense.

@kroeckx
Copy link
Member

kroeckx commented Apr 12, 2024

It's not clear why we're adding SHAKE-128/128 and SHAKE-256/256.

I would prefer that we just don't support a shake with a fixed length, something should always set the length.

@t8m
Copy link
Member Author

t8m commented Apr 12, 2024

It's not clear why we're adding SHAKE-128/128 and SHAKE-256/256.

I would prefer that we just don't support a shake with a fixed length, something should always set the length.

This is up to debate. IMO we definitely need to add SHAKE-128/256 and SHAKE-256/512. As for these shortened ones, the reason is to provide a simple replacement for those existing use-cases which depend on the existing shortened default lengths. It is however questionable, whether these use-cases are important enough and whether either using DigestFinalXOF or explicitly set the XOFLEN parameter wouldn't be a more appropriate workaround.

@tomato42
Copy link
Contributor

and why those use-cases can't use sha-3-256 and sha-3-512 respectively?

also, do we really want to define a hash function in 2023 that has a 64 bit level of security of collision resistance: "SHAKE-128/128:SHAKE128/128" ?

Copy link
Member

@slontis slontis left a comment

Choose a reason for hiding this comment

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

Before multiple definitions for SHAKE128 and SHAKE256 are added we need to figure out the OID problem.
It needs to work nicely with signatures (See https://github.com/openssl/openssl/pull/23114/files)

@slontis
Copy link
Member

slontis commented Apr 14, 2024

This also ties in with https://github.com/openssl/openssl/pull/22684/files.

HSS and XMSS uses
SHAKE-128-256, SHAKE-256-512,
as well as the truncated versions 256-256, 256-192

So it looks like ideally SHAKE128 and SHAKE256 SHOULD use XOFFinal only and NOT HAVE THE OID ASSOCIATED WITH THEM..
And where I was heading with this is that the others names you have added are 'fixed' and the xoflen cant be changed.

@t8m
Copy link
Member Author

t8m commented Apr 15, 2024

And where I was heading with this is that the others names you have added are 'fixed' and the xoflen cant be changed.

The question is why would this artificial limit be applied? If this was a different algorithm and produced different outputs then I would definitely apply it but it does not make much sense to me. And especially not if we move the OID!

@slontis
Copy link
Member

slontis commented Apr 15, 2024

And where I was heading with this is that the others names you have added are 'fixed' and the xoflen cant be changed.

The question is why would this artificial limit be applied? If this was a different algorithm and produced different outputs then I would definitely apply it but it does not make much sense to me. And especially not if we move the OID!

Because I was thinking of using them like any other digest algorithm that uses DigestFinal. Why would you have multiple different names and then make them equivalent by being able to set the xof length manually.

@t8m
Copy link
Member Author

t8m commented Apr 16, 2024

Because I was thinking of using them like any other digest algorithm that uses DigestFinal. Why would you have multiple different names and then make them equivalent by being able to set the xof length manually.

You could already use the existing SHAKE algorithms with DigestFinal. I do not see a reason why not to allow multiple ways how to use the newly named ones the same way.

Comment on lines 491 to 493
ossl_keccak_init(ctx, pad, bitlen, mdlen); \
if (mdlen == SIZE_MAX) \
ctx->md_size = SIZE_MAX; \
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely convinced that SIZE_MAX is the better indicator for indefinite length. How about zero?

Copy link
Contributor

Choose a reason for hiding this comment

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

SIZE_MAX is better IMO. It requires less special case code in callers and generating more than SIZE_MAX output is likely to be highly suspect and not storable or processable in reasonable time.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree. Zero is a much better indicator that you haven't initialised something to a fixed length.
This is C code after all.

Haven't we used the pattern of using 0 elsewhere - I don't know that we have used a SIZE_MAX approach to indicate indefinite elsewhere ...

Consistency here should be the guide.

Copy link
Member

Choose a reason for hiding this comment

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

I doubt there will be much of a difference for the caller. Basically, this would work as an indicator whether it's appropriate to Squeeze without limit rather than using DigestFinalXOF, at least as long as we don't really have any other way for the caller to check what sort of functionality is supported by the implementation.

So in the end, it's this check:

    // Can I squeeze?
    if (md_size == SIZE_MAX)
        ...

or this:

    // Can I squeeze?
    if (md_size == 0)
        ...

Copy link
Member

Choose a reason for hiding this comment

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

We do use SIZE_MAX quite a bit, but that's in cases where size maximums are a thing. SHAKE isn't expressed in terms of maximum size, it's expressed in "indefinite" terms (even though there are admonitions about practicality).

Furthermore, md_size is usually the (fixed) size, not a maximum, and SIZE_MAX is a bit weird of an exception from that interpretation compare to zero, in my mind.

Copy link
Contributor

Choose a reason for hiding this comment

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

I require X bytes of output.

Thus either:
if (X < max_size || max_size == 0)
versus
if (X < max_size)

The latter is, by far, the simpler pattern IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm definitely not advocating for the essentially equivalent:
if (X < max_size - 1)
which is very counter intuitive.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that 0 value is already very special and we already have a test (evp_test) that depends on EVP_DigestFinalXOF(ctx, ptr, 0) returning success! So no, we have to keep SIZE_MAX as the unset value.

@kroeckx
Copy link
Member

kroeckx commented Apr 17, 2024 via email

@t8m t8m removed the hold: discussion The community needs to establish a consensus how to move forward with the issue or PR label Apr 23, 2024
@t8m t8m requested review from levitte, paulidale and slontis April 24, 2024 16:48
sizeof(shake256_input))))
return 0;
ERR_set_mark();
if (!TEST_false(EVP_DigestFinal(ctx, out, &digest_length))) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a set the xoflen and then use digestfinal testcase?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The evp_test exercises this code path. That was actually how I found the necessity for the below fix in EVP_DigestFinal_ex().

if (ctx->digest->prov == NULL)
goto legacy;

if (sz == 0) /* Assuming a xoflen must have been set. */
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible that something could have returned 0 for other algorithms?

Copy link
Member Author

@t8m t8m Apr 26, 2024

Choose a reason for hiding this comment

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

Then it would be an useless hash if it wasn't a XOF one in the same way as SHAKE is.

Alternative is to use SIZE_MAX as the invalid default size indicator. It has its downsides as well.

@slontis
Copy link
Member

slontis commented May 14, 2024

CHANGES.md needs a rebase..

@slontis slontis 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 May 14, 2024
@t8m t8m force-pushed the shake-mishap-fix branch from 0fbb78e to 0ef6ba8 Compare May 14, 2024 07:25
@t8m
Copy link
Member Author

t8m commented May 14, 2024

The force push was just a rebase with trivial CHANGES.md conflict resolution.

@openssl-machine
Copy link
Collaborator

24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually.

@t8m t8m 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 May 15, 2024
@t8m
Copy link
Member Author

t8m commented May 15, 2024

Merged to the master branch. Thank you for the reviews.

@t8m t8m closed this May 15, 2024
openssl-machine pushed a commit that referenced this pull request May 15, 2024
It will work only if OSSL_DIGEST_PARAM_XOFLEN is set.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
(Merged from #24105)
openssl-machine pushed a commit that referenced this pull request May 15, 2024
xnox added a commit to xnox/openssl that referenced this pull request May 22, 2024
These were added as a POC in openssl#24387. However, such combinations are no
longer unusable since openssl#24105 got merged.

This should unbreak all build failures on mainline.

Partially reverts: 1bfc8d1 (rsa-oaep: block SHAKE usage in FIPS
mode, 2024-05-13)

Signed-off-by: Dimitri John Ledkov <[email protected]>
openssl-machine pushed a commit that referenced this pull request May 22, 2024
These were added as a POC in #24387. However, such combinations are no
longer unusable since #24105 got merged.

This should unbreak all build failures on mainline.

Partially reverts: 1bfc8d1 (rsa-oaep: block SHAKE usage in FIPS
mode, 2024-05-13)

Signed-off-by: Dimitri John Ledkov <[email protected]>

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #24463)
jvdsn pushed a commit to jvdsn/openssl that referenced this pull request Jun 3, 2024
It will work only if OSSL_DIGEST_PARAM_XOFLEN is set.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Shane Lontis <[email protected]>
(Merged from openssl#24105)
jvdsn pushed a commit to jvdsn/openssl that referenced this pull request Jun 3, 2024
jvdsn pushed a commit to jvdsn/openssl that referenced this pull request Jun 3, 2024
These were added as a POC in openssl#24387. However, such combinations are no
longer unusable since openssl#24105 got merged.

This should unbreak all build failures on mainline.

Partially reverts: 1bfc8d1 (rsa-oaep: block SHAKE usage in FIPS
mode, 2024-05-13)

Signed-off-by: Dimitri John Ledkov <[email protected]>

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#24463)
xnox added a commit to xnox/openssl that referenced this pull request Jun 24, 2024
These were added as a POC in openssl#24387. However, such combinations are no
longer unusable since openssl#24105 got merged.

This should unbreak all build failures on mainline.

Partially reverts: 1bfc8d1 (rsa-oaep: block SHAKE usage in FIPS
mode, 2024-05-13)

Signed-off-by: Dimitri John Ledkov <[email protected]>

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#24463)

(cherry picked from commit a0da3cb)
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 Applies to master branch severity: fips change The pull request changes FIPS provider sources tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants