ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
January 2014
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
14 participants
426 discussions
Start a n
N
ew thread
[tkreuzer] 61805: [CRYPTLIB] Add a library for common encryption/hashing algorithms. Currently implements MD4, MD5, SHA1, RC4 (all taken from advapi32 with minor modifications) and AES (taken from ...
by tkreuzer@svn.reactos.org
Author: tkreuzer Date: Sat Jan 25 13:55:08 2014 New Revision: 61805 URL:
http://svn.reactos.org/svn/reactos?rev=61805&view=rev
Log: [CRYPTLIB] Add a library for common encryption/hashing algorithms. Currently implements MD4, MD5, SHA1, RC4 (all taken from advapi32 with minor modifications) and AES (taken from OpenWrt Linux). The library is currently used by advapi32 only, but ksecdd will make use of it later as well. Added: trunk/reactos/lib/cryptlib/ (with props) trunk/reactos/lib/cryptlib/CMakeLists.txt (with props) trunk/reactos/lib/cryptlib/README.txt (with props) trunk/reactos/lib/cryptlib/md4.c - copied, changed from r61706, trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c trunk/reactos/lib/cryptlib/md4.h (with props) trunk/reactos/lib/cryptlib/md5.c - copied, changed from r61706, trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c trunk/reactos/lib/cryptlib/md5.h (with props) trunk/reactos/lib/cryptlib/mvAesAlg.c (with props) trunk/reactos/lib/cryptlib/mvAesAlg.h (with props) trunk/reactos/lib/cryptlib/mvAesBoxes.dat (with props) trunk/reactos/lib/cryptlib/mvOs.h (with props) trunk/reactos/lib/cryptlib/rc4.c - copied, changed from r61804, trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c trunk/reactos/lib/cryptlib/rc4.h (with props) trunk/reactos/lib/cryptlib/sha1.c - copied, changed from r61706, trunk/reactos/dll/win32/advapi32/crypt/crypt_sha.c trunk/reactos/lib/cryptlib/sha1.h (with props) trunk/reactos/lib/cryptlib/util.c (with props) trunk/reactos/lib/cryptlib/util.h (with props) Removed: trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c trunk/reactos/dll/win32/advapi32/crypt/crypt_sha.c Modified: trunk/reactos/dll/win32/advapi32/CMakeLists.txt trunk/reactos/dll/win32/advapi32/crypt/crypt.c trunk/reactos/dll/win32/advapi32/crypt/crypt.h trunk/reactos/dll/win32/advapi32/misc/sysfunc.c trunk/reactos/lib/CMakeLists.txt Modified: trunk/reactos/dll/win32/advapi32/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/CMakeLi…
============================================================================== --- trunk/reactos/dll/win32/advapi32/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/CMakeLists.txt [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -8,6 +8,7 @@ include_directories( ${REACTOS_SOURCE_DIR}/include/reactos/idl + ${REACTOS_SOURCE_DIR}/lib/cryptlib ${CMAKE_CURRENT_BINARY_DIR}) add_rpc_files(client @@ -17,12 +18,8 @@ list(APPEND SOURCE crypt/crypt.c - crypt/crypt_arc4.c crypt/crypt_des.c crypt/crypt_lmhash.c - crypt/crypt_md4.c - crypt/crypt_md5.c - crypt/crypt_sha.c misc/dllmain.c misc/efs.c misc/hwprofiles.c @@ -56,7 +53,7 @@ add_library(advapi32 SHARED ${SOURCE}) set_module_type(advapi32 win32dll UNICODE) -target_link_libraries(advapi32 wine ${PSEH_LIB}) +target_link_libraries(advapi32 cryptlib wine ${PSEH_LIB}) add_delay_importlibs(advapi32 rpcrt4) add_importlibs(advapi32 secur32 msvcrt kernel32 ntdll) Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/c…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/crypt/crypt.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -26,23 +26,6 @@ #include <advapi32.h> WINE_DEFAULT_DEBUG_CHANNEL(crypt); - - -/* - * Note: this code is harmless on little-endian machines. - */ -VOID byteReverse(unsigned char *buf, unsigned longs) -{ - unsigned int t; - - do - { - t = (unsigned int)((unsigned)buf[3] << 8 | buf[2]) << 16 | - ((unsigned)buf[1] << 8 | buf[0]); - *(unsigned int *)buf = t; - buf += 4; - } while (--longs); -} static HWND crypt_hWindow; @@ -323,7 +306,7 @@ * dwProvType [I] Crypto provider type to get a handle. * dwFlags [I] flags for the operation * - * RETURNS + * RETURNS * TRUE on success, FALSE on failure. */ BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer, @@ -347,7 +330,7 @@ SetLastError(NTE_BAD_PROV_TYPE); return FALSE; } - + if (!phProv) { SetLastError(ERROR_INVALID_PARAMETER); @@ -583,7 +566,7 @@ */ BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags) { - PCRYPTPROV pProv = (PCRYPTPROV)hProv; + PCRYPTPROV pProv = (PCRYPTPROV)hProv; TRACE("(0x%lx, %p, %08x)\n", hProv, pdwReserved, dwFlags); @@ -636,7 +619,7 @@ } pProv->refcount--; - if (pProv->refcount <= 0) + if (pProv->refcount <= 0) { ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags); pProv->dwMagic = 0; @@ -1144,10 +1127,10 @@ { DWORD numkeys; WCHAR *provNameW; - + RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &numkeys, pcbProvName, NULL, NULL, NULL, NULL, NULL, NULL); - + if (!(provNameW = CRYPT_Alloc(*pcbProvName * sizeof(WCHAR)))) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -1169,7 +1152,7 @@ DWORD size = sizeof(DWORD); DWORD result; HKEY subkey; - + result = RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR)); if (result) { @@ -1313,7 +1296,7 @@ *pdwProvType += (*(--ch) - '0') * 10; *pdwProvType += (*(--ch) - '0') * 100; CRYPT_Free(keyname); - + result = RegQueryValueExW(hSubkey, typenameW, NULL, &dwType, (LPBYTE)pszTypeName, pcbTypeName); if (result) { @@ -1366,7 +1349,7 @@ /****************************************************************************** * CryptExportKey (ADVAPI32.@) - * + * * Exports a cryptographic key from a CSP. * * PARAMS @@ -1507,8 +1490,8 @@ return FALSE; } CRYPT_Free(keyname); - - result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName); + + result = RegQueryValueExW(hKey, nameW, NULL, NULL, (LPBYTE)pszProvName, pcbProvName); RegCloseKey(hKey); if (result) @@ -1517,10 +1500,10 @@ SetLastError(NTE_PROV_TYPE_ENTRY_BAD); else SetLastError(result); - - return FALSE; - } - + + return FALSE; + } + return TRUE; } @@ -1768,7 +1751,7 @@ * * Compute the cryptographic hash of a session key object. * - * PARAMS + * PARAMS * hHash [I] Handle to the hash object. * hKey [I] Handle to the key to be hashed. * dwFlags [I] Can be CRYPT_LITTLE_ENDIAN. @@ -1883,7 +1866,7 @@ PCRYPTHASH hash = (PCRYPTHASH)hHash; PCRYPTPROV prov; - TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n", + TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n", hHash, dwKeySpec, debugstr_w(sDescription), dwFlags, pbSignature, pdwSigLen); if (!hash) @@ -1914,7 +1897,7 @@ LPWSTR wsDescription; BOOL result; - TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n", + TRACE("(0x%lx, %d, %s, %08x, %p, %p)\n", hHash, dwKeySpec, debugstr_a(sDescription), dwFlags, pbSignature, pdwSigLen); CRYPT_ANSIToUnicode(sDescription, &wsDescription, -1); @@ -2075,7 +2058,7 @@ return FALSE; } CRYPT_Free(keyname); - + if (dwFlags & CRYPT_DELETE_DEFAULT) { RegDeleteValueW(hTypeKey, nameW); @@ -2097,7 +2080,7 @@ return FALSE; } CRYPT_Free(keyname); - + if (RegSetValueExW(hTypeKey, nameW, 0, REG_SZ, (const BYTE *)pszProvName, (strlenW(pszProvName) + 1)*sizeof(WCHAR))) { @@ -2105,7 +2088,7 @@ RegCloseKey(hProvKey); return FALSE; } - + RegCloseKey(hProvKey); } RegCloseKey(hTypeKey); @@ -2201,7 +2184,7 @@ * RETURNS * Success: TRUE * Failure: FALSE - * + * * NOTES * Because of security flaws sDescription should not be used and should thus be * NULL. It is supported only for compatibility with Microsoft's Cryptographic @@ -2224,7 +2207,7 @@ SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } - + prov = hash->pProvider; return prov->pFuncs->pCPVerifySignature(prov->hPrivate, hash->hPrivate, pbSignature, dwSigLen, key->hPrivate, sDescription, dwFlags); @@ -2316,8 +2299,8 @@ 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. @@ -2332,10 +2315,10 @@ * 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_PROCESS + * RTL_ENCRYPT_OPTION_CROSS_PROCESS * RTL_ENCRYPT_OPTION_SAME_LOGON - * + * * RETURNS * Success: STATUS_SUCCESS * Failure: NTSTATUS error code Modified: trunk/reactos/dll/win32/advapi32/crypt/crypt.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/c…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/crypt/crypt.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -91,30 +91,12 @@ extern unsigned char *CRYPT_DESunhash( unsigned char *dst, const unsigned char *key, const unsigned char *src ) DECLSPEC_HIDDEN; -void byteReverse(unsigned char *buf, unsigned longs); struct ustring { DWORD Length; DWORD MaximumLength; unsigned char *Buffer; }; -typedef struct { - unsigned int buf[4]; - unsigned int i[2]; - unsigned char in[64]; - unsigned char digest[16]; -} MD4_CTX; - -typedef struct tag_arc4_info { - unsigned char state[256]; - unsigned char x, y; -} arc4_info; - -VOID WINAPI MD4Init( MD4_CTX *ctx ); -VOID WINAPI MD4Update( MD4_CTX *ctx, const unsigned char *buf, unsigned int len ); -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, const struct ustring *key); #endif /* __WINE_CRYPT_H_ */ Removed: trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/c…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c (removed) @@ -1,95 +0,0 @@ -/* - * Copyright 2006 Mike McCormack - * - * based on arc4.cpp - written and placed in the public domain by Wei Dai - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * 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> - -void arc4_init(arc4_info *a4i, const BYTE *key, unsigned int keyLen) -{ - unsigned int keyIndex = 0, stateIndex = 0; - unsigned int i, a; - - a4i->x = a4i->y = 0; - - for (i=0; i<256; i++) - a4i->state[i] = i; - - for (i=0; i<256; i++) - { - a = a4i->state[i]; - stateIndex += key[keyIndex] + a; - stateIndex &= 0xff; - a4i->state[i] = a4i->state[stateIndex]; - a4i->state[stateIndex] = a; - if (++keyIndex >= keyLen) - keyIndex = 0; - } -} - -void arc4_ProcessString(arc4_info *a4i, BYTE *inoutString, unsigned int length) -{ - BYTE *const s=a4i->state; - unsigned int x = a4i->x; - unsigned int y = a4i->y; - unsigned int a, b; - - while(length--) - { - x = (x+1) & 0xff; - a = s[x]; - y = (y+a) & 0xff; - b = s[y]; - s[x] = b; - s[y] = a; - *inoutString++ ^= s[(a+b) & 0xff]; - } - - a4i->x = x; - 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 Removed: trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/c…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c (removed) @@ -1,300 +0,0 @@ -/* - * Copyright (C) 2001 Nikos Mavroyanopoulos - * Copyright (C) 2004 Hans Leidekker - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/* - * This code implements the MD4 message-digest algorithm. - * It is based on code in the public domain written by Colin - * Plumb in 1993. The algorithm is due to Ron Rivest. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD4_CTX structure, pass it to MD4Init, call MD4Update as - * needed on buffers full of bytes, and then call MD4Final, which - * will fill a supplied 16-byte array with the digest. - */ - -#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 */ - -#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__ */ Removed: trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/c…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c (removed) @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2001 Nikos Mavroyanopoulos - * Copyright (C) 2004 Hans Leidekker - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/* - * This code implements the MD5 message-digest algorithm. - * It is based on code in the public domain written by Colin - * Plumb in 1993. The algorithm is due to Ron Rivest. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5_CTX structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - */ - -#include <advapi32.h> - -typedef struct -{ - unsigned int i[2]; - unsigned int buf[4]; - unsigned char in[64]; - 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 */ - -/* #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; -} Removed: trunk/reactos/dll/win32/advapi32/crypt/crypt_sha.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/crypt/c…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_sha.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/crypt/crypt_sha.c (removed) @@ -1,207 +0,0 @@ -/* - * Copyright 2004 Filip Navara - * Based on public domain SHA code by Steve Reid <steve(a)edmweb.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include <advapi32.h> - -/* SHA Context Structure Declaration */ - -typedef struct { - ULONG Unknown[6]; - ULONG State[5]; - ULONG Count[2]; - UCHAR Buffer[64]; -} SHA_CTX, *PSHA_CTX; - -/* SHA1 Helper Macros */ - -#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) -/* FIXME: This definition of DWORD2BE is little endian specific! */ -#define DWORD2BE(x) (((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000); -/* FIXME: This definition of blk0 is little endian specific! */ -#define blk0(i) (Block[i] = (rol(Block[i],24)&0xFF00FF00)|(rol(Block[i],8)&0x00FF00FF)) -#define blk1(i) (Block[i&15] = rol(Block[(i+13)&15]^Block[(i+8)&15]^Block[(i+2)&15]^Block[i&15],1)) -#define f1(x,y,z) (z^(x&(y^z))) -#define f2(x,y,z) (x^y^z) -#define f3(x,y,z) ((x&y)|(z&(x|y))) -#define f4(x,y,z) (x^y^z) -/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define R0(v,w,x,y,z,i) z+=f1(w,x,y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R1(v,w,x,y,z,i) z+=f1(w,x,y)+blk1(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R2(v,w,x,y,z,i) z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); -#define R3(v,w,x,y,z,i) z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); -#define R4(v,w,x,y,z,i) z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); - -/* Hash a single 512-bit block. This is the core of the algorithm. */ -static void SHA1Transform(ULONG State[5], UCHAR Buffer[64]) -{ - ULONG a, b, c, d, e; - ULONG *Block; - - Block = (ULONG*)Buffer; - - /* Copy Context->State[] to working variables */ - a = State[0]; - b = State[1]; - c = State[2]; - d = State[3]; - e = State[4]; - - /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); - R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); - R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); - R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); - R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); - R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); - R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); - R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); - R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); - R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); - R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); - R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); - R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); - R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); - R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); - R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); - R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); - R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); - R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); - R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); - - /* Add the working variables back into Context->State[] */ - State[0] += a; - State[1] += b; - State[2] += c; - State[3] += d; - State[4] += e; - - /* Wipe variables */ - a = b = c = d = e = 0; -} - - -/****************************************************************************** - * A_SHAInit [ADVAPI32.@] - * - * Initialize a SHA context structure. - * - * PARAMS - * Context [O] SHA context - * - * RETURNS - * Nothing - */ -VOID WINAPI -A_SHAInit(PSHA_CTX Context) -{ - /* SHA1 initialization constants */ - Context->State[0] = 0x67452301; - Context->State[1] = 0xEFCDAB89; - Context->State[2] = 0x98BADCFE; - Context->State[3] = 0x10325476; - Context->State[4] = 0xC3D2E1F0; - Context->Count[0] = - Context->Count[1] = 0; -} - -/****************************************************************************** - * A_SHAUpdate [ADVAPI32.@] - * - * Update a SHA context with a hashed data from supplied buffer. - * - * PARAMS - * Context [O] SHA context - * Buffer [I] hashed data - * BufferSize [I] hashed data size - * - * RETURNS - * Nothing - */ -VOID WINAPI -A_SHAUpdate(PSHA_CTX Context, const unsigned char *Buffer, UINT BufferSize) -{ - ULONG BufferContentSize; - - BufferContentSize = Context->Count[1] & 63; - Context->Count[1] += BufferSize; - if (Context->Count[1] < BufferSize) - Context->Count[0]++; - Context->Count[0] += (BufferSize >> 29); - - if (BufferContentSize + BufferSize < 64) - { - RtlCopyMemory(&Context->Buffer[BufferContentSize], Buffer, - BufferSize); - } - else - { - while (BufferContentSize + BufferSize >= 64) - { - RtlCopyMemory(Context->Buffer + BufferContentSize, Buffer, - 64 - BufferContentSize); - Buffer += 64 - BufferContentSize; - BufferSize -= 64 - BufferContentSize; - SHA1Transform(Context->State, Context->Buffer); - BufferContentSize = 0; - } - RtlCopyMemory(Context->Buffer + BufferContentSize, Buffer, BufferSize); - } -} - -/****************************************************************************** - * A_SHAFinal [ADVAPI32.@] - * - * Finalize SHA context and return the resulting hash. - * - * PARAMS - * Context [I/O] SHA context - * Result [O] resulting hash - * - * RETURNS - * Nothing - */ -VOID WINAPI -A_SHAFinal(PSHA_CTX Context, PULONG Result) -{ - INT Pad, Index; - UCHAR Buffer[72]; - ULONG *Count; - ULONG BufferContentSize, LengthHi, LengthLo; - - BufferContentSize = Context->Count[1] & 63; - if (BufferContentSize >= 56) - Pad = 56 + 64 - BufferContentSize; - else - Pad = 56 - BufferContentSize; - - LengthHi = (Context->Count[0] << 3) | (Context->Count[1] >> (32 - 3)); - LengthLo = (Context->Count[1] << 3); - - RtlZeroMemory(Buffer + 1, Pad - 1); - Buffer[0] = 0x80; - Count = (ULONG*)(Buffer + Pad); - Count[0] = DWORD2BE(LengthHi); - Count[1] = DWORD2BE(LengthLo); - A_SHAUpdate(Context, Buffer, Pad + 8); - - for (Index = 0; Index < 5; Index++) - Result[Index] = DWORD2BE(Context->State[Index]); - - A_SHAInit(Context); -} Modified: trunk/reactos/dll/win32/advapi32/misc/sysfunc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/misc/sy…
============================================================================== --- trunk/reactos/dll/win32/advapi32/misc/sysfunc.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/advapi32/misc/sysfunc.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -12,6 +12,9 @@ */ #include <advapi32.h> +#include <md4.h> +#include <md5.h> +#include <rc4.h> static const unsigned char CRYPT_LMhash_Magic[8] = { 'K', 'G', 'S', '!', '@', '#', '$', '%' }; @@ -502,10 +505,10 @@ 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); + RC4_CONTEXT a4i; + + rc4_init(&a4i, key->Buffer, key->Length); + rc4_crypt(&a4i, data->Buffer, data->Length); return STATUS_SUCCESS; } @@ -626,10 +629,10 @@ * 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_PROCESS + * RTL_ENCRYPT_OPTION_CROSS_PROCESS * RTL_ENCRYPT_OPTION_SAME_LOGON - * + * * RETURNS * Success: STATUS_SUCCESS * Failure: NTSTATUS error code Modified: trunk/reactos/lib/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/CMakeLists.txt?rev=618…
============================================================================== --- trunk/reactos/lib/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/lib/CMakeLists.txt [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -7,6 +7,7 @@ add_subdirectory(3rdparty) add_subdirectory(atl) add_subdirectory(cportlib) +add_subdirectory(cryptlib) #add_subdirectory(dnslib) Nothing links to this lib. add_subdirectory(drivers) add_subdirectory(epsapi) Propchange: trunk/reactos/lib/cryptlib/ ------------------------------------------------------------------------------ --- bugtraq:logregex (added) +++ bugtraq:logregex Sat Jan 25 13:55:08 2014 @@ -0,0 +1,2 @@ +([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))? +(\d+) Propchange: trunk/reactos/lib/cryptlib/ ------------------------------------------------------------------------------ bugtraq:message = See issue #%BUGID% for more details. Propchange: trunk/reactos/lib/cryptlib/ ------------------------------------------------------------------------------ bugtraq:url =
http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID%
Propchange: trunk/reactos/lib/cryptlib/ ------------------------------------------------------------------------------ tsvn:logminsize = 10 Added: trunk/reactos/lib/cryptlib/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/CMakeLists.tx…
============================================================================== --- trunk/reactos/lib/cryptlib/CMakeLists.txt (added) +++ trunk/reactos/lib/cryptlib/CMakeLists.txt [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,9 @@ + +add_library(cryptlib + md4.c + md5.c + mvAesAlg.c + rc4.c + sha1.c + util.c +) Propchange: trunk/reactos/lib/cryptlib/CMakeLists.txt ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/lib/cryptlib/README.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/README.txt?re…
============================================================================== --- trunk/reactos/lib/cryptlib/README.txt (added) +++ trunk/reactos/lib/cryptlib/README.txt [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,29 @@ + +This libbrary implements the following algorithms: + +MD4 +--- +- files: md4.c, md4.h +- Implements: MD4Init, MD4Update, MD4Final + +MD5 +--- +- files: md5.c, md5.h +- Implements: MD5Init, MD5Update, MD5Final + +RC4 +--- +- files: rc4.c, rc4.h +- Implements: rc4_init, rc4_crypt + +SHA1 +---- +- files: sha1.c, sha1.h +- Implements: A_SHAInit, A_SHAUpdate, A_SHAFinal + +AES +--- +- files: mvAesAlg.c, mvAesAlg.h, mvOs.h, mvAesBoxes.dat +- Taken from:
http://enduser.subsignal.org/~trondah/tree/target/linux/generic/files/crypt…
+- Original reference implementation:
https://github.com/briandfoy/crypt-rijndael/tree/master/rijndael-vals/refer…
+- Implements: rijndaelEncrypt128, rijndaelDecrypt128 Propchange: trunk/reactos/lib/cryptlib/README.txt ------------------------------------------------------------------------------ svn:eol-style = native Copied: trunk/reactos/lib/cryptlib/md4.c (from r61706, trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c) URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/md4.c?p2=trun…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_md4.c [iso-8859-1] (original) +++ trunk/reactos/lib/cryptlib/md4.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -33,7 +33,8 @@ * will fill a supplied 16-byte array with the digest. */ -#include <advapi32.h> +#include "md4.h" +#include "util.h" static void MD4Transform( unsigned int buf[4], unsigned int const in[16] ); @@ -41,7 +42,7 @@ * Start MD4 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -VOID WINAPI MD4Init( MD4_CTX *ctx ) +VOID NTAPI MD4Init( MD4_CTX *ctx ) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; @@ -55,7 +56,7 @@ * 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 ) +VOID NTAPI MD4Update( MD4_CTX *ctx, const unsigned char *buf, unsigned int len ) { register unsigned int t; @@ -106,10 +107,10 @@ } /* - * Final wrapup - pad to 64-byte boundary with the bit pattern + * 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 ) +VOID NTAPI MD4Final( MD4_CTX *ctx ) { unsigned int count; unsigned char *p; @@ -243,58 +244,3 @@ 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__ */ Added: trunk/reactos/lib/cryptlib/md4.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/md4.h?rev=618…
============================================================================== --- trunk/reactos/lib/cryptlib/md4.h (added) +++ trunk/reactos/lib/cryptlib/md4.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,19 @@ + +#pragma once + +#include <ntdef.h> + +typedef struct +{ + unsigned int buf[4]; + unsigned int i[2]; + unsigned char in[64]; + unsigned char digest[16]; +} MD4_CTX; + +VOID NTAPI MD4Init( MD4_CTX *ctx ); + +VOID NTAPI MD4Update( MD4_CTX *ctx, const unsigned char *buf, unsigned int len ); + +VOID NTAPI MD4Final( MD4_CTX *ctx ); + Propchange: trunk/reactos/lib/cryptlib/md4.h ------------------------------------------------------------------------------ svn:eol-style = native Copied: trunk/reactos/lib/cryptlib/md5.c (from r61706, trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c) URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/md5.c?p2=trun…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_md5.c [iso-8859-1] (original) +++ trunk/reactos/lib/cryptlib/md5.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -33,15 +33,8 @@ * will fill a supplied 16-byte array with the digest. */ -#include <advapi32.h> - -typedef struct -{ - unsigned int i[2]; - unsigned int buf[4]; - unsigned char in[64]; - unsigned char digest[16]; -} MD5_CTX; +#include "md5.h" +#include "util.h" static void MD5Transform( unsigned int buf[4], const unsigned int in[16] ); @@ -49,7 +42,7 @@ * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -VOID WINAPI MD5Init( MD5_CTX *ctx ) +VOID NTAPI MD5Init( MD5_CTX *ctx ) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; @@ -63,7 +56,7 @@ * 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 ) +VOID NTAPI MD5Update( MD5_CTX *ctx, const unsigned char *buf, unsigned int len ) { register unsigned int t; @@ -114,10 +107,10 @@ } /* - * Final wrapup - pad to 64-byte boundary with the bit pattern + * 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 ) +VOID NTAPI MD5Final( MD5_CTX *ctx ) { unsigned int count; unsigned char *p; @@ -260,3 +253,4 @@ buf[2] += c; buf[3] += d; } + Added: trunk/reactos/lib/cryptlib/md5.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/md5.h?rev=618…
============================================================================== --- trunk/reactos/lib/cryptlib/md5.h (added) +++ trunk/reactos/lib/cryptlib/md5.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,19 @@ + +#pragma once + +#include <ntdef.h> + +typedef struct +{ + unsigned int i[2]; + unsigned int buf[4]; + unsigned char in[64]; + unsigned char digest[16]; +} MD5_CTX; + +VOID NTAPI MD5Init( MD5_CTX *ctx ); + +VOID NTAPI MD5Update( MD5_CTX *ctx, const unsigned char *buf, unsigned int len ); + +VOID NTAPI MD5Final( MD5_CTX *ctx ); + Propchange: trunk/reactos/lib/cryptlib/md5.h ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/lib/cryptlib/mvAesAlg.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/mvAesAlg.c?re…
============================================================================== --- trunk/reactos/lib/cryptlib/mvAesAlg.c (added) +++ trunk/reactos/lib/cryptlib/mvAesAlg.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,317 @@ +/* rijndael-alg-ref.c v2.0 August '99 + * Reference ANSI C code + * authors: Paulo Barreto + * Vincent Rijmen, K.U.Leuven + * + * This code is placed in the public domain. + */ + +#include "mvOs.h" + +#include "mvAesAlg.h" + +#include "mvAesBoxes.dat" + + +MV_U8 mul1(MV_U8 aa, MV_U8 bb); +void KeyAddition(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC], MV_U8 BC); +void ShiftRow128Enc(MV_U8 a[4][MAXBC]); +void ShiftRow128Dec(MV_U8 a[4][MAXBC]); +void Substitution(MV_U8 a[4][MAXBC], MV_U8 box[256]); +void MixColumn(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC]); +void InvMixColumn(MV_U8 a[4][MAXBC]); + + +#define mul(aa, bb) (mask[bb] & Alogtable[aa + Logtable[bb]]) + +MV_U8 mul1(MV_U8 aa, MV_U8 bb) +{ + return mask[bb] & Alogtable[aa + Logtable[bb]]; +} + + +void KeyAddition(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC], MV_U8 BC) +{ + /* Exor corresponding text input and round key input bytes + */ + ((MV_U32*)(&(a[0][0])))[0] ^= ((MV_U32*)(&(rk[0][0])))[0]; + ((MV_U32*)(&(a[1][0])))[0] ^= ((MV_U32*)(&(rk[1][0])))[0]; + ((MV_U32*)(&(a[2][0])))[0] ^= ((MV_U32*)(&(rk[2][0])))[0]; + ((MV_U32*)(&(a[3][0])))[0] ^= ((MV_U32*)(&(rk[3][0])))[0]; + +} + +void ShiftRow128Enc(MV_U8 a[4][MAXBC]) { + /* Row 0 remains unchanged + * The other three rows are shifted a variable amount + */ + MV_U8 tmp[MAXBC]; + + tmp[0] = a[1][1]; + tmp[1] = a[1][2]; + tmp[2] = a[1][3]; + tmp[3] = a[1][0]; + + ((MV_U32*)(&(a[1][0])))[0] = ((MV_U32*)(&(tmp[0])))[0]; + /* + a[1][0] = tmp[0]; + a[1][1] = tmp[1]; + a[1][2] = tmp[2]; + a[1][3] = tmp[3]; + */ + tmp[0] = a[2][2]; + tmp[1] = a[2][3]; + tmp[2] = a[2][0]; + tmp[3] = a[2][1]; + + ((MV_U32*)(&(a[2][0])))[0] = ((MV_U32*)(&(tmp[0])))[0]; + /* + a[2][0] = tmp[0]; + a[2][1] = tmp[1]; + a[2][2] = tmp[2]; + a[2][3] = tmp[3]; + */ + tmp[0] = a[3][3]; + tmp[1] = a[3][0]; + tmp[2] = a[3][1]; + tmp[3] = a[3][2]; + + ((MV_U32*)(&(a[3][0])))[0] = ((MV_U32*)(&(tmp[0])))[0]; + /* + a[3][0] = tmp[0]; + a[3][1] = tmp[1]; + a[3][2] = tmp[2]; + a[3][3] = tmp[3]; + */ +} + +void ShiftRow128Dec(MV_U8 a[4][MAXBC]) { + /* Row 0 remains unchanged + * The other three rows are shifted a variable amount + */ + MV_U8 tmp[MAXBC]; + + tmp[0] = a[1][3]; + tmp[1] = a[1][0]; + tmp[2] = a[1][1]; + tmp[3] = a[1][2]; + + ((MV_U32*)(&(a[1][0])))[0] = ((MV_U32*)(&(tmp[0])))[0]; + /* + a[1][0] = tmp[0]; + a[1][1] = tmp[1]; + a[1][2] = tmp[2]; + a[1][3] = tmp[3]; + */ + + tmp[0] = a[2][2]; + tmp[1] = a[2][3]; + tmp[2] = a[2][0]; + tmp[3] = a[2][1]; + + ((MV_U32*)(&(a[2][0])))[0] = ((MV_U32*)(&(tmp[0])))[0]; + /* + a[2][0] = tmp[0]; + a[2][1] = tmp[1]; + a[2][2] = tmp[2]; + a[2][3] = tmp[3]; + */ + + tmp[0] = a[3][1]; + tmp[1] = a[3][2]; + tmp[2] = a[3][3]; + tmp[3] = a[3][0]; + + ((MV_U32*)(&(a[3][0])))[0] = ((MV_U32*)(&(tmp[0])))[0]; + /* + a[3][0] = tmp[0]; + a[3][1] = tmp[1]; + a[3][2] = tmp[2]; + a[3][3] = tmp[3]; + */ +} + +void Substitution(MV_U8 a[4][MAXBC], MV_U8 box[256]) { + /* Replace every byte of the input by the byte at that place + * in the nonlinear S-box + */ + int i, j; + + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) a[i][j] = box[a[i][j]] ; +} + +void MixColumn(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC]) { + /* Mix the four bytes of every column in a linear way + */ + MV_U8 b[4][MAXBC]; + int i, j; + + for(j = 0; j < 4; j++){ + b[0][j] = mul(25,a[0][j]) ^ mul(1,a[1][j]) ^ a[2][j] ^ a[3][j]; + b[1][j] = mul(25,a[1][j]) ^ mul(1,a[2][j]) ^ a[3][j] ^ a[0][j]; + b[2][j] = mul(25,a[2][j]) ^ mul(1,a[3][j]) ^ a[0][j] ^ a[1][j]; + b[3][j] = mul(25,a[3][j]) ^ mul(1,a[0][j]) ^ a[1][j] ^ a[2][j]; + } + for(i = 0; i < 4; i++) + /*for(j = 0; j < BC; j++) a[i][j] = b[i][j];*/ + ((MV_U32*)(&(a[i][0])))[0] = ((MV_U32*)(&(b[i][0])))[0] ^ ((MV_U32*)(&(rk[i][0])))[0];; +} + +void InvMixColumn(MV_U8 a[4][MAXBC]) { + /* Mix the four bytes of every column in a linear way + * This is the opposite operation of Mixcolumn + */ + MV_U8 b[4][MAXBC]; + int i, j; + + for(j = 0; j < 4; j++){ + b[0][j] = mul(223,a[0][j]) ^ mul(104,a[1][j]) ^ mul(238,a[2][j]) ^ mul(199,a[3][j]); + b[1][j] = mul(223,a[1][j]) ^ mul(104,a[2][j]) ^ mul(238,a[3][j]) ^ mul(199,a[0][j]); + b[2][j] = mul(223,a[2][j]) ^ mul(104,a[3][j]) ^ mul(238,a[0][j]) ^ mul(199,a[1][j]); + b[3][j] = mul(223,a[3][j]) ^ mul(104,a[0][j]) ^ mul(238,a[1][j]) ^ mul(199,a[2][j]); + } + for(i = 0; i < 4; i++) + /*for(j = 0; j < BC; j++) a[i][j] = b[i][j];*/ + ((MV_U32*)(&(a[i][0])))[0] = ((MV_U32*)(&(b[i][0])))[0]; +} + +int rijndaelKeySched (MV_U8 k[4][MAXKC], int keyBits, int blockBits, MV_U8 W[MAXROUNDS+1][4][MAXBC]) +{ + /* Calculate the necessary round keys + * The number of calculations depends on keyBits and blockBits + */ + int KC, BC, ROUNDS; + int i, j, t, rconpointer = 0; + MV_U8 tk[4][MAXKC]; + + switch (keyBits) { + case 128: KC = 4; break; + case 192: KC = 6; break; + case 256: KC = 8; break; + default : return (-1); + } + + switch (blockBits) { + case 128: BC = 4; break; + case 192: BC = 6; break; + case 256: BC = 8; break; + default : return (-2); + } + + switch (keyBits >= blockBits ? keyBits : blockBits) { + case 128: ROUNDS = 10; break; + case 192: ROUNDS = 12; break; + case 256: ROUNDS = 14; break; + default : return (-3); /* this cannot happen */ + } + + + for(j = 0; j < KC; j++) + for(i = 0; i < 4; i++) + tk[i][j] = k[i][j]; + t = 0; + /* copy values into round key array */ + for(j = 0; (j < KC) && (t < (ROUNDS+1)*BC); j++, t++) + for(i = 0; i < 4; i++) W[t / BC][i][t % BC] = tk[i][j]; + + while (t < (ROUNDS+1)*BC) { /* while not enough round key material calculated */ + /* calculate new values */ + for(i = 0; i < 4; i++) + tk[i][0] ^= S[tk[(i+1)%4][KC-1]]; + tk[0][0] ^= rcon[rconpointer++]; + + if (KC != 8) + for(j = 1; j < KC; j++) + for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1]; + else { + for(j = 1; j < KC/2; j++) + for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1]; + for(i = 0; i < 4; i++) tk[i][KC/2] ^= S[tk[i][KC/2 - 1]]; + for(j = KC/2 + 1; j < KC; j++) + for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1]; + } + /* copy values into round key array */ + for(j = 0; (j < KC) && (t < (ROUNDS+1)*BC); j++, t++) + for(i = 0; i < 4; i++) W[t / BC][i][t % BC] = tk[i][j]; + } + + return 0; +} + + + +int rijndaelEncrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds) +{ + /* Encryption of one block. + */ + int r, BC, ROUNDS; + + BC = 4; + ROUNDS = rounds; + + /* begin with a key addition + */ + + KeyAddition(a,rk[0],BC); + + /* ROUNDS-1 ordinary rounds + */ + for(r = 1; r < ROUNDS; r++) { + Substitution(a,S); + ShiftRow128Enc(a); + MixColumn(a, rk[r]); + /*KeyAddition(a,rk[r],BC);*/ + } + + /* Last round is special: there is no MixColumn + */ + Substitution(a,S); + ShiftRow128Enc(a); + KeyAddition(a,rk[ROUNDS],BC); + + return 0; +} + + +int rijndaelDecrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds) +{ + int r, BC, ROUNDS; + + BC = 4; + ROUNDS = rounds; + + /* To decrypt: apply the inverse operations of the encrypt routine, + * in opposite order + * + * (KeyAddition is an involution: it 's equal to its inverse) + * (the inverse of Substitution with table S is Substitution with the inverse table of S) + * (the inverse of Shiftrow is Shiftrow over a suitable distance) + */ + + /* First the special round: + * without InvMixColumn + * with extra KeyAddition + */ + KeyAddition(a,rk[ROUNDS],BC); + ShiftRow128Dec(a); + Substitution(a,Si); + + /* ROUNDS-1 ordinary rounds + */ + for(r = ROUNDS-1; r > 0; r--) { + KeyAddition(a,rk[r],BC); + InvMixColumn(a); + ShiftRow128Dec(a); + Substitution(a,Si); + + } + + /* End with the extra key addition + */ + + KeyAddition(a,rk[0],BC); + + return 0; +} + Propchange: trunk/reactos/lib/cryptlib/mvAesAlg.c ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/lib/cryptlib/mvAesAlg.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/mvAesAlg.h?re…
============================================================================== --- trunk/reactos/lib/cryptlib/mvAesAlg.h (added) +++ trunk/reactos/lib/cryptlib/mvAesAlg.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,19 @@ +/* rijndael-alg-ref.h v2.0 August '99 + * Reference ANSI C code + * authors: Paulo Barreto + * Vincent Rijmen, K.U.Leuven + */ +#ifndef __RIJNDAEL_ALG_H +#define __RIJNDAEL_ALG_H + +#define MAXBC (128/32) +#define MAXKC (256/32) +#define MAXROUNDS 14 + + +int rijndaelKeySched (MV_U8 k[4][MAXKC], int keyBits, int blockBits, MV_U8 rk[MAXROUNDS+1][4][MAXBC]); + +int rijndaelEncrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds); +int rijndaelDecrypt128(MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds); + +#endif /* __RIJNDAEL_ALG_H */ Propchange: trunk/reactos/lib/cryptlib/mvAesAlg.h ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/lib/cryptlib/mvAesBoxes.dat URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/mvAesBoxes.da…
============================================================================== --- trunk/reactos/lib/cryptlib/mvAesBoxes.dat (added) +++ trunk/reactos/lib/cryptlib/mvAesBoxes.dat [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,123 @@ +static MV_U8 mask[256] = { +0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +}; + +static MV_U8 Logtable[256] = { + 0, 0, 25, 1, 50, 2, 26, 198, 75, 199, 27, 104, 51, 238, 223, 3, +100, 4, 224, 14, 52, 141, 129, 239, 76, 113, 8, 200, 248, 105, 28, 193, +125, 194, 29, 181, 249, 185, 39, 106, 77, 228, 166, 114, 154, 201, 9, 120, +101, 47, 138, 5, 33, 15, 225, 36, 18, 240, 130, 69, 53, 147, 218, 142, +150, 143, 219, 189, 54, 208, 206, 148, 19, 92, 210, 241, 64, 70, 131, 56, +102, 221, 253, 48, 191, 6, 139, 98, 179, 37, 226, 152, 34, 136, 145, 16, +126, 110, 72, 195, 163, 182, 30, 66, 58, 107, 40, 84, 250, 133, 61, 186, + 43, 121, 10, 21, 155, 159, 94, 202, 78, 212, 172, 229, 243, 115, 167, 87, +175, 88, 168, 80, 244, 234, 214, 116, 79, 174, 233, 213, 231, 230, 173, 232, + 44, 215, 117, 122, 235, 22, 11, 245, 89, 203, 95, 176, 156, 169, 81, 160, +127, 12, 246, 111, 23, 196, 73, 236, 216, 67, 31, 45, 164, 118, 123, 183, +204, 187, 62, 90, 251, 96, 177, 134, 59, 82, 161, 108, 170, 85, 41, 157, +151, 178, 135, 144, 97, 190, 220, 252, 188, 149, 207, 205, 55, 63, 91, 209, + 83, 57, 132, 60, 65, 162, 109, 71, 20, 42, 158, 93, 86, 242, 211, 171, + 68, 17, 146, 217, 35, 32, 46, 137, 180, 124, 184, 38, 119, 153, 227, 165, +103, 74, 237, 222, 197, 49, 254, 24, 13, 99, 140, 128, 192, 247, 112, 7, +}; + +static MV_U8 Alogtable[512] = { + 1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53, + 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170, +229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49, + 83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205, + 76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136, +131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154, +181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163, +254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160, +251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65, +195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117, +159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128, +155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84, +252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202, + 69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14, + 18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23, + 57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1, + + 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53, + 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170, +229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49, + 83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205, + 76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136, +131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154, +181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163, +254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160, +251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65, +195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117, +159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128, +155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84, +252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202, + 69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14, + 18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23, + 57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1, + +}; + +static MV_U8 S[256] = { + 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, +202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, +183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21, + 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117, + 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132, + 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, +208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168, + 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210, +205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115, + 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, +224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, +231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, +186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, +112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, +225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, +140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22, +}; + +static MV_U8 Si[256] = { + 82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251, +124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233, 203, + 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, 250, 195, 78, + 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, 109, 139, 209, 37, +114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92, 204, 93, 101, 182, 146, +108, 112, 72, 80, 253, 237, 185, 218, 94, 21, 70, 87, 167, 141, 157, 132, +144, 216, 171, 0, 140, 188, 211, 10, 247, 228, 88, 5, 184, 179, 69, 6, +208, 44, 30, 143, 202, 63, 15, 2, 193, 175, 189, 3, 1, 19, 138, 107, + 58, 145, 17, 65, 79, 103, 220, 234, 151, 242, 207, 206, 240, 180, 230, 115, +150, 172, 116, 34, 231, 173, 53, 133, 226, 249, 55, 232, 28, 117, 223, 110, + 71, 241, 26, 113, 29, 41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, +252, 86, 62, 75, 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, + 31, 221, 168, 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, + 96, 81, 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, +160, 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97, + 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, 125, +}; + +/* +static MV_U8 iG[4][4] = { +{0x0e, 0x09, 0x0d, 0x0b}, +{0x0b, 0x0e, 0x09, 0x0d}, +{0x0d, 0x0b, 0x0e, 0x09}, +{0x09, 0x0d, 0x0b, 0x0e}, +}; +*/ +static MV_U32 rcon[30] = { + 0x01,0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, }; Propchange: trunk/reactos/lib/cryptlib/mvAesBoxes.dat ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/lib/cryptlib/mvOs.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/mvOs.h?rev=61…
============================================================================== --- trunk/reactos/lib/cryptlib/mvOs.h (added) +++ trunk/reactos/lib/cryptlib/mvOs.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,7 @@ + +#pragma once + +typedef unsigned char MV_U8; +typedef unsigned short MV_U16; +typedef unsigned long MV_U32; + Propchange: trunk/reactos/lib/cryptlib/mvOs.h ------------------------------------------------------------------------------ svn:eol-style = native Copied: trunk/reactos/lib/cryptlib/rc4.c (from r61804, trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c) URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/rc4.c?p2=trun…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_arc4.c [iso-8859-1] (original) +++ trunk/reactos/lib/cryptlib/rc4.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -20,9 +20,9 @@ /*
http://cryptopp.sourceforge.net/docs/ref521/arc4_8cpp-source.html
*/ -#include <advapi32.h> +#include "rc4.h" -void arc4_init(arc4_info *a4i, const BYTE *key, unsigned int keyLen) +void rc4_init(RC4_CONTEXT *a4i, const unsigned char *key, unsigned int keyLen) { unsigned int keyIndex = 0, stateIndex = 0; unsigned int i, a; @@ -44,9 +44,9 @@ } } -void arc4_ProcessString(arc4_info *a4i, BYTE *inoutString, unsigned int length) +void rc4_crypt(RC4_CONTEXT *a4i, unsigned char *inoutString, unsigned int length) { - BYTE *const s=a4i->state; + unsigned char *const s=a4i->state; unsigned int x = a4i->x; unsigned int y = a4i->y; unsigned int a, b; @@ -65,31 +65,3 @@ a4i->x = x; 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 Added: trunk/reactos/lib/cryptlib/rc4.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/rc4.h?rev=618…
============================================================================== --- trunk/reactos/lib/cryptlib/rc4.h (added) +++ trunk/reactos/lib/cryptlib/rc4.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,13 @@ + +#pragma once + +typedef struct _RC4_CONTEXT +{ + unsigned char state[256]; + unsigned char x, y; +} RC4_CONTEXT; + +void rc4_init(RC4_CONTEXT *a4i, const unsigned char *key, unsigned int keyLen); + +void rc4_crypt(RC4_CONTEXT *a4i, unsigned char *inoutString, unsigned int length); + Propchange: trunk/reactos/lib/cryptlib/rc4.h ------------------------------------------------------------------------------ svn:eol-style = native Copied: trunk/reactos/lib/cryptlib/sha1.c (from r61706, trunk/reactos/dll/win32/advapi32/crypt/crypt_sha.c) URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/sha1.c?p2=tru…
============================================================================== --- trunk/reactos/dll/win32/advapi32/crypt/crypt_sha.c [iso-8859-1] (original) +++ trunk/reactos/lib/cryptlib/sha1.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -17,16 +17,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <advapi32.h> - -/* SHA Context Structure Declaration */ - -typedef struct { - ULONG Unknown[6]; - ULONG State[5]; - ULONG Count[2]; - UCHAR Buffer[64]; -} SHA_CTX, *PSHA_CTX; +#include "sha1.h" /* SHA1 Helper Macros */ @@ -107,7 +98,7 @@ * RETURNS * Nothing */ -VOID WINAPI +VOID NTAPI A_SHAInit(PSHA_CTX Context) { /* SHA1 initialization constants */ @@ -133,8 +124,8 @@ * RETURNS * Nothing */ -VOID WINAPI -A_SHAUpdate(PSHA_CTX Context, const unsigned char *Buffer, UINT BufferSize) +VOID NTAPI +A_SHAUpdate(PSHA_CTX Context, const unsigned char *Buffer, ULONG BufferSize) { ULONG BufferContentSize; @@ -146,21 +137,21 @@ if (BufferContentSize + BufferSize < 64) { - RtlCopyMemory(&Context->Buffer[BufferContentSize], Buffer, + memcpy(&Context->Buffer[BufferContentSize], Buffer, BufferSize); } else { while (BufferContentSize + BufferSize >= 64) { - RtlCopyMemory(Context->Buffer + BufferContentSize, Buffer, + memcpy(Context->Buffer + BufferContentSize, Buffer, 64 - BufferContentSize); Buffer += 64 - BufferContentSize; BufferSize -= 64 - BufferContentSize; SHA1Transform(Context->State, Context->Buffer); BufferContentSize = 0; } - RtlCopyMemory(Context->Buffer + BufferContentSize, Buffer, BufferSize); + memcpy(Context->Buffer + BufferContentSize, Buffer, BufferSize); } } @@ -176,7 +167,7 @@ * RETURNS * Nothing */ -VOID WINAPI +VOID NTAPI A_SHAFinal(PSHA_CTX Context, PULONG Result) { INT Pad, Index; @@ -193,7 +184,7 @@ LengthHi = (Context->Count[0] << 3) | (Context->Count[1] >> (32 - 3)); LengthLo = (Context->Count[1] << 3); - RtlZeroMemory(Buffer + 1, Pad - 1); + memset(Buffer + 1, 0, Pad - 1); Buffer[0] = 0x80; Count = (ULONG*)(Buffer + Pad); Count[0] = DWORD2BE(LengthHi); Added: trunk/reactos/lib/cryptlib/sha1.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/sha1.h?rev=61…
============================================================================== --- trunk/reactos/lib/cryptlib/sha1.h (added) +++ trunk/reactos/lib/cryptlib/sha1.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,24 @@ + +#pragma once + +#include <ntdef.h> + +/* SHA Context Structure Declaration */ +typedef struct +{ + ULONG Unknown[6]; + ULONG State[5]; + ULONG Count[2]; + UCHAR Buffer[64]; +} SHA_CTX, *PSHA_CTX; + +VOID NTAPI +A_SHAInit(PSHA_CTX Context); + +VOID NTAPI +A_SHAUpdate(PSHA_CTX Context, const unsigned char *Buffer, ULONG BufferSize); + +VOID NTAPI +A_SHAFinal(PSHA_CTX Context, PULONG Result); + + Propchange: trunk/reactos/lib/cryptlib/sha1.h ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/lib/cryptlib/util.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/util.c?rev=61…
============================================================================== --- trunk/reactos/lib/cryptlib/util.c (added) +++ trunk/reactos/lib/cryptlib/util.c [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,26 @@ + + +#if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#include <stdlib.h> +#include <intrin.h> + +void +byteReverse(unsigned char *buf, unsigned longs) +{ + unsigned int t; + + do + { +#if 0 + t = (unsigned int)((unsigned)buf[3] << 8 | buf[2]) << 16 | + ((unsigned)buf[1] << 8 | buf[0]); +#else + t = _byteswap_ulong(*(unsigned int *)buf); +#endif + *(unsigned int *)buf = t; + buf += 4; + } while (--longs); +} + +#endif // (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + Propchange: trunk/reactos/lib/cryptlib/util.c ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/lib/cryptlib/util.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cryptlib/util.h?rev=61…
============================================================================== --- trunk/reactos/lib/cryptlib/util.h (added) +++ trunk/reactos/lib/cryptlib/util.h [iso-8859-1] Sat Jan 25 13:55:08 2014 @@ -0,0 +1,10 @@ + +#pragma once + + +#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define byteReverse(buf, long)((void)(buf, long)) +#else +void +byteReverse(unsigned char *buf, unsigned longs); +#endif Propchange: trunk/reactos/lib/cryptlib/util.h ------------------------------------------------------------------------------ svn:eol-style = native
10 years, 11 months
1
0
0
0
[akhaldi] 61804: [SAMSRV] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Jan 25 13:16:43 2014 New Revision: 61804 URL:
http://svn.reactos.org/svn/reactos?rev=61804&view=rev
Log: [SAMSRV] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716 Modified: trunk/reactos/dll/win32/samsrv/registry.c trunk/reactos/dll/win32/samsrv/samsrv.c trunk/reactos/dll/win32/samsrv/samsrv.h trunk/reactos/dll/win32/samsrv/setup.c trunk/reactos/dll/win32/samsrv/utils.c Modified: trunk/reactos/dll/win32/samsrv/registry.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/registry.…
============================================================================== --- trunk/reactos/dll/win32/samsrv/registry.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samsrv/registry.c [iso-8859-1] Sat Jan 25 13:16:43 2014 @@ -8,6 +8,9 @@ */ #include "samsrv.h" + +#include <ndk/cmfuncs.h> +#include <ndk/obfuncs.h> /* FUNCTIONS ***************************************************************/ Modified: trunk/reactos/dll/win32/samsrv/samsrv.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/samsrv.c?…
============================================================================== --- trunk/reactos/dll/win32/samsrv/samsrv.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samsrv/samsrv.c [iso-8859-1] Sat Jan 25 13:16:43 2014 @@ -19,6 +19,8 @@ #include "samsrv.h" +#include <samsrv/samsrv.h> + /* GLOBALS *******************************************************************/ ENCRYPTED_NT_OWF_PASSWORD EmptyNtHash; Modified: trunk/reactos/dll/win32/samsrv/samsrv.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/samsrv.h?…
============================================================================== --- trunk/reactos/dll/win32/samsrv/samsrv.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samsrv/samsrv.h [iso-8859-1] Sat Jan 25 13:16:43 2014 @@ -9,31 +9,23 @@ #include <stdio.h> #include <stdlib.h> -#include <limits.h> + #define WIN32_NO_STATUS #define _INC_WINDOWS #define COM_NO_WINDOWS_H + #include <windef.h> #include <winbase.h> #include <winreg.h> -#include <winuser.h> #define NTOS_MODE_USER -#include <ndk/cmfuncs.h> #include <ndk/kefuncs.h> -#include <ndk/obfuncs.h> #include <ndk/rtlfuncs.h> #include <ddk/ntsam.h> -#include <ntsecapi.h> #include <sddl.h> - -#include <samsrv/samsrv.h> - #include <sam_s.h> #include <wine/debug.h> WINE_DEFAULT_DEBUG_CHANNEL(samsrv); - -#include "resources.h" typedef enum _SAM_DB_OBJECT_TYPE { @@ -438,5 +430,3 @@ WINAPI SystemFunction007(PUNICODE_STRING string, LPBYTE hash); - -/* EOF */ Modified: trunk/reactos/dll/win32/samsrv/setup.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/setup.c?r…
============================================================================== --- trunk/reactos/dll/win32/samsrv/setup.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samsrv/setup.c [iso-8859-1] Sat Jan 25 13:16:43 2014 @@ -8,6 +8,10 @@ */ #include "samsrv.h" + +#include <ntsecapi.h> + +#include "resources.h" /* GLOBALS *****************************************************************/ Modified: trunk/reactos/dll/win32/samsrv/utils.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/utils.c?r…
============================================================================== --- trunk/reactos/dll/win32/samsrv/utils.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samsrv/utils.c [iso-8859-1] Sat Jan 25 13:16:43 2014 @@ -8,6 +8,8 @@ */ #include "samsrv.h" + +#include <winuser.h> /* FUNCTIONS ***************************************************************/
10 years, 11 months
1
0
0
0
[akhaldi] 61803: [SAMLIB] * Remove one time inclusions from the main header and put them back where they belong. * Improve header inclusions. CORE-7716
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Jan 25 12:55:52 2014 New Revision: 61803 URL:
http://svn.reactos.org/svn/reactos?rev=61803&view=rev
Log: [SAMLIB] * Remove one time inclusions from the main header and put them back where they belong. * Improve header inclusions. CORE-7716 Modified: trunk/reactos/dll/win32/samlib/dllmain.c trunk/reactos/dll/win32/samlib/precomp.h trunk/reactos/dll/win32/samlib/samlib.c Modified: trunk/reactos/dll/win32/samlib/dllmain.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samlib/dllmain.c…
============================================================================== --- trunk/reactos/dll/win32/samlib/dllmain.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samlib/dllmain.c [iso-8859-1] Sat Jan 25 12:55:52 2014 @@ -24,7 +24,7 @@ * PROGRAMER: Eric Kohl */ -#include "precomp.h" +#include <windef.h> /* FUNCTIONS *****************************************************************/ Modified: trunk/reactos/dll/win32/samlib/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samlib/precomp.h…
============================================================================== --- trunk/reactos/dll/win32/samlib/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samlib/precomp.h [iso-8859-1] Sat Jan 25 12:55:52 2014 @@ -3,14 +3,6 @@ #define WIN32_NO_STATUS #define _INC_WINDOWS #define COM_NO_WINDOWS_H + #include <windef.h> #include <winbase.h> - -#define NTOS_MODE_USER -#include <ndk/rtlfuncs.h> -#include <ntsam.h> - -#include <sam_c.h> - -#include <wine/debug.h> -WINE_DEFAULT_DEBUG_CHANNEL(samlib); Modified: trunk/reactos/dll/win32/samlib/samlib.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samlib/samlib.c?…
============================================================================== --- trunk/reactos/dll/win32/samlib/samlib.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/samlib/samlib.c [iso-8859-1] Sat Jan 25 12:55:52 2014 @@ -26,6 +26,15 @@ #include "precomp.h" +#define NTOS_MODE_USER +#include <ndk/rtlfuncs.h> +#include <ntsam.h> +#include <sam_c.h> + +#include <wine/debug.h> + +WINE_DEFAULT_DEBUG_CHANNEL(samlib); + NTSTATUS WINAPI SystemFunction006(LPCSTR password,
10 years, 11 months
1
0
0
0
[akhaldi] 61802: [RASADHLP] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Jan 25 12:35:30 2014 New Revision: 61802 URL:
http://svn.reactos.org/svn/reactos?rev=61802&view=rev
Log: [RASADHLP] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716 Modified: trunk/reactos/dll/win32/rasadhlp/autodial.c trunk/reactos/dll/win32/rasadhlp/init.c trunk/reactos/dll/win32/rasadhlp/precomp.h trunk/reactos/dll/win32/rasadhlp/winsock.c Modified: trunk/reactos/dll/win32/rasadhlp/autodial.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/rasadhlp/autodia…
============================================================================== --- trunk/reactos/dll/win32/rasadhlp/autodial.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/rasadhlp/autodial.c [iso-8859-1] Sat Jan 25 12:35:30 2014 @@ -5,10 +5,10 @@ * PURPOSE: DLL Initialization */ -/* INCLUDES ******************************************************************/ #include "precomp.h" -/* DATA **********************************************************************/ +#include <ndk/iofuncs.h> +#include <ndk/rtltypes.h> /* FUNCTIONS *****************************************************************/ @@ -120,4 +120,3 @@ /* Send it to the driver */ return AcsHlpSendCommand(&Command); } - Modified: trunk/reactos/dll/win32/rasadhlp/init.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/rasadhlp/init.c?…
============================================================================== --- trunk/reactos/dll/win32/rasadhlp/init.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/rasadhlp/init.c [iso-8859-1] Sat Jan 25 12:35:30 2014 @@ -5,10 +5,7 @@ * PURPOSE: DLL Initialization */ -/* INCLUDES ******************************************************************/ #include "precomp.h" - -/* DATA **********************************************************************/ /* FUNCTIONS *****************************************************************/ Modified: trunk/reactos/dll/win32/rasadhlp/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/rasadhlp/precomp…
============================================================================== --- trunk/reactos/dll/win32/rasadhlp/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/rasadhlp/precomp.h [iso-8859-1] Sat Jan 25 12:35:30 2014 @@ -1,10 +1,3 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS Ancillary Function Driver DLL - * FILE: include/msafd.h - * PURPOSE: Ancillary Function Driver DLL header - */ - #define _WIN32_WINNT 0x502 #define _CRT_SECURE_NO_DEPRECATE #define WIN32_NO_STATUS @@ -16,18 +9,9 @@ /* PSDK Headers */ #include <windef.h> #include <winbase.h> -#include <winnls.h> #include <winsock2.h> -//#include <wsipx.h> #include <wsnetbs.h> #include <wininet.h> - -/* NDK */ -#include <iofuncs.h> -#include <rtltypes.h> - -/* Shared GUIDs */ -#include <nsp_dns.h> /* These should go in rasadhlp.h */ #define FILE_DEVICE_ACD 0x000000F1 Modified: trunk/reactos/dll/win32/rasadhlp/winsock.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/rasadhlp/winsock…
============================================================================== --- trunk/reactos/dll/win32/rasadhlp/winsock.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/rasadhlp/winsock.c [iso-8859-1] Sat Jan 25 12:35:30 2014 @@ -5,10 +5,10 @@ * PURPOSE: DLL Initialization */ -/* INCLUDES ******************************************************************/ #include "precomp.h" -/* DATA **********************************************************************/ +#include <winnls.h> +#include <nsp_dns.h> /* FUNCTIONS *****************************************************************/ @@ -134,4 +134,3 @@ AutodialConnection.Ip4Address = Address; AcsHlpNoteNewConnection(&AutodialAdddress, &AutodialConnection); } -
10 years, 11 months
1
0
0
0
[akhaldi] 61801: [OLEAUT32] * Move some inclusions to the main header. CORE-7716
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Jan 25 11:59:58 2014 New Revision: 61801 URL:
http://svn.reactos.org/svn/reactos?rev=61801&view=rev
Log: [OLEAUT32] * Move some inclusions to the main header. CORE-7716 Modified: trunk/reactos/dll/win32/oleaut32/olefont.c trunk/reactos/dll/win32/oleaut32/olepicture.c trunk/reactos/dll/win32/oleaut32/precomp.h trunk/reactos/dll/win32/oleaut32/tmarshal.c trunk/reactos/dll/win32/oleaut32/typelib.c trunk/reactos/dll/win32/oleaut32/usrmarshal.c trunk/reactos/dll/win32/oleaut32/variant.c trunk/reactos/dll/win32/oleaut32/vartype.c Modified: trunk/reactos/dll/win32/oleaut32/olefont.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/olefont…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/olefont.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/olefont.c [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -23,8 +23,6 @@ */ #include "precomp.h" - -#include <wine/list.h> WINE_DEFAULT_DEBUG_CHANNEL(ole); Modified: trunk/reactos/dll/win32/oleaut32/olepicture.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/olepict…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/olepicture.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/olepicture.c [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -42,7 +42,6 @@ # include <unistd.h> #endif -#include <ole2.h> #include <initguid.h> #include <wincodec.h> Modified: trunk/reactos/dll/win32/oleaut32/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/precomp…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/precomp.h [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -17,14 +17,15 @@ #include <winbase.h> #include <wingdi.h> #include <winreg.h> -#include <objbase.h> +#include <ole2.h> #include <olectl.h> -#include <oleauto.h> #include <wine/debug.h> +#include <wine/list.h> #include <wine/unicode.h> #include "connpt.h" #include "variant.h" +#include "resource.h" #endif /* _OLEAUT32_PCH_ */ Modified: trunk/reactos/dll/win32/oleaut32/tmarshal.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/tmarsha…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/tmarshal.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/tmarshal.c [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -22,8 +22,6 @@ */ #include "precomp.h" - -#include <ole2.h> #include "typelib.h" Modified: trunk/reactos/dll/win32/oleaut32/typelib.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/typelib…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/typelib.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/typelib.c [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -53,8 +53,6 @@ #include <lzexpand.h> #include "typelib.h" - -#include <wine/list.h> WINE_DEFAULT_DEBUG_CHANNEL(ole); WINE_DECLARE_DEBUG_CHANNEL(typelib); Modified: trunk/reactos/dll/win32/oleaut32/usrmarshal.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/usrmars…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/usrmarshal.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/usrmarshal.c [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -20,8 +20,6 @@ */ #include "precomp.h" - -#include <ole2.h> WINE_DEFAULT_DEBUG_CHANNEL(ole); Modified: trunk/reactos/dll/win32/oleaut32/variant.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/variant…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/variant.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/variant.c [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -26,8 +26,6 @@ */ #include "precomp.h" - -#include "resource.h" WINE_DEFAULT_DEBUG_CHANNEL(variant); Modified: trunk/reactos/dll/win32/oleaut32/vartype.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/oleaut32/vartype…
============================================================================== --- trunk/reactos/dll/win32/oleaut32/vartype.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/oleaut32/vartype.c [iso-8859-1] Sat Jan 25 11:59:58 2014 @@ -19,8 +19,6 @@ */ #include "precomp.h" - -#include "resource.h" WINE_DEFAULT_DEBUG_CHANNEL(variant);
10 years, 11 months
1
0
0
0
[akhaldi] 61800: [NEWDEV] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Jan 25 11:32:30 2014 New Revision: 61800 URL:
http://svn.reactos.org/svn/reactos?rev=61800&view=rev
Log: [NEWDEV] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716 Modified: trunk/reactos/dll/win32/newdev/newdev.c trunk/reactos/dll/win32/newdev/newdev_private.h trunk/reactos/dll/win32/newdev/wizard.c Modified: trunk/reactos/dll/win32/newdev/newdev.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/newdev/newdev.c?…
============================================================================== --- trunk/reactos/dll/win32/newdev/newdev.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/newdev/newdev.c [iso-8859-1] Sat Jan 25 11:32:30 2014 @@ -22,6 +22,9 @@ #include "newdev_private.h" +#include <stdio.h> +#include <winnls.h> + /* Global variables */ HINSTANCE hDllInstance; Modified: trunk/reactos/dll/win32/newdev/newdev_private.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/newdev/newdev_pr…
============================================================================== --- trunk/reactos/dll/win32/newdev/newdev_private.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/newdev/newdev_private.h [iso-8859-1] Sat Jan 25 11:32:30 2014 @@ -1,5 +1,7 @@ #ifndef __NEWDEV_PRIVATE_H #define __NEWDEV_PRIVATE_H + +#include <stdarg.h> #define WIN32_NO_STATUS #define _INC_WINDOWS @@ -7,24 +9,17 @@ #define COBJMACROS -#include <stdarg.h> #include <windef.h> #include <winbase.h> #include <winreg.h> #include <wingdi.h> #include <winuser.h> -#include <winnls.h> #include <windowsx.h> -#include <wincon.h> #include <newdev.h> #include <regstr.h> -#include <cfgmgr32.h> -#include <shlobj.h> #include <wine/debug.h> WINE_DEFAULT_DEBUG_CHANNEL(newdev); - -#include <stdio.h> #include "resource.h" Modified: trunk/reactos/dll/win32/newdev/wizard.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/newdev/wizard.c?…
============================================================================== --- trunk/reactos/dll/win32/newdev/wizard.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/newdev/wizard.c [iso-8859-1] Sat Jan 25 11:32:30 2014 @@ -19,6 +19,10 @@ */ #include "newdev_private.h" + +#include <wincon.h> +#include <cfgmgr32.h> +#include <shlobj.h> HANDLE hThread;
10 years, 11 months
1
0
0
0
[akhaldi] 61799: [NETSHELL] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Jan 25 10:59:27 2014 New Revision: 61799 URL:
http://svn.reactos.org/svn/reactos?rev=61799&view=rev
Log: [NETSHELL] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716 Modified: trunk/reactos/dll/win32/netshell/enumlist.h trunk/reactos/dll/win32/netshell/lanconnectui.cpp trunk/reactos/dll/win32/netshell/lanstatusui.cpp trunk/reactos/dll/win32/netshell/netshell.cpp trunk/reactos/dll/win32/netshell/precomp.h Modified: trunk/reactos/dll/win32/netshell/enumlist.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/enumlis…
============================================================================== --- trunk/reactos/dll/win32/netshell/enumlist.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/enumlist.h [iso-8859-1] Sat Jan 25 10:59:27 2014 @@ -1,3 +1,5 @@ +#pragma once + typedef struct tagGUIDStruct { BYTE dummy; /* offset 01 is unknown */ Modified: trunk/reactos/dll/win32/netshell/lanconnectui.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/lanconn…
============================================================================== --- trunk/reactos/dll/win32/netshell/lanconnectui.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/lanconnectui.cpp [iso-8859-1] Sat Jan 25 10:59:27 2014 @@ -1,4 +1,7 @@ #include "precomp.h" + +#include <netcfgx.h> +#include <netcfgn.h> /// CLASSID /// {7007ACC5-3202-11D1-AAD2-00805FC1270E} Modified: trunk/reactos/dll/win32/netshell/lanstatusui.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/lanstat…
============================================================================== --- trunk/reactos/dll/win32/netshell/lanstatusui.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/lanstatusui.cpp [iso-8859-1] Sat Jan 25 10:59:27 2014 @@ -1,4 +1,6 @@ #include "precomp.h" + +#include <winsock.h> /// CLSID /// HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{7007ACCF-3202-11D1-AAD2-00805FC1270E} Modified: trunk/reactos/dll/win32/netshell/netshell.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/netshel…
============================================================================== --- trunk/reactos/dll/win32/netshell/netshell.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/netshell.cpp [iso-8859-1] Sat Jan 25 10:59:27 2014 @@ -1,4 +1,6 @@ #include "precomp.h" + +#include <olectl.h> HINSTANCE netshell_hInstance; const GUID CLSID_LANConnectUI = {0x7007ACC5, 0x3202, 0x11D1, {0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E}}; Modified: trunk/reactos/dll/win32/netshell/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netshell/precomp…
============================================================================== --- trunk/reactos/dll/win32/netshell/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netshell/precomp.h [iso-8859-1] Sat Jan 25 10:59:27 2014 @@ -1,26 +1,23 @@ #ifndef _PRECOMP_H__ #define _PRECOMP_H__ + +#include <stdio.h> #define WIN32_NO_STATUS #define _INC_WINDOWS #define COM_NO_WINDOWS_H -#include <stdio.h> #include <windef.h> +#include <winbase.h> #include <winreg.h> -#include <winbase.h> #include <winnls.h> -#include <winsock2.h> #include <shlwapi.h> #include <shlobj.h> #include <shellapi.h> -#include <olectl.h> #include <iphlpapi.h> #include <setupapi.h> #include <devguid.h> #include <netcon.h> -#include <netcfgx.h> -#include <netcfgn.h> #include <wine/debug.h> WINE_DEFAULT_DEBUG_CHANNEL(shell); @@ -60,7 +57,6 @@ extern const GUID CLSID_NetworkConnections; extern const GUID CLSID_LANConnectUI; extern const GUID CLSID_LanConnectStatusUI; -extern const GUID GUID_DEVCLASS_NET; /* shfldr_netconnect.c */ HRESULT ShowNetConnectionProperties(INetConnection * pNetConnect, HWND hwnd); @@ -91,4 +87,4 @@ #include "enumlist.h" -#endif +#endif /* _PRECOMP_H__ */
10 years, 11 months
1
0
0
0
[akhaldi] 61798: [NETCFGX] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sat Jan 25 10:45:26 2014 New Revision: 61798 URL:
http://svn.reactos.org/svn/reactos?rev=61798&view=rev
Log: [NETCFGX] * Remove one time inclusions from the main header and put them back where they belong. CORE-7716 Modified: trunk/reactos/dll/win32/netcfgx/netcfgx.c trunk/reactos/dll/win32/netcfgx/precomp.h trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c Modified: trunk/reactos/dll/win32/netcfgx/netcfgx.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netcfgx/netcfgx.…
============================================================================== --- trunk/reactos/dll/win32/netcfgx/netcfgx.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netcfgx/netcfgx.c [iso-8859-1] Sat Jan 25 10:45:26 2014 @@ -8,6 +8,12 @@ */ #include "precomp.h" + +#include <olectl.h> + +#define NTOS_MODE_USER +#include <ndk/iofuncs.h> +#include <ndk/rtlfuncs.h> #define NDEBUG #include <debug.h> Modified: trunk/reactos/dll/win32/netcfgx/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netcfgx/precomp.…
============================================================================== --- trunk/reactos/dll/win32/netcfgx/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netcfgx/precomp.h [iso-8859-1] Sat Jan 25 10:45:26 2014 @@ -1,36 +1,26 @@ #ifndef _PRECOMP_H__ #define _PRECOMP_H__ + +#include <stdio.h> + +#define WIN32_NO_STATUS +#define _INC_WINDOWS +#define COM_NO_WINDOWS_H #define COBJMACROS #define NONAMELESSUNION #define NONAMELESSSTRUCT -#define WIN32_NO_STATUS -#define _INC_WINDOWS -#define COM_NO_WINDOWS_H -#include <stdarg.h> #include <windef.h> +#include <winbase.h> #include <winreg.h> -#include <winbase.h> -#include <winnls.h> #include <objbase.h> -#include <winsock2.h> -#define NTOS_MODE_USER -#include <ndk/iofuncs.h> -#include <ndk/rtlfuncs.h> #include <netcfgx.h> #include <setupapi.h> -#include <stdio.h> -#include <iphlpapi.h> -#include <dhcpcsdk.h> -#include <dhcpcapi.h> -#include <olectl.h> #include <netcfgn.h> +#include <devguid.h> + #include "resource.h" -//#include <prsht.h> - -//#include <initguid.h> -#include <devguid.h> typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject); typedef struct { @@ -72,4 +62,4 @@ extern const GUID CLSID_TcpipConfigNotifyObject; -#endif +#endif /* _PRECOMP_H__ */ Modified: trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netcfgx/tcpipcon…
============================================================================== --- trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/netcfgx/tcpipconf_notify.c [iso-8859-1] Sat Jan 25 10:45:26 2014 @@ -1,4 +1,10 @@ #include "precomp.h" + +#include <winnls.h> +#include <winsock.h> +#include <iphlpapi.h> +#include <dhcpcsdk.h> +#include <dhcpcapi.h> typedef struct {
10 years, 11 months
1
0
0
0
[aandrejevic] 61797: [NTVDM] Add two general-purpose variables to the interrupt handler stub stack. Fix INT 29h so that it works correctly when the INT 10h, AH = 0Eh call is hooked.
by aandrejevic@svn.reactos.org
Author: aandrejevic Date: Sat Jan 25 00:53:10 2014 New Revision: 61797 URL:
http://svn.reactos.org/svn/reactos?rev=61797&view=rev
Log: [NTVDM] Add two general-purpose variables to the interrupt handler stub stack. Fix INT 29h so that it works correctly when the INT 10h, AH = 0Eh call is hooked. Modified: branches/ntvdm/subsystems/ntvdm/dos/dos.c branches/ntvdm/subsystems/ntvdm/emulator.h branches/ntvdm/subsystems/ntvdm/int32.c Modified: branches/ntvdm/subsystems/ntvdm/dos/dos.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/dos/dos.…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/dos/dos.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/dos/dos.c [iso-8859-1] Sat Jan 25 00:53:10 2014 @@ -2675,15 +2675,31 @@ * See Ralf Brown:
http://www.ctyme.com/intr/rb-4124.htm
* for more information. */ - UNREFERENCED_PARAMETER(Stack); - - /* - * The default handler under DOS 2.x and 3.x simply calls INT 10/AH=0Eh. - * Do better and call directly VidBiosPrintCharacter: it's what INT 10/AH=0Eh - * does. Otherwise we would have to set BL to DOS_CHAR_ATTRIBUTE and - * BH to Bda->VideoPage. - */ - VidBiosPrintCharacter(getAL(), DOS_CHAR_ATTRIBUTE, Bda->VideoPage); + + if (Stack[STACK_COUNTER] == 0) + { + Stack[STACK_COUNTER]++; + + /* Save AX and BX */ + Stack[STACK_VAR_A] = getAX(); + Stack[STACK_VAR_B] = getBX(); + + /* Rewind the BOP manually, we can't use CF because the interrupt could modify it */ + EmulatorExecute(getCS(), getIP() - 4); + + /* Call INT 0x10, AH = 0x0E */ + setAH(0x0E); + setBL(DOS_CHAR_ATTRIBUTE); + setBH(Bda->VideoPage); + + EmulatorInterrupt(0x10); + } + else + { + /* Restore AX and BX */ + setAX(Stack[STACK_VAR_A]); + setBX(Stack[STACK_VAR_B]); + } } VOID WINAPI DosInt2Fh(LPWORD Stack) Modified: branches/ntvdm/subsystems/ntvdm/emulator.h URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] Sat Jan 25 00:53:10 2014 @@ -34,11 +34,13 @@ #define EMULATOR_FLAG_VIP (1 << 20) #define EMULATOR_FLAG_ID (1 << 21) -#define STACK_COUNTER 0 -#define STACK_INT_NUM 1 -#define STACK_IP 2 -#define STACK_CS 3 -#define STACK_FLAGS 4 +#define STACK_VAR_B 0 +#define STACK_VAR_A 1 +#define STACK_COUNTER 2 +#define STACK_INT_NUM 3 +#define STACK_IP 4 +#define STACK_CS 5 +#define STACK_FLAGS 6 /* Basic Memory Management */ Modified: branches/ntvdm/subsystems/ntvdm/int32.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/int32.c?…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/int32.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/int32.c [iso-8859-1] Sat Jan 25 00:53:10 2014 @@ -74,8 +74,14 @@ BiosCode[Offset++] = 0x6A; // push i BiosCode[Offset++] = (UCHAR)i; + /* The counter variable (initialized to 0) */ BiosCode[Offset++] = 0x6A; // push 0 BiosCode[Offset++] = 0x00; + + /* Stack variables */ + BiosCode[Offset++] = 0x83; // sub sp, 4 + BiosCode[Offset++] = 0xEC; + BiosCode[Offset++] = 0x04; BopSeqOffset = COMMON_STUB_OFFSET - (Offset + 3); @@ -107,9 +113,9 @@ BiosCode[Offset++] = 0xF5; // EXIT: - BiosCode[Offset++] = 0x83; // add sp, 4 + BiosCode[Offset++] = 0x83; // add sp, 8 BiosCode[Offset++] = 0xC4; - BiosCode[Offset++] = 0x04; + BiosCode[Offset++] = 0x08; BiosCode[Offset++] = 0xCF; // iret
10 years, 11 months
1
0
0
0
[hbelusca] 61796: [NTVDM] - Move all the hardware initialization to EmulatorInitialize (since emulator.c can be viewed as support functions for emulating a PC motherboard) --> PS2 and VGA go there....
by hbelusca@svn.reactos.org
Author: hbelusca Date: Sat Jan 25 00:21:51 2014 New Revision: 61796 URL:
http://svn.reactos.org/svn/reactos?rev=61796&view=rev
Log: [NTVDM] - Move all the hardware initialization to EmulatorInitialize (since emulator.c can be viewed as support functions for emulating a PC motherboard) --> PS2 and VGA go there. - Break bios.c into bios.c and kbdbios.c (the keyboard bios module) (according to the IBM documentation as well as other emulator sources or SeaBIOS or...). - Move Exception handling from int32.c to emulator.c, because it's something tight to the emulator, not to the interrupt system by itself (yet it happens that INT 00h to 07h are commonly set to some exception handlers). In the bios.c, initialize those vectors with the default exception handler. - Handling IRQs is done fully in bios.c now: introduce PicSetIRQMask and EnableHwIRQ helper functions (adapted from their equivalents from SeaBIOS) that allows the bios to set (and activate in the PIC) a given IRQ with its corresponding handler. Also introduce PicIRQComplete that serves as a PIC IRQ completer (i.e. sends the EOI to the right PIC(s)). - Continuing on that, at the moment I set dumb default PIC IRQ handlers for IRQ 08h - 0Fh and IRQ 70h - 77h). - By default I disable all the IRQs; there are then set on-demand with EnableHwIRQ. - Rework the POST (aka. BiosInitialize function): * the memory size is now get from the CMOS (as well as the extended memory size via INT 12h, AH=88h), * then we initialize the interrupts, * then platform hardware (ie. the chips) are initialized, * and finally the keyboard and video bioses. - As said before, move memory sizes into the CMOS. - Simplify video bios initialization. Added: branches/ntvdm/subsystems/ntvdm/bios/kbdbios.c - copied, changed from r61618, branches/ntvdm/subsystems/ntvdm/bios/bios.c branches/ntvdm/subsystems/ntvdm/bios/kbdbios.h - copied, changed from r61618, branches/ntvdm/subsystems/ntvdm/bios/bios.h Modified: branches/ntvdm/subsystems/ntvdm/CMakeLists.txt branches/ntvdm/subsystems/ntvdm/bios/bios.c branches/ntvdm/subsystems/ntvdm/bios/bios.h branches/ntvdm/subsystems/ntvdm/bios/vidbios.c branches/ntvdm/subsystems/ntvdm/emulator.c branches/ntvdm/subsystems/ntvdm/emulator.h branches/ntvdm/subsystems/ntvdm/hardware/cmos.c branches/ntvdm/subsystems/ntvdm/hardware/cmos.h branches/ntvdm/subsystems/ntvdm/hardware/vga.c branches/ntvdm/subsystems/ntvdm/int32.c branches/ntvdm/subsystems/ntvdm/ntvdm.c Modified: branches/ntvdm/subsystems/ntvdm/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/CMakeLis…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -7,6 +7,7 @@ list(APPEND SOURCE bios/bios.c + bios/kbdbios.c bios/vidbios.c hardware/cmos.c hardware/pic.c Modified: branches/ntvdm/subsystems/ntvdm/bios/bios.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios/bio…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios/bios.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios/bios.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -14,74 +14,23 @@ #include "bios.h" #include "io.h" +#include "hardware/cmos.h" #include "hardware/pic.h" -#include "hardware/ps2.h" #include "hardware/timer.h" #include "int32.h" -#include "registers.h" /* PRIVATE VARIABLES **********************************************************/ PBIOS_DATA_AREA Bda; -static BYTE BiosKeyboardMap[256]; /* PRIVATE FUNCTIONS **********************************************************/ -static BOOLEAN BiosKbdBufferPush(WORD Data) -{ - /* Get the location of the element after the tail */ - WORD NextElement = Bda->KeybdBufferTail + sizeof(WORD); - - /* Wrap it around if it's at or beyond the end */ - if (NextElement >= Bda->KeybdBufferEnd) NextElement = Bda->KeybdBufferStart; - - /* If it's full, fail */ - if (NextElement == Bda->KeybdBufferHead) return FALSE; - - /* Put the value in the queue */ - *((LPWORD)((ULONG_PTR)Bda + Bda->KeybdBufferTail)) = Data; - Bda->KeybdBufferTail += sizeof(WORD); - - /* Check if we are at, or have passed, the end of the buffer */ - if (Bda->KeybdBufferTail >= Bda->KeybdBufferEnd) - { - /* Return it to the beginning */ - Bda->KeybdBufferTail = Bda->KeybdBufferStart; - } - - /* Return success */ - return TRUE; -} - -static BOOLEAN BiosKbdBufferTop(LPWORD Data) -{ - /* If it's empty, fail */ - if (Bda->KeybdBufferHead == Bda->KeybdBufferTail) return FALSE; - - /* Otherwise, get the value and return success */ - *Data = *((LPWORD)((ULONG_PTR)Bda + Bda->KeybdBufferHead)); - - return TRUE; -} - -static BOOLEAN BiosKbdBufferPop(VOID) -{ - /* If it's empty, fail */ - if (Bda->KeybdBufferHead == Bda->KeybdBufferTail) return FALSE; - - /* Remove the value from the queue */ - Bda->KeybdBufferHead += sizeof(WORD); - - /* Check if we are at, or have passed, the end of the buffer */ - if (Bda->KeybdBufferHead >= Bda->KeybdBufferEnd) - { - /* Return it to the beginning */ - Bda->KeybdBufferHead = Bda->KeybdBufferStart; - } - - /* Return success */ - return TRUE; +static VOID WINAPI BiosException(LPWORD Stack) +{ + /* Get the exception number and call the emulator API */ + BYTE ExceptionNumber = LOBYTE(Stack[STACK_INT_NUM]); + EmulatorException(ExceptionNumber, Stack); } static VOID WINAPI BiosEquipmentService(LPWORD Stack) @@ -135,8 +84,17 @@ /* Get Extended Memory Size */ case 0x88: { - /* Return the number of KB of RAM after 1 MB */ - setAX((MAX_ADDRESS - 0x100000) / 1024); + UCHAR Low, High; + + /* + * Return the (usable) extended memory (after 1 MB) + * size in kB from CMOS. + */ + IOWriteB(CMOS_ADDRESS_PORT, CMOS_REG_ACTUAL_EXT_MEMORY_LOW); + Low = IOReadB(CMOS_DATA_PORT); + IOWriteB(CMOS_ADDRESS_PORT, CMOS_REG_ACTUAL_EXT_MEMORY_HIGH); + High = IOReadB(CMOS_DATA_PORT); + setAX(MAKEWORD(Low, High)); /* Clear CF */ Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF; @@ -147,88 +105,6 @@ default: { DPRINT1("BIOS Function INT 15h, AH = 0x%02X NOT IMPLEMENTED\n", - getAH()); - } - } -} - -static VOID WINAPI BiosKeyboardService(LPWORD Stack) -{ - switch (getAH()) - { - /* Wait for keystroke and read */ - case 0x00: - /* Wait for extended keystroke and read */ - case 0x10: // FIXME: Temporarily do the same as INT 16h, 00h - { - /* Read the character (and wait if necessary) */ - setAX(BiosGetCharacter()); - break; - } - - /* Get keystroke status */ - case 0x01: - /* Get extended keystroke status */ - case 0x11: // FIXME: Temporarily do the same as INT 16h, 01h - { - WORD Data = BiosPeekCharacter(); - - if (Data != 0xFFFF) - { - /* There is a character, clear ZF and return it */ - Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_ZF; - setAX(Data); - } - else - { - /* No character, set ZF */ - Stack[STACK_FLAGS] |= EMULATOR_FLAG_ZF; - } - - break; - } - - /* Get shift status */ - case 0x02: - { - /* Return the lower byte of the keyboard shift status word */ - setAL(LOBYTE(Bda->KeybdShiftFlags)); - break; - } - - /* Reserved */ - case 0x04: - { - DPRINT1("BIOS Function INT 16h, AH = 0x04 is RESERVED\n"); - break; - } - - /* Push keystroke */ - case 0x05: - { - /* Return 0 if success, 1 if failure */ - setAL(BiosKbdBufferPush(getCX()) == FALSE); - break; - } - - /* Get extended shift status */ - case 0x12: - { - /* - * Be careful! The returned word is similar to Bda->KeybdShiftFlags - * but the high byte is organized differently: - * the bytes 2 and 3 of the high byte are not the same... - */ - WORD KeybdShiftFlags = (Bda->KeybdShiftFlags & 0xF3FF); - - /* Return the extended keyboard shift status word */ - setAX(KeybdShiftFlags); - break; - } - - default: - { - DPRINT1("BIOS Function INT 16h, AH = 0x%02X NOT IMPLEMENTED\n", getAH()); } } @@ -278,206 +154,201 @@ Bda->TickCounter++; } -/* PUBLIC FUNCTIONS ***********************************************************/ - -WORD BiosPeekCharacter(VOID) -{ - WORD CharacterData = 0; - - /* Get the key from the queue, but don't remove it */ - if (BiosKbdBufferTop(&CharacterData)) return CharacterData; - else return 0xFFFF; -} - -WORD BiosGetCharacter(VOID) -{ - WORD CharacterData = 0; - - /* Check if there is a key available */ - if (BiosKbdBufferTop(&CharacterData)) + +// From SeaBIOS +static VOID PicSetIRQMask(USHORT off, USHORT on) +{ + UCHAR pic1off = off, pic1on = on, pic2off = off>>8, pic2on = on>>8; + IOWriteB(PIC_MASTER_DATA, (IOReadB(PIC_MASTER_DATA) & ~pic1off) | pic1on); + IOWriteB(PIC_SLAVE_DATA , (IOReadB(PIC_SLAVE_DATA ) & ~pic2off) | pic2on); +} + +// From SeaBIOS +VOID EnableHwIRQ(UCHAR hwirq, EMULATOR_INT32_PROC func) +{ + UCHAR vector; + + PicSetIRQMask(1 << hwirq, 0); + if (hwirq < 8) + vector = BIOS_PIC_MASTER_INT + hwirq; + else + vector = BIOS_PIC_SLAVE_INT + hwirq - 8; + + RegisterInt32(vector, func); +} + + +VOID PicIRQComplete(LPWORD Stack) +{ + /* Get the interrupt number */ + BYTE IntNum = LOBYTE(Stack[STACK_INT_NUM]); + + /* + * If this was a PIC IRQ, send an End-of-Interrupt to the PIC. + */ + + if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8) { - /* A key was available, remove it from the queue */ - BiosKbdBufferPop(); + /* It was an IRQ from the master PIC */ + IOWriteB(PIC_MASTER_CMD, PIC_OCW2_EOI); } - else + else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8) { - /* No key available. Set the handler CF to repeat the BOP */ - setCF(1); - // CharacterData = 0xFFFF; + /* It was an IRQ from the slave PIC */ + IOWriteB(PIC_SLAVE_CMD , PIC_OCW2_EOI); + IOWriteB(PIC_MASTER_CMD, PIC_OCW2_EOI); } - - return CharacterData; -} - -BOOLEAN BiosInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) -{ - /* Initialize the BDA */ - Bda = (PBIOS_DATA_AREA)SEG_OFF_TO_PTR(BDA_SEGMENT, 0); - Bda->EquipmentList = BIOS_EQUIPMENT_LIST; +} + +static VOID WINAPI BiosHandleMasterPicIRQ(LPWORD Stack) +{ + BYTE IrqNumber; + + IOWriteB(PIC_MASTER_CMD, PIC_OCW3_READ_ISR /* == 0x0B */); + IrqNumber = IOReadB(PIC_MASTER_CMD); + + DPRINT1("Master - IrqNumber = 0x%x\n", IrqNumber); + + PicIRQComplete(Stack); +} + +static VOID WINAPI BiosHandleSlavePicIRQ(LPWORD Stack) +{ + BYTE IrqNumber; + + IOWriteB(PIC_SLAVE_CMD, PIC_OCW3_READ_ISR /* == 0x0B */); + IrqNumber = IOReadB(PIC_SLAVE_CMD); + + DPRINT1("Slave - IrqNumber = 0x%x\n", IrqNumber); + + PicIRQComplete(Stack); +} + +// Timer IRQ 0 +static VOID WINAPI BiosTimerIrq(LPWORD Stack) +{ /* - * Conventional memory size is 640 kB, - * see:
http://webpages.charter.net/danrollins/techhelp/0184.HTM
- * and see Ralf Brown:
http://www.ctyme.com/intr/rb-0598.htm
- * for more information. + * Perform the system timer interrupt. + * + * Do not call directly BiosSystemTimerInterrupt(Stack); + * because some programs may hook only BIOS_SYS_TIMER_INTERRUPT + * for their purpose... */ - Bda->MemorySize = 0x0280; - Bda->KeybdBufferStart = FIELD_OFFSET(BIOS_DATA_AREA, KeybdBuffer); - Bda->KeybdBufferEnd = Bda->KeybdBufferStart + BIOS_KBD_BUFFER_SIZE * sizeof(WORD); - Bda->KeybdBufferHead = Bda->KeybdBufferTail = 0; - - /* Initialize the 32-bit Interrupt system */ - InitializeInt32(BIOS_SEGMENT); - - /* Register the BIOS 32-bit Interrupts */ - RegisterInt32(BIOS_EQUIPMENT_INTERRUPT, BiosEquipmentService ); - RegisterInt32(BIOS_MEMORY_SIZE , BiosGetMemorySize ); - RegisterInt32(BIOS_MISC_INTERRUPT , BiosMiscService ); - RegisterInt32(BIOS_KBD_INTERRUPT , BiosKeyboardService ); - RegisterInt32(BIOS_TIME_INTERRUPT , BiosTimeService ); - RegisterInt32(BIOS_SYS_TIMER_INTERRUPT, BiosSystemTimerInterrupt); - - /* Some interrupts are in fact addresses to tables */ - ((PDWORD)BaseAddress)[0x1D] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x1E] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x1F] = (DWORD)NULL; - - ((PDWORD)BaseAddress)[0x41] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x43] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x44] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x46] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x48] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x49] = (DWORD)NULL; - - /* Initialize the Video BIOS */ - if (!VidBiosInitialize(ConsoleOutput)) return FALSE; - - /* Set the console input mode */ - SetConsoleMode(ConsoleInput, ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT); - - /* Initialize PS2 */ - PS2Initialize(ConsoleInput); - - /* - * The POST (Power On-Self Test) - */ - - /* Initialize the master and the slave PICs */ + EmulatorInterrupt(BIOS_SYS_TIMER_INTERRUPT); + PicIRQComplete(Stack); +} + + +static VOID BiosHwSetup(VOID) +{ + /* Initialize the master and the slave PICs (cascade mode) */ IOWriteB(PIC_MASTER_CMD, PIC_ICW1 | PIC_ICW1_ICW4); IOWriteB(PIC_SLAVE_CMD , PIC_ICW1 | PIC_ICW1_ICW4); - /* Set the interrupt offsets */ + /* + * Set the interrupt vector offsets for each PIC + * (base IRQs: 0x08-0x0F for IRQ 0-7, 0x70-0x77 for IRQ 8-15) + */ IOWriteB(PIC_MASTER_DATA, BIOS_PIC_MASTER_INT); IOWriteB(PIC_SLAVE_DATA , BIOS_PIC_SLAVE_INT ); - /* Tell the master PIC there is a slave at IRQ 2 */ + /* Tell the master PIC that there is a slave PIC at IRQ 2 */ IOWriteB(PIC_MASTER_DATA, 1 << 2); + /* Tell the slave PIC its cascade identity */ IOWriteB(PIC_SLAVE_DATA , 2); /* Make sure both PICs are in 8086 mode */ - IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086 /* | PIC_ICW4_AEOI */); + IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086); IOWriteB(PIC_SLAVE_DATA , PIC_ICW4_8086); /* Clear the masks for both PICs */ - IOWriteB(PIC_MASTER_DATA, 0x00); - IOWriteB(PIC_SLAVE_DATA , 0x00); + // IOWriteB(PIC_MASTER_DATA, 0x00); + // IOWriteB(PIC_SLAVE_DATA , 0x00); + /* Disable all IRQs */ + IOWriteB(PIC_MASTER_DATA, 0xFF); + IOWriteB(PIC_SLAVE_DATA , 0xFF); + /* Initialize the PIT */ IOWriteB(PIT_COMMAND_PORT, 0x34); IOWriteB(PIT_DATA_PORT(0), 0x00); IOWriteB(PIT_DATA_PORT(0), 0x00); + EnableHwIRQ(0, BiosTimerIrq); +} + +/* PUBLIC FUNCTIONS ***********************************************************/ + +/* + * The BIOS POST (Power On-Self Test) + */ +BOOLEAN BiosInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) +{ + UCHAR Low, High; + UCHAR i; + + /* Initialize the BDA */ + Bda = (PBIOS_DATA_AREA)SEG_OFF_TO_PTR(BDA_SEGMENT, 0); + Bda->EquipmentList = BIOS_EQUIPMENT_LIST; + + /* + * Retrieve the conventional memory size + * in kB from CMOS, typically 640 kB. + */ + IOWriteB(CMOS_ADDRESS_PORT, CMOS_REG_BASE_MEMORY_LOW); + Low = IOReadB(CMOS_DATA_PORT); + IOWriteB(CMOS_ADDRESS_PORT, CMOS_REG_BASE_MEMORY_HIGH); + High = IOReadB(CMOS_DATA_PORT); + Bda->MemorySize = MAKEWORD(Low, High); + + /* Initialize the 32-bit Interrupt system */ + InitializeInt32(BIOS_SEGMENT); + + /* Register the BIOS 32-bit Interrupts */ + + /* Initialize the exception vector interrupts to a default Exception handler */ + for (i = 0; i < 8; i++) + RegisterInt32(i, BiosException); + + /* Initialize HW vector interrupts to a default HW handler */ + for (i = BIOS_PIC_MASTER_INT; i < BIOS_PIC_MASTER_INT + 8; i++) + RegisterInt32(i, BiosHandleMasterPicIRQ); + for (i = BIOS_PIC_SLAVE_INT ; i < BIOS_PIC_SLAVE_INT + 8; i++) + RegisterInt32(i, BiosHandleSlavePicIRQ); + + /* Initialize software vector handlers */ + RegisterInt32(BIOS_EQUIPMENT_INTERRUPT, BiosEquipmentService ); + RegisterInt32(BIOS_MEMORY_SIZE , BiosGetMemorySize ); + RegisterInt32(BIOS_MISC_INTERRUPT , BiosMiscService ); + RegisterInt32(BIOS_TIME_INTERRUPT , BiosTimeService ); + RegisterInt32(BIOS_SYS_TIMER_INTERRUPT, BiosSystemTimerInterrupt); + + /* Some interrupts are in fact addresses to tables */ + ((PDWORD)BaseAddress)[0x1E] = (DWORD)NULL; + ((PDWORD)BaseAddress)[0x41] = (DWORD)NULL; + ((PDWORD)BaseAddress)[0x46] = (DWORD)NULL; + ((PDWORD)BaseAddress)[0x48] = (DWORD)NULL; + ((PDWORD)BaseAddress)[0x49] = (DWORD)NULL; + + /* Initialize platform hardware (PIC/PIT chips, ...) */ + BiosHwSetup(); + + /* Initialize the Keyboard BIOS */ + if (!KbdBiosInitialize(ConsoleInput)) return FALSE; + + /* Set the console input mode */ + SetConsoleMode(ConsoleInput, ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT); + + /* Initialize the Video BIOS */ + if (!VidBiosInitialize(ConsoleOutput)) return FALSE; + return TRUE; } VOID BiosCleanup(VOID) { - PS2Cleanup(); VidBiosCleanup(); -} - -VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack) -{ - switch (IrqNumber) - { - /* PIT IRQ */ - case 0: - { - /* Perform the system timer interrupt */ - EmulatorInterrupt(BIOS_SYS_TIMER_INTERRUPT); - break; - } - - /* Keyboard IRQ */ - case 1: - { - BYTE ScanCode, VirtualKey; - WORD Character; - - /* Get the scan code and virtual key code */ - ScanCode = IOReadB(PS2_DATA_PORT); - VirtualKey = MapVirtualKey(ScanCode & 0x7F, MAPVK_VSC_TO_VK); - - /* Check if this is a key press or release */ - if (!(ScanCode & (1 << 7))) - { - /* Key press */ - if (VirtualKey == VK_NUMLOCK || - VirtualKey == VK_CAPITAL || - VirtualKey == VK_SCROLL || - VirtualKey == VK_INSERT) - { - /* For toggle keys, toggle the lowest bit in the keyboard map */ - BiosKeyboardMap[VirtualKey] ^= ~(1 << 0); - } - - /* Set the highest bit */ - BiosKeyboardMap[VirtualKey] |= (1 << 7); - - /* Find out which character this is */ - Character = 0; - if (ToAscii(VirtualKey, ScanCode, BiosKeyboardMap, &Character, 0) == 0) - { - /* Not ASCII */ - Character = 0; - } - - /* Push it onto the BIOS keyboard queue */ - BiosKbdBufferPush(MAKEWORD(Character, ScanCode)); - } - else - { - /* Key release, unset the highest bit */ - BiosKeyboardMap[VirtualKey] &= ~(1 << 7); - } - - /* Clear the keyboard flags */ - Bda->KeybdShiftFlags = 0; - - /* Set the appropriate flags based on the state */ - if (BiosKeyboardMap[VK_RSHIFT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_RSHIFT; - if (BiosKeyboardMap[VK_LSHIFT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_LSHIFT; - if (BiosKeyboardMap[VK_CONTROL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CTRL; - if (BiosKeyboardMap[VK_MENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_ALT; - if (BiosKeyboardMap[VK_SCROLL] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SCROLL_ON; - if (BiosKeyboardMap[VK_NUMLOCK] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_NUMLOCK_ON; - if (BiosKeyboardMap[VK_CAPITAL] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CAPSLOCK_ON; - if (BiosKeyboardMap[VK_INSERT] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_INSERT_ON; - if (BiosKeyboardMap[VK_RMENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_RALT; - if (BiosKeyboardMap[VK_LMENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_LALT; - if (BiosKeyboardMap[VK_SNAPSHOT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SYSRQ; - if (BiosKeyboardMap[VK_PAUSE] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_PAUSE; - if (BiosKeyboardMap[VK_SCROLL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SCROLL; - if (BiosKeyboardMap[VK_NUMLOCK] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_NUMLOCK; - if (BiosKeyboardMap[VK_CAPITAL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CAPSLOCK; - if (BiosKeyboardMap[VK_INSERT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_INSERT; - - break; - } - } - - /* Send End-of-Interrupt to the PIC */ - if (IrqNumber >= 8) IOWriteB(PIC_SLAVE_CMD, PIC_OCW2_EOI); - IOWriteB(PIC_MASTER_CMD, PIC_OCW2_EOI); + KbdBiosCleanup(); } /* EOF */ Modified: branches/ntvdm/subsystems/ntvdm/bios/bios.h URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios/bio…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios/bios.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios/bios.h [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -12,6 +12,7 @@ /* INCLUDES *******************************************************************/ #include "ntvdm.h" +#include "kbdbios.h" #include "vidbios.h" /* DEFINES ********************************************************************/ @@ -28,29 +29,10 @@ #define BIOS_EQUIPMENT_INTERRUPT 0x11 #define BIOS_MEMORY_SIZE 0x12 #define BIOS_MISC_INTERRUPT 0x15 -#define BIOS_KBD_INTERRUPT 0x16 #define BIOS_TIME_INTERRUPT 0x1A #define BIOS_SYS_TIMER_INTERRUPT 0x1C -#define BIOS_KBD_BUFFER_SIZE 16 -#define BIOS_EQUIPMENT_LIST 0x2C // HACK: Disable FPU for now - -#define BDA_KBDFLAG_RSHIFT (1 << 0) -#define BDA_KBDFLAG_LSHIFT (1 << 1) -#define BDA_KBDFLAG_CTRL (1 << 2) -#define BDA_KBDFLAG_ALT (1 << 3) -#define BDA_KBDFLAG_SCROLL_ON (1 << 4) -#define BDA_KBDFLAG_NUMLOCK_ON (1 << 5) -#define BDA_KBDFLAG_CAPSLOCK_ON (1 << 6) -#define BDA_KBDFLAG_INSERT_ON (1 << 7) -#define BDA_KBDFLAG_RALT (1 << 8) -#define BDA_KBDFLAG_LALT (1 << 9) -#define BDA_KBDFLAG_SYSRQ (1 << 10) -#define BDA_KBDFLAG_PAUSE (1 << 11) -#define BDA_KBDFLAG_SCROLL (1 << 12) -#define BDA_KBDFLAG_NUMLOCK (1 << 13) -#define BDA_KBDFLAG_CAPSLOCK (1 << 14) -#define BDA_KBDFLAG_INSERT (1 << 15) +#define BIOS_EQUIPMENT_LIST 0x2C // HACK: Disable FPU for now /* * BIOS Data Area at 0040:XXXX @@ -134,12 +116,13 @@ extern PBIOS_DATA_AREA Bda; -WORD BiosPeekCharacter(VOID); -WORD BiosGetCharacter(VOID); +/**HACK!!**/typedef VOID (WINAPI *EMULATOR_INT32_PROC)(LPWORD Stack);/**HACK!!**/ + +VOID EnableHwIRQ(UCHAR hwirq, EMULATOR_INT32_PROC func); +VOID PicIRQComplete(LPWORD Stack); BOOLEAN BiosInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput); VOID BiosCleanup(VOID); -VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack); #endif // _BIOS_H_ Copied: branches/ntvdm/subsystems/ntvdm/bios/kbdbios.c (from r61618, branches/ntvdm/subsystems/ntvdm/bios/bios.c) URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios/kbd…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios/bios.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios/kbdbios.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -1,8 +1,8 @@ /* * COPYRIGHT: GPL - See COPYING in the top level directory * PROJECT: ReactOS Virtual DOS Machine - * FILE: bios.c - * PURPOSE: VDM BIOS + * FILE: kbdbios.c + * PURPOSE: VDM Keyboard BIOS * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org> */ @@ -11,19 +11,16 @@ #define NDEBUG #include "emulator.h" +// #include "kbdbios.h" #include "bios.h" #include "io.h" -#include "hardware/pic.h" #include "hardware/ps2.h" -#include "hardware/timer.h" #include "int32.h" -#include "registers.h" /* PRIVATE VARIABLES **********************************************************/ -PBIOS_DATA_AREA Bda; static BYTE BiosKeyboardMap[256]; /* PRIVATE FUNCTIONS **********************************************************/ @@ -84,72 +81,33 @@ return TRUE; } -static VOID WINAPI BiosEquipmentService(LPWORD Stack) -{ - /* Return the equipment list */ - setAX(Bda->EquipmentList); -} - -static VOID WINAPI BiosGetMemorySize(LPWORD Stack) -{ - /* Return the conventional memory size in kB, typically 640 kB */ - setAX(Bda->MemorySize); -} - -static VOID WINAPI BiosMiscService(LPWORD Stack) -{ - switch (getAH()) - { - /* Copy Extended Memory */ - case 0x87: - { - DWORD Count = (DWORD)getCX() * 2; - PFAST486_GDT_ENTRY Gdt = (PFAST486_GDT_ENTRY)SEG_OFF_TO_PTR(getES(), getSI()); - DWORD SourceBase = Gdt[2].Base + (Gdt[2].BaseMid << 16) + (Gdt[2].BaseHigh << 24); - DWORD SourceLimit = Gdt[2].Limit + (Gdt[2].LimitHigh << 16); - DWORD DestBase = Gdt[3].Base + (Gdt[3].BaseMid << 16) + (Gdt[3].BaseHigh << 24); - DWORD DestLimit = Gdt[3].Limit + (Gdt[3].LimitHigh << 16); - - /* Check for flags */ - if (Gdt[2].Granularity) SourceLimit = (SourceLimit << 12) | 0xFFF; - if (Gdt[3].Granularity) DestLimit = (DestLimit << 12) | 0xFFF; - - if ((Count > SourceLimit) || (Count > DestLimit)) - { - setAX(0x80); - Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF; - - break; - } - - /* Copy */ - RtlMoveMemory((PVOID)((ULONG_PTR)BaseAddress + DestBase), - (PVOID)((ULONG_PTR)BaseAddress + SourceBase), - Count); - - setAX(ERROR_SUCCESS); - Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF; - break; - } - - /* Get Extended Memory Size */ - case 0x88: - { - /* Return the number of KB of RAM after 1 MB */ - setAX((MAX_ADDRESS - 0x100000) / 1024); - - /* Clear CF */ - Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF; - - break; - } - - default: - { - DPRINT1("BIOS Function INT 15h, AH = 0x%02X NOT IMPLEMENTED\n", - getAH()); - } - } +WORD BiosPeekCharacter(VOID) +{ + WORD CharacterData = 0; + + /* Get the key from the queue, but don't remove it */ + if (BiosKbdBufferTop(&CharacterData)) return CharacterData; + else return 0xFFFF; +} + +WORD BiosGetCharacter(VOID) +{ + WORD CharacterData = 0; + + /* Check if there is a key available */ + if (BiosKbdBufferTop(&CharacterData)) + { + /* A key was available, remove it from the queue */ + BiosKbdBufferPop(); + } + else + { + /* No key available. Set the handler CF to repeat the BOP */ + setCF(1); + // CharacterData = 0xFFFF; + } + + return CharacterData; } static VOID WINAPI BiosKeyboardService(LPWORD Stack) @@ -234,250 +192,99 @@ } } -static VOID WINAPI BiosTimeService(LPWORD Stack) -{ - switch (getAH()) - { - case 0x00: - { - /* Set AL to 1 if midnight had passed, 0 otherwise */ - setAL(Bda->MidnightPassed ? 0x01 : 0x00); - - /* Return the tick count in CX:DX */ - setCX(HIWORD(Bda->TickCounter)); - setDX(LOWORD(Bda->TickCounter)); - - /* Reset the midnight flag */ - Bda->MidnightPassed = FALSE; - - break; - } - - case 0x01: - { - /* Set the tick count to CX:DX */ - Bda->TickCounter = MAKELONG(getDX(), getCX()); - - /* Reset the midnight flag */ - Bda->MidnightPassed = FALSE; - - break; - } - - default: - { - DPRINT1("BIOS Function INT 1Ah, AH = 0x%02X NOT IMPLEMENTED\n", - getAH()); - } - } -} - -static VOID WINAPI BiosSystemTimerInterrupt(LPWORD Stack) -{ - /* Increase the system tick count */ - Bda->TickCounter++; +// Keyboard IRQ 1 +static VOID WINAPI BiosKeyboardIrq(LPWORD Stack) +{ + BYTE ScanCode, VirtualKey; + WORD Character; + + /* Get the scan code and virtual key code */ + ScanCode = IOReadB(PS2_DATA_PORT); + VirtualKey = MapVirtualKey(ScanCode & 0x7F, MAPVK_VSC_TO_VK); + + /* Check if this is a key press or release */ + if (!(ScanCode & (1 << 7))) + { + /* Key press */ + if (VirtualKey == VK_NUMLOCK || + VirtualKey == VK_CAPITAL || + VirtualKey == VK_SCROLL || + VirtualKey == VK_INSERT) + { + /* For toggle keys, toggle the lowest bit in the keyboard map */ + BiosKeyboardMap[VirtualKey] ^= ~(1 << 0); + } + + /* Set the highest bit */ + BiosKeyboardMap[VirtualKey] |= (1 << 7); + + /* Find out which character this is */ + Character = 0; + if (ToAscii(VirtualKey, ScanCode, BiosKeyboardMap, &Character, 0) == 0) + { + /* Not ASCII */ + Character = 0; + } + + /* Push it onto the BIOS keyboard queue */ + BiosKbdBufferPush(MAKEWORD(Character, ScanCode)); + } + else + { + /* Key release, unset the highest bit */ + BiosKeyboardMap[VirtualKey] &= ~(1 << 7); + } + + /* Clear the keyboard flags */ + Bda->KeybdShiftFlags = 0; + + /* Set the appropriate flags based on the state */ + if (BiosKeyboardMap[VK_RSHIFT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_RSHIFT; + if (BiosKeyboardMap[VK_LSHIFT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_LSHIFT; + if (BiosKeyboardMap[VK_CONTROL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CTRL; + if (BiosKeyboardMap[VK_MENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_ALT; + if (BiosKeyboardMap[VK_SCROLL] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SCROLL_ON; + if (BiosKeyboardMap[VK_NUMLOCK] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_NUMLOCK_ON; + if (BiosKeyboardMap[VK_CAPITAL] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CAPSLOCK_ON; + if (BiosKeyboardMap[VK_INSERT] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_INSERT_ON; + if (BiosKeyboardMap[VK_RMENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_RALT; + if (BiosKeyboardMap[VK_LMENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_LALT; + if (BiosKeyboardMap[VK_SNAPSHOT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SYSRQ; + if (BiosKeyboardMap[VK_PAUSE] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_PAUSE; + if (BiosKeyboardMap[VK_SCROLL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SCROLL; + if (BiosKeyboardMap[VK_NUMLOCK] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_NUMLOCK; + if (BiosKeyboardMap[VK_CAPITAL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CAPSLOCK; + if (BiosKeyboardMap[VK_INSERT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_INSERT; + + PicIRQComplete(Stack); } /* PUBLIC FUNCTIONS ***********************************************************/ -WORD BiosPeekCharacter(VOID) -{ - WORD CharacterData = 0; - - /* Get the key from the queue, but don't remove it */ - if (BiosKbdBufferTop(&CharacterData)) return CharacterData; - else return 0xFFFF; -} - -WORD BiosGetCharacter(VOID) -{ - WORD CharacterData = 0; - - /* Check if there is a key available */ - if (BiosKbdBufferTop(&CharacterData)) - { - /* A key was available, remove it from the queue */ - BiosKbdBufferPop(); - } - else - { - /* No key available. Set the handler CF to repeat the BOP */ - setCF(1); - // CharacterData = 0xFFFF; - } - - return CharacterData; -} - -BOOLEAN BiosInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) +BOOLEAN KbdBiosInitialize(HANDLE ConsoleInput) { /* Initialize the BDA */ - Bda = (PBIOS_DATA_AREA)SEG_OFF_TO_PTR(BDA_SEGMENT, 0); - Bda->EquipmentList = BIOS_EQUIPMENT_LIST; - /* - * Conventional memory size is 640 kB, - * see:
http://webpages.charter.net/danrollins/techhelp/0184.HTM
- * and see Ralf Brown:
http://www.ctyme.com/intr/rb-0598.htm
- * for more information. - */ - Bda->MemorySize = 0x0280; Bda->KeybdBufferStart = FIELD_OFFSET(BIOS_DATA_AREA, KeybdBuffer); - Bda->KeybdBufferEnd = Bda->KeybdBufferStart + BIOS_KBD_BUFFER_SIZE * sizeof(WORD); - Bda->KeybdBufferHead = Bda->KeybdBufferTail = 0; - - /* Initialize the 32-bit Interrupt system */ - InitializeInt32(BIOS_SEGMENT); + Bda->KeybdBufferEnd = Bda->KeybdBufferStart + BIOS_KBD_BUFFER_SIZE * sizeof(WORD); + Bda->KeybdBufferHead = Bda->KeybdBufferTail = 0; /* Register the BIOS 32-bit Interrupts */ - RegisterInt32(BIOS_EQUIPMENT_INTERRUPT, BiosEquipmentService ); - RegisterInt32(BIOS_MEMORY_SIZE , BiosGetMemorySize ); - RegisterInt32(BIOS_MISC_INTERRUPT , BiosMiscService ); - RegisterInt32(BIOS_KBD_INTERRUPT , BiosKeyboardService ); - RegisterInt32(BIOS_TIME_INTERRUPT , BiosTimeService ); - RegisterInt32(BIOS_SYS_TIMER_INTERRUPT, BiosSystemTimerInterrupt); - - /* Some interrupts are in fact addresses to tables */ - ((PDWORD)BaseAddress)[0x1D] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x1E] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x1F] = (DWORD)NULL; - - ((PDWORD)BaseAddress)[0x41] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x43] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x44] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x46] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x48] = (DWORD)NULL; - ((PDWORD)BaseAddress)[0x49] = (DWORD)NULL; - - /* Initialize the Video BIOS */ - if (!VidBiosInitialize(ConsoleOutput)) return FALSE; + + /* Initialize software vector handlers */ + RegisterInt32(BIOS_KBD_INTERRUPT, BiosKeyboardService); + + /* Set up the HW vector interrupts */ + EnableHwIRQ(1, BiosKeyboardIrq); + // EnableHwIRQ(12, BiosMouseIrq); /* Set the console input mode */ - SetConsoleMode(ConsoleInput, ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT); - - /* Initialize PS2 */ - PS2Initialize(ConsoleInput); - - /* - * The POST (Power On-Self Test) - */ - - /* Initialize the master and the slave PICs */ - IOWriteB(PIC_MASTER_CMD, PIC_ICW1 | PIC_ICW1_ICW4); - IOWriteB(PIC_SLAVE_CMD , PIC_ICW1 | PIC_ICW1_ICW4); - - /* Set the interrupt offsets */ - IOWriteB(PIC_MASTER_DATA, BIOS_PIC_MASTER_INT); - IOWriteB(PIC_SLAVE_DATA , BIOS_PIC_SLAVE_INT ); - - /* Tell the master PIC there is a slave at IRQ 2 */ - IOWriteB(PIC_MASTER_DATA, 1 << 2); - IOWriteB(PIC_SLAVE_DATA , 2); - - /* Make sure both PICs are in 8086 mode */ - IOWriteB(PIC_MASTER_DATA, PIC_ICW4_8086 /* | PIC_ICW4_AEOI */); - IOWriteB(PIC_SLAVE_DATA , PIC_ICW4_8086); - - /* Clear the masks for both PICs */ - IOWriteB(PIC_MASTER_DATA, 0x00); - IOWriteB(PIC_SLAVE_DATA , 0x00); - - /* Initialize the PIT */ - IOWriteB(PIT_COMMAND_PORT, 0x34); - IOWriteB(PIT_DATA_PORT(0), 0x00); - IOWriteB(PIT_DATA_PORT(0), 0x00); - - return TRUE; -} - -VOID BiosCleanup(VOID) -{ - PS2Cleanup(); - VidBiosCleanup(); -} - -VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack) -{ - switch (IrqNumber) - { - /* PIT IRQ */ - case 0: - { - /* Perform the system timer interrupt */ - EmulatorInterrupt(BIOS_SYS_TIMER_INTERRUPT); - break; - } - - /* Keyboard IRQ */ - case 1: - { - BYTE ScanCode, VirtualKey; - WORD Character; - - /* Get the scan code and virtual key code */ - ScanCode = IOReadB(PS2_DATA_PORT); - VirtualKey = MapVirtualKey(ScanCode & 0x7F, MAPVK_VSC_TO_VK); - - /* Check if this is a key press or release */ - if (!(ScanCode & (1 << 7))) - { - /* Key press */ - if (VirtualKey == VK_NUMLOCK || - VirtualKey == VK_CAPITAL || - VirtualKey == VK_SCROLL || - VirtualKey == VK_INSERT) - { - /* For toggle keys, toggle the lowest bit in the keyboard map */ - BiosKeyboardMap[VirtualKey] ^= ~(1 << 0); - } - - /* Set the highest bit */ - BiosKeyboardMap[VirtualKey] |= (1 << 7); - - /* Find out which character this is */ - Character = 0; - if (ToAscii(VirtualKey, ScanCode, BiosKeyboardMap, &Character, 0) == 0) - { - /* Not ASCII */ - Character = 0; - } - - /* Push it onto the BIOS keyboard queue */ - BiosKbdBufferPush(MAKEWORD(Character, ScanCode)); - } - else - { - /* Key release, unset the highest bit */ - BiosKeyboardMap[VirtualKey] &= ~(1 << 7); - } - - /* Clear the keyboard flags */ - Bda->KeybdShiftFlags = 0; - - /* Set the appropriate flags based on the state */ - if (BiosKeyboardMap[VK_RSHIFT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_RSHIFT; - if (BiosKeyboardMap[VK_LSHIFT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_LSHIFT; - if (BiosKeyboardMap[VK_CONTROL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CTRL; - if (BiosKeyboardMap[VK_MENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_ALT; - if (BiosKeyboardMap[VK_SCROLL] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SCROLL_ON; - if (BiosKeyboardMap[VK_NUMLOCK] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_NUMLOCK_ON; - if (BiosKeyboardMap[VK_CAPITAL] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CAPSLOCK_ON; - if (BiosKeyboardMap[VK_INSERT] & (1 << 0)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_INSERT_ON; - if (BiosKeyboardMap[VK_RMENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_RALT; - if (BiosKeyboardMap[VK_LMENU] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_LALT; - if (BiosKeyboardMap[VK_SNAPSHOT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SYSRQ; - if (BiosKeyboardMap[VK_PAUSE] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_PAUSE; - if (BiosKeyboardMap[VK_SCROLL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_SCROLL; - if (BiosKeyboardMap[VK_NUMLOCK] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_NUMLOCK; - if (BiosKeyboardMap[VK_CAPITAL] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_CAPSLOCK; - if (BiosKeyboardMap[VK_INSERT] & (1 << 7)) Bda->KeybdShiftFlags |= BDA_KBDFLAG_INSERT; - - break; - } - } - - /* Send End-of-Interrupt to the PIC */ - if (IrqNumber >= 8) IOWriteB(PIC_SLAVE_CMD, PIC_OCW2_EOI); - IOWriteB(PIC_MASTER_CMD, PIC_OCW2_EOI); + // SetConsoleMode(ConsoleInput, ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT); + + return TRUE; +} + +VOID KbdBiosCleanup(VOID) +{ } /* EOF */ Copied: branches/ntvdm/subsystems/ntvdm/bios/kbdbios.h (from r61618, branches/ntvdm/subsystems/ntvdm/bios/bios.h) URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios/kbd…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios/bios.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios/kbdbios.h [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -1,39 +1,23 @@ /* * COPYRIGHT: GPL - See COPYING in the top level directory * PROJECT: ReactOS Virtual DOS Machine - * FILE: bios.h - * PURPOSE: VDM BIOS + * FILE: kbdbios.h + * PURPOSE: VDM Keyboard BIOS * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org> */ -#ifndef _BIOS_H_ -#define _BIOS_H_ +#ifndef _KBDBIOS_H_ +#define _KBDBIOS_H_ /* INCLUDES *******************************************************************/ #include "ntvdm.h" -#include "vidbios.h" /* DEFINES ********************************************************************/ -#define ROM_AREA_START 0xE0000 -#define ROM_AREA_END 0xFFFFF +#define BIOS_KBD_INTERRUPT 0x16 -#define BDA_SEGMENT 0x40 -#define BIOS_SEGMENT 0xF000 - -#define BIOS_PIC_MASTER_INT 0x08 -#define BIOS_PIC_SLAVE_INT 0x70 - -#define BIOS_EQUIPMENT_INTERRUPT 0x11 -#define BIOS_MEMORY_SIZE 0x12 -#define BIOS_MISC_INTERRUPT 0x15 -#define BIOS_KBD_INTERRUPT 0x16 -#define BIOS_TIME_INTERRUPT 0x1A -#define BIOS_SYS_TIMER_INTERRUPT 0x1C - -#define BIOS_KBD_BUFFER_SIZE 16 -#define BIOS_EQUIPMENT_LIST 0x2C // HACK: Disable FPU for now +#define BIOS_KBD_BUFFER_SIZE 16 #define BDA_KBDFLAG_RSHIFT (1 << 0) #define BDA_KBDFLAG_LSHIFT (1 << 1) @@ -52,95 +36,14 @@ #define BDA_KBDFLAG_CAPSLOCK (1 << 14) #define BDA_KBDFLAG_INSERT (1 << 15) -/* - * BIOS Data Area at 0040:XXXX - * - * See:
http://webpages.charter.net/danrollins/techhelp/0093.HTM
- * and:
http://www.bioscentral.com/misc/bda.htm
- * for more information. - */ -#pragma pack(push, 1) -typedef struct -{ - WORD SerialPorts[4]; // 0x00 - WORD ParallelPorts[3]; // 0x08 - WORD EbdaSegment; // 0x0e - ParallelPort in PC/XT - WORD EquipmentList; // 0x10 - BYTE Reserved0; // 0x12 - Errors in PCjr infrared keyboard link - WORD MemorySize; // 0x13 - WORD Reserved1; // 0x15 - Scratch pad for manufacturing error tests - WORD KeybdShiftFlags; // 0x17 - BYTE AlternateKeypad; // 0x19 - WORD KeybdBufferHead; // 0x1a - WORD KeybdBufferTail; // 0x1c - WORD KeybdBuffer[BIOS_KBD_BUFFER_SIZE]; // 0x1e - BYTE DriveRecalibrate; // 0x3e - BYTE DriveMotorStatus; // 0x3f - BYTE MotorShutdownCounter; // 0x40 - BYTE LastDisketteOperation; // 0x41 - BYTE Reserved2[7]; // 0x42 - BYTE VideoMode; // 0x49 - WORD ScreenColumns; // 0x4a - WORD VideoPageSize; // 0x4c - WORD VideoPageOffset; // 0x4e - WORD CursorPosition[BIOS_MAX_PAGES]; // 0x50 - BYTE CursorEndLine; // 0x60 - BYTE CursorStartLine; // 0x61 - BYTE VideoPage; // 0x62 - WORD CrtBasePort; // 0x63 - BYTE CrtModeControl; // 0x65 - BYTE CrtColorPaletteMask; // 0x66 - BYTE CassetteData[5]; // 0x67 - DWORD TickCounter; // 0x6c - BYTE MidnightPassed; // 0x70 - BYTE BreakFlag; // 0x71 - WORD SoftReset; // 0x72 - BYTE LastDiskOperation; // 0x74 - BYTE NumDisks; // 0x75 - BYTE DriveControlByte; // 0x76 - BYTE DiskPortOffset; // 0x77 - BYTE LptTimeOut[4]; // 0x78 - BYTE ComTimeOut[4]; // 0x7c - WORD KeybdBufferStart; // 0x80 - WORD KeybdBufferEnd; // 0x82 - BYTE ScreenRows; // 0x84 - WORD CharacterHeight; // 0x85 - BYTE EGAFlags[2]; // 0x87 - BYTE VGAFlags[2]; // 0x89 - DWORD Reserved3; // 0x8b - BYTE Reserved4; // 0x8f - BYTE Reserved5[2]; // 0x90 - BYTE Reserved6[2]; // 0x92 - BYTE Reserved7[2]; // 0x94 - WORD Reserved8; // 0x96 - DWORD Reserved9; // 0x98 - DWORD Reserved10; // 0x9c - DWORD Reserved11[2]; // 0xa0 - DWORD EGAPtr; // 0xa8 - BYTE Reserved12[68]; // 0xac - BYTE Reserved13[16]; // 0xf0 - - DWORD Reserved14; // 0x100 - BYTE Reserved15[12]; // 0x104 - BYTE Reserved16[17]; // 0x110 - BYTE Reserved17[15]; // 0x121 - BYTE Reserved18[3]; // 0x130 -} BIOS_DATA_AREA, *PBIOS_DATA_AREA; -#pragma pack(pop) - -C_ASSERT(sizeof(BIOS_DATA_AREA) == 0x133); - /* FUNCTIONS ******************************************************************/ - -extern PBIOS_DATA_AREA Bda; WORD BiosPeekCharacter(VOID); WORD BiosGetCharacter(VOID); -BOOLEAN BiosInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput); -VOID BiosCleanup(VOID); -VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack); +BOOLEAN KbdBiosInitialize(HANDLE ConsoleInput); +VOID KbdBiosCleanup(VOID); -#endif // _BIOS_H_ +#endif // _KBDBIOS_H_ /* EOF */ Modified: branches/ntvdm/subsystems/ntvdm/bios/vidbios.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios/vid…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios/vidbios.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios/vidbios.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -18,7 +18,6 @@ #include "hardware/vga.h" #include "int32.h" -#include "registers.h" /* MACROS *********************************************************************/ @@ -31,8 +30,6 @@ #define VGA_CRTC_DATA Bda->CrtBasePort + 1 // VGA_CRTC_DATA_MONO or VGA_CRTC_DATA_COLOR /* PRIVATE VARIABLES **********************************************************/ - -static HANDLE VidBiosConsoleOutput = INVALID_HANDLE_VALUE; /* * VGA Register Configurations for BIOS Video Modes @@ -1537,8 +1534,6 @@ BOOLEAN VidBiosInitialize(HANDLE ConsoleOutput) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - /* Some interrupts are in fact addresses to tables */ ((PDWORD)BaseAddress)[0x1D] = (DWORD)NULL; ((PDWORD)BaseAddress)[0x1F] = (DWORD)NULL; @@ -1546,25 +1541,24 @@ ((PDWORD)BaseAddress)[0x43] = (DWORD)NULL; ((PDWORD)BaseAddress)[0x44] = (DWORD)NULL; - /* Save the default BIOS console output handle for cleanup */ - if (ConsoleOutput == INVALID_HANDLE_VALUE) return FALSE; - VidBiosConsoleOutput = ConsoleOutput; - - /* Initialize VGA */ - if (!VgaInitialize(ConsoleOutput)) return FALSE; - /* Set the default video mode */ VidBiosSetVideoMode(BIOS_DEFAULT_VIDEO_MODE); - GetConsoleScreenBufferInfo(ConsoleOutput, &ConsoleInfo); - - /* Copy console data into VGA memory */ - VidBiosCopyTextConsoleToVgaMemory(ConsoleOutput, &ConsoleInfo.dwSize); - - /* Update the cursor position for the current page */ - VidBiosSetCursorPosition(ConsoleInfo.dwCursorPosition.Y, - ConsoleInfo.dwCursorPosition.X, - Bda->VideoPage); + /* Set some screen properties if the console output handle is valid */ + if (ConsoleOutput != INVALID_HANDLE_VALUE) + { + CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + + GetConsoleScreenBufferInfo(ConsoleOutput, &ConsoleInfo); + + /* Copy console data into VGA memory */ + VidBiosCopyTextConsoleToVgaMemory(ConsoleOutput, &ConsoleInfo.dwSize); + + /* Update the cursor position for the current page */ + VidBiosSetCursorPosition(ConsoleInfo.dwCursorPosition.Y, + ConsoleInfo.dwCursorPosition.X, + Bda->VideoPage); + } /* Register the BIOS 32-bit Interrupts */ RegisterInt32(BIOS_VIDEO_INTERRUPT, VidBiosVideoService); @@ -1574,8 +1568,6 @@ VOID VidBiosCleanup(VOID) { - /* Restore the old screen buffer */ - SetConsoleActiveScreenBuffer(VidBiosConsoleOutput); } /* EOF */ Modified: branches/ntvdm/subsystems/ntvdm/emulator.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -15,6 +15,7 @@ #include "bios/bios.h" #include "hardware/cmos.h" #include "hardware/pic.h" +#include "hardware/ps2.h" #include "hardware/speaker.h" #include "hardware/timer.h" #include "hardware/vga.h" @@ -22,7 +23,6 @@ #include "bop.h" #include "vddsup.h" #include "io.h" -#include "registers.h" /* PRIVATE VARIABLES **********************************************************/ @@ -31,6 +31,18 @@ BOOLEAN VdmRunning = TRUE; static BOOLEAN A20Line = FALSE; + +LPCWSTR ExceptionName[] = +{ + L"Division By Zero", + L"Debug", + L"Unexpected Error", + L"Breakpoint", + L"Integer Overflow", + L"Bound Range Exceeded", + L"Invalid Opcode", + L"FPU Not Available" +}; /* BOP Identifiers */ #define BOP_DEBUGGER 0x56 // Break into the debugger from a 16-bit app @@ -115,7 +127,7 @@ /* PUBLIC FUNCTIONS ***********************************************************/ -BOOLEAN EmulatorInitialize(VOID) +BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) { /* Allocate memory for the 16-bit address space */ BaseAddress = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_ADDRESS); @@ -148,6 +160,16 @@ CmosInitialize(); SpeakerInitialize(); + /* Initialize the PS2 port */ + PS2Initialize(ConsoleInput); + + /* Set the console input mode */ + // SetConsoleMode(ConsoleInput, ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT); + + /* Initialize the VGA */ + // if (!VgaInitialize(ConsoleOutput)) return FALSE; + VgaInitialize(ConsoleOutput); + /* Register the DebugBreak BOP */ RegisterBop(BOP_DEBUGGER, EmulatorDebugBreak); @@ -159,6 +181,9 @@ VOID EmulatorCleanup(VOID) { + // VgaCleanup(); + PS2Cleanup(); + SpeakerCleanup(); CmosCleanup(); // PitCleanup(); @@ -168,6 +193,40 @@ /* Free the memory allocated for the 16-bit address space */ if (BaseAddress != NULL) HeapFree(GetProcessHeap(), 0, BaseAddress); +} + +VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack) +{ + WORD CodeSegment, InstructionPointer; + PBYTE Opcode; + + ASSERT(ExceptionNumber < 8); + + /* Get the CS:IP */ + InstructionPointer = Stack[STACK_IP]; + CodeSegment = Stack[STACK_CS]; + Opcode = (PBYTE)SEG_OFF_TO_PTR(CodeSegment, InstructionPointer); + + /* Display a message to the user */ + DisplayMessage(L"Exception: %s occured at %04X:%04X\n" + L"Opcode: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", + ExceptionName[ExceptionNumber], + CodeSegment, + InstructionPointer, + Opcode[0], + Opcode[1], + Opcode[2], + Opcode[3], + Opcode[4], + Opcode[5], + Opcode[6], + Opcode[7], + Opcode[8], + Opcode[9]); + + /* Stop the VDM */ + VdmRunning = FALSE; + return; } // FIXME: This function assumes 16-bit mode!!! Modified: branches/ntvdm/subsystems/ntvdm/emulator.h URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -105,7 +105,9 @@ PFAST486_STATE State ); -BOOLEAN EmulatorInitialize(VOID); +VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack); + +BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput); VOID EmulatorExecute(WORD Segment, WORD Offset); VOID EmulatorInterrupt(BYTE Number); VOID EmulatorInterruptSignal(VOID); Modified: branches/ntvdm/subsystems/ntvdm/hardware/cmos.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/hardware…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/hardware/cmos.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/hardware/cmos.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -12,8 +12,8 @@ #include "emulator.h" #include "cmos.h" + #include "io.h" -#include "bios/bios.h" #include "pic.h" /* PRIVATE VARIABLES **********************************************************/ @@ -138,18 +138,6 @@ return Value; } - case CMOS_REG_BASE_MEMORY_LOW: - return Bda->MemorySize & 0xFF; - - case CMOS_REG_BASE_MEMORY_HIGH: - return Bda->MemorySize >> 8; - - case CMOS_REG_EXT_MEMORY_LOW: - return ((MAX_ADDRESS - 0x100000) / 1024) & 0xFF; - - case CMOS_REG_EXT_MEMORY_HIGH: - return ((MAX_ADDRESS - 0x100000) / 1024) >> 8; - case CMOS_REG_STATUS_A: case CMOS_REG_STATUS_B: case CMOS_REG_STATUS_D: @@ -295,6 +283,26 @@ // Status registers C and D are read-only break; + /* Is the following correct? */ + case CMOS_REG_EXT_MEMORY_LOW: + case CMOS_REG_ACTUAL_EXT_MEMORY_LOW: + { + /* Sync EMS and UMS */ + CmosMemory.Regs[CMOS_REG_EXT_MEMORY_LOW] = + CmosMemory.Regs[CMOS_REG_ACTUAL_EXT_MEMORY_LOW] = Value; + break; + } + + /* Is the following correct? */ + case CMOS_REG_EXT_MEMORY_HIGH: + case CMOS_REG_ACTUAL_EXT_MEMORY_HIGH: + { + /* Sync EMS and UMS */ + CmosMemory.Regs[CMOS_REG_EXT_MEMORY_HIGH] = + CmosMemory.Regs[CMOS_REG_ACTUAL_EXT_MEMORY_HIGH] = Value; + break; + } + default: { CmosMemory.Regs[SelectedRegister] = Value; @@ -309,6 +317,7 @@ BYTE WINAPI CmosReadPort(ULONG Port) { + ASSERT(Port == CMOS_DATA_PORT); return CmosReadData(); } @@ -430,6 +439,23 @@ CmosMemory.Diagnostics = 0x00; // Diagnostics must not find any errors. CmosMemory.ShutdownStatus = 0x00; + /* Memory settings */ + + /* + * Conventional memory size is 640 kB, + * see:
http://webpages.charter.net/danrollins/techhelp/0184.HTM
+ * and see Ralf Brown:
http://www.ctyme.com/intr/rb-0598.htm
+ * for more information. + */ + CmosMemory.Regs[CMOS_REG_BASE_MEMORY_LOW ] = LOBYTE(0x0280); + CmosMemory.Regs[CMOS_REG_BASE_MEMORY_HIGH] = HIBYTE(0x0280); + + CmosMemory.Regs[CMOS_REG_EXT_MEMORY_LOW] = + CmosMemory.Regs[CMOS_REG_ACTUAL_EXT_MEMORY_LOW] = LOBYTE((MAX_ADDRESS - 0x100000) / 1024); + + CmosMemory.Regs[CMOS_REG_EXT_MEMORY_HIGH] = + CmosMemory.Regs[CMOS_REG_ACTUAL_EXT_MEMORY_HIGH] = HIBYTE((MAX_ADDRESS - 0x100000) / 1024); + /* Register the I/O Ports */ RegisterIoPort(CMOS_ADDRESS_PORT, NULL , CmosWritePort); RegisterIoPort(CMOS_DATA_PORT , CmosReadPort, CmosWritePort); Modified: branches/ntvdm/subsystems/ntvdm/hardware/cmos.h URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/hardware…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/hardware/cmos.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/hardware/cmos.h [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -63,11 +63,13 @@ CMOS_REG_STATUS_D, CMOS_REG_DIAGNOSTICS, CMOS_REG_SHUTDOWN_STATUS, - CMOS_REG_BASE_MEMORY_LOW = 0x15, - CMOS_REG_BASE_MEMORY_HIGH = 0x16, - CMOS_REG_EXT_MEMORY_LOW = 0x17, - CMOS_REG_EXT_MEMORY_HIGH = 0x18, - CMOS_REG_MAX = 0x40 + CMOS_REG_BASE_MEMORY_LOW = 0x15, + CMOS_REG_BASE_MEMORY_HIGH = 0x16, + CMOS_REG_EXT_MEMORY_LOW = 0x17, + CMOS_REG_EXT_MEMORY_HIGH = 0x18, + CMOS_REG_ACTUAL_EXT_MEMORY_LOW = 0x30, + CMOS_REG_ACTUAL_EXT_MEMORY_HIGH = 0x31, + CMOS_REG_MAX = 0x40 } CMOS_REGISTERS, *PCMOS_REGISTERS; /* Modified: branches/ntvdm/subsystems/ntvdm/hardware/vga.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/hardware…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/hardware/vga.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/hardware/vga.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -14,7 +14,6 @@ #include "vga.h" #include "io.h" -#include "bios/bios.h" /* PRIVATE VARIABLES **********************************************************/ Modified: branches/ntvdm/subsystems/ntvdm/int32.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/int32.c?…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/int32.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/int32.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -15,22 +15,8 @@ #include "int32.h" #include "bop.h" -#include "bios/bios.h" -#include "registers.h" /* PRIVATE VARIABLES **********************************************************/ - -LPCWSTR ExceptionName[] = -{ - L"Division By Zero", - L"Debug", - L"Unexpected Error", - L"Breakpoint", - L"Integer Overflow", - L"Bound Range Exceeded", - L"Invalid Opcode", - L"FPU Not Available" -}; /* * This is the list of registered 32-bit Interrupt handlers. @@ -46,86 +32,10 @@ /* PUBLIC FUNCTIONS ***********************************************************/ -VOID WINAPI Exception(BYTE ExceptionNumber, LPWORD Stack) -{ - WORD CodeSegment, InstructionPointer; - PBYTE Opcode; - - ASSERT(ExceptionNumber < 8); - - /* Get the CS:IP */ - InstructionPointer = Stack[STACK_IP]; - CodeSegment = Stack[STACK_CS]; - Opcode = (PBYTE)SEG_OFF_TO_PTR(CodeSegment, InstructionPointer); - - /* Display a message to the user */ - DisplayMessage(L"Exception: %s occured at %04X:%04X\n" - L"Opcode: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", - ExceptionName[ExceptionNumber], - CodeSegment, - InstructionPointer, - Opcode[0], - Opcode[1], - Opcode[2], - Opcode[3], - Opcode[4], - Opcode[5], - Opcode[6], - Opcode[7], - Opcode[8], - Opcode[9]); - - /* Stop the VDM */ - VdmRunning = FALSE; - return; -} - -#if 0 -VOID WINAPI IrqDispatch(BYTE IrqNumber, LPWORD Stack) -{ - /* Check if this was an PIC IRQ */ - if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8) - { - /* It was an IRQ from the master PIC */ - BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack); - } - else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8) - { - /* It was an IRQ from the slave PIC */ - BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack); - } - - return; -} -#endif - VOID WINAPI Int32Dispatch(LPWORD Stack) { - BYTE IntNum; - /* Get the interrupt number */ - IntNum = LOBYTE(Stack[STACK_INT_NUM]); - - /* Check if this was an exception */ - if (IntNum < 8) - { - Exception(IntNum, Stack); - return; - } - - /* Check if this was an PIC IRQ */ - if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8) - { - /* It was an IRQ from the master PIC */ - BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack); - return; - } - else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8) - { - /* It was an IRQ from the slave PIC */ - BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack); - return; - } + BYTE IntNum = LOBYTE(Stack[STACK_INT_NUM]); /* Call the 32-bit Interrupt handler */ if (Int32Proc[IntNum] != NULL) Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.c?…
============================================================================== --- branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] Sat Jan 25 00:21:51 2014 @@ -55,7 +55,7 @@ case CTRL_C_EVENT: case CTRL_BREAK_EVENT: { - /* Perform interrupt 0x23 */ + /* Call INT 23h */ EmulatorInterrupt(0x23); break; } @@ -202,7 +202,7 @@ } /* Initialize the emulator */ - if (!EmulatorInitialize()) + if (!EmulatorInitialize(ConsoleInput, ConsoleOutput)) { wprintf(L"FATAL: Failed to initialize the emulator\n"); goto Cleanup;
10 years, 11 months
1
0
0
0
← Newer
1
...
7
8
9
10
11
12
13
...
43
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Results per page:
10
25
50
100
200