If it is not in the specifications then it is not guaranteed. It's really that simple; there isn't a separate specification for card implementers that says otherwise (and if there was, that might change without touching the original definition).
Operations on keys can be tricky with regard to attacks. So there is a lot to be said about keeping the key data intact and not iterate over the key bits using the generic CPU. Also, it might be tricky when other operations are performed over the key data such as calculating a Key Check Value using a hash function or for using the same key as input to a MAC (symmetric signature).
It's of course perfectly possible to perform the parity operation on the key bits using your own code. You can compare your result with test vectors or with keys generated using the Java SecretKeyFactory
. However, since the parity bits don't get used in the key calculations, this would only be needed if you want to export the key out of the device. But again, note that performing additional operations on key data is dangerous and may break all kinds of security tests/proofs/certifications.
Note that most Java Card implementations (or rather, the hardware of the underlying chip) will very likely perform checksums over all the persistent (EEPROM/flash) memory anyway. It's also very likely that the keys are protected by the Java Card implementation (or one of the underlying layers). So with regards to protection against unforeseen alterations of the data: I wouldn't worry overly much. You don't need the DES parity bits for that.
OK, I felt like doing some bit fiddling, so here's the Java Card code to set the parity yourself (I'll let you do the for loop and the inlining and stuff, if you don't mind). These calculations should be (near) constant time.
/**
* This method takes byte value <code>b</code> and then sets or unsets the least significant bit
* of that value in such a way that the parity of <code>b</code> is odd.
* So this method returns either <code>b</code> or <code>b ^ 1</code>.
*
* @param b the byte value
* @return <code>b</code> with DES parity
*/
public static byte makeDESParity(final byte b) {
byte x = b;
// trick to calculate odd parity in the lsb of x
x ^= x >>> 4;
x ^= x >>> 2;
x ^= x >>> 1;
// but we want even parity in the lsb: ~x
// get the least significant bit: ~x & 1
// xor that with b: ~x & 1 ^ b
return (byte) (~x & 1 ^ b);
}
/**
* This method takes byte value <code>b</code> and returns true if and only if
* the byte has odd parity.
*
* @param b the byte value
* @return true if <code>b</code> has DES parity
*/
public static boolean hasDESParity(byte b) {
// trick to calculate odd parity in the lsb of b
b ^= b >>> 4;
b ^= b >>> 2;
b ^= b >>> 1;
// check if last bit has indeed been set
return (b & 1) != 0;
}