# Parity checking on DES key if using ASCII chars

This is my first question here, so if I ask it to the wrong group or otherwise infringing the (written or unwritten) rules of the community, please bear with me.

My problem is this: In an exercise in futility, I am trying to write a small program (in C) that implements the DES (FIPS 46-3) standard. I stumbled upon that part in which, from each byte in the 8 byte key, the LSB is used for (odd) parity checking, and eventually discarded.

That, I assume, means that a key like "aaaaaaac" (ASCII encoding) is invalid, since "c" (0x63) has even parity.

Now, either this is correct (and my question would be how commercial / publicly - available packages treat this, since I believe I saw plain ASCII used as key) OR it is a wrong train of thoughts, in which case I would like to know what I am missing.

a key like "aaaaaaac" (ASCII encoding) is invalid, since "c" (0x63) has even parity

Right. Notice that restricting to ASCII ($$2^7$$ values per byte, of which $$2^6$$ with odd parity) severely reduces the already small keyspace of DES, from $$2^{56}$$ to $$2^{48}$$ keys ($$<2^{45.5}$$ if one restricts to printable ASCII). For this reason, DES keys are usually expressed in hexadecimal.

how commercial / publicly - available packages treat this

A very common practice is to exclude parity checking of DES keys from the functionality offered, and simply ignore the low-order bit, treating a key byte of 0x63 (ASCII c) just as 0x62 (ASCII b).

Another practice is to reject a key as invalid if any of its byte has even parity. With 64-bit x and side-channel protection aside, that could be implemented on the tune of

x = (x>>4) ^ x;
x = (x>>2) ^ x;
if (( (~((x>>1) ^ x)) & 0x0101010101010101) != 0) // error


For why DES keys have parity, see Purpose of DES parity bits.