Skip to content

Commit

Permalink
update c bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dsummers91 committed Feb 22, 2024
1 parent a198a33 commit ae55d6b
Show file tree
Hide file tree
Showing 26 changed files with 593 additions and 593 deletions.
30 changes: 15 additions & 15 deletions crypto/secp256k1/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.

// secp256k1_context_create_sign_verify creates a context for signing and signature verification.
static secp256k1_context* secp256k1_context_create_sign_verify() {
return secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
// secp256k1_context_createOP_sign_verify creates a context for signing and signature verification.
static secp256k1_context* secp256k1_context_createOP_sign_verify() {
return secp256k1_context_createOP(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
}

// secp256k1_ext_ecdsa_recover recovers the public key of an encoded compact signature.
Expand All @@ -21,17 +21,17 @@ static int secp256k1_ext_ecdsa_recover(
const unsigned char *sigdata,
const unsigned char *msgdata
) {
secp256k1_ecdsa_recoverable_signature sig;
secp256k1_ecdsa_recoverOPable_signature sig;
secp256k1_pubkey pubkey;

if (!secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &sig, sigdata, (int)sigdata[64])) {
if (!secp256k1_ecdsa_recoverOPable_signature_parse_compactOP(ctx, &sig, sigdata, (int)sigdata[64])) {
return 0;
}
if (!secp256k1_ecdsa_recover(ctx, &pubkey, &sig, msgdata)) {
if (!secp256k1_ecdsa_recoverOP(ctx, &pubkey, &sig, msgdata)) {
return 0;
}
size_t outputlen = 65;
return secp256k1_ec_pubkey_serialize(ctx, pubkey_out, &outputlen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
return secp256k1_ec_pubkey_serializeOP(ctx, pubkey_out, &outputlen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
}

// secp256k1_ext_ecdsa_verify verifies an encoded compact signature.
Expand All @@ -50,16 +50,16 @@ static int secp256k1_ext_ecdsa_verify(
const unsigned char *pubkeydata,
size_t pubkeylen
) {
secp256k1_ecdsa_signature sig;
secp256k1_ecdsa_signOPature sig;
secp256k1_pubkey pubkey;

if (!secp256k1_ecdsa_signature_parse_compact(ctx, &sig, sigdata)) {
if (!secp256k1_ecdsa_signOPature_parse_compactOP(ctx, &sig, sigdata)) {
return 0;
}
if (!secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, pubkeylen)) {
if (!secp256k1_ec_pubkey_parseOP(ctx, &pubkey, pubkeydata, pubkeylen)) {
return 0;
}
return secp256k1_ecdsa_verify(ctx, &sig, msgdata, &pubkey);
return secp256k1_ecdsa_verifyOP(ctx, &sig, msgdata, &pubkey);
}

// secp256k1_ext_reencode_pubkey decodes then encodes a public key. It can be used to
Expand All @@ -82,14 +82,14 @@ static int secp256k1_ext_reencode_pubkey(
) {
secp256k1_pubkey pubkey;

if (!secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeydata, pubkeylen)) {
if (!secp256k1_ec_pubkey_parseOP(ctx, &pubkey, pubkeydata, pubkeylen)) {
return 0;
}
unsigned int flag = (outlen == 33) ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED;
return secp256k1_ec_pubkey_serialize(ctx, out, &outlen, &pubkey, flag);
return secp256k1_ec_pubkey_serializeOP(ctx, out, &outlen, &pubkey, flag);
}

// secp256k1_ext_scalar_mul multiplies a point by a scalar in constant time.
// secp256k1_ext_scalar_mulOP multiplies a point by a scalar in constant time.
//
// Returns: 1: multiplication was successful
// 0: scalar was invalid (zero or overflow)
Expand All @@ -98,7 +98,7 @@ static int secp256k1_ext_reencode_pubkey(
// In: point: pointer to a 64-byte public point,
// encoded as two 256bit big-endian numbers.
// scalar: a 32-byte scalar with which to multiply the point
int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point, const unsigned char *scalar) {
int secp256k1_ext_scalar_mulOP(const secp256k1_context* ctx, unsigned char *point, const unsigned char *scalar) {
int ret = 0;
int overflow = 0;
secp256k1_fe feX, feY;
Expand Down
8 changes: 4 additions & 4 deletions crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

#include "lax_der_parsing.h"

int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signOPature* sig, const unsigned char *input, size_t inputlen) {
size_t rpos, rlen, spos, slen;
size_t pos = 0;
size_t lenbyte;
unsigned char tmpsig[64] = {0};
int overflow = 0;

/* Hack to initialize sig with a correctly-parsed but invalid signature. */
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
secp256k1_ecdsa_signOPature_parse_compactOP(ctx, sig, tmpsig);

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

if (!overflow) {
overflow = !secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
overflow = !secp256k1_ecdsa_signOPature_parse_compactOP(ctx, sig, tmpsig);
}
if (overflow) {
memset(tmpsig, 0, 64);
secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig);
secp256k1_ecdsa_signOPature_parse_compactOP(ctx, sig, tmpsig);
}
return 1;
}
Expand Down
6 changes: 3 additions & 3 deletions crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* certain violations are easily supported. You may need to adapt it.
*
* Do not use this for new systems. Use well-defined DER or compact signatures
* instead if you have the choice (see secp256k1_ecdsa_signature_parse_der and
* secp256k1_ecdsa_signature_parse_compact).
* instead if you have the choice (see secp256k1_ecdsa_signOPature_parse_derOP and
* secp256k1_ecdsa_signOPature_parse_compactOP).
*
* The supported violations are:
* - All numbers are parsed as nonnegative integers, even though X.609-0207
Expand Down Expand Up @@ -79,7 +79,7 @@ extern "C" {
*/
int ecdsa_signature_parse_der_lax(
const secp256k1_context* ctx,
secp256k1_ecdsa_signature* sig,
secp256k1_ecdsa_signOPature* sig,
const unsigned char *input,
size_t inputlen
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, co
return 0;
}
memcpy(out32 + 32 - privkey[1], privkey + 2, privkey[1]);
if (!secp256k1_ec_seckey_verify(ctx, out32)) {
if (!secp256k1_ec_seckey_verifyOP(ctx, out32)) {
memset(out32, 0, 32);
return 0;
}
Expand All @@ -56,7 +56,7 @@ int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, co
int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
secp256k1_pubkey pubkey;
size_t pubkeylen = 0;
if (!secp256k1_ec_pubkey_create(ctx, &pubkey, key32)) {
if (!secp256k1_ec_pubkey_createOP(ctx, &pubkey, key32)) {
*privkeylen = 0;
return 0;
}
Expand All @@ -80,7 +80,7 @@ int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey,
memcpy(ptr, key32, 32); ptr += 32;
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
pubkeylen = 33;
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
secp256k1_ec_pubkey_serializeOP(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED);
ptr += pubkeylen;
*privkeylen = ptr - privkey;
} else {
Expand All @@ -105,7 +105,7 @@ int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey,
memcpy(ptr, key32, 32); ptr += 32;
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
pubkeylen = 65;
secp256k1_ec_pubkey_serialize(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
secp256k1_ec_pubkey_serializeOP(ctx, ptr, &pubkeylen, &pubkey, SECP256K1_EC_UNCOMPRESSED);
ptr += pubkeylen;
*privkeylen = ptr - privkey;
}
Expand Down
Loading

0 comments on commit ae55d6b

Please sign in to comment.