Page 1 of 1

Importing C libraries

Posted: Tue May 12, 2009 4:02 am
by shercipher
I need to use the SHA1 function in libssl.so. The function has the following syntax:

Code: Select all

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

Code: Select all

(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:

Code: Select all

(SHA1 etc (length etc) *resultant*)
And reading *resultant* gives me

Code: Select all

?
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"?

Re: Importing C libraries

Posted: Tue May 12, 2009 5:47 am
by xytroxon
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

-- xytroxon

Posted: Tue May 12, 2009 6:03 am
by shercipher
Too late, already wrote my own function. Will consider replacing if necessary later (I have doubts that mine works correctly).