On 2025-03-10 08:05, Carsten Bormann wrote:
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?

I'm not going to try to convince you of anything; I will only explain my 
rationale for doping things this way...



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).


Yes, you can obtain the same functionality through the methods you are 
describing.

However, since you also write that you need something "a bit different from a 
generic encoder", I simply had to come up with such a solution, right?

Using the binary approach you can "probably" drop the determinism requirement.  
That I rather build on OOP concepts and data encapsulation, is for achieving the 
following:
- permitting CBOR data to be read from a stream.
- transparently dealing with notoriously difficult stuff like Date/Time objects.
- reusing functionality that may be needed for other applications.
- bi-directional objects
- and some more...

BTW, I did not invent this scheme, Bouncycastle have used this concept for 
ASN.1 since they started some 20 years ago.

Anyway, this concept allows you to do really weird things in a sane way:
https://cyberphone.github.io/doc/defensive-publications/partial-encryption-full-signature.pdf
Maybe it is akin to CRISPR for DNA :)

Anders



Grüße, Carsten


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

Reply via email to