From 87bf48fccf89460b8264bb5cedf6b0e966dde563 Mon Sep 17 00:00:00 2001 From: Andres Erbsen Date: Sun, 18 Jun 2017 15:46:40 -0400 Subject: compile X25519 C code from Makefile --- extract-function.sh | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 extract-function.sh (limited to 'extract-function.sh') diff --git a/extract-function.sh b/extract-function.sh new file mode 100755 index 000000000..4056f242c --- /dev/null +++ b/extract-function.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +case "$#" in + 0) + funcname=f + ;; + 1) + funcname="$1" + ;; + *) + exit 111 + ;; +esac + +cat < +#include +#include + +#include "$funcname.h" + +typedef unsigned int uint128_t __attribute__((mode(TI))); + +#undef force_inline +#define force_inline __attribute__((always_inline)) + +EOF + +lines=0 +show=false +while IFS= read -r line; do + case "$line" in + *"λ '"*) + echo -n "void force_inline $funcname(" + echo -n "uint64_t* out" + echo "$line" | grep -owP -- '\w+\d+' | \ + while IFS= read -r arg; do + echo -n ", uint64_t $arg" + done + echo ')' + show=true + ;; + *"Return "*|*"return "*) + i=0 + echo "$line" | \ + sed 's:return::g' | sed 's:Return::g' | tr -d '(' | tr -d ')' | tr , '\n' | sed 's/^\s\+//g' | \ + ( while IFS= read -r ret; do + echo "out[$i] = $ret;" + ((i++)) + done; + seq 2 "$lines" | while IFS= read -r _; do + echo -n "}" + done + echo "}" + echo "// caller: uint64_t out[$i];" ) + show=false + break + ;; + *) + case "$show" in + true) + ((lines++)) + echo "{ $line" | \ + sed s':^\([^,]*\) \([^, ]*\)\(\s*\),\(.*\)\(addcarryx.*\))\([; ]*\)$:\1 \2\3;\4_\5, \&\2)\6:' | \ + sed s':^\([^,]*\) \([^, ]*\)\(\s*\),\(.*\)\(subborrow.*\))\([; ]*\)$:\1 \2\3;\4_\5, \&\2)\6:' + ;; + esac + ;; + esac +done + -- cgit v1.2.3