Keeping only one finite field, header 'f_field.h' can be included from Cabal standard 'include-dirs'.
93 lines
3.2 KiB
Bash
Executable File
93 lines
3.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Usage: ./generate.sh /path/to/ed448goldilocks-code
|
|
#
|
|
# Generate all files from ed448goldilocks branch 'master'
|
|
# (available at <git://git.code.sf.net/p/ed448goldilocks/code>).
|
|
#
|
|
# Project is synced with upstream commit
|
|
# '0a6e96827595fa1a5a62d12ac83c3cc5dda6dd67', i.e. tag 'v0.9.2'.
|
|
#
|
|
# Notes about transformations applied:
|
|
#
|
|
# * only a subset of library files are used, cryptonite needing only x448
|
|
# and ed448. Some headers like point_255.h are still included but copied
|
|
# empty, as the definitions are not necessary. Only the simplest
|
|
# architectures arch_32 and arch_ref64 are used to get the best
|
|
# compatibility and generality over performance.
|
|
#
|
|
# * substitutions are performed in order to add a cryptonite_ prefix
|
|
# to all external symbols
|
|
#
|
|
# * code related to SHAKE is replaced by cryptonite code, referenced from
|
|
# a custom shake.h. As a consequence, portable_endian.h is not needed.
|
|
|
|
SRC_DIR="$1/src"
|
|
DEST_DIR="`dirname "$0"`"/..
|
|
|
|
ARCHITECTURES="arch_32 arch_ref64"
|
|
|
|
if [ ! -d "$SRC_DIR" ]; then
|
|
echo "$0: invalid source directory: $1" && exit 1
|
|
fi
|
|
|
|
convert() {
|
|
local FILE_NAME="`basename "$1"`"
|
|
sed <"$1" >"$2/$FILE_NAME" \
|
|
-e 's/decaf_/cryptonite_decaf_/g' \
|
|
-e 's/DECAF_/CRYPTONITE_DECAF_/g' \
|
|
-e 's/gf_/cryptonite_gf_/g' \
|
|
-e 's/keccakf/cryptonite_keccakf/g' \
|
|
-e 's/NO_CONTEXT_POINTS_HERE/CRYPTONITE_NO_CONTEXT_POINTS_HERE/g' \
|
|
-e 's/P25519_SQRT_MINUS_ONE/CRYPTONITE_P25519_SQRT_MINUS_ONE/g'
|
|
}
|
|
|
|
convert "$SRC_DIR"/utils.c "$DEST_DIR"
|
|
|
|
mkdir -p "$DEST_DIR"/include
|
|
convert "$SRC_DIR"/include/constant_time.h "$DEST_DIR"/include
|
|
convert "$SRC_DIR"/include/field.h "$DEST_DIR"/include
|
|
convert "$SRC_DIR"/include/word.h "$DEST_DIR"/include
|
|
|
|
for ARCH in $ARCHITECTURES; do
|
|
mkdir -p "$DEST_DIR"/include/$ARCH
|
|
convert "$SRC_DIR"/include/$ARCH/arch_intrinsics.h "$DEST_DIR"/include/$ARCH
|
|
done
|
|
|
|
mkdir -p "$DEST_DIR"/include/decaf
|
|
convert "$SRC_DIR"/GENERATED/include/decaf.h "$DEST_DIR"/include
|
|
convert "$SRC_DIR"/GENERATED/include/decaf/common.h "$DEST_DIR"/include/decaf
|
|
convert "$SRC_DIR"/GENERATED/include/decaf/ed448.h "$DEST_DIR"/include/decaf
|
|
convert "$SRC_DIR"/GENERATED/include/decaf/point_448.h "$DEST_DIR"/include/decaf
|
|
|
|
for CURVE in ed448goldilocks; do
|
|
mkdir -p "$DEST_DIR"/$CURVE
|
|
convert "$SRC_DIR"/GENERATED/c/$CURVE/decaf.c "$DEST_DIR"/$CURVE
|
|
convert "$SRC_DIR"/GENERATED/c/$CURVE/decaf_tables.c "$DEST_DIR"/$CURVE
|
|
convert "$SRC_DIR"/GENERATED/c/$CURVE/eddsa.c "$DEST_DIR"/$CURVE
|
|
convert "$SRC_DIR"/GENERATED/c/$CURVE/scalar.c "$DEST_DIR"/$CURVE
|
|
done
|
|
|
|
for FIELD in p448; do
|
|
mkdir -p "$DEST_DIR"/$FIELD
|
|
convert "$SRC_DIR"/$FIELD/f_arithmetic.c "$DEST_DIR"/$FIELD
|
|
convert "$SRC_DIR"/GENERATED/c/$FIELD/f_generic.c "$DEST_DIR"/$FIELD
|
|
convert "$SRC_DIR"/GENERATED/c/$FIELD/f_field.h "$DEST_DIR"/$FIELD
|
|
|
|
for ARCH in $ARCHITECTURES; do
|
|
mkdir -p "$DEST_DIR"/$FIELD/$ARCH
|
|
convert "$SRC_DIR"/$FIELD/$ARCH/f_impl.h "$DEST_DIR"/$FIELD/$ARCH
|
|
convert "$SRC_DIR"/$FIELD/$ARCH/f_impl.c "$DEST_DIR"/$FIELD/$ARCH
|
|
done
|
|
done
|
|
|
|
for FILE in point_255.h sha512.h; do
|
|
cat > "$DEST_DIR"/include/decaf/$FILE <<EOF
|
|
/* Not needed if 448-only */
|
|
EOF
|
|
done
|
|
|
|
cat >"$DEST_DIR"/include/portable_endian.h <<EOF
|
|
/* portable_endian.h not used */
|
|
EOF
|