commit 6735f51204d13c2138f3bea7033dac353cc5189b
parent 64cca94882ed78a1b96cb04e2dfd6e724c2d4a28
Author: Jared Tobin <jared@jtobin.io>
Date: Tue, 13 Feb 2024 10:45:55 +0400
Tweak vendoring, build.
Many of the patches employed by rust-secp256k1 are not at present of
interest here. We do patch out some stuff in secp256k1.h that causes
cabal-install to throw linker errors when it invokes ld; that stuff
is also not of interest to us at the moment.
Diffstat:
9 files changed, 18 insertions(+), 154 deletions(-)
diff --git a/secp256k1-sys/depend/lax_der_parsing.c.patch b/secp256k1-sys/depend/lax_der_parsing.c.patch
@@ -1,6 +0,0 @@
-10c10,12
-<
----
-> extern int secp256k1_ecdsa_signature_parse_compact(
-> const secp256k1_context *ctx,
-> secp256k1_ecdsa_signature *sig, const unsigned char *input64);
diff --git a/secp256k1-sys/depend/scratch_impl.h.patch b/secp256k1-sys/depend/scratch_impl.h.patch
@@ -1,26 +0,0 @@
-13,37d12
-< static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
-< const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));
-< void *alloc = checked_malloc(error_callback, base_alloc + size);
-< secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
-< if (ret != NULL) {
-< memset(ret, 0, sizeof(*ret));
-< memcpy(ret->magic, "scratch", 8);
-< ret->data = (void *) ((char *) alloc + base_alloc);
-< ret->max_size = size;
-< }
-< return ret;
-< }
-<
-< static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback, secp256k1_scratch* scratch) {
-< if (scratch != NULL) {
-< if (secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
-< secp256k1_callback_call(error_callback, "invalid scratch space");
-< return;
-< }
-< VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
-< memset(scratch->magic, 0, sizeof(scratch->magic));
-< free(scratch);
-< }
-< }
-<
diff --git a/secp256k1-sys/depend/secp256k1.c.patch b/secp256k1-sys/depend/secp256k1.c.patch
@@ -1,50 +0,0 @@
-140,150d139
-< secp256k1_context* secp256k1_context_create(unsigned int flags) {
-< size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
-< secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
-< if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
-< free(ctx);
-< return NULL;
-< }
-<
-< return ctx;
-< }
-<
-162,174d150
-< secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
-< secp256k1_context* ret;
-< size_t prealloc_size;
-<
-< VERIFY_CHECK(ctx != NULL);
-< ARG_CHECK(secp256k1_context_is_proper(ctx));
-<
-< prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
-< ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
-< ret = secp256k1_context_preallocated_clone(ctx, ret);
-< return ret;
-< }
-<
-186,197d161
-< void secp256k1_context_destroy(secp256k1_context* ctx) {
-< ARG_CHECK_VOID(ctx == NULL || secp256k1_context_is_proper(ctx));
-<
-< /* Defined as noop */
-< if (ctx == NULL) {
-< return;
-< }
-<
-< secp256k1_context_preallocated_destroy(ctx);
-< free(ctx);
-< }
-<
-220,229d183
-< }
-<
-< secp256k1_scratch_space* secp256k1_scratch_space_create(const secp256k1_context* ctx, size_t max_size) {
-< VERIFY_CHECK(ctx != NULL);
-< return secp256k1_scratch_create(&ctx->error_callback, max_size);
-< }
-<
-< void secp256k1_scratch_space_destroy(const secp256k1_context *ctx, secp256k1_scratch_space* scratch) {
-< VERIFY_CHECK(ctx != NULL);
-< secp256k1_scratch_destroy(&ctx->error_callback, scratch);
diff --git a/secp256k1-sys/depend/secp256k1.h.patch b/secp256k1-sys/depend/secp256k1.h.patch
@@ -3,33 +3,6 @@
239,240d237
< SECP256K1_API const secp256k1_context *secp256k1_context_no_precomp
< SECP256K1_DEPRECATED("Use secp256k1_context_static instead");
-286,289d282
-< SECP256K1_API secp256k1_context *secp256k1_context_create(
-< unsigned int flags
-< ) SECP256K1_WARN_UNUSED_RESULT;
-<
-302,305d294
-< SECP256K1_API secp256k1_context *secp256k1_context_clone(
-< const secp256k1_context *ctx
-< ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
-<
-320,323d308
-< SECP256K1_API void secp256k1_context_destroy(
-< secp256k1_context *ctx
-< ) SECP256K1_ARG_NONNULL(1);
-<
-402,406d386
-< SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_scratch_space_create(
-< const secp256k1_context *ctx,
-< size_t size
-< ) SECP256K1_ARG_NONNULL(1);
-<
-413,417d392
-< SECP256K1_API void secp256k1_scratch_space_destroy(
-< const secp256k1_context *ctx,
-< secp256k1_scratch_space *scratch
-< ) SECP256K1_ARG_NONNULL(1);
-<
636d610
< SECP256K1_API const secp256k1_nonce_function secp256k1_nonce_function_rfc6979;
639d612
diff --git a/secp256k1-sys/depend/secp256k1/contrib/lax_der_parsing.c b/secp256k1-sys/depend/secp256k1/contrib/lax_der_parsing.c
@@ -7,9 +7,7 @@
#include <string.h>
#include "lax_der_parsing.h"
-extern int haskellsecp256k1_v0_1_0_ecdsa_signature_parse_compact(
- const haskellsecp256k1_v0_1_0_context *ctx,
- haskellsecp256k1_v0_1_0_ecdsa_signature *sig, const unsigned char *input64);
+
int haskellsecp256k1_v0_1_0_ecdsa_signature_parse_der_lax(const haskellsecp256k1_v0_1_0_context* ctx, haskellsecp256k1_v0_1_0_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
size_t rpos, rlen, spos, slen;
size_t pos = 0;
diff --git a/secp256k1-sys/depend/secp256k1/include/secp256k1.h b/secp256k1-sys/depend/secp256k1/include/secp256k1.h
@@ -233,11 +233,8 @@ typedef int (*haskellsecp256k1_v0_1_0_nonce_function)(
*
* It is highly recommended to call haskellsecp256k1_v0_1_0_selftest before using this context.
*/
-SECP256K1_API const haskellsecp256k1_v0_1_0_context *haskellsecp256k1_v0_1_0_context_static;
/** Deprecated alias for haskellsecp256k1_v0_1_0_context_static. */
-SECP256K1_API const haskellsecp256k1_v0_1_0_context *haskellsecp256k1_v0_1_0_context_no_precomp
-SECP256K1_DEPRECATED("Use haskellsecp256k1_v0_1_0_context_static instead");
/** Perform basic self tests (to be used in conjunction with haskellsecp256k1_v0_1_0_context_static)
*
@@ -633,10 +630,8 @@ SECP256K1_API int haskellsecp256k1_v0_1_0_ecdsa_signature_normalize(
* If a data pointer is passed, it is assumed to be a pointer to 32 bytes of
* extra entropy.
*/
-SECP256K1_API const haskellsecp256k1_v0_1_0_nonce_function haskellsecp256k1_v0_1_0_nonce_function_rfc6979;
/** A default safe nonce generation function (currently equal to haskellsecp256k1_v0_1_0_nonce_function_rfc6979). */
-SECP256K1_API const haskellsecp256k1_v0_1_0_nonce_function haskellsecp256k1_v0_1_0_nonce_function_default;
/** Create an ECDSA signature.
*
diff --git a/secp256k1-sys/depend/util.h.patch b/secp256k1-sys/depend/util.h.patch
@@ -1,10 +0,0 @@
-148,152c148,150
-< void *ret = malloc(size);
-< if (ret == NULL) {
-< secp256k1_callback_call(cb, "Out of memory");
-< }
-< return ret;
----
-> (void) cb;
-> (void) size;
-> return NULL;
diff --git a/secp256k1-sys/secp256k1-sys.cabal b/secp256k1-sys/secp256k1-sys.cabal
@@ -24,21 +24,17 @@ library
, bytestring
include-dirs:
- depend/secp256k1/
- , depend/secp256k1/include/
- , depend/secp256k1/contrib/
- , depend/secp256k1/src/
+ depend/secp256k1/include/
c-sources:
- depend/secp256k1/contrib/lax_der_parsing.c
- , depend/secp256k1/src/precomputed_ecmult_gen.c
+ depend/secp256k1/src/precomputed_ecmult_gen.c
, depend/secp256k1/src/precomputed_ecmult.c
, depend/secp256k1/src/secp256k1.c
cc-options:
- -D "SECP256K1_API="
- -D "ENABLE_MODULE_ECDH=1"
- -D "ENABLE_MODULE_SCHNORRSIG=1"
- -D "ENABLE_MODULE_EXTRAKEYS=1"
- -D "ENABLE_MODULE_ELLSWIFT=1"
+ -DSECP256K1_API=
+ -DENABLE_MODULE_ECDH=1
+ -DENABLE_MODULE_SCHNORRSIG=1
+ -DENABLE_MODULE_EXTRAKEYS=1
+ -DENABLE_MODULE_ELLSWIFT=1
diff --git a/secp256k1-sys/vendor-libsecp.sh b/secp256k1-sys/vendor-libsecp.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
-# adapted from rust-secp256k1/secp256k1-sys/vendor-libsecp.sh
+# NB adapted from rust-secp256k1/secp256k1-sys/vendor-libsecp.sh
# Set default variables
if [ -z "$SECP_VENDOR_GIT_ROOT" ]; then
@@ -54,7 +54,7 @@ echo
# Check if we will do anything destructive.
if [ "$FORCE" == "no" ]; then
- if ! git diff --quiet -- "*.rs"; then
+ if ! git diff --quiet -- "*.hs"; then
echo "ERROR: There appear to be modified source files. Check these in or pass -f (some source files will be modified to have symbols renamed)."
exit 2
fi
@@ -94,15 +94,9 @@ echo "$SOURCE_REV" >> ./secp256k1-HEAD-revision.txt
# Patch source files
-# Remove all methods that use malloc.
-# To compensate, the secp_context_create and _destroy methods are redefined in Haskell.
-# patch "$DIR/include/secp256k1.h" "./secp256k1.h.patch"
-# patch "$DIR/src/secp256k1.c" "./secp256k1.c.patch"
-# patch "$DIR/src/scratch_impl.h" "./scratch_impl.h.patch"
-# patch "$DIR/src/util.h" "./util.h.patch"
+# XX patch out unused stuff that leads to duplicate object linking errors
-# Fix a linking error while cross-compiling to windowns with mingw
-patch "$DIR/contrib/lax_der_parsing.c" "./lax_der_parsing.c.patch"
+patch "$DIR/include/secp256k1.h" "./secp256k1.h.patch"
# Prefix all methods with haskellsecp and a version prefix
find "$DIR" \
@@ -123,10 +117,10 @@ cd "$SECP_SYS"
# # Update the `links = ` in the manifest file.
# sed -i -r "s/^links = \".*\"$/links = \"haskellsecp256k1_v${SECP_VENDOR_VERSION_CODE}\"/" Cargo.toml
# # Update the extern references in the Haskell FFI source files.
-# find "./lib/" \
-# -name "*.rs" \
-# -type f \
-# -print0 | xargs -0 sed -i -r "s/haskellsecp256k1_v[0-9]+_[0-9]+_[0-9]+_(.*)([\"\(])/haskellsecp256k1_v${SECP_VENDOR_VERSION_CODE}_\1\2/g"
-#
-# popd > /dev/null
+find "./lib/" \
+ -name "*.hs" \
+ -type f \
+ -print0 | xargs -0 sed -i -r "s/haskellsecp256k1_v[0-9]+_[0-9]+_[0-9]+_(.*)([\"\(])/haskellsecp256k1_v${SECP_VENDOR_VERSION_CODE}_\1\2/g"
+
+popd > /dev/null