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

Add SHA-512/224 and SHA-512/256 hash functions #55

Merged
merged 5 commits into from
Nov 15, 2015
Merged

Conversation

silmeth
Copy link
Collaborator

@silmeth silmeth commented Nov 6, 2015

SHA2-512/224 and SHA-512/256 implemented, using existing macros for sha2 functions. However, SHA2-512/224 has 224 bits, and that is not a multiple of 64. Thus, write_u64() used for writing state to resulting out slice cannot be used directly (as it would copy 4 bytes to few to out, or 4 to many).

Because of that a proxy struct _Sha512_224 which outputs 256 bits is created, and its methods are simply called by proper Sha512_224 struct. In the result() method a new vec, res is created, result is written to it, and then 28 first bytes are copied to out using a simple for loop.

SHA2-512/256 is implemented with just impl_sha!(high Sha512_256, SHA512_256_INIT, 256).

It closes #47.

@silmeth
Copy link
Collaborator Author

silmeth commented Nov 6, 2015

Ok. It isn’t as easy as I thought. Found test with longer messages, and for them it does not work (only for one block messages). I believe I’ll need to make proxy structs with 512 bits output for both hash functions and copying first bytes of result.

@hauleth
Copy link
Member

hauleth commented Nov 6, 2015

I think that we should find way to achieve writing &[u64] to &[u8] as there is similar problem with SHA-3 IIRC. std::mem::copy_nonoverlaping could help but this doesn't support endianess, but as there should be correct endianess in state maybe it would help?

homu added a commit that referenced this pull request Nov 7, 2015
Use `copy_nonoverlapping` instead loops

This resolves issue with strange SHA-512/224 additional struct in #55.
@hauleth
Copy link
Member

hauleth commented Nov 7, 2015

Could you fix the PR to not use _Sha512_224 temporary struct? Also I think that names Sha512224 and Sha512256 are more popular. Also is that really needed? User could truncate output by him/herself.

@silmeth
Copy link
Collaborator Author

silmeth commented Nov 7, 2015

Will do that soon. User cannot truncate output by himself from SHA-512 because the initial values are different. SHA-512/224 and SHA-512/256 are practically identical to SHA-384 in terms of relation to SHA-512. SHA-384 is not called SHA-512/384 probably only because there is no 384 hash function using 32 bit words.

@hauleth hauleth changed the title feat(digest): Add SHA-512/224 and SHA-512/256 hash functions Add SHA-512/224 and SHA-512/256 hash functions Nov 8, 2015
@GitCop
Copy link

GitCop commented Nov 15, 2015

There were the following issues with your Pull Request

  • Commit: 8be3dfc
    • Your subject line is longer than 72 characters

Guidelines are available at https://github.com/libOctavo/octavo/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

@hauleth
Copy link
Member

hauleth commented Nov 15, 2015

@homu r+

@homu
Copy link
Contributor

homu commented Nov 15, 2015

📌 Commit 8be3dfc has been approved by hauleth

@homu
Copy link
Contributor

homu commented Nov 15, 2015

⚡ Test exempted - status

@homu homu merged commit 8be3dfc into master Nov 15, 2015
homu added a commit that referenced this pull request Nov 15, 2015
Add SHA-512/224 and SHA-512/256 hash functions

SHA2-512/224 and SHA-512/256 implemented, using existing macros for sha2 functions. However, SHA2-512/224 has 224 bits, and that is not a multiple of 64. Thus, `write_u64()` used for writing state to resulting `out` slice cannot be used directly (as it would copy 4 bytes to few to out, or 4 to many).

Because of that a *proxy* struct `_Sha512_224` which outputs 256 bits is created, and its methods are simply called by proper `Sha512_224` struct. In the `result()` method a new vec, `res` is created, result is written to it, and then 28 first bytes are copied to `out` using a simple for loop.

SHA2-512/256 is implemented with just `impl_sha!(high Sha512_256, SHA512_256_INIT, 256)`.

It closes #47.
@hauleth hauleth deleted the sha-512-224-and-256 branch November 15, 2015 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement SHA-512/224 and SHA-512/256 functions
4 participants