Reorganize source tree: no .c for non-objects
This commit is contained in:
parent
ea165f47da
commit
7a4b7691b6
14
Makefile
14
Makefile
|
@ -4,7 +4,7 @@ FLAGS_DEBUG:=-DVERIFY -ggdb3 -O1
|
|||
FLAGS_TEST:=-DVERIFY -ggdb3 -O2 -march=native
|
||||
|
||||
SECP256K1_FILES := src/num.h src/field.h src/field_5x52.h src/group.h src/ecmult.h src/ecdsa.h \
|
||||
src/num.c src/field.c src/field_5x52.c src/group.c src/ecmult.c src/ecdsa.c
|
||||
src/impl/*.h
|
||||
|
||||
JAVA_FILES := src/java/org_bitcoin_NativeSecp256k1.h src/java/org_bitcoin_NativeSecp256k1.c
|
||||
|
||||
|
@ -19,33 +19,33 @@ default: all
|
|||
ifeq ($(CONF), gmpgmp)
|
||||
FLAGS_COMMON := $(FLAGS_COMMON) -DUSE_NUM_GMP -DUSE_FIELD_GMP
|
||||
LIBS := -lgmp
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/num_gmp.c src/field_gmp.c src/field_gmp.h
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/field_gmp.h
|
||||
else
|
||||
ifeq ($(CONF), gmp32)
|
||||
FLAGS_COMMON := $(FLAGS_COMMON) -DUSE_NUM_GMP -DUSE_FIELD_10X26
|
||||
LIBS := -lgmp
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/num_gmp.c src/field_10x26.c src/field_10x26.h
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/field_10x26.h
|
||||
else
|
||||
ifeq ($(CONF), openssl)
|
||||
FLAGS_COMMON := $(FLAGS_COMMON) -DUSE_NUM_OPENSSL -DUSE_FIELD_INV_BUILTIN
|
||||
LIBS := -lcrypto
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_openssl.h src/num_openssl.c src/field_5x52_int128.c
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_openssl.h src/field_5x52.h
|
||||
else
|
||||
ifeq ($(CONF), gmp)
|
||||
FLAGS_COMMON := $(FLAGS_COMMON) -DUSE_NUM_GMP
|
||||
LIBS := -lgmp
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/num_gmp.c src/field_5x52_int128.c
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/field_5x52.h
|
||||
else
|
||||
ifeq ($(CONF), gmpasm)
|
||||
FLAGS_COMMON := $(FLAGS_COMMON) -DUSE_NUM_GMP -DUSE_FIELD_5X52_ASM
|
||||
LIBS := -lgmp
|
||||
OBJS := $(OBJS) obj/field_5x52_asm.o
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/num_gmp.c src/field_5x52_asm.c
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/field_5x52.h
|
||||
|
||||
obj/field_5x52_asm.o: src/field_5x52_asm.asm
|
||||
yasm -f elf64 -o obj/field_5x52_asm.o src/field_5x52_asm.asm
|
||||
else
|
||||
SECP256K1_FILES := $(SECP256K1_FILES) src/field_5x52_int128.c
|
||||
error
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
|
10
src/bench.c
10
src/bench.c
|
@ -1,10 +1,10 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "num.c"
|
||||
#include "field.c"
|
||||
#include "group.c"
|
||||
#include "ecmult.c"
|
||||
#include "ecdsa.c"
|
||||
#include "impl/num.h"
|
||||
#include "impl/field.h"
|
||||
#include "impl/group.h"
|
||||
#include "impl/ecmult.h"
|
||||
#include "impl/ecdsa.h"
|
||||
|
||||
int main() {
|
||||
secp256k1_num_start();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _SECP256K1_FIELD_10x26_
|
||||
#define _SECP256K1_FIELD_10x26_
|
||||
#ifndef _SECP256K1_FIELD_REPR_
|
||||
#define _SECP256K1_FIELD_REPR_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _SECP256K1_FIELD_5x52_
|
||||
#define _SECP256K1_FIELD_5x52_
|
||||
#ifndef _SECP256K1_FIELD_REPR_
|
||||
#define _SECP256K1_FIELD_REPR_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _SECP256K1_FIELD_GMP_
|
||||
#define _SECP256K1_FIELD_GMP_
|
||||
#ifndef _SECP256K1_FIELD_REPR_
|
||||
#define _SECP256K1_FIELD_REPR_
|
||||
|
||||
#include <gmp.h>
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#include "num.h"
|
||||
#include "field.h"
|
||||
#include "group.h"
|
||||
#include "ecmult.h"
|
||||
#include "ecdsa.h"
|
||||
#ifndef _SECP256K1_ECDSA_IMPL_H_
|
||||
#define _SECP256K1_ECDSA_IMPL_H_
|
||||
|
||||
#include "../num.h"
|
||||
#include "../field.h"
|
||||
#include "../group.h"
|
||||
#include "../ecmult.h"
|
||||
#include "../ecdsa.h"
|
||||
|
||||
void static secp256k1_ecdsa_sig_init(secp256k1_ecdsa_sig_t *r) {
|
||||
secp256k1_num_init(&r->r);
|
||||
|
@ -141,3 +144,5 @@ void static secp256k1_ecdsa_sig_set_rs(secp256k1_ecdsa_sig_t *sig, const secp256
|
|||
secp256k1_num_copy(&sig->r, r);
|
||||
secp256k1_num_copy(&sig->s, s);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,6 +1,9 @@
|
|||
#include "num.h"
|
||||
#include "group.h"
|
||||
#include "ecmult.h"
|
||||
#ifndef _SECP256K1_ECMULT_IMPL_H_
|
||||
#define _SECP256K1_ECMULT_IMPL_H_
|
||||
|
||||
#include "../num.h"
|
||||
#include "../group.h"
|
||||
#include "../ecmult.h"
|
||||
|
||||
// optimal for 128-bit and 256-bit exponents.
|
||||
#define WINDOW_A 5
|
||||
|
@ -226,3 +229,5 @@ void static secp256k1_ecmult(secp256k1_gej_t *r, const secp256k1_gej_t *a, const
|
|||
secp256k1_num_free(&ng_1);
|
||||
secp256k1_num_free(&ng_128);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,10 +1,13 @@
|
|||
#ifndef _SECP256K1_FIELD_IMPL_H_
|
||||
#define _SECP256K1_FIELD_IMPL_H_
|
||||
|
||||
#ifdef USE_FIELD_GMP
|
||||
#include "field_gmp.c"
|
||||
#include "field_gmp.h"
|
||||
#else
|
||||
#ifdef USE_FIELD_10X26
|
||||
#include "field_10x26.c"
|
||||
#include "field_10x26.h"
|
||||
#else
|
||||
#include "field_5x52.c"
|
||||
#include "field_5x52.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -158,3 +161,5 @@ void static secp256k1_fe_stop(void) {
|
|||
secp256k1_fe_consts = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef _SECP256K1_FIELD_REPR_IMPL_H_
|
||||
#define _SECP256K1_FIELD_REPR_IMPL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "num.h"
|
||||
#include "field.h"
|
||||
#include "../num.h"
|
||||
#include "../field.h"
|
||||
|
||||
void static secp256k1_fe_normalize(secp256k1_fe_t *r) {
|
||||
// fog("normalize in: ", r);
|
||||
|
@ -473,3 +476,5 @@ void static secp256k1_fe_sqr(secp256k1_fe_t *r, const secp256k1_fe_t *a) {
|
|||
#endif
|
||||
secp256k1_fe_sqr_inner(a->n, r->n);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,12 +1,15 @@
|
|||
#ifndef _SECP256K1_FIELD_REPR_IMPL_H_
|
||||
#define _SECP256K1_FIELD_REPR_IMPL_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "num.h"
|
||||
#include "field.h"
|
||||
#include "../num.h"
|
||||
#include "../field.h"
|
||||
|
||||
#ifdef USE_FIELD_5X52_ASM
|
||||
#include "field_5x52_asm.c"
|
||||
#include "field_5x52_asm.h"
|
||||
#else
|
||||
#include "field_5x52_int128.c"
|
||||
#include "field_5x52_int128.h"
|
||||
#endif
|
||||
|
||||
/** Implements arithmetic modulo FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F,
|
||||
|
@ -180,3 +183,5 @@ void static secp256k1_fe_sqr(secp256k1_fe_t *r, const secp256k1_fe_t *a) {
|
|||
#endif
|
||||
secp256k1_fe_sqr_inner(a->n, r->n);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,2 +1,7 @@
|
|||
#ifndef _SECP256K1_FIELD_INNER5X52_IMPL_H_
|
||||
#define _SECP256K1_FIELD_INNER5X52_IMPL_H_
|
||||
|
||||
void __attribute__ ((sysv_abi)) secp256k1_fe_mul_inner(const uint64_t *a, const uint64_t *b, uint64_t *r);
|
||||
void __attribute__ ((sysv_abi)) secp256k1_fe_sqr_inner(const uint64_t *a, uint64_t *r);
|
||||
|
||||
#endif
|
|
@ -1,4 +1,7 @@
|
|||
#include "field.h"
|
||||
#ifndef _SECP256K1_FIELD_INNER5X52_IMPL_H_
|
||||
#define _SECP256K1_FIELD_INNER5X52_IMPL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void static inline secp256k1_fe_mul_inner(const uint64_t *a, const uint64_t *b, uint64_t *r) {
|
||||
__int128 c = (__int128)a[0] * b[0];
|
||||
|
@ -94,3 +97,5 @@ void static inline secp256k1_fe_sqr_inner(const uint64_t *a, uint64_t *r) {
|
|||
r[1] = t1 + c;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef _SECP256K1_FIELD_REPR_IMPL_H_
|
||||
#define _SECP256K1_FIELD_REPR_IMPL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "num.h"
|
||||
#include "field.h"
|
||||
#include "../num.h"
|
||||
#include "../field.h"
|
||||
|
||||
void static secp256k1_fe_normalize(secp256k1_fe_t *r) {
|
||||
#if (GMP_NUMB_BITS >= 40)
|
||||
|
@ -119,3 +122,5 @@ void static secp256k1_fe_sqr(secp256k1_fe_t *r, const secp256k1_fe_t *a) {
|
|||
mpn_sqr(tmp, ac.n, FIELD_LIMBS);
|
||||
secp256k1_fe_reduce(r, tmp);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef _SECP256K1_GROUP_IMPL_H_
|
||||
#define _SECP256K1_GROUP_IMPL_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "num.h"
|
||||
#include "field.h"
|
||||
#include "group.h"
|
||||
#include "../num.h"
|
||||
#include "../field.h"
|
||||
#include "../group.h"
|
||||
|
||||
void static secp256k1_ge_set_infinity(secp256k1_ge_t *r) {
|
||||
r->infinity = 1;
|
||||
|
@ -370,3 +373,5 @@ void static secp256k1_ge_stop(void) {
|
|||
secp256k1_ge_consts = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _SECP256K1_NUM_IMPL_H_
|
||||
#define _SECP256K1_NUM_IMPL_H_
|
||||
|
||||
#include "../num.h"
|
||||
|
||||
#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
|
||||
|
||||
#endif
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef _SECP256K1_NUM_REPR_IMPL_H_
|
||||
#define _SECP256K1_NUM_REPR_IMPL_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -153,3 +156,5 @@ void static secp256k1_num_negate(secp256k1_num_t *r) {
|
|||
void static secp256k1_num_set_rand(secp256k1_num_t *r, const secp256k1_num_t *a) {
|
||||
mpz_urandomm(r->bn, secp256k1_num_state.rng, a->bn);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,10 +1,13 @@
|
|||
#ifndef _SECP256K1_NUM_REPR_IMPL_H_
|
||||
#define _SECP256K1_NUM_REPR_IMPL_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "num.h"
|
||||
#include "../num.h"
|
||||
|
||||
void static secp256k1_num_start() {
|
||||
}
|
||||
|
@ -148,3 +151,5 @@ void static secp256k1_num_negate(secp256k1_num_t *r) {
|
|||
void static secp256k1_num_set_rand(secp256k1_num_t *r, const secp256k1_num_t *a) {
|
||||
BN_pseudo_rand_range(&r->bn, &a->bn);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,7 +0,0 @@
|
|||
#if defined(USE_NUM_GMP)
|
||||
#include "num_gmp.c"
|
||||
#elif defined(USE_NUM_OPENSSL)
|
||||
#include "num_openssl.c"
|
||||
#else
|
||||
#error "Please select num implementation"
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _SECP256K1_NUM_GMP_
|
||||
#define _SECP256K1_NUM_GMP_
|
||||
#ifndef _SECP256K1_NUM_REPR_
|
||||
#define _SECP256K1_NUM_REPR_
|
||||
|
||||
#include <gmp.h>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _SECP256K1_NUM_OPENSSL_
|
||||
#define _SECP256K1_NUM_OPENSSL_
|
||||
#ifndef _SECP256K1_NUM_REPR_
|
||||
#define _SECP256K1_NUM_REPR_
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "num.c"
|
||||
#include "field.c"
|
||||
#include "group.c"
|
||||
#include "ecmult.c"
|
||||
#include "ecdsa.c"
|
||||
#include "impl/num.h"
|
||||
#include "impl/field.h"
|
||||
#include "impl/group.h"
|
||||
#include "impl/ecmult.h"
|
||||
#include "impl/ecdsa.h"
|
||||
|
||||
void secp256k1_start(void) {
|
||||
secp256k1_num_start();
|
||||
|
|
10
src/tests.c
10
src/tests.c
|
@ -1,10 +1,10 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "num.c"
|
||||
#include "field.c"
|
||||
#include "group.c"
|
||||
#include "ecmult.c"
|
||||
#include "ecdsa.c"
|
||||
#include "impl/num.h"
|
||||
#include "impl/field.h"
|
||||
#include "impl/group.h"
|
||||
#include "impl/ecmult.h"
|
||||
#include "impl/ecdsa.h"
|
||||
|
||||
// #define COUNT 2
|
||||
#define COUNT 100
|
||||
|
|
Loading…
Reference in New Issue