Difference between revisions of "Kernel/XcDESKeyParity"

From xboxdevwiki
Jump to: navigation, search
(Port from my Python code, but with added comments)
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
=== Pseudocode ===
+
The ''XcDESKeyParity'' function turns a key into a DES key which requires odd-parity per byte.
  
<pre>
+
{{FIXME|reason=Mention crypto vector}}
XBAPI VOID NTAPI XcDESKeyParity(IN OUT PUCHAR pbKey, IN ULONG dwKeyLength) {
 
  
  // For each number between 0x0 and 0xF, this tells how many set bits there are.
+
=== Links ===
  const uint8_t parity_table[] = {
 
    0x00, 0x01, 0x01, 0x02, 0x01, 0x02, 0x02, 0x03,
 
    0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04
 
  };
 
  
  // Count number of set bits in each byte, and flip the lowest bit if there's an even number.
+
* [https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/blob/f73114df61d943ba73b329a6e4bd6805254af243/src/CxbxKrnl/EmuKrnlXc.cpp#L234 XcDESKeyParity implementation in Cxbx-Reloaded]
  // This forces each byte to have odd parity, as required by DES.
 
  for(ULONG i = 0; i < dwKeyLength; i++) {
 
    high_parity = parity_table[(pbKey[i] >> 4) & 0xF];
 
    low_parity = parity_table[(pbKey[i] >> 0) & 0xF];
 
    if ((high_parity + low_parity) % 2) == 0 {
 
      pbKey[i] ^= 0x01;
 
    }
 
  }
 
 
 
  return;
 
}
 
</pre>
 

Latest revision as of 00:03, 3 October 2018

The XcDESKeyParity function turns a key into a DES key which requires odd-parity per byte.

[FIXME]

Links