59 const secp256k1_context* ctx,
61 const secp256k1_pubkey* pk,
62 const secp256k1_pubkey* T,
63 const unsigned char* context_id)
66 unsigned char buf[33];
69 const char* domain =
"MPT_POK_SK_REGISTER";
72 SHA256_Update(&sha, domain, strlen(domain));
75 secp256k1_ec_pubkey_serialize(ctx, buf, &len, pk, SECP256K1_EC_COMPRESSED);
76 SHA256_Update(&sha, buf, 33);
79 secp256k1_ec_pubkey_serialize(ctx, buf, &len, T, SECP256K1_EC_COMPRESSED);
80 SHA256_Update(&sha, buf, 33);
83 SHA256_Update(&sha, context_id, 32);
86 SHA256_Final(h, &sha);
93 const secp256k1_context* ctx,
94 unsigned char* proof_out,
95 const secp256k1_pubkey* pk,
96 const unsigned char* sk,
97 const unsigned char* context_id)
102 unsigned char term[32];
107 if (!secp256k1_ec_seckey_verify(ctx, sk))
return 0;
109 if (!secp256k1_ec_pubkey_create(ctx, &T, k))
goto cleanup;
114 memcpy(term, sk, 32);
115 if (!secp256k1_ec_seckey_tweak_mul(ctx, term, e))
goto cleanup;
117 if (!secp256k1_ec_seckey_tweak_add(ctx, s, term))
goto cleanup;
120 unsigned char* ptr = proof_out;
122 if (!secp256k1_ec_pubkey_serialize(ctx, ptr, &len, &T, SECP256K1_EC_COMPRESSED))
goto cleanup;
129 OPENSSL_cleanse(k, 32);
130 OPENSSL_cleanse(term, 32);
131 OPENSSL_cleanse(s, 32);
136 const secp256k1_context* ctx,
137 const unsigned char* proof,
138 const secp256k1_pubkey* pk,
139 const unsigned char* context_id)
141 secp256k1_pubkey T, LHS, RHS, ePk;
142 unsigned char e[32], s[32];
143 const unsigned char* ptr = proof;
147 if (!secp256k1_ec_pubkey_parse(ctx, &T, ptr, 33))
goto cleanup;
152 if (!secp256k1_ec_seckey_verify(ctx, s))
goto cleanup;
158 if (!secp256k1_ec_pubkey_create(ctx, &LHS, s))
goto cleanup;
161 if (!secp256k1_ec_pubkey_tweak_mul(ctx, &ePk, e))
goto cleanup;
163 const secp256k1_pubkey* addends[2] = {&T, &ePk};
164 if (!secp256k1_ec_pubkey_combine(ctx, &RHS, addends, 2))
goto cleanup;
static void build_pok_challenge(const secp256k1_context *ctx, unsigned char *e_out, const secp256k1_pubkey *pk, const secp256k1_pubkey *T, const unsigned char *context_id)
int secp256k1_mpt_pok_sk_prove(const secp256k1_context *ctx, unsigned char *proof_out, const secp256k1_pubkey *pk, const unsigned char *sk, const unsigned char *context_id)