-
Notifications
You must be signed in to change notification settings - Fork 4
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
.github/workflows/build.yml: run 'make tests' #19
Conversation
2fbf539
to
d22cfcf
Compare
d2cb1b7
to
f16a0d0
Compare
This enables SHA tests to check if different compilers produce the same results. Definitions in string.h were moved outside of __STDC_HOSTED__ to avoid compiler warnings (promoted to errors because of -Werror) due to incompatible implicit declaration of built-in functions. Signed-off-by: Krystian Hebel <[email protected]>
d22cfcf
to
9db046c
Compare
@SergiiDmytruk Can you please take a look? |
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.
This is more of a workaround in its current form, because undefined behaviour is still there and requires volatile
to make things work, but instead of being caused by a type cast it now comes from mixing accesses to different fields of a union
(write one field, read another one). We might be better off just dropping them and doing memcpy()
which is always well-defined.
I'll push WIP commit here to show what I mean which also gets rid of another UB caused by unaligned access at the beginning of transformation step. I think we should either make it work without hacks like volatile
or keep the code as is and use -fno-strict-aliasing
.
Also, a note on use of constants. Highly specific code like this which implements, as opposed to just using, a well-documented algorithm doesn't need them much, because you still need to know their meaning and they are even mentioned in comments (64
, 56
) alongside sizeof(...)
anyway.
I was under the impression that writing one, reading another field of I agree that the use of constants may be a bit much. I've noticed that SHA256 already had a constant but didn't really used it, so I added it where it belonged, did the same for SHA1 and went few steps too far 🙂 Anyway, I'll include your WIP commit with few minor changes like not declaring variables in the middle of a function. |
-fstrict-aliasing is enabled by default when using optimization levels higher than 1, including -Os. With that option, compiler may assume that object of one type never resides at the same address as object of a different type. Both sha1_final() and sha256_final() used to write message length by casting a pointer to buffer into a pointer to u64, while surrounding code operated on the buffer directly. The problem manifests in GCC 11 and later versions. The commit fixes this issue and another UB caused by unaligned access at the beginning of transformation step by using memcpy() in both cases. Signed-off-by: Krystian Hebel <[email protected]> Signed-off-by: Sergii Dmytruk <[email protected]>
8ef5b89
to
c00c554
Compare
Hm, actually I'm not so sure now and there are also differences between C and C++ which don't help either.
which isn't there in https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf and both have
And in all cases these are footnotes which are non-normative.
So maybe that's the correct explanation. Either way, |
No description provided.