Juan Lang : rsaenh: Add simple tests for SHA-256, SHA-384, and SHA-512.

Alexandre Julliard julliard at winehq.org
Mon Mar 15 12:19:39 CDT 2010


Module: wine
Branch: master
Commit: 972031643fc10a923afb372d1e713ebb4bb52286
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=972031643fc10a923afb372d1e713ebb4bb52286

Author: Juan Lang <juan.lang at gmail.com>
Date:   Mon Mar  8 10:56:56 2010 -0800

rsaenh: Add simple tests for SHA-256, SHA-384, and SHA-512.

---

 dlls/rsaenh/tests/rsaenh.c |  112 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/dlls/rsaenh/tests/rsaenh.c b/dlls/rsaenh/tests/rsaenh.c
index 743a300..ce907f5 100644
--- a/dlls/rsaenh/tests/rsaenh.c
+++ b/dlls/rsaenh/tests/rsaenh.c
@@ -452,6 +452,17 @@ static void test_hashes(void)
 
     result = CryptDestroyHash(hHash);
     ok(result, "%08x\n", GetLastError());
+
+    /* The SHA-2 variants aren't supported in the RSA full provider */
+    result = CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash);
+    ok(!result && GetLastError() == NTE_BAD_ALGID,
+       "expected NTE_BAD_ALGID, got %08x\n", GetLastError());
+    result = CryptCreateHash(hProv, CALG_SHA_384, 0, 0, &hHash);
+    ok(!result && GetLastError() == NTE_BAD_ALGID,
+       "expected NTE_BAD_ALGID, got %08x\n", GetLastError());
+    result = CryptCreateHash(hProv, CALG_SHA_512, 0, 0, &hHash);
+    ok(!result && GetLastError() == NTE_BAD_ALGID,
+       "expected NTE_BAD_ALGID, got %08x\n", GetLastError());
 }
 
 static void test_block_cipher_modes(void)
@@ -758,6 +769,106 @@ static void test_aes(int keylen)
     ok(result, "%08x\n", GetLastError());
 }
 
+static void test_sha2(void)
+{
+    static const unsigned char sha256hash[32] = {
+        0x10, 0xfc, 0x3c, 0x51, 0xa1, 0x52, 0xe9, 0x0e, 0x5b, 0x90,
+        0x31, 0x9b, 0x60, 0x1d, 0x92, 0xcc, 0xf3, 0x72, 0x90, 0xef,
+        0x53, 0xc3, 0x5f, 0xf9, 0x25, 0x07, 0x68, 0x7d, 0x8a, 0x91,
+        0x1a, 0x08
+    };
+    static const unsigned char sha384hash[48] = {
+        0x98, 0xd3, 0x3f, 0x89, 0x0b, 0x23, 0x33, 0x44, 0x61, 0x32,
+        0x5a, 0x7c, 0xa3, 0x03, 0x89, 0xb5, 0x11, 0xd7, 0x41, 0xc8,
+        0x54, 0x6b, 0x12, 0x0c, 0x40, 0x15, 0xb6, 0x2a, 0x03, 0x43,
+        0xe5, 0x64, 0x7f, 0x10, 0x1e, 0xae, 0x47, 0xa9, 0x39, 0x05,
+        0x6f, 0x40, 0x60, 0x94, 0xd6, 0xad, 0x80, 0x55
+    };
+    static const unsigned char sha512hash[64] = {
+        0x37, 0x86, 0x0e, 0x7d, 0x25, 0xd9, 0xf9, 0x84, 0x3e, 0x3d,
+        0xc7, 0x13, 0x95, 0x73, 0x42, 0x04, 0xfd, 0x13, 0xad, 0x23,
+        0x39, 0x16, 0x32, 0x5f, 0x99, 0x3e, 0x3c, 0xee, 0x3f, 0x11,
+        0x36, 0xf9, 0xc9, 0x66, 0x08, 0x70, 0xcc, 0x49, 0xd8, 0xe0,
+        0x7d, 0xa1, 0x57, 0x62, 0x71, 0xa6, 0xc9, 0xa4, 0x24, 0x60,
+        0xfc, 0xde, 0x9d, 0xb2, 0xf1, 0xd2, 0xc2, 0xfb, 0x2d, 0xbf,
+        0xb7, 0xf4, 0x81, 0xd4
+    };
+    unsigned char pbData[2048];
+    BOOL result;
+    HCRYPTHASH hHash;
+    BYTE pbHashValue[64];
+    DWORD hashlen, len;
+    int i;
+
+    for (i=0; i<2048; i++) pbData[i] = (unsigned char)i;
+
+    /* SHA-256 hash */
+    result = CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash);
+    todo_wine
+    ok(result, "%08x\n", GetLastError());
+    if (result) {
+        len = sizeof(DWORD);
+        result = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)&hashlen, &len, 0);
+        ok(result && (hashlen == 32), "%08x, hashlen: %d\n", GetLastError(), hashlen);
+
+        result = CryptHashData(hHash, pbData, sizeof(pbData), 0);
+        ok(result, "%08x\n", GetLastError());
+
+        len = 32;
+        result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
+        ok(result, "%08x\n", GetLastError());
+
+        ok(!memcmp(pbHashValue, sha256hash, 32), "Wrong SHA-256 hash!\n");
+
+        result = CryptDestroyHash(hHash);
+        ok(result, "%08x\n", GetLastError());
+    }
+
+    /* SHA-384 hash */
+    result = CryptCreateHash(hProv, CALG_SHA_384, 0, 0, &hHash);
+    todo_wine
+    ok(result, "%08x\n", GetLastError());
+    if (result) {
+        len = sizeof(DWORD);
+        result = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)&hashlen, &len, 0);
+        ok(result && (hashlen == 48), "%08x, hashlen: %d\n", GetLastError(), hashlen);
+
+        result = CryptHashData(hHash, pbData, sizeof(pbData), 0);
+        ok(result, "%08x\n", GetLastError());
+
+        len = 48;
+        result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
+        ok(result, "%08x\n", GetLastError());
+
+        ok(!memcmp(pbHashValue, sha384hash, 48), "Wrong SHA-384 hash!\n");
+
+        result = CryptDestroyHash(hHash);
+        ok(result, "%08x\n", GetLastError());
+    }
+
+    /* SHA-512 hash */
+    result = CryptCreateHash(hProv, CALG_SHA_512, 0, 0, &hHash);
+    todo_wine
+    ok(result, "%08x\n", GetLastError());
+    if (result) {
+        len = sizeof(DWORD);
+        result = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)&hashlen, &len, 0);
+        ok(result && (hashlen == 64), "%08x, hashlen: %d\n", GetLastError(), hashlen);
+
+        result = CryptHashData(hHash, pbData, sizeof(pbData), 0);
+        ok(result, "%08x\n", GetLastError());
+
+        len = 64;
+        result = CryptGetHashParam(hHash, HP_HASHVAL, pbHashValue, &len, 0);
+        ok(result, "%08x\n", GetLastError());
+
+        ok(!memcmp(pbHashValue, sha512hash, 64), "Wrong SHA-512 hash!\n");
+
+        result = CryptDestroyHash(hHash);
+        ok(result, "%08x\n", GetLastError());
+    }
+}
+
 static void test_rc2(void)
 {
     static const BYTE rc2_40_encrypted[16] = {
@@ -2581,5 +2692,6 @@ START_TEST(rsaenh)
     test_aes(128);
     test_aes(192);
     test_aes(256);
+    test_sha2();
     clean_up_aes_environment();
 }




More information about the wine-cvs mailing list