[erlang-questions] crypto:md5/1 vs openssl md5

CGS cgsmcmlxxv@REDACTED
Fri Feb 10 06:26:24 CET 2012


Hi,

Just for my curiosity, does anybody know if crypto:md5/1 in R14B03 is
intentionally different from openssl md5? (The sha matches perfectly.)

Just a short test (Erlang shell):
1> RB =
crypto:rand_bytes(16).
<<141,190,84,7,129,230,147,112,200,205,68,80,240,78,68,198>>

2> MD5 =
crypto:md5(RB).
<<97,59,0,195,229,254,195,237,238,126,156,14,33,142,206,183>>
3> lists:flatten(lists:map(fun([X,Y])->[case X>64 of true -> X+32; false->
X end,case Y>64 of true -> Y+32; false -> Y end];([X])->[$0,case X>64 of
true -> X+32; false -> X end] end, lists:map(fun(X)->integer_to_list(X,16)
end, binary_to_list(RB)))).
"8dbe540781e69370c8cd4450f04e44c6"
4> lists:flatten(lists:map(fun([X,Y])->[case X>64 of true -> X+32; false->
X end,case Y>64 of true -> Y+32; false -> Y end];([X])->[$0,case X>64 of
true -> X+32; false -> X end] end, lists:map(fun(X)->integer_to_list(X,16)
end, binary_to_list(MD5)))).
"613b00c3e5fec3edee7e9c0e218eceb7"
5> os:cmd("echo \"8dbe540781e69370c8cd4450f04e44c6\" | openssl
md5").
"(stdin)=
6007d8f36b589078f3565b5c90cedffc\n"

As you can see the same rand number, "8dbe540781e69370c8cd4450f04e44c6",
gives in crypto:md5 "613b00c3e5fec3edee7e9c0e218eceb7" while in openssl md5
"6007d8f36b589078f3565b5c90cedffc". Please, let me know if I do something
wrong.

CGS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120210/1103b3c3/attachment.htm>


More information about the erlang-questions mailing list