@@ -379,15 +379,7 @@ pub(super) fn verify_recipient_metadata<'a, T: secp256k1::Signing>(
379379 signing_pubkey : PublicKey , tlv_stream : impl core:: iter:: Iterator < Item = TlvRecord < ' a > > ,
380380 secp_ctx : & Secp256k1 < T > ,
381381) -> 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) ?;
391383 hmac. input ( WITHOUT_ENCRYPTED_PAYMENT_ID_HMAC_INPUT ) ;
392384
393385 verify_metadata ( metadata, Hmac :: from_engine ( hmac) , signing_pubkey, secp_ctx)
@@ -432,16 +424,24 @@ fn hmac_for_message<'a>(
432424 metadata : & [ u8 ] , expanded_key : & ExpandedKey , iv_bytes : & [ u8 ; IV_LEN ] ,
433425 tlv_stream : impl core:: iter:: Iterator < Item = TlvRecord < ' a > > ,
434426) -> Result < HmacEngine < Sha256 > , ( ) > {
427+ let mut hmac = expanded_key. hmac_for_offer ( ) ;
428+ hmac. input ( iv_bytes) ;
429+
435430 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+ }
437439 }
438440
439441 let nonce = match Nonce :: try_from ( & metadata[ ..Nonce :: LENGTH ] ) {
440442 Ok ( nonce) => nonce,
441443 Err ( _) => return Err ( ( ) ) ,
442444 } ;
443- let mut hmac = expanded_key. hmac_for_offer ( ) ;
444- hmac. input ( iv_bytes) ;
445445 hmac. input ( & nonce. 0 ) ;
446446
447447 for record in tlv_stream {
0 commit comments