Mailing List Archive

AES decrypted text mismatch
I was following Tobias Bayer's example code to perform some AES
encryption. Code available at:

http://www.tobias-bayer.de/main/tutorials/libgcrypt.html

I made a simple modification to allow command line input to
demonstrate the problem, changing only the following lines:

int main(int argc, char *argv[])
{
const int BLOCKSIZE = 16;
int TEXTLEN = strlen(argv[1]);
unsigned char* plaintext = argv[1];

When I run the program (using libgcrypt 1.2.0, I realize it's out of
date, trying to get the sysadmin to update it), some input strings
are decrypted back with extra characters on the end. Note the
different length after decryption as well:

angus@dev:~/aes_test>./aes 12345678901
Key is: 92 75 26 AD C8 BC 36 C7 C 52 8 E3 BF 13 8C F9
Encrypting plaintext: 12345678901...
plaintext len: 11
Resulting ciphertext (hex): BA C6 2A 23 DC 39 0 D5 7E 48 CB
Decrypted text len: 11
Decrypted text: 12345678901

angus@dev:~/aes_test>./aes 123456789012
Key is: FF 5 76 50 41 9F 2B A0 1B 2F 3 D2 B0 9 A8 9D
Encrypting plaintext: 123456789012...
plaintext len: 12
Resulting ciphertext (hex): D6 FD 6E 93 53 4B 1F 1B 4F 6 41 99
Decrypted text len: 15
Decrypted text: 123456789012?


Is this a known bug in 1.2.0? I didn't see anything in the archives
or the change log, but didn't really find release notes.

Thanks in advance,

Steve Cochran

_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Re: AES decrypted text mismatch [ In reply to ]
On Wed, 11 Oct 2006 04:56, Stephen A. Cochran Lists said:

> const int BLOCKSIZE = 16;
> int TEXTLEN = strlen(argv[1]);
> unsigned char* plaintext = argv[1];
>
> When I run the program (using libgcrypt 1.2.0, I realize it's out of
> date, trying to get the sysadmin to update it), some input strings
> are decrypted back with extra characters on the end. Note the
> different length after decryption as well:

With only the changes above you won't be able to get that output.
Thus you changed more and introduced a bug.


Shalom-Salam,

Werner


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Re: AES decrypted text mismatch [ In reply to ]
On Oct 11, 2006, at 5:21 AM, Werner Koch wrote:

> With only the changes above you won't be able to get that output.
> Thus you changed more and introduced a bug.

I added two printf statements that highlighted the change:

printf("plaintext len: %u\n", strlen(plaintext));
printf("Decrypted text len: %u\n", strlen(decryptedtext));

I highly doubt that they are the problem. But to rule out any other
change I had made, I even tested the original code and only modified
the plaintext and TEXTLEN lines:

const int TEXTLEN = 12;
unsigned char* plaintext = "123456789012";

Again, the same output:

angus@dev:~/aes_test>./aes
Initializing... Version: 1.2.0
Generating symmetric key (128 bit)...
Key is: 25 86 9D 2F 2D F7 23 43 1A 8A 7B B2 E6 32 95 D9
Opening AES cipher...
Setting the key...
Setting the initialization vector 1234567812345678...
Encrypting plaintext: 123456789012...
Resulting ciphertext (hex): 28 B1 A8 BC D8 BF 4C 21 76 D3 37 A
Resetting initialization vector...
Decrypting...
Decrypted text: 123456789012?

Steve


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Re: AES decrypted text mismatch [ In reply to ]
On Wed, 11 Oct 2006 14:22, Stephen A. Cochran Lists said:

> printf("plaintext len: %u\n", strlen(plaintext));
> printf("Decrypted text len: %u\n", strlen(decryptedtext));

You are using strlen for the decypted text but you didn't encypted the
trailing Nul. Thus your printf as well as the strlen accesses
uninitialized memory and stops output only at the next Nul byte found.
This is also a bug in the original program.


Salam-Shalom,

Werner


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel