I guess I technically have to claim my own bounty for ripemd160
Here is working code for ripemd160 adapted nearly verbatim from
here. Sorry about the formatting, but it should paste back into Mathematica nicely.
(*
This function finds the RIPEMD160 hash of a list of bytes expressed as integers.
Integers greater than 255 and less than 0 are truncated to 8 bits.
This code was adapted from: http://www.win.tue.nl/~berry/2WC01/CryptographicHash-Collisions.nb
*)
ripemd160[bytelist_List/;Or[And@@IntegerQ/@bytelist, Length[bytelist]==0]]:=Module[{f,y,z,s,h1,h2,h3,h4,h5,a,b,c,d,e,t,m,X,r,xx,i,j,k, x, BitRotateLeft, convert},
x = Flatten[IntegerDigits[bytelist, 2, 8]];
BitRotateLeft[x_,n_] := FromDigits[ RotateLeft[IntegerDigits[x,2,32],n],2];
convert[x_] := FromDigits[Reverse[IntegerDigits[x,256,4]],256];
f[j_,u_,v_,w_]:=
If[j<=16, BitXor[u,v,w],
If[j<=32, BitOr[BitAnd[u,v],BitAnd[BitNot[u],w]],
If[j<=48, BitXor[BitOr[u,BitNot[v]],w],
If[j<=64, BitOr[BitAnd[u,w],BitAnd[v,BitNot[w]]],
BitXor[u,BitOr[v,BitNot[w]]]
]]]];
y[0,j_] := y[0,j] =If[j<=16, 0, If[j<=32, 16^^5a827999, If[j<=48, 16^^6ed9eba1, If[j<=64,16^^8f1bbcdc,16^^a953fd4e]] ]];
y[1,j_] := y[1,j] =If[j<=16, 16^^50a28be6, If[j<=32, 16^^5c4dd124, If[j<=48, 16^^6d703ef3, If[j<=64,16^^7a6d76e9,0]] ]];
z[0]=Flatten[{{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},{7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8},
{3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12},{1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2},{4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13}}];
z[1]=Flatten[{{5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12},{6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2},{15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13},{8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14},{12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11}}];
s[0]=Flatten[{{11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8},{7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12},{11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5},{11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12},{9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6}}];
s[1]=Flatten[{{8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6},{9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11},{9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5},{15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8},{8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11}}];
m=Ceiling[(Length[x]+65)/512];
r = 512m-Length[x]-64;
xx = Join[x,{1},Table[0,{r-1}],Flatten[IntegerDigits[Reverse[IntegerDigits[Mod[Length[x],2^64],256,8]],2,8]]];
{h1,h2,h3,h4,h5} = {16^^67452301,16^^efcdab89,16^^98badcfe,16^^10325476,16^^c3d2e1f0};
For[i=0, iFor[j=0, j<16, j++, X[j]=FromDigits[Take[xx,512i+32j+{1,32}],2];];
For[k=0,k<=1,k++,
{a[k],b[k],c[k],d[k],e[k]} = {h1,h2,h3,h4,h5};
For[j=1, j<=80, j++, t = Mod[a[k] + f[(1-k) j+k(81-j),b[k],c[k],d[k]] +convert[ X[z[k][[j]]]] + y[k,j],2^32];
{a[k],b[k],c[k],d[k],e[k]} = {e[k],Mod[e[k]+BitRotateLeft[t,s[k][[j]]],2^32],b[k],BitRotateLeft[c[k],10],d[k]};
];
];
{h1,h2,h3,h4,h5}=Mod[{h2+c[0]+d[1],h3+d[0]+e[1],h4+e[0]+a[1],h5+a[0]+b[1],h1+b[0]+c[1]},2^32];
];
FromDigits[convert/@{h1,h2,h3,h4,h5},2^32]
];
If you want to add ripemd160 to the default Mathematica fuction Hash[], here's how for the most useful pattern types:
Unprotect[Hash];
Hash[x_List , "RIPEMD160"] := ripemd160[x]
Hash[x_String, "RIPEMD160"] := ripemd160[ToCharacterCode[x]]
Hash[x_Integer, "RIPEMD160"] := ripemd160[IntegerDigits[x, 256, 20]] (*160 bit integer assumed*)
Here is the correct output to the test vectors from
http://homes.esat.kuleuven.be/~bosselae/ripemd160.htmlIn[63]:=
Hash["", "RIPEMD160"]//IntegerString[#, 16]&
Hash["a", "RIPEMD160"]//IntegerString[#, 16]&
Hash["abc", "RIPEMD160"]//IntegerString[#, 16]&
Hash["message digest", "RIPEMD160"]//IntegerString[#, 16]&
Hash["abcdefghijklmnopqrstuvwxyz", "RIPEMD160"]//IntegerString[#, 16]&
Hash["abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "RIPEMD160"]//IntegerString[#, 16]&
Hash["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "RIPEMD160"]//IntegerString[#, 16]&
Hash[StringJoin@@Table["1234567890", {8}], "RIPEMD160"]//IntegerString[#, 16]&
Hash[StringJoin@@Table["a", {10^6}], "RIPEMD160"]//IntegerString[#, 16]&
Out[63]= 9c1185a5c5e9fc54612808977ee8f548b2258d31
Out[64]= bdc9d2d256b3ee9daae347be6f4dc835a467ffe
Out[65]= 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc
Out[66]= 5d0689ef49d2fae572b881b123a85ffa21595f36
Out[67]= f71c27109c692c1b56bbdceb5b9d2865b3708dbc
Out[68]= 12a053384a9c0c88e405a06c27dcf49ada62eb2b
Out[69]= b0e20b6e3116640286ed3a87a5713079b21f5189
Out[70]= 9b752e45573d4b39f4dbd3323cab82bf63326bfb
Out[71]= 52783243c1697bdbe16d37f97f68f08325dc1528