rsaenh/tests: Add more AES encrypt/decrypt tests.

This commit is contained in:
Bruno Jesus 2014-07-01 01:05:41 -03:00 committed by Alexandre Julliard
parent 69ff6f74b2
commit 87f214c7ff
1 changed files with 32 additions and 2 deletions

View File

@ -1048,24 +1048,54 @@ static void test_aes(int keylen)
HCRYPTKEY hKey;
BOOL result;
DWORD dwLen, dwMode;
unsigned char pbData[16], enc_data[16], bad_data[16];
unsigned char pbData[48], enc_data[16], bad_data[16];
int i;
static const BYTE aes_plain[32] = {
"AES Test With 2 Blocks Of Data." };
static const BYTE aes_cbc_enc[3][48] = {
/* 128 bit key encrypted text */
{ 0xfe, 0x85, 0x3b, 0xe1, 0xf5, 0xe1, 0x58, 0x75, 0xd5, 0xa9, 0x74, 0xe3, 0x09, 0xea, 0xa5, 0x04,
0x23, 0x35, 0xa2, 0x3b, 0x5c, 0xf1, 0x6c, 0x6f, 0xb9, 0xcd, 0x64, 0x06, 0x3e, 0x41, 0x83, 0xef,
0x2a, 0xfe, 0xea, 0xb5, 0x6c, 0x17, 0x20, 0x79, 0x8c, 0x51, 0x3e, 0x56, 0xed, 0xe1, 0x47, 0x68 },
/* 192 bit key encrypted text */
{ 0x6b, 0xf0, 0xfd, 0x32, 0xee, 0xc6, 0x06, 0x13, 0xa8, 0xe6, 0x3c, 0x81, 0x85, 0xb8, 0x2e, 0xa1,
0xd4, 0x3b, 0xe8, 0x22, 0xa5, 0x74, 0x4a, 0xbe, 0x9d, 0xcf, 0xcc, 0x37, 0x26, 0x19, 0x5a, 0xd1,
0x7f, 0x76, 0xbf, 0x94, 0x28, 0xce, 0x27, 0x21, 0x61, 0x87, 0xeb, 0xb9, 0x8b, 0xa8, 0xb4, 0x57 },
/* 256 bit key encrypted text */
{ 0x20, 0x57, 0x17, 0x0b, 0x17, 0x76, 0xd8, 0x3b, 0x26, 0x90, 0x8b, 0x4c, 0xf2, 0x00, 0x79, 0x33,
0x29, 0x2b, 0x13, 0x9c, 0xe2, 0x95, 0x09, 0xc1, 0xcd, 0x20, 0x87, 0x22, 0x32, 0x70, 0x9d, 0x75,
0x9a, 0x94, 0xf5, 0x76, 0x5c, 0xb1, 0x62, 0x2c, 0xe1, 0x76, 0x7c, 0x86, 0x73, 0xe6, 0x7a, 0x23 }
};
switch (keylen)
{
case 256:
result = derive_key(CALG_AES_256, &hKey, 0);
i = 2;
break;
case 192:
result = derive_key(CALG_AES_192, &hKey, 0);
i = 1;
break;
default:
case 128:
result = derive_key(CALG_AES_128, &hKey, 0);
i = 0;
break;
}
if (!result) return;
dwLen = sizeof(aes_plain);
memcpy(pbData, aes_plain, dwLen);
result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwLen, sizeof(pbData));
ok(result, "Expected OK, got last error %d\n", GetLastError());
ok(dwLen == 48, "Expected dwLen 48, got %d\n", dwLen);
todo_wine
ok(!memcmp(aes_cbc_enc[i], pbData, dwLen), "Expected equal data sequences\n");
result = CryptDecrypt(hKey, 0, TRUE, 0, pbData, &dwLen);
ok(result && dwLen == 32 && !memcmp(aes_plain, pbData, dwLen),
"%08x, dwLen: %d\n", GetLastError(), dwLen);
for (i=0; i<sizeof(pbData); i++) pbData[i] = (unsigned char)i;
/* Does AES provider support salt? */