Bruno Jesus : rsaenh: A 40 bit key on Enhanced provider will not have salt even if asked for.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Aug 5 18:03:06 CDT 2014


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

Author: Bruno Jesus <00cpxxx at gmail.com>
Date:   Tue Aug  5 00:16:05 2014 -0300

rsaenh: A 40 bit key on Enhanced provider will not have salt even if asked for.

---

 dlls/rsaenh/rsaenh.c       | 12 +++++++++++-
 dlls/rsaenh/tests/rsaenh.c | 25 -------------------------
 2 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c
index aa415e7..fa9071d 100644
--- a/dlls/rsaenh/rsaenh.c
+++ b/dlls/rsaenh/rsaenh.c
@@ -873,6 +873,7 @@ static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTK
                            destroy_key, (OBJECTHDR**)&pCryptKey);
     if (hCryptKey != (HCRYPTKEY)INVALID_HANDLE_VALUE)
     {
+        KEYCONTAINER *pKeyContainer = get_key_container(hProv);
         pCryptKey->aiAlgid = aiAlgid;
         pCryptKey->hProv = hProv;
         pCryptKey->dwModeBits = 0;
@@ -882,7 +883,16 @@ static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTK
             pCryptKey->dwPermissions |= CRYPT_EXPORT;
         pCryptKey->dwKeyLen = dwKeyLen >> 3;
         pCryptKey->dwEffectiveKeyLen = 0;
-        if ((dwFlags & CRYPT_CREATE_SALT) || (dwKeyLen == 40 && !(dwFlags & CRYPT_NO_SALT))) 
+
+        /*
+         * For compatibility reasons a 40 bit key on the Enhanced
+         * provider will not have salt
+         */
+        if (pKeyContainer->dwPersonality == RSAENH_PERSONALITY_ENHANCED
+            && (aiAlgid == CALG_RC2 || aiAlgid == CALG_RC4)
+            && (dwFlags & CRYPT_CREATE_SALT) && dwKeyLen == 40)
+            pCryptKey->dwSaltLen = 0;
+        else if ((dwFlags & CRYPT_CREATE_SALT) || (dwKeyLen == 40 && !(dwFlags & CRYPT_NO_SALT)))
             pCryptKey->dwSaltLen = 16 /*FIXME*/ - pCryptKey->dwKeyLen;
         else
             pCryptKey->dwSaltLen = 0;
diff --git a/dlls/rsaenh/tests/rsaenh.c b/dlls/rsaenh/tests/rsaenh.c
index bf105de..41b51c1 100644
--- a/dlls/rsaenh/tests/rsaenh.c
+++ b/dlls/rsaenh/tests/rsaenh.c
@@ -1604,22 +1604,10 @@ static void test_rc2(void)
         result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwDataLen, 24);
         if(result)
         {
-            /* Remove IF when fixed */
-            if(ENHANCED_PROV)
-            {
-            todo_wine
             ok((ENHANCED_PROV && !memcmp(pbData, rc2_40_salt_enh, dwDataLen)) ||
                (STRONG_PROV && !memcmp(pbData, rc2_40_salt_strong, dwDataLen)) ||
                (BASE_PROV && !memcmp(pbData, rc2_40_salt_base, dwDataLen)),
                "RC2 encryption failed!\n");
-            }
-            else
-            {
-            ok((ENHANCED_PROV && !memcmp(pbData, rc2_40_salt_enh, dwDataLen)) ||
-               (STRONG_PROV && !memcmp(pbData, rc2_40_salt_strong, dwDataLen)) ||
-               (BASE_PROV && !memcmp(pbData, rc2_40_salt_base, dwDataLen)),
-               "RC2 encryption failed!\n");
-            }
         }
         else /* <= XP */
         {
@@ -1640,7 +1628,6 @@ static void test_rc2(void)
         if (!ENHANCED_PROV)
             ok(dwLen == 11, "Expected 11, got %d\n", dwLen);
         else
-            todo_wine
             ok(dwLen == 0, "Expected 0, got %d\n", dwLen);
 
         result = CryptDestroyKey(hKey);
@@ -1778,20 +1765,9 @@ static void test_rc4(void)
         SetLastError(0xdeadbeef);
         result = CryptEncrypt(hKey, 0, TRUE, 0, pbData, &dwDataLen, 24);
         ok(result, "%08x\n", GetLastError());
-        /* Remove IF when fixed */
-        if (ENHANCED_PROV)
-        {
-        todo_wine
-        ok((ENHANCED_PROV && !memcmp(pbData, rc4_40_salt, dwDataLen)) ||
-           (!ENHANCED_PROV && !memcmp(pbData, rc4_40_salt_base, dwDataLen)),
-           "RC4 encryption failed!\n");
-        }
-        else
-        {
         ok((ENHANCED_PROV && !memcmp(pbData, rc4_40_salt, dwDataLen)) ||
            (!ENHANCED_PROV && !memcmp(pbData, rc4_40_salt_base, dwDataLen)),
            "RC4 encryption failed!\n");
-        }
 
         dwLen = sizeof(DWORD);
         dwKeyLen = 12345;
@@ -1806,7 +1782,6 @@ static void test_rc4(void)
         if (!ENHANCED_PROV)
             ok(dwLen == 11, "Expected 11, got %d\n", dwLen);
         else
-            todo_wine
             ok(dwLen == 0, "Expected 0, got %d\n", dwLen);
 
         result = CryptDestroyKey(hKey);




More information about the wine-cvs mailing list