diff --git a/libs/nacl/Makefile b/libs/nacl/Makefile new file mode 100644 index 000000000..88d42c3c8 --- /dev/null +++ b/libs/nacl/Makefile @@ -0,0 +1,45 @@ +# +# Copyright (C) 2011-2014 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=nacl +PKG_VERSION:=20110221 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Matthias Schiffer +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE_URL:=http://hyperelliptic.org/nacl +PKG_MD5SUM:=7efb5715561c3d10dafd3fa97b4f2d20 + +include $(INCLUDE_DIR)/package.mk + +define Package/nacl + SECTION:=libs + CATEGORY:=Libraries + TITLE:=NaCl Networking and Cryptography library + URL:=http://nacl.cace-project.eu/ +endef + +define Build/Compile + (cd $(PKG_BUILD_DIR) && \ + CC="$(TARGET_CC)" \ + CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \ + AR="$(TARGET_CROSS)ar" \ + RANLIB="$(TARGET_CROSS)ranlib" \ + $(CURDIR)/do-openwrt \ + ) +endef + +define Build/InstallDev + $(INSTALL_DIR) $(1)/usr/include/nacl + $(CP) $(PKG_BUILD_DIR)/build/include/*.h $(1)/usr/include/nacl/ + $(INSTALL_DIR) $(1)/usr/lib + $(CP) $(PKG_BUILD_DIR)/build/lib/libnacl.a $(1)/usr/lib/ +endef + +$(eval $(call BuildPackage,nacl)) diff --git a/libs/nacl/do-openwrt b/libs/nacl/do-openwrt new file mode 100755 index 000000000..ba4fde3b8 --- /dev/null +++ b/libs/nacl/do-openwrt @@ -0,0 +1,206 @@ +#!/bin/sh +set -e + +# nacl/do +# D. J. Bernstein +# Public domain. + +version=`cat version` +project=nacl + +top="`pwd`/build" +bin="$top/bin" +lib="$top/lib" +include="$top/include" +work="$top/work" + + +# and work around bug in GNU sort +LANG=C +export LANG + +rm -rf "$top" +mkdir -p "$top" +mkdir -p "$bin" +mkdir -p "$lib" +mkdir -p "$include" + +exec >"$top/log" +exec 2>&1 +exec 5>"$top/data" +exec " + echo "" + echo "typedef ${target}_t crypto_${target};" + echo "" + echo "#endif" + ) > "$include/crypto_$target.h" +done + +echo "=== `date` === building randombytes" +rm -rf "$work" +mkdir -p "$work" +cp -pr randombytes/* "$work" +( + cd "$work" + + cp devurandom.c randombytes-impl.c + cp devurandom.h randombytes-impl.h + $CC $CFLAGS -c randombytes-impl.c + mkdir -p lib + mv randombytes-impl.o lib/randombytes.o + mkdir -p include + mv randombytes-impl.h include/randombytes.h +) +cp -pr "$work"/lib/* "$lib" +cp -pr "$work"/include/* "$include" + +rm -rf "$work" +mkdir -p "$work" +echo 'void crypto_'"$project"'_base(void) { ; }' > "$work/${project}_base.c" +( cd "$work" && $CC $CFLAGS -c ${project}_base.c ) +$AR cr "$lib/lib${project}.a" "$work/${project}_base.o" +( $RANLIB "$lib/lib${project}.a" || exit 0 ) + +# loop over operations +cat OPERATIONS \ +| while read o +do + [ -d "$o" ] || continue + + # for each operation, loop over primitives + ls "$o" \ + | sort \ + | while read p + do + [ -d "$o/$p" ] || continue + op="${o}_${p}" + + startdate=`date +%Y%m%d` + + echo "=== `date` === $o/$p" + + rm -rf "$work" + mkdir -p "$work" + + if [ -d "$o/$p/ref" ]; then + implementationdir="$o/$p/ref" + else + implementationdir="$o/$p/portable" + fi + + opi=`echo "$implementationdir" | tr ./- ___` + + echo "=== `date` === $implementationdir" + + cfiles=`ls "$implementationdir" | grep '\.c$' || :` + sfiles=`ls "$implementationdir" | grep '\.[sS]$' || :` + + cp -p "$o"/*.c "$work" + + cp -pr "$implementationdir"/* "$work" + + cp -p MACROS "$work/MACROS" + cp -p PROTOTYPES.c "$work/PROTOTYPES.c" + + ( + cd "$work" + ( + echo "#ifndef ${o}_H" + echo "#define ${o}_H" + echo "" + echo "#include \"${op}.h\"" + echo "" + egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \ + | sed "s/$o/$op/" | while read mop + do + echo "#define ${mop} ${mop}" | sed "s/$op/$o/" + done + echo "#define ${o}_PRIMITIVE \"${p}\"" + echo "#define ${o}_IMPLEMENTATION ${op}_IMPLEMENTATION" + echo "#define ${o}_VERSION ${op}_VERSION" + echo "" + echo "#endif" + ) > "$o.h" + ( + echo "#ifndef ${op}_H" + echo "#define ${op}_H" + echo "" + sed 's/[ ]CRYPTO_/ '"${opi}"'_/g' < api.h + echo '#ifdef __cplusplus' + #echo '#include ' + #egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.cpp \ + # | sed "s/$o/$opi/" + echo 'extern "C" {' + echo '#endif' + egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.c \ + | sed "s/$o/$opi/" + echo '#ifdef __cplusplus' + echo '}' + echo '#endif' + echo "" + egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \ + | sed "s/$o/$opi/" | while read mopi + do + echo "#define ${mopi} ${mopi}" | sed "s/$opi/$op/" + done + echo "#define ${op}_IMPLEMENTATION \"${implementationdir}\"" + echo "#ifndef ${opi}_VERSION" + echo "#define ${opi}_VERSION \"-\"" + echo "#endif" + echo "#define ${op}_VERSION ${opi}_VERSION" + echo "" + echo "#endif" + ) > "$op.h" + + echo "=== `date` === $implementationdir $CC $CFLAGS" + for f in $cfiles $sfiles + do + ok=1 + $CC $CFLAGS \ + -I. -I"$include" \ + -c "$f" >errors 2>&1 || ok=0 + ( if [ `wc -l < errors` -lt 25 ] + then + cat errors + else + head errors + echo ... + tail errors + fi + ) \ + | while read err + do + echo "$version $startdate $o $p fromcompiler $implementationdir $f $err" >&5 + done + + [ "$ok" = 1 ] + done + + for f in *.o + do + mv "$f" "${opi}-$f" + done + ) + + echo "=== `date` === $implementationdir $CC $CFLAGS finishing" + + $AR cr "$lib/lib${project}.a" "$work"/*.o \ + && ( $RANLIB "$lib/lib${project}.a" || exit 0 ) \ + && cp -p "$work/$op.h" "$include/$op.h" \ + && [ -f "$o/$p/selected" ] \ + && cp -p "$work/$o.h" "$include/$o.h" \ + || : + done +done + +echo "=== `date` === finishing"