Author: akhaldi
Date: Fri Dec  6 15:04:04 2013
New Revision: 61234

URL: http://svn.reactos.org/svn/reactos?rev=61234&view=rev
Log:
[ADVAPI32/CRYPT]
* Sync with Wine 1.7.1.
CORE-7469

Modified:
    trunk/reactos/dll/win32/advapi32/crypt/crypt.c
    trunk/reactos/dll/win32/advapi32/crypt/crypt.h
    trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c
    trunk/reactos/dll/win32/advapi32/crypt/crypt_lmhash.c
    trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c
    trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c
    trunk/reactos/dll/win32/advapi32/misc/sysfunc.c
    trunk/reactos/media/doc/README.WINE

Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/crypt.c?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/crypt/crypt.c      [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/crypt/crypt.c      [iso-8859-1] Fri Dec  6 
15:04:04 2013
@@ -24,6 +24,7 @@
  *  - Thread-safing
   */
 
+#define WINE_STRICT_PROTOTYPES
 #include <advapi32.h>
 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
 
@@ -44,7 +45,7 @@
     } while (--longs);
 }
 
-static HWND crypt_hWindow ;
+static HWND crypt_hWindow;
 
 #define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size))
 #define CRYPT_Free(buffer) (LocalFree(buffer))
@@ -102,33 +103,38 @@
        return keyname;
 }
 
-/* CRYPT_UnicodeTOANSI
+/* CRYPT_UnicodeToANSI
  * wstr - unicode string
- * str - pointer to ANSI string
- * strsize - size of buffer pointed to by str or -1 if we have to do the 
allocation
+ * str - pointer to ANSI string or pointer to null pointer if we have to do 
the allocation
+ * strsize - size of buffer pointed to by str
  *
  * returns TRUE if unsuccessful, FALSE otherwise.
  * if wstr is NULL, returns TRUE and sets str to NULL! Value of str should be 
checked after call
  */
 static inline BOOL CRYPT_UnicodeToANSI(LPCWSTR wstr, LPSTR* str, int strsize)
 {
-       int count;
-
        if (!wstr)
        {
                *str = NULL;
                return TRUE;
        }
-       count = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
-       if (strsize == -1)
-               *str = CRYPT_Alloc(count * sizeof(CHAR));
-       else
-               count = min( count, strsize );
+
+       if (!*str)
+       {
+               strsize = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, 
NULL, NULL);
+               *str = CRYPT_Alloc(strsize * sizeof(CHAR));
+       }
+       else if (strsize < 0)
+       {
+               strsize = INT_MAX; /* windows will pretend that the buffer is 
infinitely long */
+       }
+
        if (*str)
        {
-               WideCharToMultiByte(CP_ACP, 0, wstr, -1, *str, count, NULL, 
NULL);
+               WideCharToMultiByte(CP_ACP, 0, wstr, -1, *str, strsize, NULL, 
NULL);
                return TRUE;
        }
+
        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
        return FALSE;
 }
@@ -175,12 +181,9 @@
        return TRUE;
 }
 
-static BOOL CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
-{
-       if (!phWnd)
-               return FALSE;
-       *phWnd = crypt_hWindow;
-       return TRUE;
+static void CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
+{
+       if (phWnd) *phWnd = crypt_hWindow;
 }
 
 #define CRYPT_GetProvFunc(name) \
@@ -233,7 +236,7 @@
 
        /* FIXME: Not sure what the pbContextInfo field is for.
         *        Does it need memory allocation?
-        */
+         */
        provider->pVTable->Version = 3;
        provider->pVTable->FuncVerifyImage = CRYPT_VerifyImage;
        provider->pVTable->FuncReturnhWnd = CRYPT_ReturnhWnd;
@@ -477,13 +480,13 @@
                goto error;
        }
        pProv->pVTable->dwProvType = dwProvType;
-       if(!CRYPT_UnicodeToANSI(provname, &provnameA, -1))
+       if(!CRYPT_UnicodeToANSI(provname, &provnameA, 0))
        {
                /* CRYPT_UnicodeToANSI calls SetLastError */
                goto error;
        }
        pProv->pVTable->pszProvName = provnameA;
-       if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, -1))
+       if(!CRYPT_UnicodeToANSI(pszContainer, &pszContainerA, 0))
        {
                /* CRYPT_UnicodeToANSI calls SetLastError */
                goto error;
@@ -541,8 +544,8 @@
        PWSTR pProvider = NULL, pContainer = NULL;
        BOOL ret = FALSE;
 
-       TRACE("(%p, %s, %s, %d, %08x)\n", phProv, pszContainer,
-               pszProvider, dwProvType, dwFlags);
+       TRACE("(%p, %s, %s, %d, %08x)\n", phProv, debugstr_a(pszContainer),
+              debugstr_a(pszProvider), dwProvType, dwFlags);
 
        if ( !CRYPT_ANSIToUnicode(pszContainer, &pContainer, -1) )
        {
@@ -716,12 +719,8 @@
 
        TRACE("(0x%lx, 0x%x, 0x%lx, %08x, %p)\n", hProv, Algid, hKey, dwFlags, 
phHash);
 
-       if (!prov)
-       {
-               SetLastError(ERROR_INVALID_HANDLE);
-               return FALSE;
-       }
-       if (!phHash || prov->dwMagic != MAGIC_CRYPTPROV)
+       if (!prov || !phHash || prov->dwMagic != MAGIC_CRYPTPROV ||
+               (key && key->dwMagic != MAGIC_CRYPTKEY))
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -738,7 +737,7 @@
        }
 
        hash->pProvider = prov;
-
+       hash->dwMagic = MAGIC_CRYPTHASH;
        if (prov->pFuncs->pCPCreateHash(prov->hPrivate, Algid,
                        key ? key->hPrivate : 0, 0, &hash->hPrivate))
         {
@@ -747,6 +746,7 @@
         }
 
        /* CSP error! */
+       hash->dwMagic = 0;
        CRYPT_Free(hash);
        *phHash = 0;
        return FALSE;
@@ -779,7 +779,9 @@
 
        TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hHash, Final, 
dwFlags, pbData, pdwDataLen);
 
-       if (!key || !pbData || !pdwDataLen || !key->pProvider || 
key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+       if (!key || !pbData || !pdwDataLen ||
+               !key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
+               key->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -820,7 +822,7 @@
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
        }
-       if (!phKey || prov->dwMagic != MAGIC_CRYPTPROV)
+       if (!phKey || prov->dwMagic != MAGIC_CRYPTPROV || hash->dwMagic != 
MAGIC_CRYPTHASH)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -832,6 +834,7 @@
        }
 
        key->pProvider = prov;
+       key->dwMagic = MAGIC_CRYPTKEY;
        if (prov->pFuncs->pCPDeriveKey(prov->hPrivate, Algid, hash->hPrivate, 
dwFlags, &key->hPrivate))
         {
             *phKey = (HCRYPTKEY)key;
@@ -839,6 +842,7 @@
         }
 
        /* CSP error! */
+       key->dwMagic = 0;
        CRYPT_Free(key);
        *phKey = 0;
        return FALSE;
@@ -870,7 +874,8 @@
                return FALSE;
        }
 
-       if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+       if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
+               hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -878,6 +883,7 @@
 
        prov = hash->pProvider;
        ret = prov->pFuncs->pCPDestroyHash(prov->hPrivate, hash->hPrivate);
+       hash->dwMagic = 0;
        CRYPT_Free(hash);
        return ret;
 }
@@ -908,7 +914,8 @@
                return FALSE;
        }
 
-       if (!key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
+       if (!key->pProvider || key->dwMagic != MAGIC_CRYPTKEY ||
+               key->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -916,6 +923,7 @@
 
        prov = key->pProvider;
        ret = prov->pFuncs->pCPDestroyKey(prov->hPrivate, key->hPrivate);
+       key->dwMagic = 0;
        CRYPT_Free(key);
        return ret;
 }
@@ -944,8 +952,8 @@
        TRACE("(0x%lx, %p, %08x, %p)\n", hHash, pdwReserved, dwFlags, phHash);
 
        orghash = (PCRYPTHASH)hHash;
-       if (!orghash || pdwReserved || !phHash || !orghash->pProvider || 
-               orghash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+       if (!orghash || pdwReserved || !phHash || !orghash->pProvider ||
+               orghash->dwMagic != MAGIC_CRYPTHASH || 
orghash->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -965,11 +973,13 @@
        }
 
        newhash->pProvider = prov;
+       newhash->dwMagic = MAGIC_CRYPTHASH;
        if (prov->pFuncs->pCPDuplicateHash(prov->hPrivate, orghash->hPrivate, 
pdwReserved, dwFlags, &newhash->hPrivate))
        {
                *phHash = (HCRYPTHASH)newhash;
                return TRUE;
        }
+       newhash->dwMagic = 0;
        CRYPT_Free(newhash);
        return FALSE;
 }
@@ -997,7 +1007,8 @@
        TRACE("(0x%lx, %p, %08x, %p)\n", hKey, pdwReserved, dwFlags, phKey);
 
        orgkey = (PCRYPTKEY)hKey;
-       if (!orgkey || pdwReserved || !phKey || !orgkey->pProvider || 
+       if (!orgkey || pdwReserved || !phKey || !orgkey->pProvider ||
+               orgkey->dwMagic != MAGIC_CRYPTKEY ||
                orgkey->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
@@ -1018,11 +1029,13 @@
        }
 
        newkey->pProvider = prov;
+       newkey->dwMagic = MAGIC_CRYPTKEY;
        if (prov->pFuncs->pCPDuplicateKey(prov->hPrivate, orgkey->hPrivate, 
pdwReserved, dwFlags, &newkey->hPrivate))
        {
                *phKey = (HCRYPTKEY)newkey;
                return TRUE;
        }
+       newkey->dwMagic = 0;
        CRYPT_Free(newkey);
        return FALSE;
 }
@@ -1059,7 +1072,8 @@
 
        TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p, %d)\n", hKey, hHash, Final, 
dwFlags, pbData, pdwDataLen, dwBufLen);
 
-       if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic 
!= MAGIC_CRYPTPROV)
+       if (!key || !pdwDataLen || !key->pProvider ||
+               key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1189,7 +1203,7 @@
 {
        PWSTR str = NULL;
        DWORD bufsize;
-       BOOL ret; /* = FALSE; */
+       BOOL ret;
 
        TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
                        pdwProvType, pszProvName, pcbProvName);
@@ -1276,19 +1290,24 @@
        if (dwIndex >= numkeys)
        {
                SetLastError(ERROR_NO_MORE_ITEMS);
+               RegCloseKey(hKey);
                return FALSE;
        }
        keylen++;
        if ( !(keyname = CRYPT_Alloc(keylen*sizeof(WCHAR))) )
        {
                SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+               RegCloseKey(hKey);
                return FALSE;
        }
        if ( RegEnumKeyW(hKey, dwIndex, keyname, keylen) ) {
                 CRYPT_Free(keyname);
+               RegCloseKey(hKey);
                return FALSE;
         }
        RegOpenKeyW(hKey, keyname, &hSubkey);
+       RegCloseKey(hKey);
+
        ch = keyname + strlenW(keyname);
        /* Convert "Type 000" to 0, etc/ */
        *pdwProvType = *(--ch) - '0';
@@ -1300,11 +1319,11 @@
        if (result)
        {
                SetLastError(result);
+               RegCloseKey(hSubkey);
                return FALSE;
        }
 
        RegCloseKey(hSubkey);
-       RegCloseKey(hKey);
        return TRUE;
 }
 
@@ -1375,7 +1394,8 @@
 
        TRACE("(0x%lx, 0x%lx, %d, %08x, %p, %p)\n", hKey, hExpKey, dwBlobType, 
dwFlags, pbData, pdwDataLen);
 
-       if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic 
!= MAGIC_CRYPTPROV)
+       if (!key || !pdwDataLen || !key->pProvider ||
+               key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1408,11 +1428,6 @@
 
        TRACE("(0x%lx, %d, %08x, %p)\n", hProv, Algid, dwFlags, phKey);
 
-       if (!prov)
-       {
-               SetLastError(ERROR_INVALID_HANDLE);
-               return FALSE;
-       }
        if (!phKey || !prov || prov->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
@@ -1425,7 +1440,7 @@
        }
 
        key->pProvider = prov;
-
+       key->dwMagic = MAGIC_CRYPTKEY;
        if (prov->pFuncs->pCPGenKey(prov->hPrivate, Algid, dwFlags, 
&key->hPrivate))
         {
             *phKey = (HCRYPTKEY)key;
@@ -1433,6 +1448,7 @@
         }
 
        /* CSP error! */
+       key->dwMagic = 0;
        CRYPT_Free(key);
        return FALSE;
 }
@@ -1494,6 +1510,8 @@
        CRYPT_Free(keyname);
        
        result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, 
pcbProvName); 
+       RegCloseKey(hKey);
+
        if (result)
        {
                if (result != ERROR_MORE_DATA)
@@ -1504,7 +1522,6 @@
                return FALSE;
        }
        
-       RegCloseKey(hKey);
        return TRUE;
 }
 
@@ -1518,7 +1535,7 @@
 {
        PWSTR str = NULL;
        DWORD bufsize;
-       BOOL ret = FALSE;
+       BOOL ret;
 
        TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType, pdwReserved, dwFlags, 
pszProvName, pcbProvName);
 
@@ -1571,7 +1588,8 @@
 
        TRACE("(0x%lx, %d, %p, %p, %08x)\n", hHash, dwParam, pbData, 
pdwDataLen, dwFlags);
 
-       if (!hash || !pdwDataLen || !hash->pProvider || 
hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+       if (!hash || !pdwDataLen || !hash->pProvider ||
+               hash->dwMagic != MAGIC_CRYPTHASH || hash->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1609,7 +1627,8 @@
 
        TRACE("(0x%lx, %d, %p, %p, %08x)\n", hKey, dwParam, pbData, pdwDataLen, 
dwFlags);
 
-       if (!key || !pdwDataLen || !key->pProvider || key->pProvider->dwMagic 
!= MAGIC_CRYPTPROV)
+       if (!key || !pdwDataLen || !key->pProvider ||
+               key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1693,7 +1712,7 @@
        }
 
        key->pProvider = prov;
-
+       key->dwMagic = MAGIC_CRYPTKEY;
        if (prov->pFuncs->pCPGetUserKey(prov->hPrivate, dwKeySpec, 
&key->hPrivate))
         {
             *phUserKey = (HCRYPTKEY)key;
@@ -1701,6 +1720,7 @@
         }
 
        /* CSP Error */
+       key->dwMagic = 0;
        CRYPT_Free(key);
        *phUserKey = 0;
        return FALSE;
@@ -1733,7 +1753,8 @@
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
        }
-       if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+       if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
+               hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1771,7 +1792,8 @@
                return FALSE;
        }
 
-       if (!hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
+       if (!hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH ||
+               hash->pProvider->dwMagic != MAGIC_CRYPTPROV || key->dwMagic != 
MAGIC_CRYPTKEY)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1806,7 +1828,9 @@
 
        TRACE("(0x%lx, %p, %d, 0x%lx, %08x, %p)\n", hProv, pbData, dwDataLen, 
hPubKey, dwFlags, phKey);
 
-       if (!prov || !pbData || !dwDataLen || !phKey || prov->dwMagic != 
MAGIC_CRYPTPROV)
+       if (!prov || !pbData || !dwDataLen || !phKey ||
+               prov->dwMagic != MAGIC_CRYPTPROV ||
+               (pubkey && pubkey->dwMagic != MAGIC_CRYPTKEY))
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1819,6 +1843,7 @@
        }
 
        importkey->pProvider = prov;
+       importkey->dwMagic = MAGIC_CRYPTKEY;
        if (prov->pFuncs->pCPImportKey(prov->hPrivate, pbData, dwDataLen,
                        pubkey ? pubkey->hPrivate : 0, dwFlags, 
&importkey->hPrivate))
        {
@@ -1826,6 +1851,7 @@
                return TRUE;
        }
 
+       importkey->dwMagic = 0;
        CRYPT_Free(importkey);
        return FALSE;
 }
@@ -1866,7 +1892,8 @@
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
        }
-       if (!pdwSigLen || !hash->pProvider || hash->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
+       if (!pdwSigLen || !hash->pProvider || hash->dwMagic != MAGIC_CRYPTHASH 
||
+                hash->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1920,7 +1947,8 @@
 
        TRACE("(0x%lx, %d, %p, %08x)\n", hHash, dwParam, pbData, dwFlags);
 
-       if (!hash || !pbData || !hash->pProvider || hash->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
+       if (!hash || !pbData || !hash->pProvider ||
+               hash->dwMagic != MAGIC_CRYPTHASH || hash->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -1953,7 +1981,8 @@
 
        TRACE("(0x%lx, %d, %p, %08x)\n", hKey, dwParam, pbData, dwFlags);
 
-       if (!key || !pbData || !key->pProvider || key->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
+       if (!key || !pbData || !key->pProvider ||
+               key->dwMagic != MAGIC_CRYPTKEY || key->pProvider->dwMagic != 
MAGIC_CRYPTPROV)
        {
                SetLastError(ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -2189,7 +2218,7 @@
        TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature,
                        dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags);
 
-       if (!hash || !key ||
+       if (!hash || !key || key->dwMagic != MAGIC_CRYPTKEY || hash->dwMagic != 
MAGIC_CRYPTHASH ||
            !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV ||
            !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV)
        {
@@ -2222,3 +2251,132 @@
 
        return result;
 }
+
+#ifndef __REACTOS__
+/******************************************************************************
+ * SystemFunction030   (ADVAPI32.@)
+ *
+ * Tests if two blocks of 16 bytes are equal
+ *
+ * PARAMS
+ *  b1,b2   [I] block of 16 bytes
+ *
+ * RETURNS
+ *  TRUE  if blocks are the same
+ *  FALSE if blocks are different
+ */
+BOOL WINAPI SystemFunction030(LPCVOID b1, LPCVOID b2)
+{
+    return !memcmp(b1, b2, 0x10);
+}
+
+/******************************************************************************
+ * SystemFunction035   (ADVAPI32.@)
+ *
+ * Described here:
+http://disc.server.com/discussion.cgi?disc=148775;article=942;title=Coding%2FASM%2FSystem
+ *
+ * NOTES
+ *  Stub, always return TRUE.
+ */
+BOOL WINAPI SystemFunction035(LPCSTR lpszDllFilePath)
+{
+    FIXME("%s: stub\n", debugstr_a(lpszDllFilePath));
+    return TRUE;
+}
+
+/******************************************************************************
+ * SystemFunction036   (ADVAPI32.@)
+ *
+ * MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h
+ *
+ * PARAMS
+ *  pbBufer [O] Pointer to memory to receive random bytes.
+ *  dwLen   [I] Number of random bytes to fetch.
+ *
+ * RETURNS
+ *  Success: TRUE
+ *  Failure: FALSE
+ */
+
+BOOLEAN WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen)
+{
+    int dev_random;
+
+    dev_random = open("/dev/urandom", O_RDONLY);
+    if (dev_random != -1)
+    {
+        if (read(dev_random, pbBuffer, dwLen) == (ssize_t)dwLen)
+        {
+            close(dev_random);
+            return TRUE;
+        }
+        close(dev_random);
+    }
+    else
+        FIXME("couldn't open /dev/urandom\n");
+    SetLastError(NTE_FAIL);
+    return FALSE;
+}    
+    
+/*
+   These functions have nearly identical prototypes to CryptProtectMemory and 
CryptUnprotectMemory,
+   in crypt32.dll.
+ */
+
+/******************************************************************************
+ * SystemFunction040   (ADVAPI32.@)
+ *
+ * MSDN documents this function as RtlEncryptMemory and declares it in 
ntsecapi.h.
+ *
+ * PARAMS
+ *  memory [I/O] Pointer to memory to encrypt.
+ *  length [I] Length of region to encrypt in bytes.
+ *  flags  [I] Control whether other processes are able to decrypt the memory.
+ *    RTL_ENCRYPT_OPTION_SAME_PROCESS 
+ *    RTL_ENCRYPT_OPTION_CROSS_PROCESS 
+ *    RTL_ENCRYPT_OPTION_SAME_LOGON
+ *    
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: NTSTATUS error code
+ *
+ * NOTES
+ *  length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
+ *  If flags are specified when encrypting, the same flag value must be given
+ *  when decrypting the memory.
+ */
+NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)
+{
+       FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory, length, flags);
+       return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction041  (ADVAPI32.@)
+ *
+ * MSDN documents this function as RtlDecryptMemory and declares it in 
ntsecapi.h.
+ *
+ * PARAMS
+ *  memory [I/O] Pointer to memory to decrypt.
+ *  length [I] Length of region to decrypt in bytes.
+ *  flags  [I] Control whether other processes are able to decrypt the memory.
+ *    RTL_ENCRYPT_OPTION_SAME_PROCESS
+ *    RTL_ENCRYPT_OPTION_CROSS_PROCESS
+ *    RTL_ENCRYPT_OPTION_SAME_LOGON
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: NTSTATUS error code
+ *
+ * NOTES
+ *  length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
+ *  If flags are specified when encrypting, the same flag value must be given
+ *  when decrypting the memory.
+ */
+NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)
+{
+       FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, flags);
+       return STATUS_SUCCESS;
+}
+#endif /* !__REACTOS __ */

Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/crypt.h?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/crypt/crypt.h      [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/crypt/crypt.h      [iso-8859-1] Fri Dec  6 
15:04:04 2013
@@ -57,6 +57,8 @@
 } PROVFUNCS, *PPROVFUNCS;
 
 #define MAGIC_CRYPTPROV 0xA39E741F
+#define MAGIC_CRYPTKEY  0xA39E741E
+#define MAGIC_CRYPTHASH 0xA39E741D
 
 typedef struct tagCRYPTPROV
 {
@@ -70,12 +72,14 @@
 
 typedef struct tagCRYPTKEY
 {
+       DWORD dwMagic;
        PCRYPTPROV pProvider;
         HCRYPTKEY hPrivate;    /*CSP's handle - Should not be given to 
application under any circumstances!*/
 } CRYPTKEY, *PCRYPTKEY;
 
 typedef struct tagCRYPTHASH
 {
+       DWORD dwMagic;
        PCRYPTPROV pProvider;
         HCRYPTHASH hPrivate;    /*CSP's handle - Should not be given to 
application under any circumstances!*/
 } CRYPTHASH, *PCRYPTHASH;
@@ -83,9 +87,9 @@
 #define MAXPROVTYPES 999
 
 extern unsigned char *CRYPT_DEShash( unsigned char *dst, const unsigned char 
*key,
-                                     const unsigned char *src );
+                                     const unsigned char *src ) 
DECLSPEC_HIDDEN;
 extern unsigned char *CRYPT_DESunhash( unsigned char *dst, const unsigned char 
*key,
-                                       const unsigned char *src );
+                                       const unsigned char *src ) 
DECLSPEC_HIDDEN;
 
 void byteReverse(unsigned char *buf, unsigned longs);
 struct ustring {
@@ -111,7 +115,6 @@
 VOID WINAPI MD4Final(MD4_CTX *ctx);
 void arc4_init(arc4_info *a4i, const BYTE *key, unsigned int keyLen);
 void arc4_ProcessString(arc4_info *a4i, BYTE *inoutString, unsigned int 
length);
-NTSTATUS WINAPI SystemFunction032(struct ustring *data, struct ustring *key);
-
+NTSTATUS WINAPI SystemFunction032(struct ustring *data, const struct ustring 
*key);
 
 #endif /* __WINE_CRYPT_H_ */

Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c [iso-8859-1] Fri Dec  6 
15:04:04 2013
@@ -17,6 +17,7 @@
  *  License along with this library; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
+
 /* http://cryptopp.sourceforge.net/docs/ref521/arc4_8cpp-source.html */
 
 #include <advapi32.h>
@@ -65,3 +66,30 @@
     a4i->y = y;
 }
 
+#ifndef __REACTOS__
+/******************************************************************************
+ * SystemFunction032  [ADVAPI32.@]
+ *
+ * Encrypts a string data using ARC4
+ *
+ * PARAMS
+ *   data    [I/O] data to encrypt
+ *   key     [I] key data
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ * NOTES
+ *  see http://web.it.kth.se/~rom/ntsec.html#crypto-strongavail
+ */
+NTSTATUS WINAPI SystemFunction032(struct ustring *data, const struct ustring 
*key)
+{
+    arc4_info a4i;
+
+    arc4_init(&a4i, key->Buffer, key->Length);
+    arc4_ProcessString(&a4i, data->Buffer, data->Length);
+
+    return STATUS_SUCCESS;
+}
+#endif

Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt_lmhash.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/crypt_lmhash.c?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/crypt/crypt_lmhash.c       [iso-8859-1] 
(original)
+++ trunk/reactos/dll/win32/advapi32/crypt/crypt_lmhash.c       [iso-8859-1] 
Fri Dec  6 15:04:04 2013
@@ -45,3 +45,355 @@
 
     return STATUS_SUCCESS;
 }
+
+#ifndef __REACTOS__
+/******************************************************************************
+ * SystemFunction008  [ADVAPI32.@]
+ *
+ * Creates a LM response from a challenge and a password hash
+ *
+ * PARAMS
+ *   challenge  [I] Challenge from authentication server
+ *   hash       [I] NTLM hash (from SystemFunction006)
+ *   response   [O] response to send back to the server
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ * NOTES
+ *  see http://davenport.sourceforge.net/ntlm.html#theLmResponse
+ *
+ */
+NTSTATUS WINAPI SystemFunction008(const BYTE *challenge, const BYTE *hash, 
LPBYTE response)
+{
+    BYTE key[7*3];
+
+    if (!challenge || !response)
+        return STATUS_UNSUCCESSFUL;
+
+    memset(key, 0, sizeof key);
+    memcpy(key, hash, 0x10);
+
+    CRYPT_DEShash(response, key, challenge);
+    CRYPT_DEShash(response+8, key+7, challenge);
+    CRYPT_DEShash(response+16, key+14, challenge);
+
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction009  [ADVAPI32.@]
+ *
+ * Seems to do the same as SystemFunction008 ...
+ */
+NTSTATUS WINAPI SystemFunction009(const BYTE *challenge, const BYTE *hash, 
LPBYTE response)
+{
+    return SystemFunction008(challenge, hash, response);
+}
+
+/******************************************************************************
+ * SystemFunction001  [ADVAPI32.@]
+ *
+ * Encrypts a single block of data using DES
+ *
+ * PARAMS
+ *   data    [I] data to encrypt    (8 bytes)
+ *   key     [I] key data           (7 bytes)
+ *   output  [O] the encrypted data (8 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ */
+NTSTATUS WINAPI SystemFunction001(const BYTE *data, const BYTE *key, LPBYTE 
output)
+{
+    if (!data || !output)
+        return STATUS_UNSUCCESSFUL;
+    CRYPT_DEShash(output, key, data);
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction002  [ADVAPI32.@]
+ *
+ * Decrypts a single block of data using DES
+ *
+ * PARAMS
+ *   data    [I] data to decrypt    (8 bytes)
+ *   key     [I] key data           (7 bytes)
+ *   output  [O] the decrypted data (8 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ */
+NTSTATUS WINAPI SystemFunction002(const BYTE *data, const BYTE *key, LPBYTE 
output)
+{
+    if (!data || !output)
+        return STATUS_UNSUCCESSFUL;
+    CRYPT_DESunhash(output, key, data);
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction003  [ADVAPI32.@]
+ *
+ * Hashes a key using DES and a fixed datablock
+ *
+ * PARAMS
+ *   key     [I] key data    (7 bytes)
+ *   output  [O] hashed key  (8 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ */
+NTSTATUS WINAPI SystemFunction003(const BYTE *key, LPBYTE output)
+{
+    if (!output)
+        return STATUS_UNSUCCESSFUL;
+    CRYPT_DEShash(output, key, CRYPT_LMhash_Magic);
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction004  [ADVAPI32.@]
+ *
+ * Encrypts a block of data with DES in ECB mode, preserving the length
+ *
+ * PARAMS
+ *   data    [I] data to encrypt
+ *   key     [I] key data (up to 7 bytes)
+ *   output  [O] buffer to receive encrypted data
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_BUFFER_TOO_SMALL     if the output buffer is too small
+ *  Failure: STATUS_INVALID_PARAMETER_2  if the key is zero length
+ *
+ * NOTES
+ *  Encrypt buffer size should be input size rounded up to 8 bytes
+ *   plus an extra 8 bytes.
+ */
+NTSTATUS WINAPI SystemFunction004(const struct ustring *in,
+                                  const struct ustring *key,
+                                  struct ustring *out)
+{
+    union {
+         unsigned char uc[8];
+         unsigned int  ui[2];
+    } data;
+    unsigned char deskey[7];
+    unsigned int crypt_len, ofs;
+
+    if (key->Length<=0)
+        return STATUS_INVALID_PARAMETER_2;
+
+    crypt_len = ((in->Length+7)&~7);
+    if (out->MaximumLength < (crypt_len+8))
+        return STATUS_BUFFER_TOO_SMALL;
+
+    data.ui[0] = in->Length;
+    data.ui[1] = 1;
+
+    if (key->Length<sizeof deskey)
+    {
+        memset(deskey, 0, sizeof deskey);
+        memcpy(deskey, key->Buffer, key->Length);
+    }
+    else
+        memcpy(deskey, key->Buffer, sizeof deskey);
+
+    CRYPT_DEShash(out->Buffer, deskey, data.uc);
+
+    for(ofs=0; ofs<(crypt_len-8); ofs+=8)
+        CRYPT_DEShash(out->Buffer+8+ofs, deskey, in->Buffer+ofs);
+
+    memset(data.uc, 0, sizeof data.uc);
+    memcpy(data.uc, in->Buffer+ofs, in->Length +8-crypt_len);
+    CRYPT_DEShash(out->Buffer+8+ofs, deskey, data.uc);
+
+    out->Length = crypt_len+8;
+
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction005  [ADVAPI32.@]
+ *
+ * Decrypts a block of data with DES in ECB mode
+ *
+ * PARAMS
+ *   data    [I] data to decrypt
+ *   key     [I] key data (up to 7 bytes)
+ *   output  [O] buffer to receive decrypted data
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_BUFFER_TOO_SMALL     if the output buffer is too small
+ *  Failure: STATUS_INVALID_PARAMETER_2  if the key is zero length
+ *
+ */
+NTSTATUS WINAPI SystemFunction005(const struct ustring *in,
+                                  const struct ustring *key,
+                                  struct ustring *out)
+{
+    union {
+         unsigned char uc[8];
+         unsigned int  ui[2];
+    } data;
+    unsigned char deskey[7];
+    unsigned int ofs, crypt_len;
+
+    if (key->Length<=0)
+        return STATUS_INVALID_PARAMETER_2;
+
+    if (key->Length<sizeof deskey)
+    {
+        memset(deskey, 0, sizeof deskey);
+        memcpy(deskey, key->Buffer, key->Length);
+    }
+    else
+        memcpy(deskey, key->Buffer, sizeof deskey);
+
+    CRYPT_DESunhash(data.uc, deskey, in->Buffer);
+
+    if (data.ui[1] != 1)
+        return STATUS_UNKNOWN_REVISION;
+
+    crypt_len = data.ui[0];
+    if (crypt_len > out->MaximumLength)
+        return STATUS_BUFFER_TOO_SMALL;
+
+    for (ofs=0; (ofs+8)<crypt_len; ofs+=8)
+        CRYPT_DESunhash(out->Buffer+ofs, deskey, in->Buffer+ofs+8);
+
+    if (ofs<crypt_len)
+    {
+        CRYPT_DESunhash(data.uc, deskey, in->Buffer+ofs+8);
+        memcpy(out->Buffer+ofs, data.uc, crypt_len-ofs);
+    }
+
+    out->Length = crypt_len;
+
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction012  [ADVAPI32.@]
+ * SystemFunction014  [ADVAPI32.@]
+ * SystemFunction016  [ADVAPI32.@]
+ * SystemFunction018  [ADVAPI32.@]
+ * SystemFunction020  [ADVAPI32.@]
+ * SystemFunction022  [ADVAPI32.@]
+ *
+ * Encrypts two DES blocks with two keys
+ *
+ * PARAMS
+ *   data    [I] data to encrypt (16 bytes)
+ *   key     [I] key data (two lots of 7 bytes)
+ *   output  [O] buffer to receive encrypted data (16 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL  if the input or output buffer is NULL
+ */
+NTSTATUS WINAPI SystemFunction012(const BYTE *in, const BYTE *key, LPBYTE out)
+{
+    if (!in || !out)
+        return STATUS_UNSUCCESSFUL;
+
+    CRYPT_DEShash(out, key, in);
+    CRYPT_DEShash(out+8, key+7, in+8);
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction013  [ADVAPI32.@]
+ * SystemFunction015  [ADVAPI32.@]
+ * SystemFunction017  [ADVAPI32.@]
+ * SystemFunction019  [ADVAPI32.@]
+ * SystemFunction021  [ADVAPI32.@]
+ * SystemFunction023  [ADVAPI32.@]
+ *
+ * Decrypts two DES blocks with two keys
+ *
+ * PARAMS
+ *   data    [I] data to decrypt (16 bytes)
+ *   key     [I] key data (two lots of 7 bytes)
+ *   output  [O] buffer to receive decrypted data (16 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL  if the input or output buffer is NULL
+ */
+NTSTATUS WINAPI SystemFunction013(const BYTE *in, const BYTE *key, LPBYTE out)
+{
+    if (!in || !out)
+        return STATUS_UNSUCCESSFUL;
+
+    CRYPT_DESunhash(out, key, in);
+    CRYPT_DESunhash(out+8, key+7, in+8);
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction024  [ADVAPI32.@]
+ *
+ * Encrypts two DES blocks with a 32 bit key...
+ *
+ * PARAMS
+ *   data    [I] data to encrypt (16 bytes)
+ *   key     [I] key data (4 bytes)
+ *   output  [O] buffer to receive encrypted data (16 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ */
+NTSTATUS WINAPI SystemFunction024(const BYTE *in, const BYTE *key, LPBYTE out)
+{
+    BYTE deskey[0x10];
+
+    memcpy(deskey, key, 4);
+    memcpy(deskey+4, key, 4);
+    memcpy(deskey+8, key, 4);
+    memcpy(deskey+12, key, 4);
+
+    CRYPT_DEShash(out, deskey, in);
+    CRYPT_DEShash(out+8, deskey+7, in+8);
+
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction025  [ADVAPI32.@]
+ *
+ * Decrypts two DES blocks with a 32 bit key...
+ *
+ * PARAMS
+ *   data    [I] data to encrypt (16 bytes)
+ *   key     [I] key data (4 bytes)
+ *   output  [O] buffer to receive encrypted data (16 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ */
+NTSTATUS WINAPI SystemFunction025(const BYTE *in, const BYTE *key, LPBYTE out)
+{
+    BYTE deskey[0x10];
+
+    memcpy(deskey, key, 4);
+    memcpy(deskey+4, key, 4);
+    memcpy(deskey+8, key, 4);
+    memcpy(deskey+12, key, 4);
+
+    CRYPT_DESunhash(out, deskey, in);
+    CRYPT_DESunhash(out+8, deskey+7, in+8);
+
+    return STATUS_SUCCESS;
+}
+#endif /* !__REACTOS__ */

Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c  [iso-8859-1] Fri Dec  6 
15:04:04 2013
@@ -34,6 +34,124 @@
  */
 
 #include <advapi32.h>
+
+static void MD4Transform( unsigned int buf[4], unsigned int const in[16] );
+
+/*
+ * Start MD4 accumulation.  Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+VOID WINAPI MD4Init( MD4_CTX *ctx )
+{
+    ctx->buf[0] = 0x67452301;
+    ctx->buf[1] = 0xefcdab89;
+    ctx->buf[2] = 0x98badcfe;
+    ctx->buf[3] = 0x10325476;
+
+    ctx->i[0] = ctx->i[1] = 0;
+}
+
+/*
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+VOID WINAPI MD4Update( MD4_CTX *ctx, const unsigned char *buf, unsigned int 
len )
+{
+    register unsigned int t;
+
+    /* Update bitcount */
+    t = ctx->i[0];
+
+    if ((ctx->i[0] = t + (len << 3)) < t)
+        ctx->i[1]++;        /* Carry from low to high */
+
+    ctx->i[1] += len >> 29;
+    t = (t >> 3) & 0x3f;
+
+    /* Handle any leading odd-sized chunks */
+    if (t)
+    {
+        unsigned char *p = (unsigned char *)ctx->in + t;
+        t = 64 - t;
+
+        if (len < t)
+        {
+            memcpy( p, buf, len );
+            return;
+        }
+
+        memcpy( p, buf, t );
+        byteReverse( ctx->in, 16 );
+
+        MD4Transform( ctx->buf, (unsigned int *)ctx->in );
+
+        buf += t;
+        len -= t;
+    }
+
+    /* Process data in 64-byte chunks */
+    while (len >= 64)
+    {
+        memcpy( ctx->in, buf, 64 );
+        byteReverse( ctx->in, 16 );
+
+        MD4Transform( ctx->buf, (unsigned int *)ctx->in );
+
+        buf += 64;
+        len -= 64;
+    }
+
+    /* Handle any remaining bytes of data. */
+    memcpy( ctx->in, buf, len );
+}
+
+/*
+ * Final wrapup - pad to 64-byte boundary with the bit pattern 
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+VOID WINAPI MD4Final( MD4_CTX *ctx )
+{
+    unsigned int count;
+    unsigned char *p;
+
+    /* Compute number of bytes mod 64 */
+    count = (ctx->i[0] >> 3) & 0x3F;
+
+    /* Set the first char of padding to 0x80.  This is safe since there is
+       always at least one byte free */
+    p = ctx->in + count;
+    *p++ = 0x80;
+
+    /* Bytes of padding needed to make 64 bytes */
+    count = 64 - 1 - count;
+
+    /* Pad out to 56 mod 64 */
+    if (count < 8)
+    {
+        /* Two lots of padding:  Pad the first block to 64 bytes */
+        memset( p, 0, count );
+        byteReverse( ctx->in, 16 );
+        MD4Transform( ctx->buf, (unsigned int *)ctx->in );
+
+        /* Now fill the next block with 56 bytes */
+        memset( ctx->in, 0, 56 );
+    }
+    else
+    {
+        /* Pad block to 56 bytes */
+        memset( p, 0, count - 8 );
+    }
+
+    byteReverse( ctx->in, 14 );
+
+    /* Append length in bits and transform */
+    ((unsigned int *)ctx->in)[14] = ctx->i[0];
+    ((unsigned int *)ctx->in)[15] = ctx->i[1];
+
+    MD4Transform( ctx->buf, (unsigned int *)ctx->in );
+    byteReverse( (unsigned char *)ctx->buf, 4 );
+    memcpy( ctx->digest, ctx->buf, 16 );
+}
 
 /* The three core functions */
 
@@ -125,118 +243,58 @@
     buf[3] += d;
 }
 
-/*
- * Start MD4 accumulation.  Set bit count to 0 and buffer to mysterious
- * initialization constants.
- */
-VOID WINAPI MD4Init( MD4_CTX *ctx )
-{
-    ctx->buf[0] = 0x67452301;
-    ctx->buf[1] = 0xefcdab89;
-    ctx->buf[2] = 0x98badcfe;
-    ctx->buf[3] = 0x10325476;
-
-    ctx->i[0] = ctx->i[1] = 0;
-}
-
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
- */
-VOID WINAPI MD4Update( MD4_CTX *ctx, const unsigned char *buf, unsigned int 
len )
-{
-    register unsigned int t;
-
-    /* Update bitcount */
-    t = ctx->i[0];
-
-    if ((ctx->i[0] = t + (len << 3)) < t)
-        ctx->i[1]++;        /* Carry from low to high */
-
-    ctx->i[1] += len >> 29;
-    t = (t >> 3) & 0x3f;
-
-    /* Handle any leading odd-sized chunks */
-    if (t)
-    {
-        unsigned char *p = (unsigned char *)ctx->in + t;
-        t = 64 - t;
-
-        if (len < t)
-        {
-            memcpy( p, buf, len );
-            return;
-        }
-
-        memcpy( p, buf, t );
-        byteReverse( ctx->in, 16 );
-
-        MD4Transform( ctx->buf, (unsigned int *)ctx->in );
-
-        buf += t;
-        len -= t;
-    }
-
-    /* Process data in 64-byte chunks */
-    while (len >= 64)
-    {
-        memcpy( ctx->in, buf, 64 );
-        byteReverse( ctx->in, 16 );
-
-        MD4Transform( ctx->buf, (unsigned int *)ctx->in );
-
-        buf += 64;
-        len -= 64;
-    }
-
-    /* Handle any remaining bytes of data. */
-    memcpy( ctx->in, buf, len );
-}
-
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern 
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-VOID WINAPI MD4Final( MD4_CTX *ctx )
-{
-    unsigned int count;
-    unsigned char *p;
-
-    /* Compute number of bytes mod 64 */
-    count = (ctx->i[0] >> 3) & 0x3F;
-
-    /* Set the first char of padding to 0x80.  This is safe since there is
-       always at least one byte free */
-    p = ctx->in + count;
-    *p++ = 0x80;
-
-    /* Bytes of padding needed to make 64 bytes */
-    count = 64 - 1 - count;
-
-    /* Pad out to 56 mod 64 */
-    if (count < 8)
-    {
-        /* Two lots of padding:  Pad the first block to 64 bytes */
-        memset( p, 0, count );
-        byteReverse( ctx->in, 16 );
-        MD4Transform( ctx->buf, (unsigned int *)ctx->in );
-
-        /* Now fill the next block with 56 bytes */
-        memset( ctx->in, 0, 56 );
-    }
-    else
-    {
-        /* Pad block to 56 bytes */
-        memset( p, 0, count - 8 );
-    }
-
-    byteReverse( ctx->in, 14 );
-
-    /* Append length in bits and transform */
-    ((unsigned int *)ctx->in)[14] = ctx->i[0];
-    ((unsigned int *)ctx->in)[15] = ctx->i[1];
-
-    MD4Transform( ctx->buf, (unsigned int *)ctx->in );
-    byteReverse( (unsigned char *)ctx->buf, 4 );
-    memcpy( ctx->digest, ctx->buf, 16 );
-}
+#ifndef __REACTOS__
+/******************************************************************************
+ * SystemFunction007  [ADVAPI32.@]
+ *
+ * MD4 hash a unicode string
+ *
+ * PARAMS
+ *   string  [I] the string to hash
+ *   output  [O] the md4 hash of the string (16 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ */
+NTSTATUS WINAPI SystemFunction007(const UNICODE_STRING *string, LPBYTE hash)
+{
+    MD4_CTX ctx;
+
+    MD4Init( &ctx );
+    MD4Update( &ctx, (const BYTE *)string->Buffer, string->Length );
+    MD4Final( &ctx );
+    memcpy( hash, ctx.digest, 0x10 );
+
+    return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ * SystemFunction010  [ADVAPI32.@]
+ * SystemFunction011  [ADVAPI32.@]
+ *
+ * MD4 hashes 16 bytes of data
+ *
+ * PARAMS
+ *   unknown []  seems to have no effect on the output
+ *   data    [I] pointer to data to hash (16 bytes)
+ *   output  [O] the md4 hash of the data (16 bytes)
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: STATUS_UNSUCCESSFUL
+ *
+ */
+NTSTATUS WINAPI SystemFunction010(LPVOID unknown, const BYTE *data, LPBYTE 
hash)
+{
+    MD4_CTX ctx;
+
+    MD4Init( &ctx );
+    MD4Update( &ctx, data, 0x10 );
+    MD4Final( &ctx );
+    memcpy( hash, ctx.digest, 0x10 );
+
+    return STATUS_SUCCESS;
+}
+#endif /* !__REACTOS__ */

Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c  [iso-8859-1] Fri Dec  6 
15:04:04 2013
@@ -43,6 +43,123 @@
     unsigned char digest[16];
 } MD5_CTX;
 
+static void MD5Transform( unsigned int buf[4], const unsigned int in[16] );
+
+/*
+ * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+VOID WINAPI MD5Init( MD5_CTX *ctx )
+{
+    ctx->buf[0] = 0x67452301;
+    ctx->buf[1] = 0xefcdab89;
+    ctx->buf[2] = 0x98badcfe;
+    ctx->buf[3] = 0x10325476;
+
+    ctx->i[0] = ctx->i[1] = 0;
+}
+
+/*
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+VOID WINAPI MD5Update( MD5_CTX *ctx, const unsigned char *buf, unsigned int 
len )
+{
+    register unsigned int t;
+
+    /* Update bitcount */
+    t = ctx->i[0];
+
+    if ((ctx->i[0] = t + (len << 3)) < t)
+        ctx->i[1]++;        /* Carry from low to high */
+
+    ctx->i[1] += len >> 29;
+    t = (t >> 3) & 0x3f;
+
+    /* Handle any leading odd-sized chunks */
+    if (t)
+    {
+        unsigned char *p = (unsigned char *)ctx->in + t;
+        t = 64 - t;
+
+        if (len < t)
+        {
+            memcpy( p, buf, len );
+            return;
+        }
+
+        memcpy( p, buf, t );
+        byteReverse( ctx->in, 16 );
+
+        MD5Transform( ctx->buf, (unsigned int *)ctx->in );
+
+        buf += t;
+        len -= t;
+    }
+
+    /* Process data in 64-byte chunks */
+    while (len >= 64)
+    {
+        memcpy( ctx->in, buf, 64 );
+        byteReverse( ctx->in, 16 );
+
+        MD5Transform( ctx->buf, (unsigned int *)ctx->in );
+
+        buf += 64;
+        len -= 64;
+    }
+
+    /* Handle any remaining bytes of data. */
+    memcpy( ctx->in, buf, len );
+}
+
+/*
+ * Final wrapup - pad to 64-byte boundary with the bit pattern 
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+VOID WINAPI MD5Final( MD5_CTX *ctx )
+{
+    unsigned int count;
+    unsigned char *p;
+
+    /* Compute number of bytes mod 64 */
+    count = (ctx->i[0] >> 3) & 0x3F;
+
+    /* Set the first char of padding to 0x80.  This is safe since there is
+       always at least one byte free */
+    p = ctx->in + count;
+    *p++ = 0x80;
+
+    /* Bytes of padding needed to make 64 bytes */
+    count = 64 - 1 - count;
+
+    /* Pad out to 56 mod 64 */
+    if (count < 8)
+    {
+        /* Two lots of padding:  Pad the first block to 64 bytes */
+        memset( p, 0, count );
+        byteReverse( ctx->in, 16 );
+        MD5Transform( ctx->buf, (unsigned int *)ctx->in );
+
+        /* Now fill the next block with 56 bytes */
+        memset( ctx->in, 0, 56 );
+    }
+    else
+    {
+        /* Pad block to 56 bytes */
+        memset( p, 0, count - 8 );
+    }
+
+    byteReverse( ctx->in, 14 );
+
+    /* Append length in bits and transform */
+    ((unsigned int *)ctx->in)[14] = ctx->i[0];
+    ((unsigned int *)ctx->in)[15] = ctx->i[1];
+
+    MD5Transform( ctx->buf, (unsigned int *)ctx->in );
+    byteReverse( (unsigned char *)ctx->buf, 4 );
+    memcpy( ctx->digest, ctx->buf, 16 );
+}
 
 /* The four core functions - F1 is optimized somewhat */
 
@@ -143,119 +260,3 @@
     buf[2] += c;
     buf[3] += d;
 }
-
-/*
- * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
- * initialization constants.
- */
-VOID WINAPI MD5Init( MD5_CTX *ctx )
-{
-    ctx->buf[0] = 0x67452301;
-    ctx->buf[1] = 0xefcdab89;
-    ctx->buf[2] = 0x98badcfe;
-    ctx->buf[3] = 0x10325476;
-
-    ctx->i[0] = ctx->i[1] = 0;
-}
-
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
- */
-VOID WINAPI MD5Update( MD5_CTX *ctx, const unsigned char *buf, unsigned int 
len )
-{
-    register unsigned int t;
-
-    /* Update bitcount */
-    t = ctx->i[0];
-
-    if ((ctx->i[0] = t + (len << 3)) < t)
-        ctx->i[1]++;        /* Carry from low to high */
-
-    ctx->i[1] += len >> 29;
-    t = (t >> 3) & 0x3f;
-
-    /* Handle any leading odd-sized chunks */
-    if (t)
-    {
-        unsigned char *p = (unsigned char *)ctx->in + t;
-        t = 64 - t;
-
-        if (len < t)
-        {
-            memcpy( p, buf, len );
-            return;
-        }
-
-        memcpy( p, buf, t );
-        byteReverse( ctx->in, 16 );
-
-        MD5Transform( ctx->buf, (unsigned int *)ctx->in );
-
-        buf += t;
-        len -= t;
-    }
-
-    /* Process data in 64-byte chunks */
-    while (len >= 64)
-    {
-        memcpy( ctx->in, buf, 64 );
-        byteReverse( ctx->in, 16 );
-
-        MD5Transform( ctx->buf, (unsigned int *)ctx->in );
-
-        buf += 64;
-        len -= 64;
-    }
-
-    /* Handle any remaining bytes of data. */
-    memcpy( ctx->in, buf, len );
-}
-
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern 
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-VOID WINAPI MD5Final( MD5_CTX *ctx )
-{
-    unsigned int count;
-    unsigned char *p;
-
-    /* Compute number of bytes mod 64 */
-    count = (ctx->i[0] >> 3) & 0x3F;
-
-    /* Set the first char of padding to 0x80.  This is safe since there is
-       always at least one byte free */
-    p = ctx->in + count;
-    *p++ = 0x80;
-
-    /* Bytes of padding needed to make 64 bytes */
-    count = 64 - 1 - count;
-
-    /* Pad out to 56 mod 64 */
-    if (count < 8)
-    {
-        /* Two lots of padding:  Pad the first block to 64 bytes */
-        memset( p, 0, count );
-        byteReverse( ctx->in, 16 );
-        MD5Transform( ctx->buf, (unsigned int *)ctx->in );
-
-        /* Now fill the next block with 56 bytes */
-        memset( ctx->in, 0, 56 );
-    }
-    else
-    {
-        /* Pad block to 56 bytes */
-        memset( p, 0, count - 8 );
-    }
-
-    byteReverse( ctx->in, 14 );
-
-    /* Append length in bits and transform */
-    ((unsigned int *)ctx->in)[14] = ctx->i[0];
-    ((unsigned int *)ctx->in)[15] = ctx->i[1];
-
-    MD5Transform( ctx->buf, (unsigned int *)ctx->in );
-    byteReverse( (unsigned char *)ctx->buf, 4 );
-    memcpy( ctx->digest, ctx->buf, 16 );
-}

Modified: trunk/reactos/dll/win32/advapi32/misc/sysfunc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/misc/sysfunc.c?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/misc/sysfunc.c     [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/misc/sysfunc.c     [iso-8859-1] Fri Dec  6 
15:04:04 2013
@@ -477,7 +477,7 @@
  *  FALSE if blocks are different
  */
 BOOL
-WINAPI SystemFunction030(PVOID b1, PVOID b2)
+WINAPI SystemFunction030(LPCVOID b1, LPCVOID b2)
 {
        return !memcmp(b1, b2, 0x10);
 }
@@ -500,7 +500,7 @@
  *  see http://web.it.kth.se/~rom/ntsec.html#crypto-strongavail
  */
 NTSTATUS
-WINAPI SystemFunction032(struct ustring *data, struct ustring *key)
+WINAPI SystemFunction032(struct ustring *data, const struct ustring *key)
 {
     arc4_info a4i;
 
@@ -540,15 +540,19 @@
 }
 
 
-/**********************************************************************
- *
- * @unimplemented
- */
-BOOL
-WINAPI
-SystemFunction035(LPCSTR lpszDllFilePath)
-{
-       return TRUE;
+/******************************************************************************
+ * SystemFunction035   (ADVAPI32.@)
+ *
+ * Described here:
+http://disc.server.com/discussion.cgi?disc=148775;article=942;title=Coding%2FASM%2FSystem
+ *
+ * NOTES
+ *  Stub, always return TRUE.
+ */
+BOOL WINAPI SystemFunction035(LPCSTR lpszDllFilePath)
+{
+    //FIXME("%s: stub\n", debugstr_a(lpszDllFilePath));
+    return TRUE;
 }
 
 /******************************************************************************
@@ -616,32 +620,56 @@
 /******************************************************************************
  * SystemFunction040   (ADVAPI32.@)
  *
- * PARAMS:
- *   memory : pointer to memory to encrypt
- *   length : length of region to encrypt, in bytes. must be multiple of 
RTL_ENCRYPT_MEMORY_SIZE
- *   flags  : RTL_ENCRYPT_OPTION_SAME_PROCESS | 
RTL_ENCRYPT_OPTION_CROSS_PROCESS, | RTL_ENCRYPT_OPTION_SAME_LOGON
- *            control whether other processes are able to decrypt the memory. 
The same value must be given
- *            when decrypting the memory.
- */
-NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)  /* 
RtlEncryptMemory */
-{
-       //FIXME("(%p, %lx, %lx): stub [RtlEncryptMemory]\n", memory, length, 
flags);
+ * MSDN documents this function as RtlEncryptMemory and declares it in 
ntsecapi.h.
+ *
+ * PARAMS
+ *  memory [I/O] Pointer to memory to encrypt.
+ *  length [I] Length of region to encrypt in bytes.
+ *  flags  [I] Control whether other processes are able to decrypt the memory.
+ *    RTL_ENCRYPT_OPTION_SAME_PROCESS 
+ *    RTL_ENCRYPT_OPTION_CROSS_PROCESS 
+ *    RTL_ENCRYPT_OPTION_SAME_LOGON
+ *    
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: NTSTATUS error code
+ *
+ * NOTES
+ *  length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
+ *  If flags are specified when encrypting, the same flag value must be given
+ *  when decrypting the memory.
+ */
+NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)
+{
+       //FIXME("(%p, %x, %x): stub [RtlEncryptMemory]\n", memory, length, 
flags);
        return STATUS_SUCCESS;
 }
 
 /******************************************************************************
  * SystemFunction041  (ADVAPI32.@)
  *
- * PARAMS:
- *   memory : pointer to memory to decrypt
- *   length : length of region to decrypt, in bytes. must be multiple of 
RTL_ENCRYPT_MEMORY_SIZE
- *   flags  : RTL_ENCRYPT_OPTION_SAME_PROCESS | 
RTL_ENCRYPT_OPTION_CROSS_PROCESS, | RTL_ENCRYPT_OPTION_SAME_LOGON
- *            control whether other processes are able to decrypt the memory. 
The same value must be given
- *            when encrypting the memory.
- */
-NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)  /* 
RtlDecryptMemory */
-{
-       //FIXME("(%p, %lx, %lx): stub [RtlDecryptMemory]\n", memory, length, 
flags);
+ * MSDN documents this function as RtlDecryptMemory and declares it in 
ntsecapi.h.
+ *
+ * PARAMS
+ *  memory [I/O] Pointer to memory to decrypt.
+ *  length [I] Length of region to decrypt in bytes.
+ *  flags  [I] Control whether other processes are able to decrypt the memory.
+ *    RTL_ENCRYPT_OPTION_SAME_PROCESS
+ *    RTL_ENCRYPT_OPTION_CROSS_PROCESS
+ *    RTL_ENCRYPT_OPTION_SAME_LOGON
+ *
+ * RETURNS
+ *  Success: STATUS_SUCCESS
+ *  Failure: NTSTATUS error code
+ *
+ * NOTES
+ *  length must be a multiple of RTL_ENCRYPT_MEMORY_SIZE.
+ *  If flags are specified when encrypting, the same flag value must be given
+ *  when decrypting the memory.
+ */
+NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)
+{
+       //FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, 
flags);
        return STATUS_SUCCESS;
 }
 

Modified: trunk/reactos/media/doc/README.WINE
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/media/doc/README.WINE?rev=61234&r1=61233&r2=61234&view=diff
==============================================================================
--- trunk/reactos/media/doc/README.WINE [iso-8859-1] (original)
+++ trunk/reactos/media/doc/README.WINE [iso-8859-1] Fri Dec  6 15:04:04 2013
@@ -249,7 +249,7 @@
 reactos/lib/3rdparty/strmbase             # Synced to Wine-1.7.1
 
 advapi32 -
-  reactos/dll/win32/advapi32/crypt/*.c          # Unknown
+  reactos/dll/win32/advapi32/crypt/*.c          # Synced to Wine-1.7.1
   reactos/dll/win32/advapi32/sec/cred.c         # Out of Sync
   reactos/dll/win32/advapi32/sec/sid.c          # Out of Sync
 


Reply via email to