[BACK]Return to sntrup761.sh CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/sntrup761.sh, Revision 1.6

1.1       djm         1: #!/bin/sh
1.6     ! jmc         2: #       $OpenBSD: sntrup761.sh,v 1.5 2021/01/08 02:33:13 dtucker 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" \
                     57:            $i | \
1.4       dtucker    58:        case "$i" in
                     59:        # Use int64_t for intermediate values in int32_MINMAX to prevent signed
                     60:        # 32-bit integer overflow when called by crypto_sort_uint32.
                     61:        */int32_minmax.inc)
                     62:            sed -e "s/int32 ab = b ^ a/int64_t ab = (int64_t)b ^ (int64_t)a/" \
1.5       dtucker    63:                -e "s/int32 c = b - a/int64_t c = (int64_t)b - (int64_t)a/"
1.4       dtucker    64:            ;;
                     65:        */int32/portable4/sort.c)
1.5       dtucker    66:            sed -e "s/void crypto_sort/void crypto_sort_int32/g"
1.4       dtucker    67:            ;;
                     68:        */uint32/useint32/sort.c)
1.5       dtucker    69:            sed -e "s/void crypto_sort/void crypto_sort_uint32/g"
1.4       dtucker    70:            ;;
1.5       dtucker    71:        # Remove unused function to prevent warning.
                     72:        */crypto_kem/sntrup761/ref/int32.c)
                     73:            sed -e '/ int32_div_uint14/,/^}$/d'
                     74:            ;;
                     75:        # Remove unused function to prevent warning.
                     76:        */crypto_kem/sntrup761/ref/uint32.c)
                     77:            sed -e '/ uint32_div_uint14/,/^}$/d'
                     78:            ;;
                     79:        # Default: pass through.
1.4       dtucker    80:        *)
1.5       dtucker    81:            cat
                     82:            ;;
1.4       dtucker    83:        esac
1.1       djm        84:        echo
                     85: done