@@ -175,9 +175,11 @@ static int secp256k1_silentpayments_create_output_pubkey(const secp256k1_context
175
175
return ret ;
176
176
}
177
177
178
- int secp256k1_silentpayments_sender_create_outputs (
178
+ int secp256k1_silentpayments_sender_create_outputs_with_proof (
179
179
const secp256k1_context * ctx ,
180
180
secp256k1_xonly_pubkey * * generated_outputs ,
181
+ secp256k1_silentpayments_dleq_data * * dleq_data ,
182
+ size_t * n_dleq_size ,
181
183
const secp256k1_silentpayments_recipient * * recipients ,
182
184
size_t n_recipients ,
183
185
const unsigned char * outpoint_smallest36 ,
@@ -191,10 +193,14 @@ int secp256k1_silentpayments_sender_create_outputs(
191
193
secp256k1_ge A_sum_ge ;
192
194
secp256k1_gej A_sum_gej ;
193
195
unsigned char input_hash [32 ];
194
- unsigned char shared_secret [33 ];
196
+ secp256k1_ge shared_secret ;
197
+ unsigned char shared_secret33 [33 ];
198
+ unsigned char proof64 [64 ];
195
199
secp256k1_silentpayments_recipient last_recipient ;
196
200
int overflow = 0 ;
197
201
int ret = 1 ;
202
+ int j = 0 ;
203
+ size_t len ;
198
204
199
205
/* Sanity check inputs. */
200
206
VERIFY_CHECK (ctx != NULL );
@@ -264,13 +270,30 @@ int secp256k1_silentpayments_sender_create_outputs(
264
270
secp256k1_ge pk ;
265
271
ret &= secp256k1_pubkey_load (ctx , & pk , & recipients [i ]-> scan_pubkey );
266
272
if (!ret ) break ;
267
- secp256k1_silentpayments_create_shared_secret (ctx , shared_secret , & a_sum_scalar , & pk );
273
+ /* Compute shared_secret = tweaked_secret_component * Public_component */
274
+ secp256k1_silentpayments_create_shared_secret_with_proof (ctx , proof64 , & shared_secret , & a_sum_scalar , & pk );
275
+ if (dleq_data != NULL ) {
276
+ secp256k1_pubkey pubkey ;
277
+ size_t pklen = 33 ;
278
+ secp256k1_pubkey_save (& pubkey , & shared_secret );
279
+ secp256k1_ec_pubkey_serialize (ctx , dleq_data [j ]-> shared_secret , & pklen , & pubkey , SECP256K1_EC_COMPRESSED );
280
+ memcpy (dleq_data [j ]-> proof , proof64 , 64 );
281
+ dleq_data [j ]-> index = recipients [i ]-> index ;
282
+ }
283
+ /* This can only fail if the shared secret is the point at infinity, which should be
284
+ * impossible at this point, considering we have already validated the public key and
285
+ * the secret key being used
286
+ */
287
+ ret = secp256k1_eckey_pubkey_serialize (& shared_secret , shared_secret33 , & len , 1 );
288
+ VERIFY_CHECK (ret && len == 33 );
268
289
k = 0 ;
290
+ j ++ ;
269
291
}
270
- ret &= secp256k1_silentpayments_create_output_pubkey (ctx , generated_outputs [recipients [i ]-> index ], shared_secret , & recipients [i ]-> spend_pubkey , k );
292
+ ret &= secp256k1_silentpayments_create_output_pubkey (ctx , generated_outputs [recipients [i ]-> index ], shared_secret33 , & recipients [i ]-> spend_pubkey , k );
271
293
k ++ ;
272
294
last_recipient = * recipients [i ];
273
295
}
296
+ * n_dleq_size = j ;
274
297
/* Explicitly clear variables containing secret data */
275
298
secp256k1_scalar_clear (& addend );
276
299
secp256k1_scalar_clear (& a_sum_scalar );
@@ -279,10 +302,25 @@ int secp256k1_silentpayments_sender_create_outputs(
279
302
* could result in a third party being able to identify the transaction as a silent payments transaction
280
303
* and potentially link the transaction back to a silent payment address
281
304
*/
282
- memset (& shared_secret , 0 , sizeof (shared_secret ));
305
+ memset (& shared_secret33 , 0 , sizeof (shared_secret33 ));
283
306
return ret ;
284
307
}
285
308
309
+ int secp256k1_silentpayments_sender_create_outputs (
310
+ const secp256k1_context * ctx ,
311
+ secp256k1_xonly_pubkey * * generated_outputs ,
312
+ const secp256k1_silentpayments_recipient * * recipients ,
313
+ size_t n_recipients ,
314
+ const unsigned char * outpoint_smallest36 ,
315
+ const secp256k1_keypair * const * taproot_seckeys ,
316
+ size_t n_taproot_seckeys ,
317
+ const unsigned char * const * plain_seckeys ,
318
+ size_t n_plain_seckeys
319
+ ) {
320
+ size_t n_dleq_size ;
321
+ return secp256k1_silentpayments_sender_create_outputs_with_proof (ctx , generated_outputs , NULL , & n_dleq_size , recipients , n_recipients , outpoint_smallest36 , taproot_seckeys , n_taproot_seckeys , plain_seckeys , n_plain_seckeys );
322
+ }
323
+
286
324
/** Set hash state to the BIP340 tagged hash midstate for "BIP0352/Label". */
287
325
static void secp256k1_silentpayments_sha256_init_label (secp256k1_sha256 * hash ) {
288
326
secp256k1_sha256_initialize (hash );
0 commit comments