generator: Port bitcoin-core/secp256k1#1779 to zkp-specific code
This commit is contained in:
@@ -343,6 +343,9 @@ int secp256k1_pedersen_blind_sum(const secp256k1_context* ctx, unsigned char *bl
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(blind_out != NULL);
|
||||
ARG_CHECK(blinds != NULL);
|
||||
for (i = 0; i < n; i++) {
|
||||
ARG_CHECK(blinds[i] != NULL);
|
||||
}
|
||||
ARG_CHECK(npositive <= n);
|
||||
(void) ctx;
|
||||
secp256k1_scalar_set_int(&acc, 0);
|
||||
@@ -370,6 +373,12 @@ int secp256k1_pedersen_verify_tally(const secp256k1_context* ctx, const secp256k
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(!pcnt || (commits != NULL));
|
||||
ARG_CHECK(!ncnt || (ncommits != NULL));
|
||||
for (i = 0; i < pcnt; i++) {
|
||||
ARG_CHECK(commits[i] != NULL);
|
||||
}
|
||||
for (i = 0; i < ncnt; i++) {
|
||||
ARG_CHECK(ncommits[i] != NULL);
|
||||
}
|
||||
(void) ctx;
|
||||
secp256k1_gej_set_infinity(&accj);
|
||||
for (i = 0; i < ncnt; i++) {
|
||||
@@ -394,6 +403,10 @@ int secp256k1_pedersen_blind_generator_blind_sum(const secp256k1_context* ctx, c
|
||||
ARG_CHECK(n_total == 0 || generator_blind != NULL);
|
||||
ARG_CHECK(n_total == 0 || blinding_factor != NULL);
|
||||
ARG_CHECK(n_total > n_inputs);
|
||||
for (i = 0; i < n_total; i++) {
|
||||
ARG_CHECK(generator_blind[i] != NULL);
|
||||
ARG_CHECK(blinding_factor[i] != NULL);
|
||||
}
|
||||
(void) ctx;
|
||||
|
||||
if (n_total == 0) {
|
||||
|
||||
@@ -227,6 +227,13 @@ static void test_pedersen_api(void) {
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_blind_generator_blind_sum(CTX, NULL, &blind_ptr, &blind_out_ptr, 1, 0));
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_blind_generator_blind_sum(CTX, &val, NULL, &blind_out_ptr, 1, 0));
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, NULL, 1, 0));
|
||||
/* check that NULL in array of generator_blind pointers is not allowed */
|
||||
blind_ptr = NULL;
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, &blind_out_ptr, 1, 0));
|
||||
blind_ptr = blind;
|
||||
/* check that NULL in array of blinding_factor pointers is not allowed */
|
||||
blind_out_ptr = NULL;
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, &blind_out_ptr, 1, 0));
|
||||
}
|
||||
|
||||
static void test_pedersen_internal(void) {
|
||||
@@ -264,6 +271,14 @@ static void test_pedersen_internal(void) {
|
||||
secp256k1_scalar_get_b32(&blinds[i * 32], &s);
|
||||
}
|
||||
CHECK(secp256k1_pedersen_blind_sum(CTX, &blinds[(total - 1) * 32], bptr, total - 1, inputs));
|
||||
/* check that NULL in array of blind pointers is not allowed */
|
||||
for (i = 0; i < total - 1; i++) {
|
||||
unsigned char blind_out[32];
|
||||
const unsigned char *original_ptr = bptr[i];
|
||||
bptr[i] = NULL;
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_blind_sum(CTX, blind_out, bptr, total - 1, inputs));
|
||||
bptr[i] = original_ptr;
|
||||
}
|
||||
for (i = 0; i < total; i++) {
|
||||
unsigned char result[33];
|
||||
secp256k1_pedersen_commitment parse;
|
||||
@@ -275,6 +290,20 @@ static void test_pedersen_internal(void) {
|
||||
}
|
||||
CHECK(secp256k1_pedersen_verify_tally(CTX, cptr, inputs, &cptr[inputs], outputs));
|
||||
CHECK(secp256k1_pedersen_verify_tally(CTX, &cptr[inputs], outputs, cptr, inputs));
|
||||
/* check that NULL in array of commits pointers is not allowed */
|
||||
for (i = 0; i < inputs; i++) {
|
||||
const secp256k1_pedersen_commitment *original_ptr = cptr[i];
|
||||
cptr[i] = NULL;
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_verify_tally(CTX, cptr, inputs, &cptr[inputs], outputs));
|
||||
cptr[i] = original_ptr;
|
||||
}
|
||||
/* check that NULL in array of ncommits pointers is not allowed */
|
||||
for (i = 0; i < outputs; i++) {
|
||||
const secp256k1_pedersen_commitment *original_ptr = cptr[inputs + i];
|
||||
cptr[inputs + i] = NULL;
|
||||
CHECK_ILLEGAL(CTX, secp256k1_pedersen_verify_tally(CTX, cptr, inputs, &cptr[inputs], outputs));
|
||||
cptr[inputs + i] = original_ptr;
|
||||
}
|
||||
if (inputs > 0 && values[0] > 0) {
|
||||
CHECK(!secp256k1_pedersen_verify_tally(CTX, cptr, inputs - 1, &cptr[inputs], outputs));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user