[crypt32] CryptProtectData test

Kees Cook kees at outflux.net
Wed May 18 08:03:18 CDT 2005


ChangeLog:
	Adds tests for CryptProtectData function.

-- 
Kees Cook                                            @outflux.net
-------------- next part --------------
--- dlls/crypt32/tests/protectdata.c.orig	2005-05-18 05:59:16.017897741 -0700
+++ dlls/crypt32/tests/protectdata.c	2005-05-18 06:02:04.077803129 -0700
@@ -44,6 +44,83 @@
 #define todo_wine
 #endif
 
+#include <winerror.h>
+#include <wincrypt.h>
+
+static const char * secret  = "I am a super secret string that no one can see!";
+static const char * secret2 = "I am a super secret string indescribable string";
+static const char * key = "Wibble wibble wibble";
+static const WCHAR desc[] = {'U','l','t','r','a',' ','s','e','c','r','e','t',' ','t','e','s','t',' ','m','e','s','s','a','g','e',0};
+static BOOL protected = FALSE; /* if true, the unprotect tests can run */
+static DATA_BLOB cipher;
+static DATA_BLOB cipher_entropy;
+static DATA_BLOB cipher_no_desc;
+
+static void test_cryptprotectdata(void)
+{
+    LONG r;
+    DATA_BLOB plain;
+    DATA_BLOB entropy;
+
+    plain.pbData=(void*)secret;
+    plain.cbData=strlen(secret)+1;
+
+    entropy.pbData=(void*)key;
+    entropy.cbData=strlen(key)+1;
+
+    SetLastError(0xDEADBEEF);
+    protected = CryptProtectData(NULL,desc,NULL,NULL,NULL,0,&cipher);
+    ok(!protected, "Encrypting without plain data source.\n");
+    r = GetLastError();
+    ok2(r == ERROR_INVALID_PARAMETER, "Wrong (%lu) GetLastError seen\n",r);
+
+    SetLastError(0xDEADBEEF);
+    protected = CryptProtectData(&plain,desc,NULL,NULL,NULL,0,NULL);
+    ok(!protected, "Encrypting without cipher destination.\n");
+    r = GetLastError();
+    ok2(r == ERROR_INVALID_PARAMETER, "Wrong (%lu) GetLastError seen\n",r);
+
+    cipher.pbData=NULL;
+    cipher.cbData=0;
+
+    /* without entropy */
+    SetLastError(0xDEADBEEF);
+    protected = CryptProtectData(&plain,desc,NULL,NULL,NULL,0,&cipher);
+    ok(protected, "Encrypting without entropy.\n");
+    r = GetLastError();
+    ok2(r == ERROR_SUCCESS, "Wrong (%lu) GetLastError seen\n",r);
+
+    cipher_entropy.pbData=NULL;
+    cipher_entropy.cbData=0;
+
+    /* with entropy */
+    SetLastError(0xDEADBEEF);
+    protected = CryptProtectData(&plain,desc,&entropy,NULL,NULL,0,&cipher_entropy);
+    ok(protected, "Encrypting with entropy.\n");
+    r = GetLastError();
+    ok2(r == ERROR_SUCCESS, "Wrong (%lu) GetLastError seen\n",r);
+
+    cipher_no_desc.pbData=NULL;
+    cipher_no_desc.cbData=0;
+
+    /* with entropy but no description */
+    plain.pbData=(void*)secret2;
+    plain.cbData=strlen(secret2)+1;
+    SetLastError(0xDEADBEEF);
+    protected = CryptProtectData(&plain,NULL,&entropy,NULL,NULL,0,&cipher_no_desc);
+    ok(protected, "Encrypting with entropy and no description.\n");
+    r = GetLastError();
+    ok2(r == ERROR_SUCCESS, "Wrong (%lu) GetLastError seen\n",r);
+}
+
 START_TEST(protectdata)
 {
+    protected=FALSE;
+
+    test_cryptprotectdata();
+
+    /* deinit globals here */
+    if (cipher.pbData) LocalFree(cipher.pbData);
+    if (cipher_entropy.pbData) LocalFree(cipher_entropy.pbData);
+    if (cipher_no_desc.pbData) LocalFree(cipher_no_desc.pbData);
 }


More information about the wine-patches mailing list