mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-22 06:27:51 +00:00
f55a6525a2
(static is always the safer option for crypto libraries to avoid nasty run-time suprises)
88 lines
1.8 KiB
Plaintext
Executable File
88 lines
1.8 KiB
Plaintext
Executable File
# Fetch latest version of source as recommended by nacl installation page
|
|
if [ ! -e nacl-source.tar.bz2 ]; then
|
|
`wget -q -O - http://nacl.cr.yp.to/install.html | grep wget | sed -e 's/^ *//g' -e 's/^wget /wget -q -O nacl-source.tar.bz2 /'`
|
|
fi
|
|
|
|
# Extract tarball
|
|
mkdir -p nacl-source
|
|
|
|
arlist=`find . -name libnacl.a`
|
|
arcount=`echo $arlist | wc -l`
|
|
if [ $arcount -eq 0 ]; then
|
|
cd nacl-source
|
|
bzip2 -d ../nacl-source.tar | tar xvf -
|
|
nacldir=`echo *`
|
|
cd ${nacldir}
|
|
|
|
./do
|
|
|
|
cd ..
|
|
fi
|
|
|
|
# Test which one works for us
|
|
include=`find . -name crypto_box.h | head -1`
|
|
cat <<EOF >test.c
|
|
#include <stdio.h>
|
|
#include "${include}"
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
/* it's really stupid that there isn't a syscall for this */
|
|
|
|
static int fd = -1;
|
|
|
|
void randombytes(unsigned char *x,unsigned long long xlen)
|
|
{
|
|
int i;
|
|
|
|
if (fd == -1) {
|
|
for (;;) {
|
|
fd = open("/dev/urandom",O_RDONLY);
|
|
if (fd != -1) break;
|
|
sleep(1);
|
|
}
|
|
}
|
|
|
|
while (xlen > 0) {
|
|
if (xlen < 1048576) i = xlen; else i = 1048576;
|
|
|
|
i = read(fd,x,i);
|
|
if (i < 1) {
|
|
sleep(1);
|
|
continue;
|
|
}
|
|
|
|
x += i;
|
|
xlen -= i;
|
|
}
|
|
}
|
|
|
|
unsigned char pk[crypto_box_PUBLICKEYBYTES];
|
|
unsigned char sk[crypto_box_SECRETKEYBYTES];
|
|
|
|
int main(int argc,char **argv) {
|
|
|
|
crypto_box_keypair(pk,sk);
|
|
printf("The compilation worked.\n");
|
|
}
|
|
EOF
|
|
for ar in $arlist
|
|
do
|
|
if [ -e test ]; then
|
|
rm test
|
|
fi
|
|
gcc -o test test.c $ar >/dev/null 2>&1
|
|
if [ -e test ]; then
|
|
naclbuilddir=`echo $ar | sed -e s,/libnacl.a,,`
|
|
echo "${naclbuilddir}" > naclbuilddir.txt
|
|
fi
|
|
done
|
|
if [ -e test ]; then
|
|
rm test
|
|
fi
|
|
|
|
includedir=`cat naclbuilddir.txt | sed s,/lib/,/include/,`
|
|
ls -1 ${includedir} | sed -e 's,^,#include "'"${includedir}"'/,' -e 's,$,",' > nacl.h
|