From 78c3b4b3ae3d0d2eef13f148d8ec4932e385c28c Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Mon, 13 Apr 2020 16:11:02 +0300 Subject: build: import-curve448 -> import-ecc As the script now imports not just Curve448, but also gost code, rename the script, target directory and symbols to follow that. Signed-off-by: Dmitry Baryshkov --- bootstrap.conf | 2 +- devel/import-curve448-from-nettle.sh | 201 ----------------------------------- devel/import-ecc-from-nettle.sh | 201 +++++++++++++++++++++++++++++++++++ lib/nettle/Makefile.am | 68 ++++++------ lib/nettle/pk.c | 4 +- 5 files changed, 238 insertions(+), 238 deletions(-) delete mode 100755 devel/import-curve448-from-nettle.sh create mode 100755 devel/import-ecc-from-nettle.sh diff --git a/bootstrap.conf b/bootstrap.conf index a2e9ae661d..9a5b3639b0 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -102,6 +102,6 @@ bootstrap_post_import_hook () # Automake requires that ChangeLog exist. touch ChangeLog || return 1 - devel/import-curve448-from-nettle.sh + devel/import-ecc-from-nettle.sh devel/import-chacha-from-nettle.sh } diff --git a/devel/import-curve448-from-nettle.sh b/devel/import-curve448-from-nettle.sh deleted file mode 100755 index 8b04f13653..0000000000 --- a/devel/import-curve448-from-nettle.sh +++ /dev/null @@ -1,201 +0,0 @@ -#!/bin/sh - -# This script copies the Curve448 and Ed448, GOST 34.10 implementation from the -# nettle upstream, with necessary adjustments for bundling in GnuTLS. - -set +e - -: ${srcdir=.} -SRC=$srcdir/devel/nettle -DST=$srcdir/lib/nettle/curve448 - -IMPORTS=" -cnd-copy.c -curve448-eh-to-x.c -curve448.h -curve448-mul.c -curve448-mul-g.c -eccdata.c -ecc-curve448.c -ecc-add-eh.c -ecc-add-ehh.c -ecc-add-jja.c -ecc-add-jjj.c -ecc-a-to-j.c -ecc-dup-eh.c -ecc-dup-jj.c -ecc-eh-to-a.c -ecc-gost-gc256b.c -ecc-gost-gc512a.c -ecc-gostdsa-sign.c -ecc-gostdsa-verify.c -ecc-internal.h -ecc-j-to-a.c -ecc-mod-arith.c -ecc-mod.c -ecc-mod-inv.c -ecc-mul-a.c -ecc-mul-a-eh.c -ecc-mul-g.c -ecc-mul-g-eh.c -ecc-mul-m.c -ecc-random.c -ed448-shake256.c -ed448-shake256-pubkey.c -ed448-shake256-sign.c -ed448-shake256-verify.c -eddsa-compress.c -eddsa-decompress.c -eddsa-expand.c -eddsa.h -eddsa-hash.c -eddsa-internal.h -eddsa-pubkey.c -eddsa-sign.c -eddsa-verify.c -gostdsa.h -gostdsa-sign.c -gostdsa-verify.c -gmp-glue.h -gmp-glue.c -nettle-write.h -sec-add-1.c -sec-tabselect.c -sha3.c -sha3.h -sha3-256.c -sha3-internal.h -sha3-permute.c -shake256.c -write-le64.c -" - -PUBLIC=" -bignum.h -dsa.h -ecc-curve.h -ecc.h -ecdsa.h -macros.h -memxor.h -nettle-meta.h -nettle-types.h -" - -test -d $DST || mkdir $DST - -for f in $IMPORTS; do - src=$SRC/$f - dst=$DST/$f - if test -f $src; then - if test -f $dst; then - echo "Replacing $dst (existing file backed up in $dst~)" - mv $dst $dst~ - else - echo "Copying file $dst" - fi - cp $src $dst - # Use for public headers. - for h in $PUBLIC; do - p=$(echo $h | sed 's/\./\\./g') - if grep '^#include "'$p'"' $dst 2>&1 >/dev/null; then - sed 's!^#include "'$p'"!#include !' $dst > $dst-t && \ - mv $dst-t $dst - fi - done - # Remove unused . - if grep '^#include ' $dst 2>&1 >/dev/null; then - if ! grep 'assert *(' $dst 2>&1 >/dev/null; then - sed '/^#include /d' $dst > $dst-t && mv $dst-t $dst - fi - fi - case $dst in - *.h) - # Rename header guard so as not to conflict with the public ones. - if grep '^#ifndef NETTLE_.*_H\(_INCLUDED\)*' $dst 2>&1 >/dev/null; then - g=$(sed -n 's/^#ifndef NETTLE_\(.*_H\(_INCLUDED\)*\)/\1/p' $dst) - sed 's/\(NETTLE_'$g'\)/GNUTLS_LIB_NETTLE_CURVE448_\1/' $dst > $dst-t && \ - mv $dst-t $dst - fi - # Add prefix to function symbols avoid clashing with the public ones. - sed -e 's/^#define \(.*\) nettle_\1/#define \1 gnutls_nettle_curve448_\1/' \ - -e 's/^#define \(.*\) _nettle_\1/#define \1 _gnutls_nettle_curve448_\1/' \ - -e 's/^#define _\(.*\) _nettle_\1/#define _\1 _gnutls_nettle_curve448_\1/' \ - -e 's/^_nettle_\(.*\)(.*/#define _nettle_\1 _gnutls_nettle_curve448_\1\n\0/' \ - -e 's/^extern const struct ecc_curve _nettle_\(.*\);/#define _nettle_\1 _gnutls_nettle_curve448_\1\n\0/' \ - -e 's/^extern const struct ecc_eddsa _nettle_\(.*\);/#define _nettle_\1 _gnutls_nettle_curve448_\1\n\0/' \ - $dst > $dst-t && \ - mv $dst-t $dst - ;; - */eccdata.c) - sed 's/^#include "mini-gmp.c"/#include /' $dst > $dst-t && \ - mv $dst-t $dst - ;; - */ecc-curve448.c) - # The generated file is arch dependent, conditionalize the - # inclusion. - sed '/^#include "ecc-curve448\.h"/ { i\ -#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)\ -# pragma GCC diagnostic ignored "-Wunused-const-variable"\ -#endif\ -#if GMP_NUMB_BITS == 32\ -#include "curve448/ecc-curve448-32.h"\ -#elif GMP_NUMB_BITS == 64\ -#include "curve448/ecc-curve448-64.h"\ -#else\ -#error unsupported configuration\ -#endif -; d -}' $dst > $dst-t && mv $dst-t $dst - ;; - */ecc-gost-gc256b.c) - # The generated file is arch dependent, conditionalize the - # inclusion. - sed '/^#include "ecc-gost-gc256b\.h"/ { i\ -#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)\ -# pragma GCC diagnostic ignored "-Wunused-const-variable"\ -#endif\ -#if GMP_NUMB_BITS == 32\ -#include "curve448/ecc-gost-gc256b-32.h"\ -#elif GMP_NUMB_BITS == 64\ -#include "curve448/ecc-gost-gc256b-64.h"\ -#else\ -#error unsupported configuration\ -#endif -; d -}' $dst | sed -e 's/#include "ecc-internal.h"/\0\n#include "ecc-gost-curve.h"/' > $dst-t && mv $dst-t $dst - ;; - */ecc-gost-gc512a.c) - # The generated file is arch dependent, conditionalize the - # inclusion. - sed '/^#include "ecc-gost-gc512a\.h"/ { i\ -#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)\ -# pragma GCC diagnostic ignored "-Wunused-const-variable"\ -#endif\ -#if GMP_NUMB_BITS == 32\ -#include "curve448/ecc-gost-gc512a-32.h"\ -#elif GMP_NUMB_BITS == 64\ -#include "curve448/ecc-gost-gc512a-64.h"\ -#else\ -#error unsupported configuration\ -#endif -; d -}' $dst | sed -e 's/#include "ecc-internal.h"/\0\n#include "ecc-gost-curve.h"/' > $dst-t && mv $dst-t $dst - ;; - */eddsa-hash.c) - # Known to be unnecessary. - sed '/^#include "nettle-internal\.h"/d' $dst > $dst-t && mv $dst-t $dst - ;; - */ecc-add-eh*.c) - # Suppress whitespace errors in 'make syntax-check'. - sed 's/ * / /g' $dst > $dst-t && mv $dst-t $dst - ;; - */ecc-random.c|*/gostdsa-sign.c) - sed 's/"nettle-internal\.h"/"nettle-alloca.h"/' $dst > $dst-t && mv $dst-t $dst - ;; - esac - else - echo "Error: $src not found" 1>&2 - exit 1 - fi -done diff --git a/devel/import-ecc-from-nettle.sh b/devel/import-ecc-from-nettle.sh new file mode 100755 index 0000000000..1fe93005e7 --- /dev/null +++ b/devel/import-ecc-from-nettle.sh @@ -0,0 +1,201 @@ +#!/bin/sh + +# This script copies the Curve448 and Ed448, GOST 34.10 implementation from the +# nettle upstream, with necessary adjustments for bundling in GnuTLS. + +set +e + +: ${srcdir=.} +SRC=$srcdir/devel/nettle +DST=$srcdir/lib/nettle/ecc + +IMPORTS=" +cnd-copy.c +curve448-eh-to-x.c +curve448.h +curve448-mul.c +curve448-mul-g.c +eccdata.c +ecc-curve448.c +ecc-add-eh.c +ecc-add-ehh.c +ecc-add-jja.c +ecc-add-jjj.c +ecc-a-to-j.c +ecc-dup-eh.c +ecc-dup-jj.c +ecc-eh-to-a.c +ecc-gost-gc256b.c +ecc-gost-gc512a.c +ecc-gostdsa-sign.c +ecc-gostdsa-verify.c +ecc-internal.h +ecc-j-to-a.c +ecc-mod-arith.c +ecc-mod.c +ecc-mod-inv.c +ecc-mul-a.c +ecc-mul-a-eh.c +ecc-mul-g.c +ecc-mul-g-eh.c +ecc-mul-m.c +ecc-random.c +ed448-shake256.c +ed448-shake256-pubkey.c +ed448-shake256-sign.c +ed448-shake256-verify.c +eddsa-compress.c +eddsa-decompress.c +eddsa-expand.c +eddsa.h +eddsa-hash.c +eddsa-internal.h +eddsa-pubkey.c +eddsa-sign.c +eddsa-verify.c +gostdsa.h +gostdsa-sign.c +gostdsa-verify.c +gmp-glue.h +gmp-glue.c +nettle-write.h +sec-add-1.c +sec-tabselect.c +sha3.c +sha3.h +sha3-256.c +sha3-internal.h +sha3-permute.c +shake256.c +write-le64.c +" + +PUBLIC=" +bignum.h +dsa.h +ecc-curve.h +ecc.h +ecdsa.h +macros.h +memxor.h +nettle-meta.h +nettle-types.h +" + +test -d $DST || mkdir $DST + +for f in $IMPORTS; do + src=$SRC/$f + dst=$DST/$f + if test -f $src; then + if test -f $dst; then + echo "Replacing $dst (existing file backed up in $dst~)" + mv $dst $dst~ + else + echo "Copying file $dst" + fi + cp $src $dst + # Use for public headers. + for h in $PUBLIC; do + p=$(echo $h | sed 's/\./\\./g') + if grep '^#include "'$p'"' $dst 2>&1 >/dev/null; then + sed 's!^#include "'$p'"!#include !' $dst > $dst-t && \ + mv $dst-t $dst + fi + done + # Remove unused . + if grep '^#include ' $dst 2>&1 >/dev/null; then + if ! grep 'assert *(' $dst 2>&1 >/dev/null; then + sed '/^#include /d' $dst > $dst-t && mv $dst-t $dst + fi + fi + case $dst in + *.h) + # Rename header guard so as not to conflict with the public ones. + if grep '^#ifndef NETTLE_.*_H\(_INCLUDED\)*' $dst 2>&1 >/dev/null; then + g=$(sed -n 's/^#ifndef NETTLE_\(.*_H\(_INCLUDED\)*\)/\1/p' $dst) + sed 's/\(NETTLE_'$g'\)/GNUTLS_LIB_NETTLE_ECC_\1/' $dst > $dst-t && \ + mv $dst-t $dst + fi + # Add prefix to function symbols avoid clashing with the public ones. + sed -e 's/^#define \(.*\) nettle_\1/#define \1 gnutls_nettle_ecc_\1/' \ + -e 's/^#define \(.*\) _nettle_\1/#define \1 _gnutls_nettle_ecc_\1/' \ + -e 's/^#define _\(.*\) _nettle_\1/#define _\1 _gnutls_nettle_ecc_\1/' \ + -e 's/^_nettle_\(.*\)(.*/#define _nettle_\1 _gnutls_nettle_ecc_\1\n\0/' \ + -e 's/^extern const struct ecc_curve _nettle_\(.*\);/#define _nettle_\1 _gnutls_nettle_ecc_\1\n\0/' \ + -e 's/^extern const struct ecc_eddsa _nettle_\(.*\);/#define _nettle_\1 _gnutls_nettle_ecc_\1\n\0/' \ + $dst > $dst-t && \ + mv $dst-t $dst + ;; + */eccdata.c) + sed 's/^#include "mini-gmp.c"/#include /' $dst > $dst-t && \ + mv $dst-t $dst + ;; + */ecc-curve448.c) + # The generated file is arch dependent, conditionalize the + # inclusion. + sed '/^#include "ecc-curve448\.h"/ { i\ +#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)\ +# pragma GCC diagnostic ignored "-Wunused-const-variable"\ +#endif\ +#if GMP_NUMB_BITS == 32\ +#include "ecc/ecc-curve448-32.h"\ +#elif GMP_NUMB_BITS == 64\ +#include "ecc/ecc-curve448-64.h"\ +#else\ +#error unsupported configuration\ +#endif +; d +}' $dst > $dst-t && mv $dst-t $dst + ;; + */ecc-gost-gc256b.c) + # The generated file is arch dependent, conditionalize the + # inclusion. + sed '/^#include "ecc-gost-gc256b\.h"/ { i\ +#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)\ +# pragma GCC diagnostic ignored "-Wunused-const-variable"\ +#endif\ +#if GMP_NUMB_BITS == 32\ +#include "ecc/ecc-gost-gc256b-32.h"\ +#elif GMP_NUMB_BITS == 64\ +#include "ecc/ecc-gost-gc256b-64.h"\ +#else\ +#error unsupported configuration\ +#endif +; d +}' $dst | sed -e 's/#include "ecc-internal.h"/\0\n#include "ecc-gost-curve.h"/' > $dst-t && mv $dst-t $dst + ;; + */ecc-gost-gc512a.c) + # The generated file is arch dependent, conditionalize the + # inclusion. + sed '/^#include "ecc-gost-gc512a\.h"/ { i\ +#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)\ +# pragma GCC diagnostic ignored "-Wunused-const-variable"\ +#endif\ +#if GMP_NUMB_BITS == 32\ +#include "ecc/ecc-gost-gc512a-32.h"\ +#elif GMP_NUMB_BITS == 64\ +#include "ecc/ecc-gost-gc512a-64.h"\ +#else\ +#error unsupported configuration\ +#endif +; d +}' $dst | sed -e 's/#include "ecc-internal.h"/\0\n#include "ecc-gost-curve.h"/' > $dst-t && mv $dst-t $dst + ;; + */eddsa-hash.c) + # Known to be unnecessary. + sed '/^#include "nettle-internal\.h"/d' $dst > $dst-t && mv $dst-t $dst + ;; + */ecc-add-eh*.c) + # Suppress whitespace errors in 'make syntax-check'. + sed 's/ * / /g' $dst > $dst-t && mv $dst-t $dst + ;; + */ecc-random.c|*/gostdsa-sign.c) + sed 's/"nettle-internal\.h"/"nettle-alloca.h"/' $dst > $dst-t && mv $dst-t $dst + ;; + esac + else + echo "Error: $src not found" 1>&2 + exit 1 + fi +done diff --git a/lib/nettle/Makefile.am b/lib/nettle/Makefile.am index f13cba4a8e..f22ea4f858 100644 --- a/lib/nettle/Makefile.am +++ b/lib/nettle/Makefile.am @@ -100,54 +100,54 @@ libcrypto_la_SOURCES += gost_keywrap.c endif if NEED_CURVE448 -curve448_generated_headers = \ - curve448/ecc-curve448-32.h curve448/ecc-curve448-64.h +ecc_generated_headers = \ + ecc/ecc-curve448-32.h ecc/ecc-curve448-64.h -BUILT_SOURCES = $(curve448_generated_headers) -EXTRA_DIST = $(curve448_generated_headers) curve448/eccdata.stamp +BUILT_SOURCES = $(ecc_generated_headers) +EXTRA_DIST = $(ecc_generated_headers) ecc/eccdata.stamp -noinst_PROGRAMS = curve448/eccdata$(EXEEXT) +noinst_PROGRAMS = ecc/eccdata$(EXEEXT) -curve448_eccdata_SOURCES = curve448/eccdata.c -curve448_eccdata_CFLAGS = $(GMP_CFLAGS) -curve448_eccdata_LDADD = $(GMP_LIBS) ../../gl/libgnu.la +ecc_eccdata_SOURCES = ecc/eccdata.c +ecc_eccdata_CFLAGS = $(GMP_CFLAGS) +ecc_eccdata_LDADD = $(GMP_LIBS) ../../gl/libgnu.la -curve448/eccdata.stamp: $(curve448_eccdata_SOURCES) - $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) curve448/eccdata$(EXEEXT) && touch $@ +ecc/eccdata.stamp: $(ecc_eccdata_SOURCES) + $(AM_V_GEN)$(MAKE) $(AM_MAKEFLAGS) ecc/eccdata$(EXEEXT) && touch $@ -curve448/ecc-curve448-32.h: curve448/eccdata.stamp - $(AM_V_GEN)curve448/eccdata$(EXEEXT) curve448 38 6 32 > $@T && mv $@T $@ +ecc/ecc-curve448-32.h: ecc/eccdata.stamp + $(AM_V_GEN)ecc/eccdata$(EXEEXT) curve448 38 6 32 > $@T && mv $@T $@ -curve448/ecc-curve448-64.h: curve448/eccdata.stamp - $(AM_V_GEN)curve448/eccdata$(EXEEXT) curve448 38 6 64 > $@T && mv $@T $@ +ecc/ecc-curve448-64.h: ecc/eccdata.stamp + $(AM_V_GEN)ecc/eccdata$(EXEEXT) curve448 38 6 64 > $@T && mv $@T $@ libcrypto_la_SOURCES += \ - curve448/write-le64.c \ - curve448/nettle-write.h curve448/gmp-glue.h curve448/gmp-glue.c + ecc/write-le64.c \ + ecc/nettle-write.h ecc/gmp-glue.h ecc/gmp-glue.c libcrypto_la_SOURCES += \ - curve448/sha3.c curve448/sha3.h curve448/sha3-256.c \ - curve448/sha3-permute.c curve448/sha3-internal.h \ - curve448/shake256.c + ecc/sha3.c ecc/sha3.h ecc/sha3-256.c \ + ecc/sha3-permute.c ecc/sha3-internal.h \ + ecc/shake256.c libcrypto_la_SOURCES += \ - curve448/ecc-internal.h \ - curve448/ecc-add-eh.c curve448/ecc-add-ehh.c curve448/ecc-dup-eh.c \ - curve448/ecc-eh-to-a.c curve448/ecc-mul-a-eh.c curve448/ecc-mul-g-eh.c \ - curve448/ecc-mul-m.c curve448/ecc-mod.c curve448/ecc-mod-arith.c \ - curve448/ecc-mod-inv.c \ - curve448/ecc-a-to-j.c \ - curve448/sec-tabselect.c curve448/cnd-copy.c curve448/sec-add-1.c \ - curve448/ecc-curve448.c $(curve448_genereated_headers) \ - curve448/curve448-eh-to-x.c curve448/curve448.h curve448/curve448-mul.c \ - curve448/curve448-mul-g.c + ecc/ecc-internal.h \ + ecc/ecc-add-eh.c ecc/ecc-add-ehh.c ecc/ecc-dup-eh.c \ + ecc/ecc-eh-to-a.c ecc/ecc-mul-a-eh.c ecc/ecc-mul-g-eh.c \ + ecc/ecc-mul-m.c ecc/ecc-mod.c ecc/ecc-mod-arith.c \ + ecc/ecc-mod-inv.c \ + ecc/ecc-a-to-j.c \ + ecc/sec-tabselect.c ecc/cnd-copy.c ecc/sec-add-1.c \ + ecc/ecc-curve448.c $(ecc_genereated_headers) \ + ecc/curve448-eh-to-x.c ecc/curve448.h ecc/curve448-mul.c \ + ecc/curve448-mul-g.c libcrypto_la_SOURCES += \ - curve448/eddsa.h curve448/eddsa-compress.c curve448/eddsa-decompress.c \ - curve448/eddsa-expand.c curve448/eddsa-hash.c curve448/eddsa-internal.h \ - curve448/eddsa-pubkey.c curve448/eddsa-sign.c curve448/eddsa-verify.c \ - curve448/ed448-shake256.c curve448/ed448-shake256-pubkey.c \ - curve448/ed448-shake256-sign.c curve448/ed448-shake256-verify.c + ecc/eddsa.h ecc/eddsa-compress.c ecc/eddsa-decompress.c \ + ecc/eddsa-expand.c ecc/eddsa-hash.c ecc/eddsa-internal.h \ + ecc/eddsa-pubkey.c ecc/eddsa-sign.c ecc/eddsa-verify.c \ + ecc/ed448-shake256.c ecc/ed448-shake256-pubkey.c \ + ecc/ed448-shake256-sign.c ecc/ed448-shake256-verify.c endif if NEED_CHACHA diff --git a/lib/nettle/pk.c b/lib/nettle/pk.c index f236cef3db..eec6a5fc7d 100644 --- a/lib/nettle/pk.c +++ b/lib/nettle/pk.c @@ -51,8 +51,8 @@ #if HAVE_CURVE448 #include #else -#include "curve448/curve448.h" -#include "curve448/eddsa.h" +#include "ecc/curve448.h" +#include "ecc/eddsa.h" #endif #include #include -- cgit v1.2.1