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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions ext/hash/hash_joaat.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ PHP_HASH_API void PHP_JOAATUpdate(PHP_JOAAT_CTX *context, const unsigned char *i

PHP_HASH_API void PHP_JOAATFinal(unsigned char digest[4], PHP_JOAAT_CTX * context)
{
uint32_t hval = context->state;
hval += (hval << 3);
hval ^= (hval >> 11);
hval += (hval << 15);

#ifdef WORDS_BIGENDIAN
memcpy(digest, &context->state, 4);
memcpy(digest, &hval, 4);
#else
int i = 0;
unsigned char *c = (unsigned char *) &context->state;
unsigned char *c = (unsigned char *) &hval;

for (i = 0; i < 4; i++) {
digest[i] = c[3 - i];
}
#endif
context->state = 0;
context->state = 0;
}

/*
Expand All @@ -79,9 +84,5 @@ joaat_buf(void *buf, size_t len, uint32_t hval)
hval ^= (hval >> 6);
}

hval += (hval << 3);
hval ^= (hval >> 11);
hval += (hval << 15);

return hval;
}
2 changes: 1 addition & 1 deletion ext/hash/tests/hash-clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ string(16) "bebc746a33b6ab62"
string(16) "893899e4415a920f"
string(5) "joaat"
string(8) "aaebf370"
string(8) "513479b4"
string(8) "836fb0e5"
string(10) "haval128,3"
string(32) "86362472c8895e68e223ef8b3711d8d9"
string(32) "ebeeeb05c18af1e53d2d127b561d5e0d"
Expand Down
2 changes: 1 addition & 1 deletion ext/hash/tests/hash_copy_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ string(16) "bebc746a33b6ab62"
string(16) "893899e4415a920f"
string(5) "joaat"
string(8) "aaebf370"
string(8) "513479b4"
string(8) "836fb0e5"
string(10) "haval128,3"
string(32) "86362472c8895e68e223ef8b3711d8d9"
string(32) "ebeeeb05c18af1e53d2d127b561d5e0d"
Expand Down