Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Sat, 7 Apr 2012 12:07:40 +0530
From: Dhiru Kholia <dhiru.kholia@...il.com>
To: john-dev@...ts.openwall.com
Subject: OpenSSL AES strange problem (first block is decrypted wrongly)

Hi,

I am trying to decrypt two blocks of encrypted data using OpenSSL AES
(in CBC mode). Second block is decrypted correctly but first block is
strangely wrong. Any ideas what is going on?. Can someone give it a
shot?

The expected output is
"3f28d3271e76e6809e00fc9670e5ef54dc94ebc3000000000000000000000000".
The attached program decrypts the second block correctly but fails for
the first block.

-- 
Cheers,
Dhiru

#include <stdio.h>
#include <string.h>
#include <openssl/aes.h>

static void print_hex(unsigned char *str, int len)
{
	int i;
	for (i = 0; i < len; ++i)
		printf("%02x", str[i]);
	printf("\n");
}

unsigned char key[] = { 0xfb,0xf5,0x4c,0x84,0x9e,0x5a,0xbd,0xe8,0x5a,0xf2,0xed,0x17,0xd9,0xe4,0x30,0x32 };
unsigned char in[] = { 0x46,0xbf,0xac,0x7f,0xb8,0x7c,0xd4,0x3b,0xd0,0xab,0x54,0xeb,0xc2,0x1c,0x12,0x0d,0xf5,0xfa,0xb7,0xe6,0xf1,0x13,0x75,0xe7,0x9e,0xe0,0x44,0xe6,0x63,0x64,0x1d,0x5e };
unsigned char iv[] = { 0xf5,0xfa,0xb7,0xe6,0xf1,0x13,0x75,0xe7,0x9e,0xe0,0x44,0xe6,0x63,0x64,0x1d,0x5e };


int main()
{
	unsigned char out[32];
	AES_KEY akey;
     	memset(&akey, 0, sizeof(AES_KEY));
	if(AES_set_decrypt_key(key, 128, &akey) < 0) {
		fprintf(stderr, "AES_set_derypt_key failed!\n");
		return 0;
	}
	AES_cbc_encrypt(in, out, 32, &akey, iv, AES_DECRYPT);
	printf("key : ");
	print_hex(key, 16);
	printf("input : ");
	print_hex(in, 32);
	printf("iv : ");
	print_hex(iv, 16);
	printf("output : ");
	print_hex(out, 32);

	return 0;
}

Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ