* Sync with Wine 1.7.1.
CORE-7469
svn path=/trunk/; revision=61234
* - Thread-safing
*/
+#define WINE_STRICT_PROTOTYPES
#include <advapi32.h>
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
} while (--longs);
}
-static HWND crypt_hWindow ;
+static HWND crypt_hWindow;
#define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size))
#define CRYPT_Free(buffer) (LocalFree(buffer))
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;
}
return TRUE;
}
-static BOOL CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
+static void CALLBACK CRYPT_ReturnhWnd(HWND *phWnd)
{
- if (!phWnd)
- return FALSE;
- *phWnd = crypt_hWindow;
- return TRUE;
+ if (phWnd) *phWnd = crypt_hWindow;
}
#define CRYPT_GetProvFunc(name) \
/* 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;
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;
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) )
{
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;
}
hash->pProvider = prov;
-
+ hash->dwMagic = MAGIC_CRYPTHASH;
if (prov->pFuncs->pCPCreateHash(prov->hPrivate, Algid,
key ? key->hPrivate : 0, 0, &hash->hPrivate))
{
}
/* CSP error! */
+ hash->dwMagic = 0;
CRYPT_Free(hash);
*phHash = 0;
return FALSE;
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;
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;
}
key->pProvider = prov;
+ key->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPDeriveKey(prov->hPrivate, Algid, hash->hPrivate, dwFlags, &key->hPrivate))
{
*phKey = (HCRYPTKEY)key;
}
/* CSP error! */
+ key->dwMagic = 0;
CRYPT_Free(key);
*phKey = 0;
return FALSE;
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;
prov = hash->pProvider;
ret = prov->pFuncs->pCPDestroyHash(prov->hPrivate, hash->hPrivate);
+ hash->dwMagic = 0;
CRYPT_Free(hash);
return ret;
}
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;
prov = key->pProvider;
ret = prov->pFuncs->pCPDestroyKey(prov->hPrivate, key->hPrivate);
+ key->dwMagic = 0;
CRYPT_Free(key);
return ret;
}
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;
}
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;
}
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);
}
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;
}
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;
{
PWSTR str = NULL;
DWORD bufsize;
- BOOL ret; /* = FALSE; */
+ BOOL ret;
TRACE("(%d, %p, %08x, %p, %p, %p)\n", dwIndex, pdwReserved, dwFlags,
pdwProvType, pszProvName, pcbProvName);
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';
if (result)
{
SetLastError(result);
+ RegCloseKey(hSubkey);
return FALSE;
}
RegCloseKey(hSubkey);
- RegCloseKey(hKey);
return TRUE;
}
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;
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);
}
key->pProvider = prov;
-
+ key->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPGenKey(prov->hPrivate, Algid, dwFlags, &key->hPrivate))
{
*phKey = (HCRYPTKEY)key;
}
/* CSP error! */
+ key->dwMagic = 0;
CRYPT_Free(key);
return FALSE;
}
CRYPT_Free(keyname);
result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName);
+ RegCloseKey(hKey);
+
if (result)
{
if (result != ERROR_MORE_DATA)
return FALSE;
}
- RegCloseKey(hKey);
return TRUE;
}
{
PWSTR str = NULL;
DWORD bufsize;
- BOOL ret = FALSE;
+ BOOL ret;
TRACE("(%d, %p, %08x, %p, %p)\n", dwProvType, pdwReserved, dwFlags, pszProvName, pcbProvName);
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;
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;
}
key->pProvider = prov;
-
+ key->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPGetUserKey(prov->hPrivate, dwKeySpec, &key->hPrivate))
{
*phUserKey = (HCRYPTKEY)key;
}
/* CSP Error */
+ key->dwMagic = 0;
CRYPT_Free(key);
*phUserKey = 0;
return FALSE;
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;
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;
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;
}
importkey->pProvider = prov;
+ importkey->dwMagic = MAGIC_CRYPTKEY;
if (prov->pFuncs->pCPImportKey(prov->hPrivate, pbData, dwDataLen,
pubkey ? pubkey->hPrivate : 0, dwFlags, &importkey->hPrivate))
{
return TRUE;
}
+ importkey->dwMagic = 0;
CRYPT_Free(importkey);
return FALSE;
}
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;
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;
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;
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)
{
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 __ */
} PROVFUNCS, *PPROVFUNCS;
#define MAGIC_CRYPTPROV 0xA39E741F
+#define MAGIC_CRYPTKEY 0xA39E741E
+#define MAGIC_CRYPTHASH 0xA39E741D
typedef struct tagCRYPTPROV
{
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;
#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 {
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_ */
* 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>
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
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__ */
#include <advapi32.h>
-/* The three core functions */
-
-#define rotl32(x,n) (((x) << ((unsigned int)(n))) | ((x) >> (32 - (unsigned int)(n))))
-
-#define F( x, y, z ) (((x) & (y)) | ((~x) & (z)))
-#define G( x, y, z ) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
-#define H( x, y, z ) ((x) ^ (y) ^ (z))
-
-#define FF( a, b, c, d, x, s ) { \
- (a) += F( (b), (c), (d) ) + (x); \
- (a) = rotl32( (a), (s) ); \
- }
-#define GG( a, b, c, d, x, s ) { \
- (a) += G( (b), (c), (d) ) + (x) + (unsigned int)0x5a827999; \
- (a) = rotl32( (a), (s) ); \
- }
-#define HH( a, b, c, d, x, s ) { \
- (a) += H( (b), (c), (d) ) + (x) + (unsigned int)0x6ed9eba1; \
- (a) = rotl32( (a), (s) ); \
- }
-
-/*
- * The core of the MD4 algorithm
- */
-static void MD4Transform( unsigned int buf[4], const unsigned int in[16] )
-{
- register unsigned int a, b, c, d;
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- FF( a, b, c, d, in[0], 3 );
- FF( d, a, b, c, in[1], 7 );
- FF( c, d, a, b, in[2], 11 );
- FF( b, c, d, a, in[3], 19 );
- FF( a, b, c, d, in[4], 3 );
- FF( d, a, b, c, in[5], 7 );
- FF( c, d, a, b, in[6], 11 );
- FF( b, c, d, a, in[7], 19 );
- FF( a, b, c, d, in[8], 3 );
- FF( d, a, b, c, in[9], 7 );
- FF( c, d, a, b, in[10], 11 );
- FF( b, c, d, a, in[11], 19 );
- FF( a, b, c, d, in[12], 3 );
- FF( d, a, b, c, in[13], 7 );
- FF( c, d, a, b, in[14], 11 );
- FF( b, c, d, a, in[15], 19 );
-
- GG( a, b, c, d, in[0], 3 );
- GG( d, a, b, c, in[4], 5 );
- GG( c, d, a, b, in[8], 9 );
- GG( b, c, d, a, in[12], 13 );
- GG( a, b, c, d, in[1], 3 );
- GG( d, a, b, c, in[5], 5 );
- GG( c, d, a, b, in[9], 9 );
- GG( b, c, d, a, in[13], 13 );
- GG( a, b, c, d, in[2], 3 );
- GG( d, a, b, c, in[6], 5 );
- GG( c, d, a, b, in[10], 9 );
- GG( b, c, d, a, in[14], 13 );
- GG( a, b, c, d, in[3], 3 );
- GG( d, a, b, c, in[7], 5 );
- GG( c, d, a, b, in[11], 9 );
- GG( b, c, d, a, in[15], 13 );
-
- HH( a, b, c, d, in[0], 3 );
- HH( d, a, b, c, in[8], 9 );
- HH( c, d, a, b, in[4], 11 );
- HH( b, c, d, a, in[12], 15 );
- HH( a, b, c, d, in[2], 3 );
- HH( d, a, b, c, in[10], 9 );
- HH( c, d, a, b, in[6], 11 );
- HH( b, c, d, a, in[14], 15 );
- HH( a, b, c, d, in[1], 3 );
- HH( d, a, b, c, in[9], 9 );
- HH( c, d, a, b, in[5], 11 );
- HH( b, c, d, a, in[13], 15 );
- HH( a, b, c, d, in[3], 3 );
- HH( d, a, b, c, in[11], 9 );
- HH( c, d, a, b, in[7], 11 );
- HH( b, c, d, a, in[15], 15 );
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
+static void MD4Transform( unsigned int buf[4], unsigned int const in[16] );
/*
* Start MD4 accumulation. Set bit count to 0 and buffer to mysterious
byteReverse( (unsigned char *)ctx->buf, 4 );
memcpy( ctx->digest, ctx->buf, 16 );
}
+
+/* The three core functions */
+
+#define rotl32(x,n) (((x) << ((unsigned int)(n))) | ((x) >> (32 - (unsigned int)(n))))
+
+#define F( x, y, z ) (((x) & (y)) | ((~x) & (z)))
+#define G( x, y, z ) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
+#define H( x, y, z ) ((x) ^ (y) ^ (z))
+
+#define FF( a, b, c, d, x, s ) { \
+ (a) += F( (b), (c), (d) ) + (x); \
+ (a) = rotl32( (a), (s) ); \
+ }
+#define GG( a, b, c, d, x, s ) { \
+ (a) += G( (b), (c), (d) ) + (x) + (unsigned int)0x5a827999; \
+ (a) = rotl32( (a), (s) ); \
+ }
+#define HH( a, b, c, d, x, s ) { \
+ (a) += H( (b), (c), (d) ) + (x) + (unsigned int)0x6ed9eba1; \
+ (a) = rotl32( (a), (s) ); \
+ }
+
+/*
+ * The core of the MD4 algorithm
+ */
+static void MD4Transform( unsigned int buf[4], const unsigned int in[16] )
+{
+ register unsigned int a, b, c, d;
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ FF( a, b, c, d, in[0], 3 );
+ FF( d, a, b, c, in[1], 7 );
+ FF( c, d, a, b, in[2], 11 );
+ FF( b, c, d, a, in[3], 19 );
+ FF( a, b, c, d, in[4], 3 );
+ FF( d, a, b, c, in[5], 7 );
+ FF( c, d, a, b, in[6], 11 );
+ FF( b, c, d, a, in[7], 19 );
+ FF( a, b, c, d, in[8], 3 );
+ FF( d, a, b, c, in[9], 7 );
+ FF( c, d, a, b, in[10], 11 );
+ FF( b, c, d, a, in[11], 19 );
+ FF( a, b, c, d, in[12], 3 );
+ FF( d, a, b, c, in[13], 7 );
+ FF( c, d, a, b, in[14], 11 );
+ FF( b, c, d, a, in[15], 19 );
+
+ GG( a, b, c, d, in[0], 3 );
+ GG( d, a, b, c, in[4], 5 );
+ GG( c, d, a, b, in[8], 9 );
+ GG( b, c, d, a, in[12], 13 );
+ GG( a, b, c, d, in[1], 3 );
+ GG( d, a, b, c, in[5], 5 );
+ GG( c, d, a, b, in[9], 9 );
+ GG( b, c, d, a, in[13], 13 );
+ GG( a, b, c, d, in[2], 3 );
+ GG( d, a, b, c, in[6], 5 );
+ GG( c, d, a, b, in[10], 9 );
+ GG( b, c, d, a, in[14], 13 );
+ GG( a, b, c, d, in[3], 3 );
+ GG( d, a, b, c, in[7], 5 );
+ GG( c, d, a, b, in[11], 9 );
+ GG( b, c, d, a, in[15], 13 );
+
+ HH( a, b, c, d, in[0], 3 );
+ HH( d, a, b, c, in[8], 9 );
+ HH( c, d, a, b, in[4], 11 );
+ HH( b, c, d, a, in[12], 15 );
+ HH( a, b, c, d, in[2], 3 );
+ HH( d, a, b, c, in[10], 9 );
+ HH( c, d, a, b, in[6], 11 );
+ HH( b, c, d, a, in[14], 15 );
+ HH( a, b, c, d, in[1], 3 );
+ HH( d, a, b, c, in[9], 9 );
+ HH( c, d, a, b, in[5], 11 );
+ HH( b, c, d, a, in[13], 15 );
+ HH( a, b, c, d, in[3], 3 );
+ HH( d, a, b, c, in[11], 9 );
+ HH( c, d, a, b, in[7], 11 );
+ HH( b, c, d, a, in[15], 15 );
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
+
+#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__ */
unsigned char digest[16];
} MD5_CTX;
-
-/* The four core functions - F1 is optimized somewhat */
-
-/* #define F1( x, y, z ) (x & y | ~x & z) */
-#define F1( x, y, z ) (z ^ (x & (y ^ z)))
-#define F2( x, y, z ) F1( z, x, y )
-#define F3( x, y, z ) (x ^ y ^ z)
-#define F4( x, y, z ) (y ^ (x | ~z))
-
-/* This is the central step in the MD5 algorithm. */
-#define MD5STEP( f, w, x, y, z, data, s ) \
- ( w += f( x, y, z ) + data, w = w << s | w >> (32 - s), w += x )
-
-/*
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data. MD5Update blocks
- * the data and converts bytes into longwords for this routine.
- */
-static void MD5Transform( unsigned int buf[4], const unsigned int in[16] )
-{
- register unsigned int a, b, c, d;
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- MD5STEP( F1, a, b, c, d, in[0] + 0xd76aa478, 7 );
- MD5STEP( F1, d, a, b, c, in[1] + 0xe8c7b756, 12 );
- MD5STEP( F1, c, d, a, b, in[2] + 0x242070db, 17 );
- MD5STEP( F1, b, c, d, a, in[3] + 0xc1bdceee, 22 );
- MD5STEP( F1, a, b, c, d, in[4] + 0xf57c0faf, 7 );
- MD5STEP( F1, d, a, b, c, in[5] + 0x4787c62a, 12 );
- MD5STEP( F1, c, d, a, b, in[6] + 0xa8304613, 17 );
- MD5STEP( F1, b, c, d, a, in[7] + 0xfd469501, 22 );
- MD5STEP( F1, a, b, c, d, in[8] + 0x698098d8, 7 );
- MD5STEP( F1, d, a, b, c, in[9] + 0x8b44f7af, 12 );
- MD5STEP( F1, c, d, a, b, in[10] + 0xffff5bb1, 17 );
- MD5STEP( F1, b, c, d, a, in[11] + 0x895cd7be, 22 );
- MD5STEP( F1, a, b, c, d, in[12] + 0x6b901122, 7 );
- MD5STEP( F1, d, a, b, c, in[13] + 0xfd987193, 12 );
- MD5STEP( F1, c, d, a, b, in[14] + 0xa679438e, 17 );
- MD5STEP( F1, b, c, d, a, in[15] + 0x49b40821, 22 );
-
- MD5STEP( F2, a, b, c, d, in[1] + 0xf61e2562, 5 );
- MD5STEP( F2, d, a, b, c, in[6] + 0xc040b340, 9 );
- MD5STEP( F2, c, d, a, b, in[11] + 0x265e5a51, 14 );
- MD5STEP( F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20 );
- MD5STEP( F2, a, b, c, d, in[5] + 0xd62f105d, 5 );
- MD5STEP( F2, d, a, b, c, in[10] + 0x02441453, 9 );
- MD5STEP( F2, c, d, a, b, in[15] + 0xd8a1e681, 14 );
- MD5STEP( F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20 );
- MD5STEP( F2, a, b, c, d, in[9] + 0x21e1cde6, 5 );
- MD5STEP( F2, d, a, b, c, in[14] + 0xc33707d6, 9 );
- MD5STEP( F2, c, d, a, b, in[3] + 0xf4d50d87, 14 );
- MD5STEP( F2, b, c, d, a, in[8] + 0x455a14ed, 20 );
- MD5STEP( F2, a, b, c, d, in[13] + 0xa9e3e905, 5 );
- MD5STEP( F2, d, a, b, c, in[2] + 0xfcefa3f8, 9 );
- MD5STEP( F2, c, d, a, b, in[7] + 0x676f02d9, 14 );
- MD5STEP( F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20 );
-
- MD5STEP( F3, a, b, c, d, in[5] + 0xfffa3942, 4 );
- MD5STEP( F3, d, a, b, c, in[8] + 0x8771f681, 11 );
- MD5STEP( F3, c, d, a, b, in[11] + 0x6d9d6122, 16 );
- MD5STEP( F3, b, c, d, a, in[14] + 0xfde5380c, 23 );
- MD5STEP( F3, a, b, c, d, in[1] + 0xa4beea44, 4 );
- MD5STEP( F3, d, a, b, c, in[4] + 0x4bdecfa9, 11 );
- MD5STEP( F3, c, d, a, b, in[7] + 0xf6bb4b60, 16 );
- MD5STEP( F3, b, c, d, a, in[10] + 0xbebfbc70, 23 );
- MD5STEP( F3, a, b, c, d, in[13] + 0x289b7ec6, 4 );
- MD5STEP( F3, d, a, b, c, in[0] + 0xeaa127fa, 11 );
- MD5STEP( F3, c, d, a, b, in[3] + 0xd4ef3085, 16 );
- MD5STEP( F3, b, c, d, a, in[6] + 0x04881d05, 23 );
- MD5STEP( F3, a, b, c, d, in[9] + 0xd9d4d039, 4 );
- MD5STEP( F3, d, a, b, c, in[12] + 0xe6db99e5, 11 );
- MD5STEP( F3, c, d, a, b, in[15] + 0x1fa27cf8, 16 );
- MD5STEP( F3, b, c, d, a, in[2] + 0xc4ac5665, 23 );
-
- MD5STEP( F4, a, b, c, d, in[0] + 0xf4292244, 6 );
- MD5STEP( F4, d, a, b, c, in[7] + 0x432aff97, 10 );
- MD5STEP( F4, c, d, a, b, in[14] + 0xab9423a7, 15 );
- MD5STEP( F4, b, c, d, a, in[5] + 0xfc93a039, 21 );
- MD5STEP( F4, a, b, c, d, in[12] + 0x655b59c3, 6 );
- MD5STEP( F4, d, a, b, c, in[3] + 0x8f0ccc92, 10 );
- MD5STEP( F4, c, d, a, b, in[10] + 0xffeff47d, 15 );
- MD5STEP( F4, b, c, d, a, in[1] + 0x85845dd1, 21 );
- MD5STEP( F4, a, b, c, d, in[8] + 0x6fa87e4f, 6 );
- MD5STEP( F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10 );
- MD5STEP( F4, c, d, a, b, in[6] + 0xa3014314, 15 );
- MD5STEP( F4, b, c, d, a, in[13] + 0x4e0811a1, 21 );
- MD5STEP( F4, a, b, c, d, in[4] + 0xf7537e82, 6 );
- MD5STEP( F4, d, a, b, c, in[11] + 0xbd3af235, 10 );
- MD5STEP( F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15 );
- MD5STEP( F4, b, c, d, a, in[9] + 0xeb86d391, 21 );
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
+static void MD5Transform( unsigned int buf[4], const unsigned int in[16] );
/*
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
byteReverse( (unsigned char *)ctx->buf, 4 );
memcpy( ctx->digest, ctx->buf, 16 );
}
+
+/* The four core functions - F1 is optimized somewhat */
+
+/* #define F1( x, y, z ) (x & y | ~x & z) */
+#define F1( x, y, z ) (z ^ (x & (y ^ z)))
+#define F2( x, y, z ) F1( z, x, y )
+#define F3( x, y, z ) (x ^ y ^ z)
+#define F4( x, y, z ) (y ^ (x | ~z))
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP( f, w, x, y, z, data, s ) \
+ ( w += f( x, y, z ) + data, w = w << s | w >> (32 - s), w += x )
+
+/*
+ * The core of the MD5 algorithm, this alters an existing MD5 hash to
+ * reflect the addition of 16 longwords of new data. MD5Update blocks
+ * the data and converts bytes into longwords for this routine.
+ */
+static void MD5Transform( unsigned int buf[4], const unsigned int in[16] )
+{
+ register unsigned int a, b, c, d;
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ MD5STEP( F1, a, b, c, d, in[0] + 0xd76aa478, 7 );
+ MD5STEP( F1, d, a, b, c, in[1] + 0xe8c7b756, 12 );
+ MD5STEP( F1, c, d, a, b, in[2] + 0x242070db, 17 );
+ MD5STEP( F1, b, c, d, a, in[3] + 0xc1bdceee, 22 );
+ MD5STEP( F1, a, b, c, d, in[4] + 0xf57c0faf, 7 );
+ MD5STEP( F1, d, a, b, c, in[5] + 0x4787c62a, 12 );
+ MD5STEP( F1, c, d, a, b, in[6] + 0xa8304613, 17 );
+ MD5STEP( F1, b, c, d, a, in[7] + 0xfd469501, 22 );
+ MD5STEP( F1, a, b, c, d, in[8] + 0x698098d8, 7 );
+ MD5STEP( F1, d, a, b, c, in[9] + 0x8b44f7af, 12 );
+ MD5STEP( F1, c, d, a, b, in[10] + 0xffff5bb1, 17 );
+ MD5STEP( F1, b, c, d, a, in[11] + 0x895cd7be, 22 );
+ MD5STEP( F1, a, b, c, d, in[12] + 0x6b901122, 7 );
+ MD5STEP( F1, d, a, b, c, in[13] + 0xfd987193, 12 );
+ MD5STEP( F1, c, d, a, b, in[14] + 0xa679438e, 17 );
+ MD5STEP( F1, b, c, d, a, in[15] + 0x49b40821, 22 );
+
+ MD5STEP( F2, a, b, c, d, in[1] + 0xf61e2562, 5 );
+ MD5STEP( F2, d, a, b, c, in[6] + 0xc040b340, 9 );
+ MD5STEP( F2, c, d, a, b, in[11] + 0x265e5a51, 14 );
+ MD5STEP( F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20 );
+ MD5STEP( F2, a, b, c, d, in[5] + 0xd62f105d, 5 );
+ MD5STEP( F2, d, a, b, c, in[10] + 0x02441453, 9 );
+ MD5STEP( F2, c, d, a, b, in[15] + 0xd8a1e681, 14 );
+ MD5STEP( F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20 );
+ MD5STEP( F2, a, b, c, d, in[9] + 0x21e1cde6, 5 );
+ MD5STEP( F2, d, a, b, c, in[14] + 0xc33707d6, 9 );
+ MD5STEP( F2, c, d, a, b, in[3] + 0xf4d50d87, 14 );
+ MD5STEP( F2, b, c, d, a, in[8] + 0x455a14ed, 20 );
+ MD5STEP( F2, a, b, c, d, in[13] + 0xa9e3e905, 5 );
+ MD5STEP( F2, d, a, b, c, in[2] + 0xfcefa3f8, 9 );
+ MD5STEP( F2, c, d, a, b, in[7] + 0x676f02d9, 14 );
+ MD5STEP( F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20 );
+
+ MD5STEP( F3, a, b, c, d, in[5] + 0xfffa3942, 4 );
+ MD5STEP( F3, d, a, b, c, in[8] + 0x8771f681, 11 );
+ MD5STEP( F3, c, d, a, b, in[11] + 0x6d9d6122, 16 );
+ MD5STEP( F3, b, c, d, a, in[14] + 0xfde5380c, 23 );
+ MD5STEP( F3, a, b, c, d, in[1] + 0xa4beea44, 4 );
+ MD5STEP( F3, d, a, b, c, in[4] + 0x4bdecfa9, 11 );
+ MD5STEP( F3, c, d, a, b, in[7] + 0xf6bb4b60, 16 );
+ MD5STEP( F3, b, c, d, a, in[10] + 0xbebfbc70, 23 );
+ MD5STEP( F3, a, b, c, d, in[13] + 0x289b7ec6, 4 );
+ MD5STEP( F3, d, a, b, c, in[0] + 0xeaa127fa, 11 );
+ MD5STEP( F3, c, d, a, b, in[3] + 0xd4ef3085, 16 );
+ MD5STEP( F3, b, c, d, a, in[6] + 0x04881d05, 23 );
+ MD5STEP( F3, a, b, c, d, in[9] + 0xd9d4d039, 4 );
+ MD5STEP( F3, d, a, b, c, in[12] + 0xe6db99e5, 11 );
+ MD5STEP( F3, c, d, a, b, in[15] + 0x1fa27cf8, 16 );
+ MD5STEP( F3, b, c, d, a, in[2] + 0xc4ac5665, 23 );
+
+ MD5STEP( F4, a, b, c, d, in[0] + 0xf4292244, 6 );
+ MD5STEP( F4, d, a, b, c, in[7] + 0x432aff97, 10 );
+ MD5STEP( F4, c, d, a, b, in[14] + 0xab9423a7, 15 );
+ MD5STEP( F4, b, c, d, a, in[5] + 0xfc93a039, 21 );
+ MD5STEP( F4, a, b, c, d, in[12] + 0x655b59c3, 6 );
+ MD5STEP( F4, d, a, b, c, in[3] + 0x8f0ccc92, 10 );
+ MD5STEP( F4, c, d, a, b, in[10] + 0xffeff47d, 15 );
+ MD5STEP( F4, b, c, d, a, in[1] + 0x85845dd1, 21 );
+ MD5STEP( F4, a, b, c, d, in[8] + 0x6fa87e4f, 6 );
+ MD5STEP( F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10 );
+ MD5STEP( F4, c, d, a, b, in[6] + 0xa3014314, 15 );
+ MD5STEP( F4, b, c, d, a, in[13] + 0x4e0811a1, 21 );
+ MD5STEP( F4, a, b, c, d, in[4] + 0xf7537e82, 6 );
+ MD5STEP( F4, d, a, b, c, in[11] + 0xbd3af235, 10 );
+ MD5STEP( F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15 );
+ MD5STEP( F4, b, c, d, a, in[9] + 0xeb86d391, 21 );
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
* FALSE if blocks are different
*/
BOOL
-WINAPI SystemFunction030(PVOID b1, PVOID b2)
+WINAPI SystemFunction030(LPCVOID b1, LPCVOID b2)
{
return !memcmp(b1, b2, 0x10);
}
* 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;
}
-/**********************************************************************
+/******************************************************************************
+ * SystemFunction035 (ADVAPI32.@)
*
- * @unimplemented
+ * 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)
+BOOL WINAPI SystemFunction035(LPCSTR lpszDllFilePath)
{
- return TRUE;
+ //FIXME("%s: stub\n", debugstr_a(lpszDllFilePath));
+ return TRUE;
}
/******************************************************************************
/******************************************************************************
* 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.
+ * 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) /* RtlEncryptMemory */
+NTSTATUS WINAPI SystemFunction040(PVOID memory, ULONG length, ULONG flags)
{
- //FIXME("(%p, %lx, %lx): stub [RtlEncryptMemory]\n", memory, length, 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.
+ * 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) /* RtlDecryptMemory */
+NTSTATUS WINAPI SystemFunction041(PVOID memory, ULONG length, ULONG flags)
{
- //FIXME("(%p, %lx, %lx): stub [RtlDecryptMemory]\n", memory, length, flags);
+ //FIXME("(%p, %x, %x): stub [RtlDecryptMemory]\n", memory, length, flags);
return STATUS_SUCCESS;
}
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