summaryrefslogtreecommitdiff
path: root/sntrup761.sh
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2021-01-08 02:33:13 +0000
committerDamien Miller <djm@mindrot.org>2021-01-08 13:49:49 +1100
commit599df78f3008cf78af21f8977be3e1dd085f8e2e (patch)
treebae023aa5b3201832a04e1829c1823ffc64e14e0 /sntrup761.sh
parent16448ff529affda7e2a15ee7c3200793abde0759 (diff)
downloadopenssh-git-599df78f3008cf78af21f8977be3e1dd085f8e2e.tar.gz
upstream: Update the sntrup761 creation script and generated code:
- remove unneeded header files and typedefs and rely on crypto_api.h - add defines to map types used to the crypto_api ones instead of typedefs. This prevents typedef name collisions in -portable. - remove CRYPTO_NAMESPACE entirely instead of making it a no-op - delete unused functions and make the remaining ones that aren't exported static. ok djm@ OpenBSD-Commit-ID: 7b9d0cf3acd5a3c1091da8afe00c904d38cf5783
Diffstat (limited to 'sntrup761.sh')
-rw-r--r--sntrup761.sh52
1 files changed, 35 insertions, 17 deletions
diff --git a/sntrup761.sh b/sntrup761.sh
index e7c5eed1..5cd5f92c 100644
--- a/sntrup761.sh
+++ b/sntrup761.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: sntrup761.sh,v 1.4 2021/01/04 21:58:58 dtucker Exp $
+# $OpenBSD: sntrup761.sh,v 1.5 2021/01/08 02:33:13 dtucker Exp $
# Placed in the Public Domain.
#
AUTHOR="supercop-20201130/crypto_kem/sntrup761/ref/implementors"
@@ -7,12 +7,6 @@ FILES="
supercop-20201130/crypto_sort/int32/portable4/int32_minmax.inc
supercop-20201130/crypto_sort/int32/portable4/sort.c
supercop-20201130/crypto_sort/uint32/useint32/sort.c
- supercop-20201130/crypto_kem/sntrup761/ref/uint64.h
- supercop-20201130/crypto_kem/sntrup761/ref/uint16.h
- supercop-20201130/crypto_kem/sntrup761/ref/uint32.h
- supercop-20201130/crypto_kem/sntrup761/ref/int8.h
- supercop-20201130/crypto_kem/sntrup761/ref/int16.h
- supercop-20201130/crypto_kem/sntrup761/ref/int32.h
supercop-20201130/crypto_kem/sntrup761/ref/uint32.c
supercop-20201130/crypto_kem/sntrup761/ref/int32.c
supercop-20201130/crypto_kem/sntrup761/ref/paramsmenu.h
@@ -38,30 +32,54 @@ echo
echo '#include <string.h>'
echo '#include "crypto_api.h"'
echo
-echo '#define CRYPTO_NAMESPACE(s) s'
+# Map the types used in this code to the ones in crypto_api.h. We use #define
+# instead of typedef since some systems have existing intXX types and do not
+# permit multiple typedefs even if they do not conflict.
+for t in int8 uint8 int16 uint16 int32 uint32 int64 uint64; do
+ echo "#define $t crypto_${t}"
+done
echo
for i in $FILES; do
echo "/* from $i */"
- grep \
- -v '#include' $i | \
+ # Changes to all files:
+ # - remove all includes, we inline everything required.
+ # - make functions not required elsewhere static.
+ # - rename the functions we do use.
+ # - remove unneccesary defines and externs.
+ sed -e "/#include/d" \
+ -e "s/crypto_kem_/crypto_kem_sntrup761_/g" \
+ -e "s/^void /static void /g" \
+ -e "s/^int16 /static int16 /g" \
+ -e "s/^uint16 /static uint16 /g" \
+ -e "/^extern /d" \
+ -e '/CRYPTO_NAMESPACE/d' \
+ -e "/^#define int32 crypto_int32/d" \
+ $i | \
case "$i" in
# Use int64_t for intermediate values in int32_MINMAX to prevent signed
# 32-bit integer overflow when called by crypto_sort_uint32.
*/int32_minmax.inc)
sed -e "s/int32 ab = b ^ a/int64_t ab = (int64_t)b ^ (int64_t)a/" \
- -e "s/int32 c = b - a/int64_t c = (int64_t)b - (int64_t)a/"
+ -e "s/int32 c = b - a/int64_t c = (int64_t)b - (int64_t)a/"
;;
*/int32/portable4/sort.c)
- sed -e "s/void crypto_sort/static void crypto_sort_int32/g"
+ sed -e "s/void crypto_sort/void crypto_sort_int32/g"
;;
*/uint32/useint32/sort.c)
- sed -e "s/void crypto_sort/static void crypto_sort_uint32/g"
+ sed -e "s/void crypto_sort/void crypto_sort_uint32/g"
+ ;;
+ # Remove unused function to prevent warning.
+ */crypto_kem/sntrup761/ref/int32.c)
+ sed -e '/ int32_div_uint14/,/^}$/d'
;;
+ # Remove unused function to prevent warning.
+ */crypto_kem/sntrup761/ref/uint32.c)
+ sed -e '/ uint32_div_uint14/,/^}$/d'
+ ;;
+ # Default: pass through.
*)
- sed -e "s/crypto_kem_/crypto_kem_sntrup761_/g" \
- -e "s/^extern void /static void /" \
- -e "s/^void /static void /" \
- -e "/^typedef int32_t int32;$/d"
+ cat
+ ;;
esac
echo
done