On 9. Mar 2025, at 21:03, Anders Rundgren <[email protected]> wrote:
> 
> let sig = csf.remove(CSF_SIG_LBL).getBytes();      // Get and remove embedded 
> signature value
> let res = hmac(alg, SHARED_KEY, object.encode());  // Note that 
> object.encode()
>                                                   // reserializes all but sig.

Why re-encode?

Since you still have the original bytes of the message (cborBinary), you might 
simply remove from that the slice that represents the CSF_SIG_LBL, update the 
counter in the map head, and then the rest of the bytes are the signing input 
for verification.
(At the decoder side, just build the message without signature, compute the 
signature with that as the signing input, and then stuff the signature into the 
CBOR encoding at the right place and update the counter in the map head.)

Obviously, you need something that is a bit different from a generic 
encoder/decoder (to indicate the slice that represents a member on the decoder 
side, and to indicate a good insertion point for that slice on the encoder 
side), but then you don’t need to care about deterministic encoding at all 
(well, except for the map head in case the removing/stuffing 
increases/decreases its encoding size).

Grüße, Carsten

_______________________________________________
COSE mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to