Skip to content

Commit

Permalink
Header protection application and removal
Browse files Browse the repository at this point in the history
This pseudocode could be dual purpose.  The current code is only for
applying header protection, but the language before talks about removal
more.  This might be clearer.
  • Loading branch information
martinthomson committed Oct 26, 2023
1 parent 8256ce9 commit a3a8cc1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rfc9001.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,20 +1190,24 @@ of the packet are masked by the least significant bits of the first mask byte,
and the packet number is masked with the remaining bytes. Any unused bytes of
mask that might result from a shorter packet number encoding are unused.

{{pseudo-hp}} shows a sample algorithm for applying header protection. Removing
header protection only differs in the order in which the packet number length
(pn_length) is determined (here "^" is used to represent exclusive OR).
{{pseudo-hp}} shows a sample algorithm for applying or removing header
protection. Applying or removing header protection only differ in the order in
which the packet number length (pn_length) is determined (here "^" is used to
represent exclusive OR).

~~~pseudocode
mask = header_protection(hp_key, sample)

pn_length = (packet[0] & 0x03) + 1
if encoding:
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
if decoding:
pn_length = (packet[0] & 0x03) + 1

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

0 comments on commit a3a8cc1

Please sign in to comment.