Importing C libraries

Started by shercipher, May 11, 2009, 09:02:41 PM

Previous topic - Next topic

shercipher

I need to use the SHA1 function in libssl.so. The function has the following syntax:



unsigned char *SHA1(const unsigned char *d, unsigned long n,
                  unsigned char *md);


With the explanation



SHA1() computes the SHA-1 message digest of the n bytes at d and places it in md (which must have space for SHA_DIGEST_LENGTH == 20 bytes of output). If md is NULL, the digest is placed in a static array.



So I was like okay, well I can't find a newLisp NULL, but I think nil should do it...

Tried



(SHA1 etc (length etc) nil)


Which crashes with a segfault if I try to do that again.



So then I was like, okay, maybe I can store it in a variable:



(SHA1 etc (length etc) *resultant*)


And reading *resultant* gives me



?


Interesting. Anything else gives me segmentation faults. How can I get these two languages to work with each other, or is the answer "write a glue library"?

xytroxon

#1
You can use the  "crypto.lsp"  module that is included in your newlisp module directory...



Read about it here:

http://newlisp.nfshost.com/code/modules/crypto.lsp.html">//http://newlisp.nfshost.com/code/modules/crypto.lsp.html



-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

shercipher

#2
Too late, already wrote my own function. Will consider replacing if necessary later (I have doubts that mine works correctly).