CFB decryption algorithm incorrect (and buffer overrun)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Python-Crypto |
New
|
Undecided
|
Unassigned |
Bug Description
The CFB algorithm is show in:
http://
Although the key encryption function is used in both encrypting and decrypting, the encrypting and decrypting algorithms are different, the are incorrectly the same in the pycrypto-2.6.1 code.
src/block_
1) in ALG_Encrypt(
in case(MODE_CFB):
line 548
the cipertext not the plaintext is used as the next IV, so the:
for (j=0; j<self-
buffer[i+j] = str[i+j] ^ temp[j];
}
should be AFTER the:
if (self->segment_size == BLOCK_SIZE * 8) {
...
2) line 553
buffer[i+j] = str[i+j] ^ temp[j];
can write past the end if 'buffer' which is 'len' bytes long.
the code with both bugs fixed is:
-------
src/block_
case(MODE_CFB):
for(i=0; i<len; i+=self-
{
block_
/* s == b: segment size is identical to
the algorithm block size */
memcpy(
}
else if ((self-
int sz = self->segment_
memmove(
BLOCK_
memcpy(self->IV + BLOCK_SIZE - sz, str + i,
sz);
}
else {
/* segment_size is not a multiple of 8;
currently this can't happen */
}
int segmentSize = self->segment_size / 8;
if (i + segmentSize > len) {
/* do not overwrite past end of 'buf' */
}
for (int j = 0; j < segmentSize; j++) {
buf[i + j] = buf[i + j] ^ temp[j];
}
}
break;