Re: mcrypt ncfb mode problem.
- From: Mario Munda <mario.munda@xxxxxxxxx>
- Date: Mon, 04 Jun 2007 11:10:00 -0700
Thnx for your answer.
I know that this is a block cipher, but when i command the device to
send encrypted command "show_list", all the device sends is a 9 bytes
of data and not 16 as it should.
Peter Pearson je napisal:
On Mon, 04 Jun 2007 05:50:06 -0700, Mario Munda <mario.munda@xxxxxxxxx> wrote:
[snip]
When the device sends data which is less than a block size, the data[snip]
gets corrupted.
This is my code:
#include <stdio.h>
#include <mcrypt.h>
int main()
{
char Key[32] =
{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,
0x0E,0x0F,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08$
char IV[16] = {0x8F,0x83,0x28,0xDF,0xC1,0x3A,0x5A,
0x96,0xF3,0xF1,0x8C,0x4D,0x25,0xA9,0xBE,0x04};
char Data[16] = {0x12,0x76,0xDE,
0x19,0x36,0xF9,0xD5,0x88,0x86,0x8E,0x84,0xE0,0x30,0x3E,0xB6,0x2E};
char Data2[6] = {0xB9,0x39,0x88,0x1A,0xAB,0x00};
char Data3[16] = {0xFE,0xB2,0xB4,0x60,0x9E,0xEE,
0x25,0x8C,0x18,0xB8,0xB4,0xB6,0x2A,0x91,0x0A,0xAE};
char Data4[16] = {0xF2,0x19,0xAB,0x89,0xBF,0x5D,
0x33,0x40,0x4F,0xE3,0x71,0xEB,0x5B,0x4F,0xB5,0xC3};
MCRYPT crypt_handle =
mcrypt_module_open(MCRYPT_RIJNDAEL_128,NULL,"ncfb",NULL);
mcrypt_generic_init(crypt_handle,Key,32,IV);
// First string, output should be abcdefghijklmnop
mdecrypt_generic(crypt_handle,Data,16);
for(int i=0;i<16;i++)
printf("%c",Data[i]);
printf("\n");
// Second string, output should be ABCDEF
mdecrypt_generic(crypt_handle,Data2,6);
for(int i=0;i<6;i++)
printf("%c",Data2[i]);
printf("\n");
// Third string, output should be klmnopqrstuvwxyz
mdecrypt_generic(crypt_handle,Data3,16);
for(int i=0;i<16;i++)
printf("%c",Data3[i]);
printf("\n");
// Fourth string, output should be klmnopqrstuvwxyz
mdecrypt_generic(crypt_handle,Data4,16);
for(int i=0;i<16;i++)
printf("%c",Data4[i]);
printf("\n");
mcrypt_generic_end(crypt_handle);
return 0;
}
command, and the output of the binary is:
abcdefghijklmnop
ABCDEF
klmnopqrstt¸G
ߺx×£E®.Ê$g
I don't know mcrypt, but I believe you're printing the results
before the decryption is complete. Remember that Rijndael works
on 16-byte blocks. If the decryption subroutine accepts ciphertexts
that aren't multiples of 16 bytes, then you should expect to
issue some kind of call that says, "That's all the ciphertext; go
ahead and finish the decryption" before having all the plaintext.
Note that the transition between plaintext and nonsense occurs
on a 16-byte boundary:
abcdefghijklmnop ABCDEFklmnopqrst t¸Gߺx×£E®.Ê$g
................ ................ |..........
0123456789abcdef 0123456789abcdef 0123456789a
--
To email me, substitute nowhere->spamcop, invalid->net.
.
- References:
- mcrypt ncfb mode problem.
- From: Mario Munda
- Re: mcrypt ncfb mode problem.
- From: Peter Pearson
- mcrypt ncfb mode problem.
- Prev by Date: Re: is CMEA cipher in use today?
- Next by Date: Re: The recent attack...
- Previous by thread: Re: mcrypt ncfb mode problem.
- Next by thread: Re: mcrypt ncfb mode problem.
- Index(es):
Relevant Pages
|
|