Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor includes #924

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ACLOCAL_AMFLAGS = -I build-aux/m4
AM_CPPFLAGS = -Iinclude/

lib_LTLIBRARIES = libsecp256k1.la
include_HEADERS = include/secp256k1.h
Expand Down Expand Up @@ -81,15 +82,15 @@ noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
bench_verify_SOURCES = src/bench_verify.c
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
bench_verify_CPPFLAGS = -DSECP256K1_BUILD $(SECP_TEST_INCLUDES)
bench_verify_CPPFLAGS = -DSECP256K1_BUILD $(SECP_TEST_INCLUDES) $(AM_CPPFLAGS)
bench_sign_SOURCES = src/bench_sign.c
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
bench_internal_SOURCES = src/bench_internal.c
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES) $(AM_CPPFLAGS)
bench_ecmult_SOURCES = src/bench_ecmult.c
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES) $(AM_CPPFLAGS)
endif

TESTS =
Expand All @@ -114,7 +115,7 @@ endif
if USE_EXHAUSTIVE_TESTS
noinst_PROGRAMS += exhaustive_tests
exhaustive_tests_SOURCES = src/tests_exhaustive.c
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES)
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES) $(AM_CPPFLAGS)
if !ENABLE_COVERAGE
exhaustive_tests_CPPFLAGS += -DVERIFY
endif
Expand All @@ -129,10 +130,10 @@ CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
gen_context_OBJECTS = gen_context.o
gen_context_BIN = gen_context$(BUILD_EXEEXT)
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(AM_CPPFLAGS) $(CFLAGS_FOR_BUILD) -c $< -o $@

$(gen_context_BIN): $(gen_context_OBJECTS)
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(AM_CPPFLAGS) $(LDFLAGS_FOR_BUILD) $^ -o $@

$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
$(tests_OBJECTS): src/ecmult_static_context.h
Expand Down
4 changes: 2 additions & 2 deletions src/bench_ecdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <string.h>

#include "include/secp256k1.h"
#include "include/secp256k1_ecdh.h"
#include "secp256k1.h"
#include "secp256k1_ecdh.h"
#include "util.h"
#include "bench.h"

Expand Down
11 changes: 8 additions & 3 deletions src/bench_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
* Distributed under the MIT software license, see the accompanying *
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#include "include/secp256k1.h"
#include "secp256k1.h"

#include "util.h"
#include "hash_impl.h"
#include "field_impl.h"
#include "group_impl.h"
#include "scalar_impl.h"
#include "ecmult_impl.h"
#include "scalar_impl.h"
#include "bench.h"
#include "secp256k1.c"
#include "group.h"
#include "hash.h"


#define POINTS 32768

Expand Down
16 changes: 10 additions & 6 deletions src/bench_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/
#include <stdio.h>
#include <string.h>

#include "include/secp256k1.h"
#include "secp256k1.h"

#include "assumptions.h"
#include "util.h"
#include "hash_impl.h"
#include "field_impl.h"
#include "bench.h"
#include "group.h"
#include "group_impl.h"
#include "scalar_impl.h"
#include "ecmult_const_impl.h"
#include "ecmult_impl.h"
#include "bench.h"
#include "field_impl.h"
#include "hash.h"
#include "hash_impl.h"
#include "scalar_impl.h"
#include "secp256k1.c"
#include "util.h"


typedef struct {
secp256k1_scalar scalar[2];
Expand Down
6 changes: 4 additions & 2 deletions src/bench_recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/

#include "include/secp256k1.h"
#include "include/secp256k1_recovery.h"
#include "secp256k1.h"
#include "secp256k1_recovery.h"
#include "util.h"
#include "bench.h"

#include <stddef.h>

typedef struct {
secp256k1_context *ctx;
unsigned char msg[32];
Expand Down
8 changes: 4 additions & 4 deletions src/bench_schnorrsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include <string.h>
#include <stdlib.h>


#include "include/secp256k1.h"
#include "include/secp256k1_schnorrsig.h"
#include "util.h"
#include "secp256k1.h"
#include "secp256k1_schnorrsig.h"
#include "secp256k1_extrakeys.h"
#include "bench.h"
#include "util.h"

typedef struct {
secp256k1_context *ctx;
Expand Down
4 changes: 3 additions & 1 deletion src/bench_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/

#include "include/secp256k1.h"
#include <stddef.h>

#include "secp256k1.h"
#include "util.h"
#include "bench.h"

Expand Down
8 changes: 3 additions & 5 deletions src/bench_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
***********************************************************************/

#include <stdio.h>
#include <string.h>

#include "include/secp256k1.h"
#include "secp256k1.h"
#include "util.h"
#include "bench.h"

#ifdef ENABLE_OPENSSL_TESTS
#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
#include <openssl/ec.h>
#include <openssl/ossl_typ.h>
#endif


typedef struct {
secp256k1_context *ctx;
unsigned char msg[32];
Expand Down
2 changes: 2 additions & 0 deletions src/ecmult_gen_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "group.h"
#include "ecmult_gen.h"
#include "hash_impl.h"
#include "field_impl.h"

#ifdef USE_ECMULT_STATIC_PRECOMPUTATION
#include "ecmult_static_context.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/gen_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* We can't require the precomputed tables when creating them. */
#undef USE_ECMULT_STATIC_PRECOMPUTATION

#include "include/secp256k1.h"
#include "secp256k1.h"
#include "assumptions.h"
#include "util.h"
#include "field_impl.h"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ecdh/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef SECP256K1_MODULE_ECDH_MAIN_H
#define SECP256K1_MODULE_ECDH_MAIN_H

#include "include/secp256k1_ecdh.h"
#include "secp256k1_ecdh.h"
#include "ecmult_const_impl.h"

static int ecdh_hash_function_sha256(unsigned char *output, const unsigned char *x32, const unsigned char *y32, void *data) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/extrakeys/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifndef SECP256K1_MODULE_EXTRAKEYS_MAIN_H
#define SECP256K1_MODULE_EXTRAKEYS_MAIN_H

#include "include/secp256k1.h"
#include "include/secp256k1_extrakeys.h"
#include "secp256k1.h"
#include "secp256k1_extrakeys.h"

static SECP256K1_INLINE int secp256k1_xonly_pubkey_load(const secp256k1_context* ctx, secp256k1_ge *ge, const secp256k1_xonly_pubkey *pubkey) {
return secp256k1_pubkey_load(ctx, ge, (const secp256k1_pubkey *) pubkey);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/extrakeys/tests_exhaustive_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define SECP256K1_MODULE_EXTRAKEYS_TESTS_EXHAUSTIVE_H

#include "src/modules/extrakeys/main_impl.h"
#include "include/secp256k1_extrakeys.h"
#include "secp256k1_extrakeys.h"

static void test_exhaustive_extrakeys(const secp256k1_context *ctx, const secp256k1_ge* group) {
secp256k1_keypair keypair[EXHAUSTIVE_TEST_ORDER - 1];
Expand Down
2 changes: 1 addition & 1 deletion src/modules/recovery/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef SECP256K1_MODULE_RECOVERY_MAIN_H
#define SECP256K1_MODULE_RECOVERY_MAIN_H

#include "include/secp256k1_recovery.h"
#include "secp256k1_recovery.h"

static void secp256k1_ecdsa_recoverable_signature_load(const secp256k1_context* ctx, secp256k1_scalar* r, secp256k1_scalar* s, int* recid, const secp256k1_ecdsa_recoverable_signature* sig) {
(void)ctx;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/recovery/tests_exhaustive_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define SECP256K1_MODULE_RECOVERY_EXHAUSTIVE_TESTS_H

#include "src/modules/recovery/main_impl.h"
#include "include/secp256k1_recovery.h"
#include "secp256k1_recovery.h"

void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const secp256k1_ge *group) {
int i, j, k;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/schnorrsig/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifndef SECP256K1_MODULE_SCHNORRSIG_MAIN_H
#define SECP256K1_MODULE_SCHNORRSIG_MAIN_H

#include "include/secp256k1.h"
#include "include/secp256k1_schnorrsig.h"
#include "secp256k1.h"
#include "secp256k1_schnorrsig.h"
#include "hash.h"

/* Initializes SHA256 with fixed midstate. This midstate was computed by applying
Expand Down
2 changes: 1 addition & 1 deletion src/modules/schnorrsig/tests_exhaustive_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef SECP256K1_MODULE_SCHNORRSIG_TESTS_EXHAUSTIVE_H
#define SECP256K1_MODULE_SCHNORRSIG_TESTS_EXHAUSTIVE_H

#include "include/secp256k1_schnorrsig.h"
#include "secp256k1_schnorrsig.h"
#include "src/modules/schnorrsig/main_impl.h"

static const unsigned char invalid_pubkey_bytes[][32] = {
Expand Down
10 changes: 6 additions & 4 deletions src/secp256k1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/

#include "include/secp256k1.h"
#include "include/secp256k1_preallocated.h"
#include <stdlib.h>
#include <string.h>

#include "secp256k1.h"
#include "secp256k1_preallocated.h"

#include "assumptions.h"
#include "util.h"
#include "field_impl.h"
#include "scalar_impl.h"
#include "group_impl.h"
#include "ecmult_impl.h"
#include "ecmult_const_impl.h"
#include "ecmult_gen_impl.h"
#include "ecdsa_impl.h"
#include "eckey_impl.h"
Expand All @@ -39,8 +41,8 @@
} while(0)

#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS
#include <stdlib.h>
#include <stdio.h>

static void secp256k1_default_illegal_callback_fn(const char* str, void* data) {
(void)data;
fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
Expand Down
1 change: 1 addition & 0 deletions src/testrand_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#include "testrand.h"
#include "hash.h"
Expand Down
27 changes: 22 additions & 5 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,40 @@
#include "libsecp256k1-config.h"
#endif

#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <time.h>

#include "secp256k1.c"
#include "include/secp256k1.h"
#include "include/secp256k1_preallocated.h"
#include "secp256k1.h"
#include "ecdsa_impl.h"
#include "eckey_impl.h"
#include "ecmult_const_impl.h"
#include "ecmult_gen.h"
#include "ecmult_gen_impl.h"
#include "ecmult_impl.h"
#include "field_impl.h"
#include "group.h"
#include "group_impl.h"
#include "hash.h"
#include "hash_impl.h"

#include "scalar_impl.h"
#include "scratch.h"
#include "scratch_impl.h"
#include "testrand_impl.h"
#include "util.h"


#ifdef ENABLE_OPENSSL_TESTS
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
#include <openssl/opensslv.h>
#include <openssl/ossl_typ.h>

# if OPENSSL_VERSION_NUMBER < 0x10100000L
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {*pr = sig->r; *ps = sig->s;}
# endif
Expand Down
19 changes: 15 additions & 4 deletions src/tests_exhaustive.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <stdio.h>
#include <stdlib.h>

#include <time.h>
#include <stdint.h>
#include <string.h>

#undef USE_ECMULT_STATIC_PRECOMPUTATION

Expand All @@ -20,11 +20,22 @@
#define EXHAUSTIVE_TEST_ORDER 13
#endif

#include "include/secp256k1.h"
#include "secp256k1.c"
#include "secp256k1.h"
#include "assumptions.h"
#include "ecmult_const_impl.h"
#include "ecmult_gen_impl.h"
#include "ecmult_impl.h"
#include "field_impl.h"
#include "group.h"
#include "secp256k1.c"
#include "group_impl.h"
#include "scalar_impl.h"
#include "scalar_low.h"
#include "scalar_low_impl.h"
#include "scratch.h"
#include "scratch_impl.h"
#include "testrand_impl.h"
#include "util.h"

static int count = 2;

Expand Down
Loading