Hi TC,

thinking about our yesterday's MD5 discussion on IRC, I think we agreed
that calling an external MD5 program is not a good solution.

However, I feel it is all right if we would call a library function.

Implementing such an algorithm on the bit-level in Lisp is extremely
inefficient, while it is perfectly suited for C. And why re-invent the
wheel if there are libraries available? After all, we are doing the same
with trigonometric functions, OpenGL etc.

The 'native' function is ideally suited for that. I just played around a
little, and came up with the following inline-C solution:

(load "lib/native.l")

(gcc "openssl" '("-lssl" "-lcrypto")
   (md5 (Str) "md5" '(B . 16) Str) )

#include <string.h>
#include <openssl/md5.h>

char *md5(char *str) {
   static unsigned char buf[MD5_DIGEST_LENGTH];  // 16 bytes

   MD5(str, strlen(str), buf);
   return buf;

You can call it then as

: (mapcar hex (md5 "The quick brown fox jumped over the lazy dog's back"))
-> ("E3" "8C" "A1" "D9" "20" "C4" "B8" "B8" "D3" "94" "6B" "2C" "72" "F0" "16" 

As we don't need that function at the moment, I would suggest that we
don't bother with implementing it also for the 32-bit version. I'm
afraid that there it is quite a bit longer, as it must build up the
return value.

What do you think?

- Alex
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to