Re: MD5 Function

2010-02-26 Thread Alexander Burger
Hi all,

sorry, please forget what I wrote yesterday:

> (load "lib/native.l")
> 
> (gcc "openssl" '("-lssl" "-lcrypto")
>(md5 (Str) "md5" '(B . 16) Str) )
> ...
> : (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" "80")


There is no need for inline C-code, calling 'gcc' etc., as the 'native'
function can handle this directly:

(let Str "The quick brown fox jumped over the lazy dog's back"
   (mapcar hex
  (native "libcrypto.so" "MD5" '(B . 16) Str (length Str) '(NIL (16))) ) )
-> ("E3" "8C" "A1" "D9" "20" "C4" "B8" "B8" "D3" "94" "6B" "2C" "72" "F0" "16" 
"80")

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


MD5 Function

2010-02-26 Thread Alexander Burger
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 
#include 

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" 
"80")


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?

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