Skip to content

Commit 55fab77

Browse files
committed
Add vendor script to prefix secp256k1 sources
1 parent 80e1935 commit 55fab77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4423
-4150
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
13,37d12
2+
< static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
3+
< const size_t base_alloc = ((sizeof(secp256k1_scratch) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT;
4+
< void *alloc = checked_malloc(error_callback, base_alloc + size);
5+
< secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
6+
< if (ret != NULL) {
7+
< memset(ret, 0, sizeof(*ret));
8+
< memcpy(ret->magic, "scratch", 8);
9+
< ret->data = (void *) ((char *) alloc + base_alloc);
10+
< ret->max_size = size;
11+
< }
12+
< return ret;
13+
< }
14+
<
15+
< static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {
16+
< if (scratch != NULL) {
17+
< VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
18+
< if (memcmp(scratch->magic, "scratch", 8) != 0) {
19+
< secp256k1_callback_call(error_callback, "invalid scratch space");
20+
< return;
21+
< }
22+
< memset(scratch->magic, 0, sizeof(scratch->magic));
23+
< free(scratch);
24+
< }
25+
< }
26+
<
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file was automatically created by ./vendor-libsecp.sh
2+
143dc6e9ee31852a60321b23eea407d2006171da
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
139,149d138
2+
< secp256k1_context* secp256k1_context_create(unsigned int flags) {
3+
< size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
4+
< secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
5+
< if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
6+
< free(ctx);
7+
< return NULL;
8+
< }
9+
<
10+
< return ctx;
11+
< }
12+
<
13+
164,174d152
14+
< secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
15+
< secp256k1_context* ret;
16+
< size_t prealloc_size;
17+
<
18+
< VERIFY_CHECK(ctx != NULL);
19+
< prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
20+
< ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
21+
< ret = secp256k1_context_preallocated_clone(ctx, ret);
22+
< return ret;
23+
< }
24+
<
25+
183,189d160
26+
< void secp256k1_context_destroy(secp256k1_context* ctx) {
27+
< if (ctx != NULL) {
28+
< secp256k1_context_preallocated_destroy(ctx);
29+
< free(ctx);
30+
< }
31+
< }
32+
<
33+
206,215d176
34+
< }
35+
<
36+
< secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
37+
< VERIFY_CHECK(ctx != NULL);
38+
< return secp256k1_scratch_create(&ctx->error_callback, max_size);
39+
< }
40+
<
41+
< void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
42+
< VERIFY_CHECK(ctx != NULL);
43+
< secp256k1_scratch_destroy(&ctx->error_callback, scratch);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
202,204d201
2+
< SECP256K1_API secp256k1_context* secp256k1_context_create(
3+
< unsigned int flags
4+
< ) SECP256K1_WARN_UNUSED_RESULT;
5+
215,217d211
6+
< SECP256K1_API secp256k1_context* secp256k1_context_clone(
7+
< const secp256k1_context* ctx
8+
< ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
9+
232,234d225
10+
< SECP256K1_API void secp256k1_context_destroy(
11+
< secp256k1_context* ctx
12+
< );
13+
311,314d301
14+
< SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space* secp256k1_scratch_space_create(
15+
< const secp256k1_context* ctx,
16+
< size_t size
17+
< ) SECP256K1_ARG_NONNULL(1);
18+
322,325d308
19+
< SECP256K1_API void secp256k1_scratch_space_destroy(
20+
< const secp256k1_context* ctx,
21+
< secp256k1_scratch_space* scratch
22+
< ) SECP256K1_ARG_NONNULL(1);

secp256k1-sys/depend/secp256k1/Makefile.am

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ ACLOCAL_AMFLAGS = -I build-aux/m4
22

33
lib_LTLIBRARIES = libsecp256k1.la
44
if USE_JNI
5-
JNI_LIB = libsecp256k1_jni.la
5+
JNI_LIB = librustsecp256k1_v0_1_0_jni.la
66
noinst_LTLIBRARIES = $(JNI_LIB)
77
else
88
JNI_LIB =
99
endif
1010
include_HEADERS = include/secp256k1.h
11-
include_HEADERS += include/secp256k1_preallocated.h
11+
include_HEADERS += include/rustsecp256k1_v0_1_0_preallocated.h
1212
noinst_HEADERS =
1313
noinst_HEADERS += src/scalar.h
1414
noinst_HEADERS += src/scalar_4x64.h
@@ -58,7 +58,7 @@ noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
5858
noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
5959

6060
if USE_EXTERNAL_ASM
61-
COMMON_LIB = libsecp256k1_common.la
61+
COMMON_LIB = librustsecp256k1_v0_1_0_common.la
6262
noinst_LTLIBRARIES = $(COMMON_LIB)
6363
else
6464
COMMON_LIB =
@@ -69,16 +69,16 @@ pkgconfig_DATA = libsecp256k1.pc
6969

7070
if USE_EXTERNAL_ASM
7171
if USE_ASM_ARM
72-
libsecp256k1_common_la_SOURCES = src/asm/field_10x26_arm.s
72+
librustsecp256k1_v0_1_0_common_la_SOURCES = src/asm/field_10x26_arm.s
7373
endif
7474
endif
7575

76-
libsecp256k1_la_SOURCES = src/secp256k1.c
77-
libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
78-
libsecp256k1_la_LIBADD = $(JNI_LIB) $(SECP_LIBS) $(COMMON_LIB)
76+
librustsecp256k1_v0_1_0_la_SOURCES = src/secp256k1.c
77+
librustsecp256k1_v0_1_0_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
78+
librustsecp256k1_v0_1_0_la_LIBADD = $(JNI_LIB) $(SECP_LIBS) $(COMMON_LIB)
7979

80-
libsecp256k1_jni_la_SOURCES = src/java/org_bitcoin_NativeSecp256k1.c src/java/org_bitcoin_Secp256k1Context.c
81-
libsecp256k1_jni_la_CPPFLAGS = -DSECP256K1_BUILD $(JNI_INCLUDES)
80+
librustsecp256k1_v0_1_0_jni_la_SOURCES = src/java/org_bitcoin_NativeSecp256k1.c src/java/org_bitcoin_Secp256k1Context.c
81+
librustsecp256k1_v0_1_0_jni_la_CPPFLAGS = -DSECP256K1_BUILD $(JNI_INCLUDES)
8282

8383
noinst_PROGRAMS =
8484
if USE_BENCHMARK
@@ -161,7 +161,7 @@ gen_%.o: src/gen_%.c
161161
$(gen_context_BIN): $(gen_context_OBJECTS)
162162
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
163163

164-
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
164+
$(librustsecp256k1_v0_1_0_la_OBJECTS): src/ecmult_static_context.h
165165
$(tests_OBJECTS): src/ecmult_static_context.h
166166
$(bench_internal_OBJECTS): src/ecmult_static_context.h
167167
$(bench_ecmult_OBJECTS): src/ecmult_static_context.h

secp256k1-sys/depend/secp256k1/configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ AC_ARG_ENABLE(external_default_callbacks,
140140
[use_external_default_callbacks=no])
141141

142142
AC_ARG_ENABLE(jni,
143-
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni [default=no]]),
143+
AS_HELP_STRING([--enable-jni],[enable librustsecp256k1_v0_1_0_jni [default=no]]),
144144
[use_jni=$enableval],
145145
[use_jni=no])
146146

secp256k1-sys/depend/secp256k1/contrib/lax_der_parsing.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
#include "lax_der_parsing.h"
1111

12-
int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
12+
int rustsecp256k1_v0_1_0_ecdsa_signature_parse_der_lax(const rustsecp256k1_v0_1_0_context* ctx, rustsecp256k1_v0_1_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
1313
size_t rpos, rlen, spos, slen;
1414
size_t pos = 0;
1515
size_t lenbyte;
1616
unsigned char tmpsig[64] = {0};
1717
int overflow = 0;
1818

1919
/* Hack to initialize sig with a correctly-parsed but invalid signature. */
20-
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
20+
rustsecp256k1_v0_1_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
2121

2222
/* Sequence tag byte */
2323
if (pos == inputlen || input[pos] != 0x30) {
@@ -139,11 +139,11 @@ int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_
139139
}
140140

141141
if (!overflow) {
142-
overflow = !secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
142+
overflow = !rustsecp256k1_v0_1_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
143143
}
144144
if (overflow) {
145145
memset(tmpsig, 0, 64);
146-
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
146+
rustsecp256k1_v0_1_0_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
147147
}
148148
return 1;
149149
}

secp256k1-sys/depend/secp256k1/contrib/lax_der_parsing.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* certain violations are easily supported. You may need to adapt it.
2727
*
2828
* Do not use this for new systems. Use well-defined DER or compact signatures
29-
* instead if you have the choice (see secp256k1_ecdsa_signature_parse_der and
30-
* secp256k1_ecdsa_signature_parse_compact).
29+
* instead if you have the choice (see rustsecp256k1_v0_1_0_ecdsa_signature_parse_der and
30+
* rustsecp256k1_v0_1_0_ecdsa_signature_parse_compact).
3131
*
3232
* The supported violations are:
3333
* - All numbers are parsed as nonnegative integers, even though X.609-0207
@@ -77,9 +77,9 @@ extern "C" {
7777
* encoded numbers are out of range, signature validation with it is
7878
* guaranteed to fail for every message and public key.
7979
*/
80-
int ecdsa_signature_parse_der_lax(
81-
const secp256k1_context* ctx,
82-
secp256k1_ecdsa_signature* sig,
80+
int rustsecp256k1_v0_1_0_ecdsa_signature_parse_der_lax(
81+
const rustsecp256k1_v0_1_0_context* ctx,
82+
rustsecp256k1_v0_1_0_ecdsa_signature* sig,
8383
const unsigned char *input,
8484
size_t inputlen
8585
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);

secp256k1-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "lax_der_privatekey_parsing.h"
1111

12-
int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) {
12+
int ec_privkey_import_der(const rustsecp256k1_v0_1_0_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) {
1313
const unsigned char *end = privkey + privkeylen;
1414
int lenb = 0;
1515
int len = 0;
@@ -46,17 +46,17 @@ int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, co
4646
return 0;
4747
}
4848
memcpy(out32 + 32 - privkey[1], privkey + 2, privkey[1]);
49-
if (!secp256k1_ec_seckey_verify(ctx, out32)) {
49+
if (!rustsecp256k1_v0_1_0_ec_seckey_verify(ctx, out32)) {
5050
memset(out32, 0, 32);
5151
return 0;
5252
}
5353
return 1;
5454
}
5555

56-
int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
57-
secp256k1_pubkey pubkey;
56+
int ec_privkey_export_der(const rustsecp256k1_v0_1_0_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
57+
rustsecp256k1_v0_1_0_pubkey pubkey;
5858
size_t pubkeylen = 0;
59-
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
59+
if (!rustsecp256k1_v0_1_0_ec_pubkey_create(ctx, &pubkey, key32)) {
6060
*privkeylen = 0;
6161
return 0;
6262
}
@@ -80,7 +80,7 @@ int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey,
8080
memcpy(ptr, key32, 32); ptr += 32;
8181
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
8282
pubkeylen = 33;
83-
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
83+
rustsecp256k1_v0_1_0_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
8484
ptr += pubkeylen;
8585
*privkeylen = ptr - privkey;
8686
} else {
@@ -105,7 +105,7 @@ int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey,
105105
memcpy(ptr, key32, 32); ptr += 32;
106106
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
107107
pubkeylen = 65;
108-
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
108+
rustsecp256k1_v0_1_0_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
109109
ptr += pubkeylen;
110110
*privkeylen = ptr - privkey;
111111
}

secp256k1-sys/depend/secp256k1/contrib/lax_der_privatekey_parsing.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ extern "C" {
5252
* simple 32-byte private keys are sufficient.
5353
*
5454
* Note that this function does not guarantee correct DER output. It is
55-
* guaranteed to be parsable by secp256k1_ec_privkey_import_der
55+
* guaranteed to be parsable by rustsecp256k1_v0_1_0_ec_privkey_import_der
5656
*/
5757
SECP256K1_WARN_UNUSED_RESULT int ec_privkey_export_der(
58-
const secp256k1_context* ctx,
58+
const rustsecp256k1_v0_1_0_context* ctx,
5959
unsigned char *privkey,
6060
size_t *privkeylen,
6161
const unsigned char *seckey,
@@ -77,7 +77,7 @@ SECP256K1_WARN_UNUSED_RESULT int ec_privkey_export_der(
7777
* key.
7878
*/
7979
SECP256K1_WARN_UNUSED_RESULT int ec_privkey_import_der(
80-
const secp256k1_context* ctx,
80+
const rustsecp256k1_v0_1_0_context* ctx,
8181
unsigned char *seckey,
8282
const unsigned char *privkey,
8383
size_t privkeylen

0 commit comments

Comments
 (0)