NaCl/Shared

From Qontrol.nl Wiki
Jump to: navigation, search

To build a shared, dynamically linkable library from the nacl sourcecode:

# Download and extract the NaCl sourcecode:
wget -O- http://hyperelliptic.org/nacl/nacl-20110221.tar.bz2 | bunzip2 | tar -xf -
cd nacl-20110221
# Remove some implementations that do not want to be relocatable (it will fall back to another implementation)
rm -r crypto_onetimeauth/poly1305/amd64
# Patch the compiler commands to create relocatable code
sed -i "s/$/ -fPIC/" okcompilers/c
# Patch the code to accept application input for the key generation functions
wget -O- http://oss.ucis.nl/nacl/shared/shared.c | patch -p1
# Build the NaCl library, this takes some time...
./do
# Build and locate some utilities used by the nacl build process to find the CPU architecture (and output directory) and an useable compiler
gcc okcompilers/abiname.c -o abiname
ABINAME="$(./abiname "" | cut -b 2-)"
BUILDDIR="build/$(hostname | sed 's/\..*//' | tr -cd '[a-z][A-Z][0-9]')"
NACLLIB="${BUILDDIR}/lib/${ABINAME}/libnacl.a"
OKCOMPILER="$($BUILDDIR/bin/okc-${ABINAME} | head -n 1)"
# Compile some frontend code into a shared library (download, preprocess with NaCl header files, rewrite some lines, compile and link with the static nacl library)
wget -O- http://oss.ucis.nl/nacl/shared/shared.c |
${OKCOMPILER} -x c -E - -I "${BUILDDIR}/include/${ABINAME}" |
       sed "s/export_//" |
       ${OKCOMPILER} -fPIC -nostdlib -shared -Wl,--no-undefined -o "libnacl.so" -x c - -x none "${NACLLIB}"
# Install library to /usr/lib
install -m 644 libnacl.so /usr/lib/
# Install header files to /usr/include/nacl
mkdir /usr/include/nacl
(
  cd /usr/include/nacl
  wget http://oss.ucis.nl/nacl/shared/crypto_box.h http://oss.ucis.nl/nacl/shared/crypto_box_curve25519xsalsa20poly1305.h http://oss.ucis.nl/nacl/shared/crypto_scalarmult_curve25519.h http://oss.ucis.nl/nacl/shared/crypto_sign_edwards25519sha512batch.h
)

File list