-
Notifications
You must be signed in to change notification settings - Fork 141
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
Function producing different outputs for same inputs from different paths #1007
Comments
(That was confusing, I at first read the name as "Juliana Shinn" and wondered when my sister had started programming...) Thank you for the detailed report! This looks like either a bug in the bitwise ops on bignums, or possibly some general heap corruption (although that seems less likely, especially if the test is repeatable). If you can narrow down the specific bitwise function and inputs where the values diverge that would help a lot, otherwise I'll take a look when I find time. |
By the way, are you using 0.11 or HEAD? |
Well, it seems that this error is not, in fact, repeatable -- not the next day, anyway. I'm not sure what happened, but the test is passing fine now.
0.11 EDIT: the bug is back! just a moment |
The specific incorrect computation is The computation unfolds thusly: (define (ch x y z)
(bitwise-ior
(bitwise-and x y)
(bitwise-and (bitwise-not x) z)))
(ch 5633329806339096767 4828357668228770026 12548180113516416124)
->
(bitwise-ior
(bitwise-and 5633329806339096767 4828357668228770026)
(bitwise-and (bitwise-not 5633329806339096767) 12548180113516416124))
->
(bitwise-ior
(bitwise-and 5633329806339096767 4828357668228770026)
(bitwise-and -5633329806339096768 12548180113516416124))
->
(bitwise-ior
4756225156975034538
11529219719034833984) At this point, the correct route produces |
consistently produces the correct result for me. Probably a GC bug in one of the C coded bitwise operators, let me audit the code. |
I cloned your repo and was able to reproduce the failed test. For simplicity I commented out all the other tests and changed to use
I was unable to reproduce a non-deterministic bitwise-ior call, however. I checked a few ways, but it's worth illustrating how to do this using
I then repeated this check with all of the other SRFI 151 procedures, your |
Hello,
I have recently implemented SHA-1 and SHA-2 in R7RS Scheme. In the process of implementing the 64-bit variants of SHA-2 (the SHA-512 family), I implemented SHA-512/t, an algorithm which generates new seed values according to the process described in FIPS 180-4 5.3.6, uses them to run SHA-512 on a given input, then truncates the result to a specific size (
t
). I implemented tests for this procedure by comparing its output when passedt = 256
andt = 224
against the standalone variants for those sizes. Most of these tests pass just fine, but one does not -- and before a recent change to usebit-field
and macros for slight runtime performance increases (bit-field
is about 4 times faster for truncation thanbitwise-and
), both of the "multiple blocks" tests failed.As you can verify yourself in the relevant code, and see more clearly by running
make
in the debug branch, the failing test ultimately callssha-2-64
twice with identical inputs, but gets a different output. Specifically, the third iteration of the compression pass of the second block is different. Even more specifically, the bitwise-only check function produces0
forsha-512/t
but an actual value forsha-512/256
despite receiving the exact same inputs for both. In the printed debug output, this would bet= 2: ...
following the message block that starts with '0's, the first and third instances oft= 2:
up from the bottom of the output.Note that when reading the debug output, there's a block between
sha-512/256
andsha-512/t
called with256
-- this is the calculation of the seeds as described in the aforementioned part of FIPS 180-4 and can be safely ignored.I suspect this may be related to the stack or bignums.
Thanks,
Juli
The text was updated successfully, but these errors were encountered: