SPARKNaCl icon indicating copy to clipboard operation
SPARKNaCl copied to clipboard

Added SHA384

Open docandrew opened this issue 1 year ago • 21 comments

Added SHA-384 to get closer to enabling yet another TLS 1.3 cipher suite. Essentially identical to SHA-512 but with smaller digest size, different IVs and truncated output. Tested against FIPS 180-4 test vectors in SHA384ShortMsg.rsp (added to expected test results)

docandrew avatar Oct 02 '23 05:10 docandrew

Code which is common to all hash algorithms (including RFSB) should go in the private part of SPARKNaCl.Hashing (like the TS64 function, for example.). Code that is common to all variants of SHA2 should go in SPARKNaCl.Hashing.SHA2_Common. Does that make sense?

rod-chapman avatar Oct 02 '23 12:10 rod-chapman

That should work, and would be my preference as well.

docandrew avatar Oct 02 '23 13:10 docandrew

I also agree and think that if we are already moving subprograms, like TS64, we should perhaps give them a names that summarise what they do. For instance, when implementing RFSB I found those names to be quite cryptic at first and generally cumbersome to work with.

MxAR avatar Oct 02 '23 17:10 MxAR

I agree - I think those short names came from TweetNaCl, so aren't really appropriate here, so please rename them as you see fit.

rod-chapman avatar Oct 03 '23 08:10 rod-chapman

@docandrew do you want/need help with that?

MxAR avatar Oct 03 '23 10:10 MxAR

I won't be able to look at it this week, if you have bandwidth and would like to take a look at the refactor sooner I'd welcome the help!

docandrew avatar Oct 03 '23 14:10 docandrew

I might be able to get to it this week… I would suggest creating a new branch where we do the refactoring, merging that one (after PR ofc), rebasing this branch and then closing this PR. Or do you want to have refactoring done in this branch?

MxAR avatar Oct 03 '23 16:10 MxAR

A new branch is probably sensible!

docandrew avatar Oct 03 '23 21:10 docandrew

Alright then

MxAR avatar Oct 04 '23 04:10 MxAR

I am currently working on DL64 and noticed that its implementation is tailored for 32bit machines. Shall I view 32bit machines as the default target in this refactoring?

MxAR avatar Oct 10 '23 18:10 MxAR

I think the default is "portable and should work on any 32 or 64 bit machine (but favour 32-bit if and where you can...)" Does that make sense?

rod-chapman avatar Oct 10 '23 19:10 rod-chapman

Yes, I can work with that

MxAR avatar Oct 11 '23 08:10 MxAR

Quick update: I am still working on the refactoring. I currently stuck on a loop invariant but hope to finish the refactoring soon.

MxAR avatar Oct 15 '23 17:10 MxAR

Unfortunately, I am currently forced to focus my attention on other things than the refactoring. I do not know when that situation will change significantly. Thus, I see two options; either I continue to work on this branch, which might take quite some time or I hand this effort over to someone else. What do you guys think is the most sensible option?

MxAR avatar Oct 22 '23 17:10 MxAR

If you can push your commits to this PR branch I'm happy to continue working on it where you left off.

docandrew avatar Oct 23 '23 15:10 docandrew

That is wonderful. But I do not have the rights to push to your branch (docandrew:master)

MxAR avatar Oct 23 '23 17:10 MxAR

OK just added you as a contributor!

docandrew avatar Oct 23 '23 23:10 docandrew

I have just added my work (everything that was finished) to your branch.

MxAR avatar Oct 24 '23 14:10 MxAR

I still need to run proofs but took @MxAR 's work a little bit further. Rather than introduce a new SHA2 package I went ahead and placed it in the private part of sparknacl-hashing. I figured since all the hashing in SPARKNaCl is SHA2 maybe this was OK, but I thought I'd have you take a look and get your thoughts.

docandrew avatar Oct 26 '23 00:10 docandrew

At a first glance it looks quite good. I think it would be better to have a separate SHA2 module for two reasons. The first one is that although the functions of the SHA2 family are the main CHFs implemented in SPARKNaCl, SPARKNaCl also contains an implementation of RFSB509. RFSB509 is by no means as important as members of the SHA2 family but it is still a CHF. Beyond that I think it would be beneficial to have a separate module in case a contributor decides to implement a CHF that is not a member of the SHA2 family like SHA3 or SM3.

But then again I should not be making suggestions that lead to more work after I excused myself from the refactoring because I do not have enough time…

MxAR avatar Oct 26 '23 05:10 MxAR

I think I agree with Max - we already have more than one "family" of hash functions in the library - SHA2 and RFSB, so the package structure should reflect that.

rod-chapman avatar Oct 26 '23 08:10 rod-chapman