1

I was using hash_pbkdf2 earlier today when I noticed something strange.

The normal way to generate a hash is to output the entire string like the code below which outputs a 128 character string (128 chars, 4 bit each, 512bit total):
echo hash_pbkdf2("sha512", "123456", "test", 30000, 0);
c7b35be6c57b716fe4beb1ca33341ea32cb0de817636c115244db9c57cea1120828ea2b9f19805b24667c876d7b0e5ec4a3b05b3b793845ece2404106d781cda

However I made a minor error which I noticed output a whole heap of extra data:
echo hash_pbkdf2("sha512", "123456", "test", 30000, 512);
c7b35be6c57b716fe4beb1ca33341ea32cb0de817636c115244db9c57cea1120828ea2b9f19805b24667c876d7b0e5ec4a3b05b3b793845ece2404106d781cda6b38792a96c1677e897dc7640c759dc660b02bdd6b590e6b90edc88484a03bbc8d5abf598cfe0493d99aea0074ba9d66c16ecc5ab92b02e27eece56253b6c55546bc0d699129d726fc9c794baaa7bbda45625e7f7efbf958baf3f77236eadd3e4b86beaf7ed302f995096ad08e95fe078a0bb0ad0ff5dd672aac76fc335b6746ee177d6f2133de667a8a49a1356129d2a34a3a57aeb341101cd78fd8998d11910d926576427da7a02da554a787efe782fe7d26f01fe3e4f8bf4f4f352470725c

What are the extra hex output by this bad code, I was under the impression that SHA-512 could only output a maximum of 512bits?

2

According to the function definition, you specified a bit length of 512. By default (raw_output = False) the extra bits come from the derived key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.