Annotation of src/usr.bin/ssh/sntrup761.sh, Revision 1.7
1.1 djm 1: #!/bin/sh
1.7 ! djm 2: # $OpenBSD: sntrup761.sh,v 1.6 2022/12/26 19:16:03 jmc Exp $
1.1 djm 3: # Placed in the Public Domain.
4: #
5: AUTHOR="supercop-20201130/crypto_kem/sntrup761/ref/implementors"
6: FILES="
1.4 dtucker 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
1.1 djm 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
19: "
20: ###
21:
22: set -e
23: cd $1
24: echo -n '/* $'
25: echo 'OpenBSD: $ */'
26: echo
27: echo '/*'
28: echo ' * Public Domain, Authors:'
29: sed -e '/Alphabetical order:/d' -e 's/^/ * - /' < $AUTHOR
30: echo ' */'
31: echo
32: echo '#include <string.h>'
33: echo '#include "crypto_api.h"'
34: echo
1.5 dtucker 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}"
40: done
1.1 djm 41: echo
42: for i in $FILES; do
43: echo "/* from $i */"
1.5 dtucker 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.
1.6 jmc 48: # - remove unnecessary defines and externs.
1.5 dtucker 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" \
54: -e "/^extern /d" \
55: -e '/CRYPTO_NAMESPACE/d' \
56: -e "/^#define int32 crypto_int32/d" \
1.7 ! djm 57: -e 's/[ ]*$//' \
1.5 dtucker 58: $i | \
1.4 dtucker 59: case "$i" in
60: # Use int64_t for intermediate values in int32_MINMAX to prevent signed
61: # 32-bit integer overflow when called by crypto_sort_uint32.
62: */int32_minmax.inc)
63: sed -e "s/int32 ab = b ^ a/int64_t ab = (int64_t)b ^ (int64_t)a/" \
1.5 dtucker 64: -e "s/int32 c = b - a/int64_t c = (int64_t)b - (int64_t)a/"
1.4 dtucker 65: ;;
66: */int32/portable4/sort.c)
1.5 dtucker 67: sed -e "s/void crypto_sort/void crypto_sort_int32/g"
1.4 dtucker 68: ;;
69: */uint32/useint32/sort.c)
1.5 dtucker 70: sed -e "s/void crypto_sort/void crypto_sort_uint32/g"
1.4 dtucker 71: ;;
1.5 dtucker 72: # Remove unused function to prevent warning.
73: */crypto_kem/sntrup761/ref/int32.c)
74: sed -e '/ int32_div_uint14/,/^}$/d'
75: ;;
76: # Remove unused function to prevent warning.
77: */crypto_kem/sntrup761/ref/uint32.c)
78: sed -e '/ uint32_div_uint14/,/^}$/d'
79: ;;
80: # Default: pass through.
1.4 dtucker 81: *)
1.5 dtucker 82: cat
83: ;;
1.4 dtucker 84: esac
1.1 djm 85: echo
86: done