I’m currently confused as to the behaviour of the DES algorithm provided by the GNU Crypto package. Here’s a link to the algorithm in question: GNU Crypto DES algorithm
Originally I was merely wanting to extract the state of the key(s) at certain points, i.e. after PC-1, PC-2, the sub keys, etc. However, this plan’s not going too well as the 56bit key expected after PC-1, appears to be 48 bits, going by the pc1m variable (working on the assumption that representation of the key (pc1m’s value) when converted from decimal to binary is sound). As such I tried to figure out this piece of code:
for (i = 0; i < 56; i++) {
l = PC1[i];
pc1m |= ((kb[l >>> 3] & (0x80 >>> (l & 7))) != 0)
? (1L << (55 – i)) : 0;
}
However, my understanding of the bitwise operations is ropey, and although I have a vague understanding of how it’s evaluating, I can’t see the overall logic to it and how it works (or, rather why it appears to not actually work — although the algorithm does encrypt and decrypt successfully going by the official test vectors). Where can I get the 56 bit permutation after PC-1?
It is also unclear to me what the code does after ” // Encryption key first. “, as the pc1m variable is unchanged, and pcr appears to just copy the value after all that.
On the brightside, it appears clear, that “cooking” the keys creates the subkeys for the Feistel rounds.
As an aside, any other non-copyrighted Java implementations you can reference would be of interest to me, however, I would quite like to work with this implementation.
Any help would be much, much appreciated! Thanks.
The code snippet indeed is reading 56 bits from
kband rearranging them intopc1m(assuming the initial value ofpc1mis 0).so the value of
kbafter the 56-bit permutation described inPC1will be available inpc1mas a single long integer.