Skip to content

Commit

Permalink
Update bitcoin/secp256k1
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Dec 19, 2024
1 parent 4dcf9e8 commit 69431fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $(LIBSECP256K1): c_src/secp256k1/Makefile
c_src/secp256k1/Makefile:
-rm -rf c_src/secp256k1
cd c_src && git clone https://github.com/bitcoin/secp256k1
cd c_src/secp256k1 && git reset --hard d33352151699bd7598b868369dace092f7855740 && ./autogen.sh && ./configure --enable-module-recovery --with-bignum=no $(HOSTFLAG)
cd c_src/secp256k1 && git reset --hard f79f46c70386c693ff4e7aef0b9e7923ba284e56 && ./autogen.sh && ./configure --enable-module-recovery $(HOSTFLAG)

test:
$(MIX) eunit
Expand Down
28 changes: 18 additions & 10 deletions c_src/libsecp256k1_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@

#include "erl_nif.h"

#include "libsecp256k1-config.h"
#include "secp256k1.c"
#include <time.h>

#include "include/secp256k1.h"
#include "testrand_impl.h"
#include "include/secp256k1_recovery.h"

#include "util.h"
#include "int128_impl.h"
#include "hash_impl.h"
#include "field_impl.h"
#include "group_impl.h"
#include "scalar_impl.h"
#include "testrand_impl.h"


// Key export
#include "contrib/lax_der_parsing.c"
#include "contrib/lax_der_privatekey_parsing.c"
Expand Down Expand Up @@ -131,7 +139,7 @@ rand32(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ERL_NIF_TERM r;
unsigned char* output = enif_make_new_binary(env, 4, &r);
uint32_t v = secp256k1_rand32();
uint32_t v = testrand32();
memcpy(&v, output, 4);
return r;
}
Expand All @@ -141,7 +149,7 @@ rand256(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ERL_NIF_TERM r;
unsigned char* output = enif_make_new_binary(env, 32, &r);
secp256k1_rand256(output);
testrand256(output);
return r;
}

Expand Down Expand Up @@ -342,7 +350,7 @@ ec_privkey_tweak_add(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
privkey_buf = enif_make_new_binary(env, 32, &r);
memcpy(privkey_buf, privkey.data, privkey.size);

result = secp256k1_ec_privkey_tweak_add(ctx, privkey_buf, tweak.data);
result = secp256k1_ec_seckey_tweak_add(ctx, privkey_buf, tweak.data);

if (result == 0) {
return error_result(env, "ec_privkey_tweak_add returned 0");
Expand Down Expand Up @@ -411,7 +419,7 @@ ec_privkey_tweak_mul(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
privkey_buf = enif_make_new_binary(env, 32, &r);
memcpy(privkey_buf, privkey.data, privkey.size);

result = secp256k1_ec_privkey_tweak_mul(ctx, privkey_buf, tweak.data);
result = secp256k1_ec_seckey_tweak_mul(ctx, privkey_buf, tweak.data);

if (result == 0) {
return error_result(env, "ec_privkey_tweak_mul returned 0");
Expand Down Expand Up @@ -491,10 +499,10 @@ ecdsa_sign(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])

// DER serialization may return a signature under buffer size
// need to delay nif binary allocation
if (secp256k1_ecdsa_signature_serialize_der(ctx, &intermediatesig, &siglen, &signature) != 1) {
if (secp256k1_ecdsa_signature_serialize_der(ctx, &intermediatesig[0], &siglen, &signature) != 1) {
return error_result(env, "ecdsa_signature_serialize returned 0");
}
CHECK(secp256k1_ecdsa_signature_parse_der(ctx, &signature, &intermediatesig, siglen) == 1);
CHECK(secp256k1_ecdsa_signature_parse_der(ctx, &signature, &intermediatesig[0], siglen) == 1);
finishedsig = enif_make_new_binary(env, siglen, &r);
memcpy(finishedsig, intermediatesig, siglen);
return ok_result(env, &r);
Expand Down Expand Up @@ -733,7 +741,7 @@ int get_nonce_function(ErlNifEnv* env, ERL_NIF_TERM nonce_term, ERL_NIF_TERM non
noncedata->size = 0;
return 1;
} else if (strcmp(nonce_atom, "nonce_function_rfc6979") == 0) {
*noncefp = nonce_function_rfc6979;
*noncefp = secp256k1_nonce_function_rfc6979;

if (!enif_inspect_binary(env, nonce_data_term, noncedata)) {
return 0;
Expand Down

0 comments on commit 69431fd

Please sign in to comment.