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

Correct implementation of joaat hash. #5749

Closed
wants to merge 1 commit into from
Closed

Conversation

kohler
Copy link
Contributor

@kohler kohler commented Jun 22, 2020

Before this commit, the result produced by a joaat hash depended
on how the input data was chunked. A hash produced by multiple
hash_update operations was incorrect. For example, this code,
which should produce three identical lines:

var_dump(hash("joaat", "abcd"));

$hash = hash_init("joaat");
hash_update($hash, "ab");
hash_update($hash, "cd");
var_dump(hash_final($hash));

$hash = hash_init("joaat");
hash_update($hash, "abc");
hash_update($hash, "d");
var_dump(hash_final($hash));

instead produced:

string(8) "cd8b6206"
string(8) "e590d137"
string(8) "2d59d087"

This is because the finalization step, involving shift operations
and adds, was applied on every chunk, rather than once at the end
as is required by the hash definition.

After this commit, the code above produces:

string(8) "cd8b6206"
string(8) "cd8b6206"
string(8) "cd8b6206"

as expected.

Some tests encoded the wrong behavior and were corrected.

Before this commit, the result produced by a joaat hash depended
on how the input data was chunked. A hash produced by multiple
`hash_update` operations was incorrect. For example, this code,
which should produce three identical lines:

    var_dump(hash("joaat", "abcd"));

    $hash = hash_init("joaat");
    hash_update($hash, "ab");
    hash_update($hash, "cd");
    var_dump(hash_final($hash));

    $hash = hash_init("joaat");
    hash_update($hash, "abc");
    hash_update($hash, "d");
    var_dump(hash_final($hash));

instead produced:

    string(8) "cd8b6206"
    string(8) "e590d137"
    string(8) "2d59d087"

This is because the finalization step, involving shift operations
and adds, was applied on every chunk, rather than once at the end
as is required by the hash definition.

After this commit, the code above produces:

    string(8) "cd8b6206"
    string(8) "cd8b6206"
    string(8) "cd8b6206"

as expected.

Some tests encoded the wrong behavior and were corrected.
@php-pulls php-pulls closed this in efad137 Jun 22, 2020
@kohler kohler deleted the fix-joaat branch June 30, 2020 00:57
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.

None yet

2 participants