diff --git a/.travis.yml b/.travis.yml index 8d1b6f4c4b3..44563d1b18d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,21 @@ language: cpp compiler: gcc install: - - if [ "$BIGNUM" = "gmp" -o "$FIELD" = "gmp" ]; then sudo apt-get install -qq libgmp-dev; fi + - sudo apt-get install -qq libssl-dev + - if [ "$BIGNUM" = "gmp" -o "$BIGNUM" = "auto" -o "$FIELD" = "gmp" ]; then sudo apt-get install -qq libgmp-dev; fi - if [ "$FIELD" = "64bit_asm" ]; then sudo apt-get install -qq yasm; fi env: global: - - FIELD=auto BIGNUM=auto ENDOMORPHISM=no BUILD=check + - FIELD=auto BIGNUM=auto ENDOMORPHISM=no BUILD=check matrix: - - FIELD=gmp BIGNUM=gmp - - FIELD=gmp BIGNUM=openssl - - FIELD=64bit_asm BIGNUM=gmp - - FIELD=64bit_asm BIGNUM=openssl - - FIELD=64bit BIGNUM=gmp - - FIELD=64bit BIGNUM=openssl - - FIELD=32bit BIGNUM=gmp - - FIELD=32bit BIGNUM=openssl - - FIELD=gmp BIGNUM=gmp ENDOMORPHISM=yes - - FIELD=gmp BIGNUM=openssl ENDOMORPHISM=yes - - FIELD=64bit_asm BIGNUM=gmp ENDOMORPHISM=yes - - FIELD=64bit_asm BIGNUM=openssl ENDOMORPHISM=yes - - FIELD=64bit BIGNUM=gmp ENDOMORPHISM=yes - - FIELD=64bit BIGNUM=openssl ENDOMORPHISM=yes - - FIELD=32bit BIGNUM=gmp ENDOMORPHISM=yes - - FIELD=32bit BIGNUM=openssl ENDOMORPHISM=yes + - FIELD=gmp + - FIELD=gmp ENDOMORPHISM=yes + - FIELD=64bit_asm + - FIELD=64bit_asm ENDOMORPHISM=yes + - FIELD=64bit + - FIELD=64bit ENDOMORPHISM=yes + - FIELD=32bit + - FIELD=32bit ENDOMORPHISM=yes - BUILD=distcheck before_script: ./autogen.sh script: ./configure --enable-endomorphism=$ENDOMORPHISM --with-field=$FIELD --with-bignum=$BIGNUM && make -j2 $BUILD diff --git a/Makefile.am b/Makefile.am index c6612d8df2e..22916951086 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,8 +8,6 @@ noinst_HEADERS += src/scalar.h noinst_HEADERS += src/scalar_impl.h noinst_HEADERS += src/group.h noinst_HEADERS += src/group_impl.h -noinst_HEADERS += src/num_openssl.h -noinst_HEADERS += src/num_openssl_impl.h noinst_HEADERS += src/num_gmp.h noinst_HEADERS += src/num_gmp_impl.h noinst_HEADERS += src/ecdsa.h diff --git a/configure.ac b/configure.ac index 1671d589734..dd0892af8bd 100644 --- a/configure.ac +++ b/configure.ac @@ -58,7 +58,7 @@ AC_ARG_ENABLE(endomorphism, AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=gmp|64bit|64bit_asm|32bit|auto], [Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto]) -AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|openssl|auto], +AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|auto], [Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto]) AC_CHECK_TYPES([__int128]) @@ -132,11 +132,6 @@ if test x"$has_libcrypto" == x"yes" && test x"$has_openssl_ec" = x; then ],[has_openssl_ec=yes], [has_openssl_ec=no]) AC_MSG_RESULT([$has_openssl_ec]) fi -if test x"$set_bignum" = x"openssl"; then - if test x"$has_libcrypto" != x"yes"; then - AC_MSG_ERROR([$set_bignum field support explicitly requested but libcrypto was not found]) - fi -fi ]) AC_CHECK_DECL(__builtin_expect,AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]),,) @@ -202,13 +197,6 @@ if test x"$req_bignum" = x"auto"; then set_bignum=gmp fi - if test x"$set_bignum" = x; then - SECP_OPENSSL_CHECK - if test x"$has_libcrypto" = x"yes"; then - set_bignum=openssl - fi - fi - if test x"$set_bignum" = x; then AC_MSG_ERROR([no working bignum implementation found]) fi @@ -256,12 +244,6 @@ gmp) AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation]) AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the USE_FIELD_INV_NUM implementation]) ;; -openssl) - AC_DEFINE(USE_NUM_OPENSSL, 1,[Define this symbol to use the openssl implementation]) - AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the FIELD_INV_BUILTIN implementation]) - SECP_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS" - SECP_LIBS="$CRYPTO_LIBS" - ;; *) AC_MSG_ERROR([invalid bignum implementation]) ;; diff --git a/src/num.h b/src/num.h index 4bc2e16c617..c1ccbb515fd 100644 --- a/src/num.h +++ b/src/num.h @@ -11,8 +11,6 @@ #if defined(USE_NUM_GMP) #include "num_gmp.h" -#elif defined(USE_NUM_OPENSSL) -#include "num_openssl.h" #else #error "Please select num implementation" #endif diff --git a/src/num_impl.h b/src/num_impl.h index fda1270ecd0..a6644fda703 100644 --- a/src/num_impl.h +++ b/src/num_impl.h @@ -13,8 +13,6 @@ #if defined(USE_NUM_GMP) #include "num_gmp_impl.h" -#elif defined(USE_NUM_OPENSSL) -#include "num_openssl_impl.h" #else #error "Please select num implementation" #endif diff --git a/src/num_openssl.h b/src/num_openssl.h deleted file mode 100644 index bb4df38a13f..00000000000 --- a/src/num_openssl.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2013 Pieter Wuille -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef _SECP256K1_NUM_REPR_ -#define _SECP256K1_NUM_REPR_ - -#include - -typedef struct { - BIGNUM bn; -#ifdef VERIFY - void* init; -#endif -} secp256k1_num_t; - -#endif diff --git a/src/num_openssl_impl.h b/src/num_openssl_impl.h deleted file mode 100644 index 0c0049ed1a0..00000000000 --- a/src/num_openssl_impl.h +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright (c) 2013 Pieter Wuille -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef _SECP256K1_NUM_REPR_IMPL_H_ -#define _SECP256K1_NUM_REPR_IMPL_H_ - -#include -#include -#include -#include -#include - -#include "util.h" -#include "num.h" - -void static secp256k1_num_init(secp256k1_num_t *r) { -#ifdef VERIFY - r->init = r; -#endif - BN_init(&r->bn); -} - -void static secp256k1_num_free(secp256k1_num_t *r) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - r->init = NULL; -#endif - BN_free(&r->bn); -} - -void static secp256k1_num_clear(secp256k1_num_t *r) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); -#endif - BN_clear(&r->bn); -} - -void static secp256k1_num_copy(secp256k1_num_t *r, const secp256k1_num_t *a) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(a->init == a); -#endif - BN_copy(&r->bn, &a->bn); -} - -void static secp256k1_num_get_bin(unsigned char *r, unsigned int rlen, const secp256k1_num_t *a) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); -#endif - unsigned int size = BN_num_bytes(&a->bn); - VERIFY_CHECK(size <= rlen); - memset(r,0,rlen); - BN_bn2bin(&a->bn, r + rlen - size); -} - -void static secp256k1_num_set_bin(secp256k1_num_t *r, const unsigned char *a, unsigned int alen) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); -#endif - BN_bin2bn(a, alen, &r->bn); -} - -void static secp256k1_num_set_int(secp256k1_num_t *r, int a) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); -#endif - BN_set_word(&r->bn, a < 0 ? -a : a); - BN_set_negative(&r->bn, a < 0); -} - -void static secp256k1_num_mod_inverse(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *m) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(m->init == m); -#endif - BN_CTX *ctx = BN_CTX_new(); - BN_mod_inverse(&r->bn, &a->bn, &m->bn, ctx); - BN_CTX_free(ctx); -} - -void static secp256k1_num_mod_mul(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b, const secp256k1_num_t *m) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(b->init == b); - VERIFY_CHECK(m->init == m); -#endif - BN_CTX *ctx = BN_CTX_new(); - BN_mod_mul(&r->bn, &a->bn, &b->bn, &m->bn, ctx); - BN_CTX_free(ctx); -} - -int static secp256k1_num_cmp(const secp256k1_num_t *a, const secp256k1_num_t *b) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(b->init == b); -#endif - return BN_ucmp(&a->bn, &b->bn); -} - -int static secp256k1_num_eq(const secp256k1_num_t *a, const secp256k1_num_t *b) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(b->init == b); -#endif - return BN_cmp(&a->bn, &b->bn) == 0; -} - -void static secp256k1_num_add(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(b->init == b); -#endif - BN_add(&r->bn, &a->bn, &b->bn); -} - -void static secp256k1_num_sub(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(b->init == b); -#endif - BN_sub(&r->bn, &a->bn, &b->bn); -} - -void static secp256k1_num_mul(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(b->init == b); -#endif - BN_CTX *ctx = BN_CTX_new(); - BN_mul(&r->bn, &a->bn, &b->bn, ctx); - BN_CTX_free(ctx); -} - -void static secp256k1_num_div(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(a->init == a); - VERIFY_CHECK(b->init == b); -#endif - BN_CTX *ctx = BN_CTX_new(); - BN_div(&r->bn, NULL, &a->bn, &b->bn, ctx); - BN_CTX_free(ctx); -} - -void static secp256k1_num_mod(secp256k1_num_t *r, const secp256k1_num_t *m) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); - VERIFY_CHECK(m->init == m); -#endif - BN_CTX *ctx = BN_CTX_new(); - BN_nnmod(&r->bn, &r->bn, &m->bn, ctx); - BN_CTX_free(ctx); -} - -int static secp256k1_num_bits(const secp256k1_num_t *a) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); -#endif - return BN_num_bits(&a->bn); -} - -int static secp256k1_num_shift(secp256k1_num_t *r, int bits) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); -#endif - int ret = BN_is_zero(&r->bn) ? 0 : r->bn.d[0] & ((1 << bits) - 1); - BN_rshift(&r->bn, &r->bn, bits); - return ret; -} - -int static secp256k1_num_is_zero(const secp256k1_num_t *a) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); -#endif - return BN_is_zero(&a->bn); -} - -int static secp256k1_num_is_odd(const secp256k1_num_t *a) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); -#endif - return BN_is_odd(&a->bn); -} - -int static secp256k1_num_is_neg(const secp256k1_num_t *a) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); -#endif - return BN_is_negative(&a->bn); -} - -int static secp256k1_num_get_bit(const secp256k1_num_t *a, int pos) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); -#endif - return BN_is_bit_set(&a->bn, pos); -} - -void static secp256k1_num_inc(secp256k1_num_t *r) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); -#endif - BN_add_word(&r->bn, 1); -} - -void static secp256k1_num_set_hex(secp256k1_num_t *r, const char *a, int alen) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); -#endif - char *str = (char*)malloc(alen+1); - memcpy(str, a, alen); - str[alen] = 0; - BIGNUM *pbn = &r->bn; - BN_hex2bn(&pbn, str); - free(str); -} - -void static secp256k1_num_get_hex(char *r, int rlen, const secp256k1_num_t *a) { -#ifdef VERIFY - VERIFY_CHECK(a->init == a); -#endif - char *str = BN_bn2hex(&a->bn); - int len = strlen(str); - VERIFY_CHECK(rlen >= len); - for (int i=0; iinit == a); - VERIFY_CHECK(rl->init == rl); - VERIFY_CHECK(rh->init == rh); -#endif - BN_copy(&rl->bn, &a->bn); - BN_rshift(&rh->bn, &a->bn, bits); - BN_mask_bits(&rl->bn, bits); -} - -void static secp256k1_num_negate(secp256k1_num_t *r) { -#ifdef VERIFY - VERIFY_CHECK(r->init == r); -#endif - BN_set_negative(&r->bn, !BN_is_negative(&r->bn)); -} - -int static secp256k1_num_get_bits(const secp256k1_num_t *a, int offset, int count) { - int ret = 0; - for (int i = 0; i < count; i++) { - ret |= BN_is_bit_set(&a->bn, offset + i) << i; - } - return ret; -} - -#endif