frost_enrollment: add reduced enrollment protocol
This commit is contained in:
1 parent
4690e742ab
commit
49272f1b2f
4 files changed
+459
-22
No files matched your search
@@ -28,6 +28,14 @@ extern "C" {
|
||||
* parameter serialization used here are this module's own, frozen by the
|
||||
* regression vectors in src/modules/frost_enrollment/vectors.h.
|
||||
*
|
||||
* The `reduced_` entry points implement the reduced enrollment RTS of Section
|
||||
* 4.1.3 of the same survey, as discussed in
|
||||
* https://gist.github.com/nickfarrow/64c2e65191cde6a1a47bbd4572bf8cf8.
|
||||
* They are a separately versioned protocol: they bind a session identifier,
|
||||
* use different tagged-hash domains, exchange a triangular rather than a full
|
||||
* share matrix, and require every target-side verification check. The two
|
||||
* protocols must not be mixed within a run.
|
||||
*
|
||||
* Identifiers follow the frost module: participants are identified by uint32
|
||||
* values 0..n-1, and participant id i sits at polynomial x-coordinate i+1.
|
||||
* The party receiving a share is identified by `new_id`, which selects the
|
||||
@@ -400,6 +408,134 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_secsha
|
||||
const secp256k1_pubkey *expected_pubshare
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);
|
||||
|
||||
/** Compute the version 2 reduced-enrollment parameters hash.
|
||||
*
|
||||
* The hash commits to the reduced-protocol domain, threshold public key,
|
||||
* n_participants, threshold, new_id, the sorted helper set and session_id32.
|
||||
* It is incompatible with secp256k1_frost_enrollment_params_hash by design.
|
||||
*
|
||||
* session_id32 must identify exactly one enrollment or repair request. It
|
||||
* should be generated freshly by the target and authenticated by every helper
|
||||
* as part of its authorization decision. It need not be secret.
|
||||
*
|
||||
* The parameter ranges and output behavior are the same as for
|
||||
* secp256k1_frost_enrollment_params_hash.
|
||||
*/
|
||||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_reduced_params_hash(
|
||||
const secp256k1_context *ctx,
|
||||
unsigned char *out32,
|
||||
const secp256k1_pubkey *thresh_pk,
|
||||
const uint32_t *ids,
|
||||
size_t n_ids,
|
||||
uint32_t new_id,
|
||||
size_t n_participants,
|
||||
uint32_t threshold,
|
||||
const unsigned char *session_id32
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(9);
|
||||
|
||||
/** Round 1.1 of reduced enrollment: generate a helper's triangular share row.
|
||||
*
|
||||
* The weighted share v = lambda_my_id(x_new)*secshare is split using the
|
||||
* Section 4.1.3 triangular matrix. Numerically sorting the helper identifiers
|
||||
* defines the protocol rank, independently of the order of `ids`:
|
||||
*
|
||||
* - for every helper with a larger identifier, the corresponding output
|
||||
* entry is a masking share to send to that helper;
|
||||
* - the entry at my_id's position is the locally retained remainder;
|
||||
* - every entry for a smaller identifier is zero and has no message.
|
||||
*
|
||||
* Thus a run with u helpers sends only u*(u-1)/2 helper-to-helper deltas,
|
||||
* rather than the full protocol's u*(u-1). Arrays remain aligned with `ids`
|
||||
* and shares32_out remains u*32 bytes. Routing is determined by identifiers,
|
||||
* never by testing whether an entry is zero.
|
||||
*
|
||||
* Send every larger-identifier entry with params_hash32_out, my_id and the
|
||||
* recipient identifier over a confidential and authenticated channel. Keep
|
||||
* the entry at my_id's position for reduced_share_agg.
|
||||
*
|
||||
* session_secrand32 must be fresh uniform randomness and is wiped on every
|
||||
* path that enters the function body. All other randomness, validation,
|
||||
* domain-separation and failure-output rules match shares_gen, except that
|
||||
* the reduced tags also bind session_id32.
|
||||
*/
|
||||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_reduced_shares_gen(
|
||||
const secp256k1_context *ctx,
|
||||
unsigned char *shares32_out,
|
||||
unsigned char *params_hash32_out,
|
||||
unsigned char *session_secrand32,
|
||||
const unsigned char *secshare32,
|
||||
const secp256k1_pubkey *thresh_pk,
|
||||
const uint32_t *ids,
|
||||
size_t n_ids,
|
||||
uint32_t my_id,
|
||||
uint32_t new_id,
|
||||
size_t n_participants,
|
||||
uint32_t threshold,
|
||||
const unsigned char *session_id32
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(13);
|
||||
|
||||
/** Round 1.2 of reduced enrollment: aggregate one triangular matrix column.
|
||||
*
|
||||
* Helper my_id reads all_shares32 entries from itself and helpers with smaller
|
||||
* identifiers. Entries from larger helpers must be zero: there is no message
|
||||
* in those cells. received_params_hashes32 is read only for helpers with
|
||||
* smaller identifiers; the own slot and all larger-helper slots are ignored
|
||||
* and may be zero. Each read hash is compared with a freshly recomputed hash.
|
||||
*
|
||||
* On success, send sigma32_out, the recomputed parameters hash and my_id to
|
||||
* the target over a confidential and authenticated channel. mismatch_id has
|
||||
* the same meaning as in the full protocol, including attribution for a
|
||||
* nonzero structurally omitted share.
|
||||
*/
|
||||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_reduced_share_agg(
|
||||
const secp256k1_context *ctx,
|
||||
unsigned char *sigma32_out,
|
||||
uint32_t *mismatch_id,
|
||||
const unsigned char *all_shares32,
|
||||
const unsigned char *received_params_hashes32,
|
||||
const secp256k1_pubkey *thresh_pk,
|
||||
const uint32_t *ids,
|
||||
size_t n_ids,
|
||||
uint32_t my_id,
|
||||
uint32_t new_id,
|
||||
size_t n_participants,
|
||||
uint32_t threshold,
|
||||
const unsigned char *session_id32
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(13);
|
||||
|
||||
/** Round 2 of reduced enrollment: derive and verify the target secret share.
|
||||
*
|
||||
* received_params_hashes32 is u*32 bytes aligned with `ids`; every entry must
|
||||
* equal the hash recomputed from thresh_pk, the parameter tuple and
|
||||
* session_id32. sigmas32 is the corresponding array of u secret values. The
|
||||
* caller must have established exactly one sigma from every expected helper.
|
||||
*
|
||||
* expected_pubshare is REQUIRED and must come from authenticated group data,
|
||||
* either through secp256k1_frost_enrollment_pubshare_derive or through an
|
||||
* authenticated commitment polynomial. The function succeeds only if the sum
|
||||
* of the sigmas is a nonzero scalar whose public key equals
|
||||
* expected_pubshare. It requires a signing-capable context and wipes
|
||||
* secshare32_out on failure.
|
||||
*
|
||||
* thresh_pk and the data used to derive expected_pubshare MUST be
|
||||
* authenticated independently of the helpers' enrollment messages. Otherwise
|
||||
* colluding helpers can provide a consistent fabricated polynomial.
|
||||
*/
|
||||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_reduced_secshare_gen(
|
||||
const secp256k1_context *ctx,
|
||||
unsigned char *secshare32_out,
|
||||
const unsigned char *sigmas32,
|
||||
const unsigned char *received_params_hashes32,
|
||||
const secp256k1_pubkey *thresh_pk,
|
||||
const uint32_t *ids,
|
||||
size_t n_ids,
|
||||
uint32_t new_id,
|
||||
size_t n_participants,
|
||||
uint32_t threshold,
|
||||
const unsigned char *session_id32,
|
||||
const secp256k1_pubkey *expected_pubshare
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(11) SECP256K1_ARG_NONNULL(12);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,15 @@ static void secp256k1_frost_enrollment_sha256_tagged_share_split(const secp256k1
|
||||
secp256k1_sha256_initialize_tagged(hash_ctx, sha, (const unsigned char *)"FROST enrollment/share_split", sizeof("FROST enrollment/share_split") - 1);
|
||||
}
|
||||
|
||||
/* Checks the parameter tuple shared by all five entry points. Ids must be
|
||||
static void secp256k1_frost_enrollment_sha256_tagged_reduced_params_hash(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *sha) {
|
||||
secp256k1_sha256_initialize_tagged(hash_ctx, sha, (const unsigned char *)"FROST enrollment/reduced/params_hash", sizeof("FROST enrollment/reduced/params_hash") - 1);
|
||||
}
|
||||
|
||||
static void secp256k1_frost_enrollment_sha256_tagged_reduced_share_split(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *sha) {
|
||||
secp256k1_sha256_initialize_tagged(hash_ctx, sha, (const unsigned char *)"FROST enrollment/reduced/share_split", sizeof("FROST enrollment/reduced/share_split") - 1);
|
||||
}
|
||||
|
||||
/* Checks the parameter tuple shared by the enrollment entry points. Ids must be
|
||||
* unique, in range and distinct from new_id; the helper count must lie between
|
||||
* the threshold and the participant count; and new_id must select exactly one
|
||||
* of the two modes:
|
||||
@@ -175,6 +183,49 @@ static int secp256k1_frost_enrollment_params_hash_checked(const secp256k1_contex
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void secp256k1_frost_enrollment_reduced_params_hash_internal(const secp256k1_hash_ctx *hash_ctx, unsigned char *out32, secp256k1_ge *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold, const unsigned char *session_id32) {
|
||||
uint32_t sorted_ids[SECP256K1_FROST_MAX_PARTICIPANTS];
|
||||
unsigned char thresh_pk33[33];
|
||||
unsigned char buf[4];
|
||||
secp256k1_sha256 sha;
|
||||
size_t i;
|
||||
|
||||
VERIFY_CHECK(n_ids <= SECP256K1_FROST_MAX_PARTICIPANTS);
|
||||
|
||||
secp256k1_eckey_pubkey_serialize33(thresh_pk, thresh_pk33);
|
||||
secp256k1_frost_enrollment_sha256_tagged_reduced_params_hash(hash_ctx, &sha);
|
||||
secp256k1_sha256_write(hash_ctx, &sha, thresh_pk33, sizeof(thresh_pk33));
|
||||
secp256k1_write_be32(buf, (uint32_t)n_participants);
|
||||
secp256k1_sha256_write(hash_ctx, &sha, buf, sizeof(buf));
|
||||
secp256k1_write_be32(buf, threshold);
|
||||
secp256k1_sha256_write(hash_ctx, &sha, buf, sizeof(buf));
|
||||
secp256k1_write_be32(buf, new_id);
|
||||
secp256k1_sha256_write(hash_ctx, &sha, buf, sizeof(buf));
|
||||
secp256k1_write_be32(buf, (uint32_t)n_ids);
|
||||
secp256k1_sha256_write(hash_ctx, &sha, buf, sizeof(buf));
|
||||
secp256k1_frost_sort_ids(sorted_ids, ids, n_ids);
|
||||
for (i = 0; i < n_ids; i++) {
|
||||
secp256k1_write_be32(buf, sorted_ids[i]);
|
||||
secp256k1_sha256_write(hash_ctx, &sha, buf, sizeof(buf));
|
||||
}
|
||||
secp256k1_sha256_write(hash_ctx, &sha, session_id32, 32);
|
||||
secp256k1_sha256_finalize(hash_ctx, &sha, out32);
|
||||
secp256k1_sha256_clear(&sha);
|
||||
}
|
||||
|
||||
static int secp256k1_frost_enrollment_reduced_params_hash_checked(const secp256k1_context *ctx, unsigned char *out32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold, const unsigned char *session_id32) {
|
||||
secp256k1_ge pk;
|
||||
|
||||
if (!secp256k1_frost_enrollment_params_are_valid(ids, n_ids, new_id, n_participants, threshold)) {
|
||||
return 0;
|
||||
}
|
||||
if (!secp256k1_pubkey_load(ctx, &pk, thresh_pk)) {
|
||||
return 0;
|
||||
}
|
||||
secp256k1_frost_enrollment_reduced_params_hash_internal(secp256k1_get_hash_context(ctx), out32, &pk, ids, n_ids, new_id, n_participants, threshold, session_id32);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Computes the Lagrange basis polynomial of my_id over the helper set,
|
||||
* evaluated at the target identifier:
|
||||
*
|
||||
@@ -225,10 +276,12 @@ static void secp256k1_frost_enrollment_lagrange_at(secp256k1_scalar *out, const
|
||||
/* Derives one masking share as
|
||||
*
|
||||
* Scalar.from_bytes_wrapping(
|
||||
* TH("FROST enrollment/share_split",
|
||||
* TH(protocol_share_split_tag,
|
||||
* rand32 || params_hash32 || ser32(my_id) || ser32(recipient_id)))
|
||||
*
|
||||
* where rand32 is the session randomness masked with the secret share.
|
||||
* where rand32 is the session randomness masked with the secret share. Full
|
||||
* and reduced enrollment use separate tags; the reduced parameters hash also
|
||||
* binds the caller's session identifier.
|
||||
*
|
||||
* The reduction wraps rather than rejects, following chilldkg's
|
||||
* from_bytes_wrapping (src/modules/chilldkg/util_impl.h:394): the statistical
|
||||
@@ -239,12 +292,16 @@ static void secp256k1_frost_enrollment_lagrange_at(secp256k1_scalar *out, const
|
||||
* caller's ids array, so the split does not depend on the order a caller
|
||||
* happens to list the helper set in. Identifiers are unique, so this is
|
||||
* injective, which is all a counter had to be. */
|
||||
static void secp256k1_frost_enrollment_derive_mask(const secp256k1_hash_ctx *hash_ctx, secp256k1_scalar *out, const unsigned char *rand32, const unsigned char *params_hash32, uint32_t my_id, uint32_t recipient_id) {
|
||||
static void secp256k1_frost_enrollment_derive_mask(const secp256k1_hash_ctx *hash_ctx, secp256k1_scalar *out, const unsigned char *rand32, const unsigned char *params_hash32, uint32_t my_id, uint32_t recipient_id, int reduced) {
|
||||
unsigned char buf[4];
|
||||
unsigned char hash32[32];
|
||||
secp256k1_sha256 sha;
|
||||
|
||||
secp256k1_frost_enrollment_sha256_tagged_share_split(hash_ctx, &sha);
|
||||
if (reduced) {
|
||||
secp256k1_frost_enrollment_sha256_tagged_reduced_share_split(hash_ctx, &sha);
|
||||
} else {
|
||||
secp256k1_frost_enrollment_sha256_tagged_share_split(hash_ctx, &sha);
|
||||
}
|
||||
secp256k1_sha256_write(hash_ctx, &sha, rand32, 32);
|
||||
secp256k1_sha256_write(hash_ctx, &sha, params_hash32, 32);
|
||||
secp256k1_write_be32(buf, my_id);
|
||||
@@ -274,7 +331,17 @@ int secp256k1_frost_enrollment_params_hash(const secp256k1_context *ctx, unsigne
|
||||
return secp256k1_frost_enrollment_params_hash_checked(ctx, out32, thresh_pk, ids, n_ids, new_id, n_participants, threshold);
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_shares_gen(const secp256k1_context *ctx, unsigned char *shares32_out, unsigned char *params_hash32_out, unsigned char *session_secrand32, const unsigned char *secshare32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
int secp256k1_frost_enrollment_reduced_params_hash(const secp256k1_context *ctx, unsigned char *out32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold, const unsigned char *session_id32) {
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(out32 != NULL);
|
||||
memset(out32, 0, 32);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
ARG_CHECK(session_id32 != NULL);
|
||||
return secp256k1_frost_enrollment_reduced_params_hash_checked(ctx, out32, thresh_pk, ids, n_ids, new_id, n_participants, threshold, session_id32);
|
||||
}
|
||||
|
||||
static int secp256k1_frost_enrollment_shares_gen_internal(const secp256k1_context *ctx, unsigned char *shares32_out, unsigned char *params_hash32_out, unsigned char *session_secrand32, const unsigned char *secshare32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold, int reduced, const unsigned char *session_id32) {
|
||||
const secp256k1_hash_ctx *hash_ctx;
|
||||
secp256k1_scalar secshare, lambda, v, mask;
|
||||
secp256k1_sha256 sha;
|
||||
@@ -290,6 +357,7 @@ int secp256k1_frost_enrollment_shares_gen(const secp256k1_context *ctx, unsigned
|
||||
ARG_CHECK(secshare32 != NULL);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
ARG_CHECK(!reduced || session_id32 != NULL);
|
||||
|
||||
/* Validate BEFORE touching shares32_out, which is the only output in this
|
||||
* module whose size is caller-supplied. A caller that passes a fixed
|
||||
@@ -312,10 +380,16 @@ int secp256k1_frost_enrollment_shares_gen(const secp256k1_context *ctx, unsigned
|
||||
hash_ctx = secp256k1_get_hash_context(ctx);
|
||||
memset(rand32, 0, sizeof(rand32));
|
||||
|
||||
/* Re-validates, which is cheap and keeps this the single place the hash
|
||||
* encoding is produced. */
|
||||
if (!secp256k1_frost_enrollment_params_hash_checked(ctx, params_hash32_out, thresh_pk, ids, n_ids, new_id, n_participants, threshold)) {
|
||||
goto cleanup;
|
||||
/* Re-validates, which is cheap and selects the appropriate full or reduced
|
||||
* hash encoding. */
|
||||
if (reduced) {
|
||||
if (!secp256k1_frost_enrollment_reduced_params_hash_checked(ctx, params_hash32_out, thresh_pk, ids, n_ids, new_id, n_participants, threshold, session_id32)) {
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
if (!secp256k1_frost_enrollment_params_hash_checked(ctx, params_hash32_out, thresh_pk, ids, n_ids, new_id, n_participants, threshold)) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
my_pos = secp256k1_frost_enrollment_id_pos(ids, n_ids, my_id);
|
||||
if (my_pos == n_ids) {
|
||||
@@ -339,7 +413,11 @@ int secp256k1_frost_enrollment_shares_gen(const secp256k1_context *ctx, unsigned
|
||||
* secshare32. Masking the derived randomness with the secret share is the
|
||||
* secp256k1_frost_nonce_gen pattern (session_impl.h:340): it means a
|
||||
* broken random number generator alone does not reveal the split. */
|
||||
secp256k1_frost_enrollment_sha256_tagged_share_split(hash_ctx, &sha);
|
||||
if (reduced) {
|
||||
secp256k1_frost_enrollment_sha256_tagged_reduced_share_split(hash_ctx, &sha);
|
||||
} else {
|
||||
secp256k1_frost_enrollment_sha256_tagged_share_split(hash_ctx, &sha);
|
||||
}
|
||||
secp256k1_sha256_write(hash_ctx, &sha, session_secrand32, 32);
|
||||
secp256k1_sha256_finalize(hash_ctx, &sha, rand32);
|
||||
secp256k1_sha256_clear(&sha);
|
||||
@@ -347,14 +425,15 @@ int secp256k1_frost_enrollment_shares_gen(const secp256k1_context *ctx, unsigned
|
||||
rand32[i] ^= secshare32[i];
|
||||
}
|
||||
|
||||
/* Split v into n_ids additive shares. Every share but the one kept at
|
||||
* my_pos is masking randomness; the kept one absorbs the remainder, so the
|
||||
* whole set sums to v. */
|
||||
/* Split v into additive shares. In the full protocol every non-kept entry
|
||||
* is masking randomness. Reduced enrollment generates randomness only for
|
||||
* larger helper identifiers and leaves smaller-identifier entries zero.
|
||||
* The kept entry absorbs the remainder, so the whole row sums to v. */
|
||||
for (i = 0; i < n_ids; i++) {
|
||||
if (i == my_pos) {
|
||||
if (i == my_pos || (reduced && ids[i] < my_id)) {
|
||||
continue;
|
||||
}
|
||||
secp256k1_frost_enrollment_derive_mask(hash_ctx, &mask, rand32, params_hash32_out, my_id, ids[i]);
|
||||
secp256k1_frost_enrollment_derive_mask(hash_ctx, &mask, rand32, params_hash32_out, my_id, ids[i], reduced);
|
||||
secp256k1_scalar_get_b32(&shares32_out[32 * i], &mask);
|
||||
secp256k1_scalar_negate(&mask, &mask);
|
||||
secp256k1_scalar_add(&v, &v, &mask);
|
||||
@@ -378,7 +457,15 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_share_agg(const secp256k1_context *ctx, unsigned char *sigma32_out, uint32_t *mismatch_id, const unsigned char *all_shares32, const unsigned char *received_params_hashes32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
int secp256k1_frost_enrollment_shares_gen(const secp256k1_context *ctx, unsigned char *shares32_out, unsigned char *params_hash32_out, unsigned char *session_secrand32, const unsigned char *secshare32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
return secp256k1_frost_enrollment_shares_gen_internal(ctx, shares32_out, params_hash32_out, session_secrand32, secshare32, thresh_pk, ids, n_ids, my_id, new_id, n_participants, threshold, 0, NULL);
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_reduced_shares_gen(const secp256k1_context *ctx, unsigned char *shares32_out, unsigned char *params_hash32_out, unsigned char *session_secrand32, const unsigned char *secshare32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold, const unsigned char *session_id32) {
|
||||
return secp256k1_frost_enrollment_shares_gen_internal(ctx, shares32_out, params_hash32_out, session_secrand32, secshare32, thresh_pk, ids, n_ids, my_id, new_id, n_participants, threshold, 1, session_id32);
|
||||
}
|
||||
|
||||
static int secp256k1_frost_enrollment_share_agg_internal(const secp256k1_context *ctx, unsigned char *sigma32_out, uint32_t *mismatch_id, const unsigned char *all_shares32, const unsigned char *received_params_hashes32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold, int reduced, const unsigned char *session_id32) {
|
||||
secp256k1_scalar sigma, term;
|
||||
unsigned char params_hash32[32];
|
||||
size_t my_pos, i;
|
||||
@@ -394,6 +481,7 @@ int secp256k1_frost_enrollment_share_agg(const secp256k1_context *ctx, unsigned
|
||||
ARG_CHECK(received_params_hashes32 != NULL);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
ARG_CHECK(!reduced || session_id32 != NULL);
|
||||
|
||||
/* set_int, not scalar_clear: this accumulator is READ on the first add,
|
||||
* and secp256k1_memclear_explicit marks its target undefined in VERIFY
|
||||
@@ -405,8 +493,14 @@ int secp256k1_frost_enrollment_share_agg(const secp256k1_context *ctx, unsigned
|
||||
|
||||
/* The full parameter tuple is present here, so the mode and bounds are
|
||||
* re-validated rather than trusted from the round 1.1 call site. */
|
||||
if (!secp256k1_frost_enrollment_params_hash_checked(ctx, params_hash32, thresh_pk, ids, n_ids, new_id, n_participants, threshold)) {
|
||||
goto cleanup;
|
||||
if (reduced) {
|
||||
if (!secp256k1_frost_enrollment_reduced_params_hash_checked(ctx, params_hash32, thresh_pk, ids, n_ids, new_id, n_participants, threshold, session_id32)) {
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
if (!secp256k1_frost_enrollment_params_hash_checked(ctx, params_hash32, thresh_pk, ids, n_ids, new_id, n_participants, threshold)) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
my_pos = secp256k1_frost_enrollment_id_pos(ids, n_ids, my_id);
|
||||
if (my_pos == n_ids) {
|
||||
@@ -419,7 +513,7 @@ int secp256k1_frost_enrollment_share_agg(const secp256k1_context *ctx, unsigned
|
||||
* slot and launder a mismatch into a pass. Public data, so the
|
||||
* variable-time compare and the early exit are fine. */
|
||||
for (i = 0; i < n_ids; i++) {
|
||||
if (i == my_pos) {
|
||||
if (i == my_pos || (reduced && ids[i] > my_id)) {
|
||||
continue;
|
||||
}
|
||||
if (secp256k1_memcmp_var(&received_params_hashes32[32 * i], params_hash32, 32) != 0) {
|
||||
@@ -436,6 +530,15 @@ int secp256k1_frost_enrollment_share_agg(const secp256k1_context *ctx, unsigned
|
||||
* signature. */
|
||||
for (i = 0; i < n_ids; i++) {
|
||||
int overflow;
|
||||
if (reduced && ids[i] > my_id) {
|
||||
if (!secp256k1_is_zero_array(&all_shares32[32 * i], 32)) {
|
||||
if (mismatch_id != NULL) {
|
||||
*mismatch_id = ids[i];
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
secp256k1_scalar_set_b32(&term, &all_shares32[32 * i], &overflow);
|
||||
secp256k1_declassify(ctx, &overflow, sizeof(overflow));
|
||||
if (overflow) {
|
||||
@@ -459,6 +562,14 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_share_agg(const secp256k1_context *ctx, unsigned char *sigma32_out, uint32_t *mismatch_id, const unsigned char *all_shares32, const unsigned char *received_params_hashes32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
return secp256k1_frost_enrollment_share_agg_internal(ctx, sigma32_out, mismatch_id, all_shares32, received_params_hashes32, thresh_pk, ids, n_ids, my_id, new_id, n_participants, threshold, 0, NULL);
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_reduced_share_agg(const secp256k1_context *ctx, unsigned char *sigma32_out, uint32_t *mismatch_id, const unsigned char *all_shares32, const unsigned char *received_params_hashes32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold, const unsigned char *session_id32) {
|
||||
return secp256k1_frost_enrollment_share_agg_internal(ctx, sigma32_out, mismatch_id, all_shares32, received_params_hashes32, thresh_pk, ids, n_ids, my_id, new_id, n_participants, threshold, 1, session_id32);
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_pubshare_derive(const secp256k1_context *ctx, secp256k1_pubkey *new_pubshare_out, const secp256k1_pubkey *pubshares, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
secp256k1_ge points[SECP256K1_FROST_MAX_PARTICIPANTS];
|
||||
secp256k1_ge result;
|
||||
@@ -590,4 +701,83 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_reduced_secshare_gen(const secp256k1_context *ctx, unsigned char *secshare32_out, const unsigned char *sigmas32, const unsigned char *received_params_hashes32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold, const unsigned char *session_id32, const secp256k1_pubkey *expected_pubshare) {
|
||||
secp256k1_scalar secshare, term;
|
||||
unsigned char params_hash32[32];
|
||||
size_t i;
|
||||
int ret = 0;
|
||||
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(secshare32_out != NULL);
|
||||
memset(secshare32_out, 0, 32);
|
||||
ARG_CHECK(sigmas32 != NULL);
|
||||
ARG_CHECK(received_params_hashes32 != NULL);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
ARG_CHECK(session_id32 != NULL);
|
||||
ARG_CHECK(expected_pubshare != NULL);
|
||||
ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));
|
||||
|
||||
secp256k1_scalar_set_int(&secshare, 0);
|
||||
memset(params_hash32, 0, sizeof(params_hash32));
|
||||
|
||||
if (!secp256k1_frost_enrollment_reduced_params_hash_checked(ctx, params_hash32, thresh_pk, ids, n_ids, new_id, n_participants, threshold, session_id32)) {
|
||||
goto cleanup;
|
||||
}
|
||||
for (i = 0; i < n_ids; i++) {
|
||||
if (secp256k1_memcmp_var(&received_params_hashes32[32 * i], params_hash32, 32) != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < n_ids; i++) {
|
||||
int overflow;
|
||||
secp256k1_scalar_set_b32(&term, &sigmas32[32 * i], &overflow);
|
||||
secp256k1_declassify(ctx, &overflow, sizeof(overflow));
|
||||
if (overflow) {
|
||||
goto cleanup;
|
||||
}
|
||||
secp256k1_scalar_add(&secshare, &secshare, &term);
|
||||
}
|
||||
{
|
||||
int is_zero = secp256k1_scalar_is_zero(&secshare);
|
||||
secp256k1_declassify(ctx, &is_zero, sizeof(is_zero));
|
||||
if (is_zero) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
secp256k1_ge expected, derived;
|
||||
secp256k1_gej derivedj;
|
||||
int eq;
|
||||
|
||||
if (!secp256k1_pubkey_load(ctx, &expected, expected_pubshare)) {
|
||||
goto cleanup;
|
||||
}
|
||||
secp256k1_ecmult_gen_gej(&ctx->ecmult_gen_ctx, &derivedj, &secshare);
|
||||
secp256k1_ge_set_gej(&derived, &derivedj);
|
||||
VERIFY_CHECK(!secp256k1_ge_is_infinity(&derived));
|
||||
secp256k1_declassify(ctx, &derived, sizeof(derived));
|
||||
eq = secp256k1_ge_eq_var(&derived, &expected);
|
||||
secp256k1_ge_clear(&derived);
|
||||
secp256k1_gej_clear(&derivedj);
|
||||
if (!eq) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
secp256k1_scalar_get_b32(secshare32_out, &secshare);
|
||||
ret = 1;
|
||||
|
||||
cleanup:
|
||||
if (!ret) {
|
||||
secp256k1_memzero_explicit(secshare32_out, 32);
|
||||
}
|
||||
secp256k1_memclear_explicit(params_hash32, sizeof(params_hash32));
|
||||
secp256k1_scalar_clear(&secshare);
|
||||
secp256k1_scalar_clear(&term);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -104,8 +104,9 @@ parameters hash binds the reduced-protocol domain, threshold public key, n, t,
|
||||
new_id, sorted helper identifiers and session identifier. The share-splitting
|
||||
hash has a separate reduced-protocol domain and binds the same parameters hash
|
||||
as well as the sender and recipient identifiers. These version 2 tags and
|
||||
encodings deliberately replace the frozen version 1 encodings; there is no
|
||||
implicit wire compatibility between the full and reduced protocols.
|
||||
encodings are exposed through explicit `reduced_` entry points alongside the
|
||||
frozen version 1 API; there is no implicit wire compatibility between the full
|
||||
and reduced protocols.
|
||||
|
||||
Every transmitted delta or sigma is accompanied by its parameters hash and
|
||||
sender identifier; a delta also names its recipient. A recipient accepts only
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
typedef struct {
|
||||
size_t n, t, u;
|
||||
uint32_t new_id;
|
||||
unsigned char session_id[32];
|
||||
unsigned char thresh_sk[32];
|
||||
unsigned char secshares[SECP256K1_FROST_MAX_PARTICIPANTS][32];
|
||||
secp256k1_pubkey pubshares[SECP256K1_FROST_MAX_PARTICIPANTS];
|
||||
@@ -134,6 +135,59 @@ static void frost_enrollment_test_full_run(frost_enrollment_test_run *r, size_t
|
||||
frost_enrollment_test_round2(r);
|
||||
}
|
||||
|
||||
static void frost_enrollment_test_reduced_round1_gen(frost_enrollment_test_run *r) {
|
||||
size_t i;
|
||||
|
||||
testrand256(r->session_id);
|
||||
for (i = 0; i < r->u; i++) {
|
||||
unsigned char secrand[32];
|
||||
testrand256(secrand);
|
||||
CHECK(secp256k1_frost_enrollment_reduced_shares_gen(CTX, r->shares[i], r->params_hashes[i], secrand, r->secshares[r->ids[i]], &r->thresh_pk, r->ids, r->u, r->ids[i], r->new_id, r->n, (uint32_t)r->t, r->session_id) == 1);
|
||||
CHECK(secp256k1_is_zero_array(secrand, sizeof(secrand)));
|
||||
}
|
||||
}
|
||||
|
||||
static void frost_enrollment_test_reduced_collect(const frost_enrollment_test_run *r, size_t j, unsigned char *all_shares, unsigned char *received) {
|
||||
size_t i;
|
||||
|
||||
memset(received, 0, r->u * 32);
|
||||
for (i = 0; i < r->u; i++) {
|
||||
memcpy(&all_shares[32 * i], &r->shares[i][32 * j], 32);
|
||||
if (r->ids[i] < r->ids[j]) {
|
||||
memcpy(&received[32 * i], r->params_hashes[i], 32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void frost_enrollment_test_reduced_round1_agg(frost_enrollment_test_run *r) {
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < r->u; j++) {
|
||||
unsigned char all_shares[SECP256K1_FROST_MAX_PARTICIPANTS * 32];
|
||||
unsigned char received[SECP256K1_FROST_MAX_PARTICIPANTS * 32];
|
||||
uint32_t mismatch_id = 0;
|
||||
|
||||
frost_enrollment_test_reduced_collect(r, j, all_shares, received);
|
||||
CHECK(secp256k1_frost_enrollment_reduced_share_agg(CTX, &r->sigmas[32 * j], &mismatch_id, all_shares, received, &r->thresh_pk, r->ids, r->u, r->ids[j], r->new_id, r->n, (uint32_t)r->t, r->session_id) == 1);
|
||||
CHECK(mismatch_id == UINT32_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
static void frost_enrollment_test_reduced_round2(frost_enrollment_test_run *r) {
|
||||
secp256k1_pubkey helper_pubshares[SECP256K1_FROST_MAX_PARTICIPANTS];
|
||||
|
||||
frost_enrollment_test_helper_pubshares(r, helper_pubshares);
|
||||
CHECK(secp256k1_frost_enrollment_pubshare_derive(CTX, &r->new_pubshare, helper_pubshares, r->ids, r->u, r->new_id, r->n, (uint32_t)r->t) == 1);
|
||||
CHECK(secp256k1_frost_enrollment_reduced_secshare_gen(CTX, r->new_secshare, r->sigmas, &r->params_hashes[0][0], &r->thresh_pk, r->ids, r->u, r->new_id, r->n, (uint32_t)r->t, r->session_id, &r->new_pubshare) == 1);
|
||||
}
|
||||
|
||||
static void frost_enrollment_test_reduced_full_run(frost_enrollment_test_run *r, size_t n, size_t t, size_t u, uint32_t new_id) {
|
||||
frost_enrollment_test_deal(r, n, t, u, new_id);
|
||||
frost_enrollment_test_reduced_round1_gen(r);
|
||||
frost_enrollment_test_reduced_round1_agg(r);
|
||||
frost_enrollment_test_reduced_round2(r);
|
||||
}
|
||||
|
||||
/* Reconstructs the threshold secret from the shares of the given identifiers
|
||||
* and checks it against the threshold public key. shares[k] must be the share
|
||||
* of ids[k]. */
|
||||
@@ -256,6 +310,61 @@ static void run_frost_enrollment_signing_test(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The reduced protocol computes the same share as the full protocol while
|
||||
* sending only the upper triangle of the share-exchange matrix. */
|
||||
static void run_frost_enrollment_reduced_roundtrip_test(void) {
|
||||
static frost_enrollment_test_run full, reduced;
|
||||
secp256k1_pubkey extended[4];
|
||||
const unsigned char *shares[2];
|
||||
size_t i, j, messages = 0;
|
||||
uint32_t ids[2] = { 2, 3 };
|
||||
|
||||
frost_enrollment_test_deal(&reduced, 3, 2, 3, 3);
|
||||
memcpy(&full, &reduced, sizeof(full));
|
||||
frost_enrollment_test_round1_gen(&full);
|
||||
frost_enrollment_test_round1_agg(&full);
|
||||
frost_enrollment_test_round2(&full);
|
||||
frost_enrollment_test_reduced_round1_gen(&reduced);
|
||||
frost_enrollment_test_reduced_round1_agg(&reduced);
|
||||
frost_enrollment_test_reduced_round2(&reduced);
|
||||
|
||||
CHECK(secp256k1_memcmp_var(full.new_secshare, reduced.new_secshare, 32) == 0);
|
||||
CHECK(secp256k1_memcmp_var(&full.new_pubshare, &reduced.new_pubshare, sizeof(full.new_pubshare)) == 0);
|
||||
CHECK(secp256k1_memcmp_var(full.params_hashes[0], reduced.params_hashes[0], 32) != 0);
|
||||
|
||||
for (i = 0; i < reduced.u; i++) {
|
||||
for (j = 0; j < reduced.u; j++) {
|
||||
if (i == j) {
|
||||
continue;
|
||||
}
|
||||
if (reduced.ids[j] > reduced.ids[i]) {
|
||||
messages++;
|
||||
} else {
|
||||
CHECK(secp256k1_is_zero_array(&reduced.shares[i][32 * j], 32));
|
||||
}
|
||||
}
|
||||
}
|
||||
CHECK(messages == reduced.u * (reduced.u - 1) / 2);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
extended[i] = reduced.pubshares[i];
|
||||
}
|
||||
extended[3] = reduced.new_pubshare;
|
||||
CHECK(secp256k1_frost_threshold_info_validate(CTX, &reduced.thresh_pk, extended, 4, 2) == 1);
|
||||
shares[0] = reduced.secshares[2];
|
||||
shares[1] = reduced.new_secshare;
|
||||
{
|
||||
secp256k1_pubkey signer_pubshares[2];
|
||||
signer_pubshares[0] = extended[2];
|
||||
signer_pubshares[1] = extended[3];
|
||||
frost_enrollment_test_sign(ids, shares, signer_pubshares, 2, 4, 2, &reduced.thresh_pk);
|
||||
}
|
||||
|
||||
frost_enrollment_test_reduced_full_run(&reduced, 3, 2, 2, 1);
|
||||
CHECK(secp256k1_memcmp_var(reduced.new_secshare, reduced.secshares[1], 32) == 0);
|
||||
CHECK(secp256k1_memcmp_var(&reduced.new_pubshare, &reduced.pubshares[1], sizeof(reduced.new_pubshare)) == 0);
|
||||
}
|
||||
|
||||
/* Repair mode: participant 1 "loses" its share and the same protocol run at
|
||||
* new_id = 1 reproduces it, byte for byte. The share is f(x_1), a fixed value,
|
||||
* not a fresh random one, so anything short of exact equality is a bug. */
|
||||
@@ -1158,6 +1267,7 @@ static const struct tf_test_entry tests_frost_enrollment[] = {
|
||||
CASE1(run_frost_enrollment_vectors_test),
|
||||
CASE1(run_frost_enrollment_reconstruction_test),
|
||||
CASE1(run_frost_enrollment_signing_test),
|
||||
CASE1(run_frost_enrollment_reduced_roundtrip_test),
|
||||
CASE1(run_frost_enrollment_repair_test),
|
||||
CASE1(run_frost_enrollment_oversized_set_test),
|
||||
CASE1(run_frost_enrollment_fault_injection_test),
|
||||
|
||||
Reference in new issue
Block a user