@@ -379,15 +379,7 @@ pub(super) fn verify_recipient_metadata<'a, T: secp256k1::Signing>(
379
379
signing_pubkey : PublicKey , tlv_stream : impl core:: iter:: Iterator < Item = TlvRecord < ' a > > ,
380
380
secp_ctx : & Secp256k1 < T > ,
381
381
) -> Result < Option < Keypair > , ( ) > {
382
- let hmac_res = hmac_for_message ( metadata, expanded_key, iv_bytes, tlv_stream) ;
383
- #[ cfg( fuzzing) ]
384
- if hmac_res. is_err ( ) {
385
- // In fuzzing its relatively challenging for the fuzzer to find cases where we have issues
386
- // in a BOLT 12 object but also have a right-sized nonce. So instead we allow any size
387
- // nonce (i.e. `hmac_for_message` failing) and simply treat it as "no keypair").
388
- return Ok ( None ) ;
389
- }
390
- let mut hmac = hmac_res?;
382
+ let mut hmac = hmac_for_message ( metadata, expanded_key, iv_bytes, tlv_stream) ?;
391
383
hmac. input ( WITHOUT_ENCRYPTED_PAYMENT_ID_HMAC_INPUT ) ;
392
384
393
385
verify_metadata ( metadata, Hmac :: from_engine ( hmac) , signing_pubkey, secp_ctx)
@@ -432,16 +424,24 @@ fn hmac_for_message<'a>(
432
424
metadata : & [ u8 ] , expanded_key : & ExpandedKey , iv_bytes : & [ u8 ; IV_LEN ] ,
433
425
tlv_stream : impl core:: iter:: Iterator < Item = TlvRecord < ' a > > ,
434
426
) -> Result < HmacEngine < Sha256 > , ( ) > {
427
+ let mut hmac = expanded_key. hmac_for_offer ( ) ;
428
+ hmac. input ( iv_bytes) ;
429
+
435
430
if metadata. len ( ) < Nonce :: LENGTH {
436
- return Err ( ( ) ) ;
431
+ // In fuzzing its relatively challenging for the fuzzer to find cases where we have issues
432
+ // in a BOLT 12 object but also have a right-sized nonce. So instead we allow any size
433
+ // nonce.
434
+ if cfg ! ( fuzzing) {
435
+ return Ok ( hmac) ;
436
+ } else {
437
+ return Err ( ( ) ) ;
438
+ }
437
439
}
438
440
439
441
let nonce = match Nonce :: try_from ( & metadata[ ..Nonce :: LENGTH ] ) {
440
442
Ok ( nonce) => nonce,
441
443
Err ( _) => return Err ( ( ) ) ,
442
444
} ;
443
- let mut hmac = expanded_key. hmac_for_offer ( ) ;
444
- hmac. input ( iv_bytes) ;
445
445
hmac. input ( & nonce. 0 ) ;
446
446
447
447
for record in tlv_stream {
0 commit comments