-
Notifications
You must be signed in to change notification settings - Fork 578
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
KMAC, 2nd: added keccak-fips as standalone; added KMAC-256 #3570
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good direction, I think! Some remarks/questions regarding the basic design of Keccak_FIPS
:
- Is there a use-case for handling the basic data structures (
m_S
,m_S_pos
, ...) outside of the class?
Maybe we should just fully encapsulate them and replace the low-level static methodabsorb()
,finish()
,expand()
,permute()
with ordinary members that handle the data structures internally. Exposing those data structures via getters and setters would probably give enough flexibility if needed, while hiding some of the Keccak complexity inside the class. - For new code, I'd love to see full adoption of
std::span<>
andstd::string_view
where applicable. Instead of C-style pointer-length-parameters or even raw pointer+hope kind of interfaces. - With
Keccak_FIPS
deliberately being designed as a component for composition rather than a base for inheritance, I think it should be afinal
class without any virtual methods.
Some more details are in inline comments.
I have implemented the encapsulation now for SHA3 and Keccak, but not yet for SHAKE and SHAKE-CIPHER.
I am using std::span now in the interface (everywhere I hope).
virtuality is removed now and the class is final. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! A few more minor things. Also, I'd be really curious what @randombit has to say to this proposal. :)
As a more generic remark: Would it make sense to pull the |
Done as well. |
Could you squash your commits and rebase to master? There are a few minor conflicts. If possible, maybe separate the SHA3/Keccak refactoring from the addition of KMAC in the commit history. |
6833325
to
5dde615
Compare
Done. |
5dde615
to
e2e9bc6
Compare
I would like to inquire about the state of this PR as we need KMAC integrated upstream in our project. If there any open issues remaining with this PR please let me know. |
@falko-strenzke I don't know about the state of the review, but as minimum for this to get merged the CI would need to be green. |
e2e9bc6
to
87838a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requested changes below should fix the remaining CI issues.
Once the CI is fixed, I would suggest the following:
@falko-strenzke If you need any assistance, please don't hesitate to contact me on my work email or schedule a Teams meeting. |
c4655b3
to
45bd450
Compare
I rewrote history now so that there are only two commits, one for SHA-3 refactoring and one for the addition to keccak. So do I understand correctly, that the goal is to have both PRs on top of master:
where PR 2 will compile only after rebasing onto master after the merge of PR 1? |
Thanks for rewriting the history. That helps a lot already. Usually, I'd open two PRs on top of each other: I.e. (without rebasing any commits): One PR that contains 8f126dd and 1b089e1 (the refactoring) and another one containing 8f126dd, 1b089e1 and 45bd450 (the refactoring + KMAC). In fact, the second proposed PR basically is this one already. Typically, GitHub is clever enough to notice once the "smaller" PR is merged and adapts the diff view of the "bigger" PR accordingly. At least that's the workflow @randombit and me are typically using when splitting change sets like that. One noteworthy downside: In case the reviewer of the "smaller" PR desires changes, it becomes a bit messy as the "bigger" PR must be rebased to the "smaller" one. |
OK, I have now created #3673. |
Thanks. I'll review (hopefully) tomorrow morning. |
45bd450
to
e07e82d
Compare
…ck for SHA-3 renamed keccak_fips to keccak_perm(utation) everywhere keccak finish now without output removed output length from keccak permutation Clean up the Keccak_Permutation * replace single-shot ::expand() with more versatile ::squeeze() * use BufferStuffer/BufferSlicer in ::squeeze() and ::absorb() * remove low-level access to Keccak state * remove static Keccak state mutation methods * ::permute() is now private
adapted kmac to new keccak permutation
e07e82d
to
7b94190
Compare
Before going deeper into a review: NIST SP.800-185 defines KMAC in terms of cSHAKE (customizable SHAKE) which is defined in terms of SHAKE. As I understand it, cSHAKE is basically SHAKE with incorporated domain separation byte strings. You are intermingling the cSHAKE implementation with KMAC, which is technically fine. Though, I'm wondering whether we should split this up to ease future implementations of other functions defined in SP.800-185. We could either extend Botan's SHAKE implementation to optionally take the domain separators What do you think? @falko-strenzke @randombit |
Either option is fine for me. Given that apparently it is forbidden to use inheritance other than for mere interface inheritance, I would fear that a cSHAKE implementation would introduce a great deal of code duplication. If the SHAKE interface is extended as you propose, it should be well documented how to use it as cSHAKE. |
7b4c6da
to
7b94190
Compare
General remark: Consider adding KMAC to the |
@falko-strenzke This now needs a rebase to |
In #3671 I now added a XOF implementation of cSHAKE-128/256. This required implementing some of the helper functions in SP.800-185 a bit more generically. See Basically, cSHAKE_256_XOF xof("KMAC");
xof.start(S, {});
xof.update(/* incorporate key using helpers in keccak_helpers.h */);
xof.update(msg)
xof.output(output_len); @falko-strenzke If you're okay with it, I'm going to give the adaption of the KMAC implementation a try tomorrow. |
See: #3689 |
Closing in favor of #3689. |
This is a new PR for the addition of KMAC. This time, Keccak[c], the building block underlying all SHA-3 derived hash functions and also KMAC (build on cSHAKE, currently not implemented in Botan) is added as a freestanding class that is used as a member in the SHA-3 derived functions.
This PR supersedes the previous PR for KMAC: #3525