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