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