1*ba1276acSMatthew Dillon#!/bin/sh 2*ba1276acSMatthew Dillon# $OpenBSD: ed25519.sh,v 1.2 2024/05/17 02:39:11 jsg Exp $ 3*ba1276acSMatthew Dillon# Placed in the Public Domain. 4*ba1276acSMatthew Dillon# 5*ba1276acSMatthew DillonAUTHOR="supercop-20221122/crypto_sign/ed25519/ref/implementors" 6*ba1276acSMatthew DillonFILES=" 7*ba1276acSMatthew Dillon supercop-20221122/crypto_verify/32/ref/verify.c 8*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/fe25519.h 9*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/fe25519.c 10*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/sc25519.h 11*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/sc25519.c 12*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/ge25519.h 13*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/ge25519.c 14*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/keypair.c 15*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/sign.c 16*ba1276acSMatthew Dillon supercop-20221122/crypto_sign/ed25519/ref/open.c 17*ba1276acSMatthew Dillon" 18*ba1276acSMatthew Dillon### 19*ba1276acSMatthew Dillon 20*ba1276acSMatthew DillonDATA="supercop-20221122/crypto_sign/ed25519/ref/ge25519_base.data" 21*ba1276acSMatthew Dillon 22*ba1276acSMatthew Dillonset -e 23*ba1276acSMatthew Dilloncd $1 24*ba1276acSMatthew Dillonecho -n '/* $' 25*ba1276acSMatthew Dillonecho 'OpenBSD: $ */' 26*ba1276acSMatthew Dillonecho 27*ba1276acSMatthew Dillonecho '/*' 28*ba1276acSMatthew Dillonecho ' * Public Domain, Authors:' 29*ba1276acSMatthew Dillonsed -e '/Alphabetical order:/d' -e 's/^/ * - /' < $AUTHOR 30*ba1276acSMatthew Dillonecho ' */' 31*ba1276acSMatthew Dillonecho 32*ba1276acSMatthew Dillonecho '#include <string.h>' 33*ba1276acSMatthew Dillonecho 34*ba1276acSMatthew Dillonecho '#include "crypto_api.h"' 35*ba1276acSMatthew Dillonecho 36*ba1276acSMatthew Dillon# Map the types used in this code to the ones in crypto_api.h. We use #define 37*ba1276acSMatthew Dillon# instead of typedef since some systems have existing intXX types and do not 38*ba1276acSMatthew Dillon# permit multiple typedefs even if they do not conflict. 39*ba1276acSMatthew Dillonfor t in int8 uint8 int16 uint16 int32 uint32 int64 uint64; do 40*ba1276acSMatthew Dillon echo "#define $t crypto_${t}" 41*ba1276acSMatthew Dillondone 42*ba1276acSMatthew Dillonecho 43*ba1276acSMatthew Dillonfor i in $FILES; do 44*ba1276acSMatthew Dillon echo "/* from $i */" 45*ba1276acSMatthew Dillon # Changes to all files: 46*ba1276acSMatthew Dillon # - inline ge25519_base.data where it is included 47*ba1276acSMatthew Dillon # - expand CRYPTO_NAMESPACE() namespacing define 48*ba1276acSMatthew Dillon # - remove all includes, we inline everything required. 49*ba1276acSMatthew Dillon # - make functions not required elsewhere static. 50*ba1276acSMatthew Dillon # - rename the functions we do use. 51*ba1276acSMatthew Dillon sed \ 52*ba1276acSMatthew Dillon -e "/#include \"ge25519_base.data\"/r $DATA" \ 53*ba1276acSMatthew Dillon -e "/#include/d" \ 54*ba1276acSMatthew Dillon -e "s/^void /static void /g" \ 55*ba1276acSMatthew Dillon -e 's/CRYPTO_NAMESPACE[(]\([a-zA-Z0-9_]*\)[)]/crypto_sign_ed25519_ref_\1/g' \ 56*ba1276acSMatthew Dillon $i | \ 57*ba1276acSMatthew Dillon case "$i" in 58*ba1276acSMatthew Dillon */crypto_verify/32/ref/verify.c) 59*ba1276acSMatthew Dillon # rename crypto_verify() to the name that the ed25519 code expects. 60*ba1276acSMatthew Dillon sed -e "/^#include.*/d" \ 61*ba1276acSMatthew Dillon -e "s/crypto_verify/crypto_verify_32/g" \ 62*ba1276acSMatthew Dillon -e "s/^int /static int /g" 63*ba1276acSMatthew Dillon ;; 64*ba1276acSMatthew Dillon */crypto_sign/ed25519/ref/sign.c) 65*ba1276acSMatthew Dillon # rename signing function to the name OpenSSH expects 66*ba1276acSMatthew Dillon sed -e "s/crypto_sign/crypto_sign_ed25519/g" 67*ba1276acSMatthew Dillon ;; 68*ba1276acSMatthew Dillon */crypto_sign/ed25519/ref/keypair.c) 69*ba1276acSMatthew Dillon # rename key generation function to the name OpenSSH expects 70*ba1276acSMatthew Dillon sed -e "s/crypto_sign_keypair/crypto_sign_ed25519_keypair/g" 71*ba1276acSMatthew Dillon ;; 72*ba1276acSMatthew Dillon */crypto_sign/ed25519/ref/open.c) 73*ba1276acSMatthew Dillon # rename verification function to the name OpenSSH expects 74*ba1276acSMatthew Dillon sed -e "s/crypto_sign_open/crypto_sign_ed25519_open/g" 75*ba1276acSMatthew Dillon ;; 76*ba1276acSMatthew Dillon */crypto_sign/ed25519/ref/fe25519.*) 77*ba1276acSMatthew Dillon # avoid a couple of name collisions with other files 78*ba1276acSMatthew Dillon sed -e "s/reduce_add_sub/fe25519_reduce_add_sub/g" \ 79*ba1276acSMatthew Dillon -e "s/ equal[(]/ fe25519_equal(/g" \ 80*ba1276acSMatthew Dillon -e "s/^int /static int /g" 81*ba1276acSMatthew Dillon ;; 82*ba1276acSMatthew Dillon */crypto_sign/ed25519/ref/sc25519.h) 83*ba1276acSMatthew Dillon # Lots of unused prototypes to remove 84*ba1276acSMatthew Dillon sed -e "s/^int /static int /g" \ 85*ba1276acSMatthew Dillon -e '/shortsc25519_from16bytes/d' \ 86*ba1276acSMatthew Dillon -e '/sc25519_iszero_vartime/d' \ 87*ba1276acSMatthew Dillon -e '/sc25519_isshort_vartime/d' \ 88*ba1276acSMatthew Dillon -e '/sc25519_lt_vartime/d' \ 89*ba1276acSMatthew Dillon -e '/sc25519_sub_nored/d' \ 90*ba1276acSMatthew Dillon -e '/sc25519_mul_shortsc/d' \ 91*ba1276acSMatthew Dillon -e '/sc25519_from_shortsc/d' \ 92*ba1276acSMatthew Dillon -e '/sc25519_window5/d' 93*ba1276acSMatthew Dillon ;; 94*ba1276acSMatthew Dillon */crypto_sign/ed25519/ref/sc25519.c) 95*ba1276acSMatthew Dillon # Lots of unused code to remove, some name collisions to avoid 96*ba1276acSMatthew Dillon sed -e "s/reduce_add_sub/sc25519_reduce_add_sub/g" \ 97*ba1276acSMatthew Dillon -e "s/ equal[(]/ sc25519_equal(/g" \ 98*ba1276acSMatthew Dillon -e "s/^int /static int /g" \ 99*ba1276acSMatthew Dillon -e "s/m[[]/sc25519_m[/g" \ 100*ba1276acSMatthew Dillon -e "s/mu[[]/sc25519_mu[/g" \ 101*ba1276acSMatthew Dillon -e '/shortsc25519_from16bytes/,/^}$/d' \ 102*ba1276acSMatthew Dillon -e '/sc25519_iszero_vartime/,/^}$/d' \ 103*ba1276acSMatthew Dillon -e '/sc25519_isshort_vartime/,/^}$/d' \ 104*ba1276acSMatthew Dillon -e '/sc25519_lt_vartime/,/^}$/d' \ 105*ba1276acSMatthew Dillon -e '/sc25519_sub_nored/,/^}$/d' \ 106*ba1276acSMatthew Dillon -e '/sc25519_mul_shortsc/,/^}$/d' \ 107*ba1276acSMatthew Dillon -e '/sc25519_from_shortsc/,/^}$/d' \ 108*ba1276acSMatthew Dillon -e '/sc25519_window5/,/^}$/d' 109*ba1276acSMatthew Dillon ;; 110*ba1276acSMatthew Dillon */crypto_sign/ed25519/ref//ge25519.*) 111*ba1276acSMatthew Dillon sed -e "s/^int /static int /g" 112*ba1276acSMatthew Dillon ;; 113*ba1276acSMatthew Dillon # Default: pass through. 114*ba1276acSMatthew Dillon *) 115*ba1276acSMatthew Dillon cat 116*ba1276acSMatthew Dillon ;; 117*ba1276acSMatthew Dillon esac | \ 118*ba1276acSMatthew Dillon sed -e 's/[ ]*$//' 119*ba1276acSMatthew Dillondone 120