119261079SEd Maste#!/bin/sh 2*f374ba41SEd Maste# $OpenBSD: sntrup761.sh,v 1.7 2023/01/11 02:13:52 djm Exp $ 319261079SEd Maste# Placed in the Public Domain. 419261079SEd Maste# 519261079SEd MasteAUTHOR="supercop-20201130/crypto_kem/sntrup761/ref/implementors" 619261079SEd MasteFILES=" 719261079SEd Maste supercop-20201130/crypto_sort/int32/portable4/int32_minmax.inc 819261079SEd Maste supercop-20201130/crypto_sort/int32/portable4/sort.c 919261079SEd Maste supercop-20201130/crypto_sort/uint32/useint32/sort.c 1019261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/uint32.c 1119261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/int32.c 1219261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/paramsmenu.h 1319261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/params.h 1419261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/Decode.h 1519261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/Decode.c 1619261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/Encode.h 1719261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/Encode.c 1819261079SEd Maste supercop-20201130/crypto_kem/sntrup761/ref/kem.c 1919261079SEd Maste" 2019261079SEd Maste### 2119261079SEd Maste 2219261079SEd Masteset -e 2319261079SEd Mastecd $1 2419261079SEd Masteecho -n '/* $' 2519261079SEd Masteecho 'OpenBSD: $ */' 2619261079SEd Masteecho 2719261079SEd Masteecho '/*' 2819261079SEd Masteecho ' * Public Domain, Authors:' 2919261079SEd Mastesed -e '/Alphabetical order:/d' -e 's/^/ * - /' < $AUTHOR 3019261079SEd Masteecho ' */' 3119261079SEd Masteecho 3219261079SEd Masteecho '#include <string.h>' 3319261079SEd Masteecho '#include "crypto_api.h"' 3419261079SEd Masteecho 3519261079SEd Maste# Map the types used in this code to the ones in crypto_api.h. We use #define 3619261079SEd Maste# instead of typedef since some systems have existing intXX types and do not 3719261079SEd Maste# permit multiple typedefs even if they do not conflict. 3819261079SEd Mastefor t in int8 uint8 int16 uint16 int32 uint32 int64 uint64; do 3919261079SEd Maste echo "#define $t crypto_${t}" 4019261079SEd Mastedone 4119261079SEd Masteecho 4219261079SEd Mastefor i in $FILES; do 4319261079SEd Maste echo "/* from $i */" 4419261079SEd Maste # Changes to all files: 4519261079SEd Maste # - remove all includes, we inline everything required. 4619261079SEd Maste # - make functions not required elsewhere static. 4719261079SEd Maste # - rename the functions we do use. 48*f374ba41SEd Maste # - remove unnecessary defines and externs. 4919261079SEd Maste sed -e "/#include/d" \ 5019261079SEd Maste -e "s/crypto_kem_/crypto_kem_sntrup761_/g" \ 5119261079SEd Maste -e "s/^void /static void /g" \ 5219261079SEd Maste -e "s/^int16 /static int16 /g" \ 5319261079SEd Maste -e "s/^uint16 /static uint16 /g" \ 5419261079SEd Maste -e "/^extern /d" \ 5519261079SEd Maste -e '/CRYPTO_NAMESPACE/d' \ 5619261079SEd Maste -e "/^#define int32 crypto_int32/d" \ 57*f374ba41SEd Maste -e 's/[ ]*$//' \ 5819261079SEd Maste $i | \ 5919261079SEd Maste case "$i" in 6019261079SEd Maste # Use int64_t for intermediate values in int32_MINMAX to prevent signed 6119261079SEd Maste # 32-bit integer overflow when called by crypto_sort_uint32. 6219261079SEd Maste */int32_minmax.inc) 6319261079SEd Maste sed -e "s/int32 ab = b ^ a/int64_t ab = (int64_t)b ^ (int64_t)a/" \ 6419261079SEd Maste -e "s/int32 c = b - a/int64_t c = (int64_t)b - (int64_t)a/" 6519261079SEd Maste ;; 6619261079SEd Maste */int32/portable4/sort.c) 6719261079SEd Maste sed -e "s/void crypto_sort/void crypto_sort_int32/g" 6819261079SEd Maste ;; 6919261079SEd Maste */uint32/useint32/sort.c) 7019261079SEd Maste sed -e "s/void crypto_sort/void crypto_sort_uint32/g" 7119261079SEd Maste ;; 7219261079SEd Maste # Remove unused function to prevent warning. 7319261079SEd Maste */crypto_kem/sntrup761/ref/int32.c) 7419261079SEd Maste sed -e '/ int32_div_uint14/,/^}$/d' 7519261079SEd Maste ;; 7619261079SEd Maste # Remove unused function to prevent warning. 7719261079SEd Maste */crypto_kem/sntrup761/ref/uint32.c) 7819261079SEd Maste sed -e '/ uint32_div_uint14/,/^}$/d' 7919261079SEd Maste ;; 8019261079SEd Maste # Default: pass through. 8119261079SEd Maste *) 8219261079SEd Maste cat 8319261079SEd Maste ;; 8419261079SEd Maste esac 8519261079SEd Maste echo 8619261079SEd Mastedone 87