The now commonly used Linux/FreeBSD passwd hashes being a modified version of md5. The orginal code can be found in the FreeBSD source tree under src/lib/libcrypt/crypt-md5.c or here.
The implementation is basically trying to slow down the md5 process as much as possible from what I can tell. It runs through the basic md5 function over a thousand times over and over using the salt and the password.
After doing more research (or in other words understanding more what I’m doing). I need to implement the RSA defined functions MD5Init, MD5Update and MD5Final. MD5Init being quite simple. It basically initializes the a,b,c,d values. The PS3 uses vectors so we will initialize it this way.
vec_uint4 a = (vec_uint4){0×67452301, 0×67452301, 0×67452301, 0×67452301};
vec_uint4 b = (vec_uint4){0xefcdab89, 0xefcdab89, 0xefcdab89, 0xefcdab89};
vec_uint4 c = (vec_uint4){0×98badcfe, 0×98badcfe, 0×98badcfe, 0×98badcfe};
vec_uint4 d = (vec_uint4){0×10325476, 0×10325476, 0×10325476, 0×10325476};
Now MD5Update is quite a bit trickier. It appears to perform the MD5 transformation on every 64 bytes chunk of data, which in this case, one chunk should be plenty enough for password storage. The MD5 Transformation itself performs the following operations. I hope wikipedia won’t mind this.
For which I’ve respectively implemented using these operations and of course, vectorized, so in other words it performs the operations 4 times.
F: vec_t = spu_xor(*vec_d, spu_and(*vec_b, spu_xor(*vec_c, *vec_d)));
G: vec_t = spu_xor(*vec_c, spu_and(*vec_d, spu_xor(*vec_b, *vec_c)));
H: vec_t = spu_xor ( spu_xor ( *vec_b, *vec_c ), *vec_d );
I: vec_t = spu_xor ( *vec_c ,spu_or(*vec_b, spu_eqv (*vec_d,vec_null)) );
Honestly, I’m still trying to figure out what MD5Update does exactly. While it may appear to be simple for some coders out there, my mind is still trying to grasp the concept for lack of documentation about it.
Finally MD5Final appears to be adding padding to the 512 bit buffer, adds the bit count and then does a final transformation.
So how fast can the MD5 algorithm really go on the PS3? 80 million hashes per second.Thats not too shabby I believe although a bit deceiving.
With the MD5crypt algorithm, the MD5 hashing function is executed ~1000 times per encryption so one can ball park the number of key/s second to about 75,000 key/s.
This is pretty good considering these benchmarks. On a E6750 overclocked at 3.6ghz it reaches 15500 keys/s per core or 31,000 on both cores. Considering the price of building a PC supporting this CPU not to mention overclocking it to those speeds, the ps3’s performance isn’t too bad.
-G