Subject: [quicwg/base-drafts] Confused about Header Protection Application? (#2994)

From: Ainiroad <[email-masked]>
Date: Wed, 28 Aug 2019 00:33:52 -0700

In [tls draft](https://quicwg.org/base-drafts/draft-ietf-quic-tls.html#rfc.section.5.4.1)
Section 5.4.1 figure 4 shows a sample algorithm for applying header protection:
```
mask = header_protection(hp_key, sample)

pn_length = (packet[0] & 0x03) + 1
if (packet[0] & 0x80) == 0x80:
   # Long header: 4 bits masked
   packet[0] ^= mask[0] & 0x0f
else:
   # Short header: 5 bits masked
   packet[0] ^= mask[0] & 0x1f

# pn_offset is the start of the Packet Number field.
packet[pn_offset:pn_offset+pn_length] ^= mask[1:1+pn_length]
```
I think pn_length should be calculate after decode packet[0], like:
```
mask = header_protection(hp_key, sample)

if (packet[0] & 0x80) == 0x80:
   # Long header: 4 bits masked
   packet[0] ^= mask[0] & 0x0f
else:
   # Short header: 5 bits masked
   packet[0] ^= mask[0] & 0x1f

pn_length = (packet[0] & 0x03) + 1 // move here

# pn_offset is the start of the Packet Number field.
packet[pn_offset:pn_offset+pn_length] ^= mask[1:1+pn_length]
```

Do I have any misunderstanding? 
Thanks a lot!

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/quicwg/base-drafts/issues/2994

---

From: MikkelFJ <[email-masked]>
Date: Wed, 28 Aug 2019 00:41:07 -0700

The algorithm is for applying header protection. The text just above says:

> Removing header protection only differs in the order in which the packet number length (pn_length) is determined.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/quicwg/base-drafts/issues/2994#issuecomment-525623769

---

From: Ainiroad <[email-masked]>
Date: Wed, 28 Aug 2019 00:47:56 -0700

> > Removing header protection only differs in the order in which the packet number length (pn_length) is determined.

understood,  thanks!!!

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/quicwg/base-drafts/issues/2994#issuecomment-525625991

---

From: Ainiroad <[email-masked]>
Date: Wed, 28 Aug 2019 00:48:30 -0700

Closed #2994.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/quicwg/base-drafts/issues/2994#event-2589537603