Importing C libraries

Q&A's, tips, howto's
Locked
shercipher
Posts: 15
Joined: Sun May 10, 2009 3:11 am

Importing C libraries

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

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: Importing C libraries

Post 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
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

shercipher
Posts: 15
Joined: Sun May 10, 2009 3:11 am

Post by shercipher »

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

Locked