php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #13206 MD5 option for 128 bytes long digest (standard)
Submitted: 2001-09-07 18:32 UTC Modified: 2001-09-08 12:24 UTC
From: neurobasher at planetquake dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: Windows 98
Private report: No CVE-ID: None
 [2001-09-07 18:32 UTC] neurobasher at planetquake dot com
It's a feature request regarding the MD5 string function.

The standard MD5 hash algorithm provides a 16 bytes long digest. PHP's MD5, even though it says it's "using the RSA Data Security, Inc. MD5 Message-Digest Algorithm", is non-standard: gives out a 32 bytes long digest.

I like the MD5 function very much, but I don't like it being described as using MD5 if it doesn't act like the standard MD5 algorithm, so my suggestion is that you should at least provide an option to choose between "32 bytes digest (non-standard)" and "16 bytes digest (standard)" modes.

It also would help a lot if source code/reference to PHP's unique MD5 implementation (which I can't seem to find ANYWHERE on the net) would be made available.

Thank you in advance,


Dan 'Neurobasher' Gomes

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-07 19:13 UTC] heyesr@php.net
md5() outputs 32 hex characters. 1 hex character = 4 bits.

32 * 4 = 128 bits.

128 bits / 8 = 16 bytes
 [2001-09-07 21:17 UTC] rasmus@php.net
Read RFC1321 (http://www.ietf.org/rfc/rfc1321.txt) where this is clearly stated and a number of testcases are listed.  PHP's md5() function performs each and every test case in the RFC perfectly (from the RFC):

MD5 test suite:
MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
d174ab98d277d9f5a5611c2c9f419d9f
MD5 ("123456789012345678901234567890123456789012345678901234567890123456
78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
 [2001-09-08 12:19 UTC] neurobasher at planetquake dot com
OMG, I'm sorry for my mistake. I never noticed MD5 returned hex characters instead of bytes, so I was treating them as bytes and I counted 32 of them instead of the 16 bytes those 32 hex characters represent.

I would REALLY appreciate if someone removed the embarrasing note I left on the MD5 command function that says "It should be noted that PHP's MD5 implementation gives you a 256 bits hash (32 bytes)..."

Thank you,


Dan 'Neurobasher' Gomes
 [2001-09-08 12:24 UTC] sander@php.net
I've removed the note from the manual.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 09:01:31 2024 UTC