2 # $OpenBSD: sntrup761.sh,v 1.5 2021/01/08 02:33:13 dtucker Exp $
3 # Placed in the Public Domain.
5 AUTHOR="supercop-20201130/crypto_kem/sntrup761/ref/implementors"
7 supercop-20201130/crypto_sort/int32/portable4/int32_minmax.inc
8 supercop-20201130/crypto_sort/int32/portable4/sort.c
9 supercop-20201130/crypto_sort/uint32/useint32/sort.c
10 supercop-20201130/crypto_kem/sntrup761/ref/uint32.c
11 supercop-20201130/crypto_kem/sntrup761/ref/int32.c
12 supercop-20201130/crypto_kem/sntrup761/ref/paramsmenu.h
13 supercop-20201130/crypto_kem/sntrup761/ref/params.h
14 supercop-20201130/crypto_kem/sntrup761/ref/Decode.h
15 supercop-20201130/crypto_kem/sntrup761/ref/Decode.c
16 supercop-20201130/crypto_kem/sntrup761/ref/Encode.h
17 supercop-20201130/crypto_kem/sntrup761/ref/Encode.c
18 supercop-20201130/crypto_kem/sntrup761/ref/kem.c
28 echo ' * Public Domain, Authors:'
29 sed -e '/Alphabetical order:/d' -e 's/^/ * - /' < $AUTHOR
32 echo '#include <string.h>'
33 echo '#include "crypto_api.h"'
35 # Map the types used in this code to the ones in crypto_api.h. We use #define
36 # instead of typedef since some systems have existing intXX types and do not
37 # permit multiple typedefs even if they do not conflict.
38 for t in int8 uint8 int16 uint16 int32 uint32 int64 uint64; do
39 echo "#define $t crypto_${t}"
44 # Changes to all files:
45 # - remove all includes, we inline everything required.
46 # - make functions not required elsewhere static.
47 # - rename the functions we do use.
48 # - remove unneccesary defines and externs.
49 sed -e "/#include/d" \
50 -e "s/crypto_kem_/crypto_kem_sntrup761_/g" \
51 -e "s/^void /static void /g" \
52 -e "s/^int16 /static int16 /g" \
53 -e "s/^uint16 /static uint16 /g" \
55 -e '/CRYPTO_NAMESPACE/d' \
56 -e "/^#define int32 crypto_int32/d" \
59 # Use int64_t for intermediate values in int32_MINMAX to prevent signed
60 # 32-bit integer overflow when called by crypto_sort_uint32.
62 sed -e "s/int32 ab = b ^ a/int64_t ab = (int64_t)b ^ (int64_t)a/" \
63 -e "s/int32 c = b - a/int64_t c = (int64_t)b - (int64_t)a/"
65 */int32/portable4/sort.c)
66 sed -e "s/void crypto_sort/void crypto_sort_int32/g"
68 */uint32/useint32/sort.c)
69 sed -e "s/void crypto_sort/void crypto_sort_uint32/g"
71 # Remove unused function to prevent warning.
72 */crypto_kem/sntrup761/ref/int32.c)
73 sed -e '/ int32_div_uint14/,/^}$/d'
75 # Remove unused function to prevent warning.
76 */crypto_kem/sntrup761/ref/uint32.c)
77 sed -e '/ uint32_div_uint14/,/^}$/d'
79 # Default: pass through.