Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header protection application and removal #5003

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading