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

SHA3 extended function variable output. #33

Closed
05nelsonm opened this issue Apr 8, 2023 · 2 comments · Fixed by #39
Closed

SHA3 extended function variable output. #33

05nelsonm opened this issue Apr 8, 2023 · 2 comments · Fixed by #39
Labels
enhancement New feature or request

Comments

@05nelsonm
Copy link
Member

05nelsonm commented Apr 8, 2023

According to NIST.SP.800-185 , the extended functions should all have L (desired number of bits to output) as an input to produce variable length output when digest (or doFinal for Macs) is called. It specifies L as an input parameter for producing L / 8 bytes of output. The derived functions KMAC, TupleHash and ParallelHash are to rightEncode this value and then apply it before producing output. When the functions are being utilized as XOFs, this value will be 0 to indicate an arbitrary length.

After looking around at some different implementations (go, rust), I only see the option to utilize SHAKE, CSHAKE and functions derived from CSHAKE, as having the ability to be used as XOFs and skipping the customization of L all together.

As the publication specifies L as a function input, I believe the best course of action is to add the customization via an additional constructor which can be utilized when the default digest length is not wanted.

public class CSHAKE128: SHAKEDigest {
    public constructor(
        N: ByteArray?,
        S: ByteArray?,
        outputByteLength: Int,
        // ...
    )
}

I see in BouncyCastle that they simply have on their Xof interface the doFinal and doOutput functions which provides this functionality, but holy shit does it wreak havoc on the implementations. I am very happy that I went with the XofDelegate route for a clean separation of concerns.

@05nelsonm
Copy link
Member Author

05nelsonm commented Apr 8, 2023

Also, L can be 0 which would return an empty ByteArray. Digest would need an update b/c currently passing digestLength of 0 throws an exception. Digest should only throw exception if it's less than 0.

@05nelsonm
Copy link
Member Author

Also, L can be 0 which would return an empty ByteArray. Digest would need an update b/c currently passing digestLength of 0 throws an exception. Digest should only throw exception if it's less than 0.

See KotlinCrypto/core#30 (comment)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant