Skip to content

Function producing different outputs for same inputs from different paths #1007

@Marie-Joseph

Description

@Marie-Joseph

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 passed t = 256 and t = 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 use bit-field and macros for slight runtime performance increases (bit-field is about 4 times faster for truncation than bitwise-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 calls sha-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 produces 0 for sha-512/t but an actual value for sha-512/256 despite receiving the exact same inputs for both. In the printed debug output, this would be t= 2: ... following the message block that starts with '0's, the first and third instances of t= 2: up from the bottom of the output.

Note that when reading the debug output, there's a block between sha-512/256 and sha-512/t called with 256 -- 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions