Skip to content

Commit

Permalink
Ensure no IV collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Jan 14, 2024
1 parent 3430ee2 commit 6083a75
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ControlStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ static bool encryptControlMessage(PNVCTL_ENCRYPTED_PACKET_HEADER encPacket, PNVC
iv[2] = (unsigned char)(encPacket->seq >> 16);
iv[1] = (unsigned char)(encPacket->seq >> 8);
iv[0] = (unsigned char)(encPacket->seq >> 0);

// Set high bytes to something unique to ensure no IV collisions
iv[14] = (unsigned char)'C'; // Client originated
iv[15] = (unsigned char)'C'; // Control stream
}
else {
// This is a truncating cast, but it's what Nvidia does, so we have to mimic it.
Expand Down Expand Up @@ -560,6 +564,10 @@ static bool decryptControlMessageToV1(PNVCTL_ENCRYPTED_PACKET_HEADER encPacket,
iv[2] = (unsigned char)(encPacket->seq >> 16);
iv[1] = (unsigned char)(encPacket->seq >> 8);
iv[0] = (unsigned char)(encPacket->seq >> 0);

// Set high bytes to something unique to ensure no IV collisions
iv[14] = (unsigned char)'H'; // Host originated
iv[15] = (unsigned char)'C'; // Control stream
}
else {
// This is a truncating cast, but it's what Nvidia does, so we have to mimic it.
Expand Down

0 comments on commit 6083a75

Please sign in to comment.