|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-08-20 15:00 UTC] letsgolee at naver dot com
Description:
------------
HAVAL pads a string with a wrong pad length, if the remaining string is over 64 and under 118 bytes length. The suspect code is:
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
when the remaining string is under 63 bytes long then there seems no problem, but when a string is over 64 and under 118 then it seems to have a wrong padding length.
If you test "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ0123456789" then, it will give you right hash value, because the string length is 183 and it is above 128 and the remaining string length is 55. And 55 is under 64 so it will give a right result.
Test script:
---------------
hash('haval256,5', '1234567890123456789012345678901234567890123456789012345678901234');
Expected result:
----------------
fb73c19300b14d5cb393d929bf005e6c2d459a4c9c009e9813af1d2d3637ee8f
Actual result:
--------------
498f3710ed9373908405d608e15df8157ef777abe85794b67f590347b4506fb2
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 09:00:01 2025 UTC |
The reference implementation which can be downloaded from www.schneier.com is apparently meant for 32bit systems only (see haval.h line 45, for instance). There are some certification data available in cert.data; running ./haval -c is supposed to reproduce these. Anyhow, building on 32bit Debian Jessie with PASS=5 and FPTLEN=256 (LITTLE_ENDIAN is irrelevant for the result) produces: HAVAL("1234567890123456789012345678901234567890123456789012345678901234") = FB73C19300B14D5CB393D929BF005E6C2D459A4C9C009E9813AF1D2D3637EE8F