rsaenh: Add tests for CALG_SSL3_SHAMD5 hashing.

This commit is contained in:
Juan Lang 2010-05-20 17:22:35 -07:00 committed by Alexandre Julliard
parent 7abdcd2c45
commit 71a9d1380c
1 changed files with 146 additions and 78 deletions

View File

@ -301,6 +301,84 @@ static BOOL derive_key(ALG_ID aiAlgid, HCRYPTKEY *phKey, DWORD len)
return TRUE;
}
static BYTE abPlainPrivateKey[596] = {
0x07, 0x02, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x00,
0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x9b, 0x64, 0xef, 0xce,
0x31, 0x7c, 0xad, 0x56, 0xe2, 0x1e, 0x9b, 0x96,
0xb3, 0xf0, 0x29, 0x88, 0x6e, 0xa8, 0xc2, 0x11,
0x33, 0xd6, 0xcc, 0x8c, 0x69, 0xb2, 0x1a, 0xfd,
0xfc, 0x23, 0x21, 0x30, 0x4d, 0x29, 0x45, 0xb6,
0x3a, 0x67, 0x11, 0x80, 0x1a, 0x91, 0xf2, 0x9f,
0x01, 0xac, 0xc0, 0x11, 0x50, 0x5f, 0xcd, 0xb9,
0xad, 0x76, 0x9f, 0x6e, 0x91, 0x55, 0x71, 0xda,
0x97, 0x96, 0x96, 0x22, 0x75, 0xb4, 0x83, 0x44,
0x89, 0x9e, 0xf8, 0x44, 0x40, 0x7c, 0xd6, 0xcd,
0x9d, 0x88, 0xd6, 0x88, 0xbc, 0x56, 0xb7, 0x64,
0xe9, 0x2c, 0x24, 0x2f, 0x0d, 0x78, 0x55, 0x1c,
0xb2, 0x67, 0xb1, 0x5e, 0xbc, 0x0c, 0xcf, 0x1c,
0xe9, 0xd3, 0x9e, 0xa2, 0x15, 0x24, 0x73, 0xd6,
0xdb, 0x6f, 0x83, 0xb2, 0xf8, 0xbc, 0xe7, 0x47,
0x3b, 0x01, 0xef, 0x49, 0x08, 0x98, 0xd6, 0xa3,
0xf9, 0x25, 0x57, 0xe9, 0x39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x42, 0x5a, 0x77,
0x92, 0x98, 0x34, 0xf3, 0x56, 0x6c, 0x96, 0x10,
0x40, 0x59, 0x16, 0xcb, 0x77, 0x61, 0xe3, 0xbf,
0x4b, 0xd4, 0x39, 0xfb, 0xb1, 0x4e, 0xc1, 0x74,
0xec, 0x7a, 0xea, 0x3d, 0x68, 0xbb, 0x0b, 0xe6,
0xc6, 0x06, 0xbf, 0xdd, 0x7f, 0x94, 0x42, 0xc0,
0x0f, 0xe4, 0x92, 0x33, 0x6c, 0x6e, 0x1b, 0xba,
0x73, 0xf9, 0x79, 0x84, 0xdf, 0x45, 0x00, 0xe4,
0x94, 0x88, 0x9d, 0x08, 0x89, 0xcf, 0xf2, 0xa4,
0xc5, 0x47, 0x45, 0x85, 0x86, 0xa5, 0xcc, 0xa8,
0xf2, 0x5d, 0x58, 0x07
};
static void test_hashes(void)
{
static const unsigned char md2hash[16] = {
@ -318,11 +396,24 @@ static void test_hashes(void)
static const unsigned char sha1hash[20] = {
0xf1, 0x0c, 0xcf, 0xde, 0x60, 0xc1, 0x7d, 0xb2, 0x6e, 0x7d,
0x85, 0xd3, 0x56, 0x65, 0xc7, 0x66, 0x1d, 0xbb, 0xeb, 0x2c };
static const unsigned char signed_ssl3_shamd5_hash[] = {
0x4f,0xcc,0x2f,0x33,0x44,0x60,0x76,0x16,0x13,0xc8,0xff,0xd4,0x59,0x19,
0xde,0x85,0x44,0x72,0x47,0x98,0x01,0xfb,0x67,0x5c,0x5b,0x35,0x15,0x0f,
0x91,0xda,0xc7,0x7c,0xfb,0xe2,0x18,0xef,0xac,0x31,0x40,0x7b,0xa9,0x83,
0xdb,0x30,0xcd,0x94,0x4b,0x8e,0x3b,0x6c,0x7a,0x86,0x59,0xf0,0xd1,0xd2,
0x5e,0xce,0xd4,0x1b,0x7f,0xed,0x24,0xee,0x53,0x5c,0x15,0x97,0x21,0x7c,
0x5c,0xea,0xab,0xf5,0xd6,0x4b,0xb3,0xbb,0x14,0xf5,0x59,0x9e,0x21,0x90,
0x21,0x99,0x19,0xad,0xa2,0xa6,0xea,0x61,0xc1,0x41,0xe2,0x70,0x77,0xf7,
0x15,0x68,0x96,0x1e,0x5c,0x84,0x97,0xe3,0x5c,0xd2,0xd9,0xfb,0x87,0x6f,
0x11,0x21,0x82,0x43,0x76,0x32,0xa4,0x38,0x7b,0x85,0x22,0x30,0x1e,0x55,
0x79,0x93 };
unsigned char pbData[2048];
BOOL result;
HCRYPTHASH hHash, hHashClone;
HCRYPTPROV prov;
BYTE pbHashValue[36];
BYTE pbSigValue[128];
HCRYPTKEY hKeyExchangeKey;
DWORD hashlen, len, error;
int i;
@ -522,6 +613,61 @@ static void test_hashes(void)
result = CryptReleaseContext(prov, 0);
ok(result, "CryptReleaseContext failed 0x%08x\n", GetLastError());
/* Test CALG_SSL3_SHAMD5 */
result = CryptAcquireContextA(&prov, NULL, szProvider, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
ok(result, "CryptAcquireContext failed 0x%08x\n", GetLastError());
/* Step 1: create an MD5 hash of the data */
result = CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
ok(result, "CryptCreateHash failed 0x%08x\n", GetLastError());
result = CryptHashData(hHash, pbData, sizeof(pbData), 0);
ok(result, "%08x\n", GetLastError());
len = 16;
result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
ok(result, "CryptGetHashParam failed 0x%08x\n", GetLastError());
result = CryptDestroyHash(hHash);
ok(result, "CryptDestroyHash failed 0x%08x\n", GetLastError());
/* Step 2: create a SHA1 hash of the data */
result = CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash);
ok(result, "CryptCreateHash failed 0x%08x\n", GetLastError());
result = CryptHashData(hHash, pbData, sizeof(pbData), 0);
ok(result, "%08x\n", GetLastError());
len = 20;
result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue + 16, &len, 0);
ok(result, "CryptGetHashParam failed 0x%08x\n", GetLastError());
result = CryptDestroyHash(hHash);
ok(result, "CryptDestroyHash failed 0x%08x\n", GetLastError());
/* Step 3: create a CALG_SSL3_SHAMD5 hash handle */
result = CryptCreateHash(hProv, CALG_SSL3_SHAMD5, 0, 0, &hHash);
ok(result, "CryptCreateHash failed 0x%08x\n", GetLastError());
/* Test that CryptHashData fails on this hash */
result = CryptHashData(hHash, pbData, sizeof(pbData), 0);
ok(!result && GetLastError() == NTE_BAD_ALGID, "%08x\n", GetLastError());
result = CryptSetHashParam(hHash, HP_HASHVAL, pbHashValue, 0);
ok(result, "%08x\n", GetLastError());
len = (DWORD)sizeof(abPlainPrivateKey);
result = CryptImportKey(hProv, abPlainPrivateKey, len, 0, 0, &hKeyExchangeKey);
ok(result, "%08x\n", GetLastError());
len = 0;
result = CryptSignHash(hHash, AT_KEYEXCHANGE, NULL, 0, NULL, &len);
ok(result, "%08x\n", GetLastError());
ok(len == 128, "expected len 128, got %d\n", len);
result = CryptSignHash(hHash, AT_KEYEXCHANGE, NULL, 0, pbSigValue, &len);
todo_wine
ok(result, "%08x\n", GetLastError());
todo_wine
ok(!memcmp(pbSigValue, signed_ssl3_shamd5_hash, len), "unexpected value\n");
if (len != 128 || memcmp(pbSigValue, signed_ssl3_shamd5_hash, len))
{
printBytes("expected", signed_ssl3_shamd5_hash,
sizeof(signed_ssl3_shamd5_hash));
printBytes("got", pbSigValue, len);
}
result = CryptDestroyHash(hHash);
ok(result, "CryptDestroyHash failed 0x%08x\n", GetLastError());
result = CryptReleaseContext(prov, 0);
ok(result, "CryptReleaseContext failed 0x%08x\n", GetLastError());
}
static void test_block_cipher_modes(void)
@ -1338,84 +1484,6 @@ static void test_mac(void) {
ok(result, "%08x\n", GetLastError());
}
static BYTE abPlainPrivateKey[596] = {
0x07, 0x02, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x00,
0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x9b, 0x64, 0xef, 0xce,
0x31, 0x7c, 0xad, 0x56, 0xe2, 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0xa4,
0xc5, 0x47, 0x45, 0x85, 0x86, 0xa5, 0xcc, 0xa8,
0xf2, 0x5d, 0x58, 0x07
};
static void test_import_private(void)
{
DWORD dwLen, dwVal;