port crypt and trustee support from Wine. Patch by Steven Edwards.

svn path=/trunk/; revision=12007
This commit is contained in:
Thomas Bluemel
2004-12-11 00:21:33 +00:00
parent 2c781cf79e
commit 4173776e7b
14 changed files with 3225 additions and 59 deletions
+41 -32
View File
@@ -1,4 +1,4 @@
; $Id: advapi32.def,v 1.25 2004/11/21 20:14:36 gdalsnes Exp $
; $Id: advapi32.def,v 1.26 2004/12/11 00:21:33 weiden Exp $
;
; advapi32.def
;
@@ -6,6 +6,9 @@
;
LIBRARY advapi32.dll
EXPORTS
A_SHAFinal@8
A_SHAInit@4
A_SHAUpdate@12
AbortSystemShutdownA@4
AbortSystemShutdownW@4
AccessCheck@32
@@ -36,10 +39,10 @@ BackupEventLogW@8
;BuildImpersonateTrusteeW@8
;BuildSecurityDescriptorA@36
;BuildSecurityDescriptorW@36
;BuildTrusteeWithNameA@8
;BuildTrusteeWithNameW@8
;BuildTrusteeWithSidA@8
;BuildTrusteeWithSidW@8
BuildTrusteeWithNameA@8
BuildTrusteeWithNameW@8
BuildTrusteeWithSidA@8
BuildTrusteeWithSidW@8
ChangeServiceConfigA@44
ChangeServiceConfigW@44
ClearEventLogA@8
@@ -55,34 +58,34 @@ CreateProcessAsUserA@44
CreateProcessAsUserW@44
CreateServiceA@52
CreateServiceW@52
;CryptAcquireContextA@20
;CryptAcquireContextW@20
;CryptContextAddRef@12
;CryptCreateHash@20
;CryptDecrypt@24
;CryptDeriveKey@20
;CryptDestroyHash@4
;CryptDestroyKey@4
;CryptEncrypt@28
;CryptExportKey@24
;CryptGenKey@16
;CryptGenRandom@12
;CryptGetHashParam@20
;CryptGetKeyParam@20
;CryptGetProvParam@20
;CryptGetUserKey@12
;CryptHashData@16
;CryptHashSessionKey@12
;CryptImportKey@24
;CryptReleaseContext@8
;CryptSetHashParam@16
;CryptSetKeyParam@16
;CryptSetProvParam@16
;CryptSetProviderA@8
;CryptSetProviderW@8
;CryptSignHashA@24
CryptAcquireContextA@20
CryptAcquireContextW@20
CryptContextAddRef@12
CryptCreateHash@20
CryptDecrypt@24
CryptDeriveKey@20
CryptDestroyHash@4
CryptDestroyKey@4
CryptEncrypt@28
CryptExportKey@24
CryptGenKey@16
CryptGenRandom@12
CryptGetHashParam@20
CryptGetKeyParam@20
CryptGetProvParam@20
CryptGetUserKey@12
CryptHashData@16
CryptHashSessionKey@12
CryptImportKey@24
CryptReleaseContext@8
CryptSetHashParam@16
CryptSetKeyParam@16
CryptSetProvParam@16
CryptSetProviderA@8
CryptSetProviderW@8
CryptSignHashA@24
;CryptSignHashW@24
;CryptVerifySignatureA@24
CryptVerifySignatureA@24
;CryptVerifySignatureW@24
DeleteAce@8
DeleteService@4
@@ -259,6 +262,12 @@ LsaQueryInformationPolicy@12
MakeAbsoluteSD@44
MakeSelfRelativeSD@12
MapGenericMask@8
MD4Final@4
MD4Init@4
MD4Update@12
MD5Final@4
MD5Init@4
MD5Update@12
;NTAccessMaskToProvAccessRights@12
;NotifyBootConfigStatus@4
NotifyChangeEventLog@8
+1
View File
@@ -8,3 +8,4 @@
#include <windows.h>
#include <sddl.h>
#include <rosrtl/string.h>
#include <accctrl.h>
+2
View File
@@ -0,0 +1,2 @@
*.o
.*.d
File diff suppressed because it is too large Load Diff
+86
View File
@@ -0,0 +1,86 @@
/*
* Driver routines
*
* Copyright 2001 - Travis Michielsen
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WINE_CRYPT_H
#define __WINE_CRYPT_H
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wincrypt.h"
typedef struct tagPROVFUNCS
{
BOOL (WINAPI *pCPAcquireContext)(HCRYPTPROV *phProv, LPSTR pszContainer, DWORD dwFlags, PVTableProvStruc pVTable);
BOOL (WINAPI *pCPCreateHash)(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash);
BOOL (WINAPI *pCPDecrypt)(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen);
BOOL (WINAPI *pCPDeriveKey)(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData, DWORD dwFlags, HCRYPTKEY *phKey);
BOOL (WINAPI *pCPDestroyHash)(HCRYPTPROV hProv, HCRYPTHASH hHash);
BOOL (WINAPI *pCPDestroyKey)(HCRYPTPROV hProv, HCRYPTKEY hKey);
BOOL (WINAPI *pCPDuplicateHash)(HCRYPTPROV hUID, HCRYPTHASH hHash, DWORD *pdwReserved, DWORD dwFlags, HCRYPTHASH *phHash);
BOOL (WINAPI *pCPDuplicateKey)(HCRYPTPROV hUID, HCRYPTKEY hKey, DWORD *pdwReserved, DWORD dwFlags, HCRYPTKEY *phKey);
BOOL (WINAPI *pCPEncrypt)(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen);
BOOL (WINAPI *pCPExportKey)(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTKEY hPubKey, DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen);
BOOL (WINAPI *pCPGenKey)(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey);
BOOL (WINAPI *pCPGenRandom)(HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer);
BOOL (WINAPI *pCPGetHashParam)(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags);
BOOL (WINAPI *pCPGetKeyParam)(HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags);
BOOL (WINAPI *pCPGetProvParam)(HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags);
BOOL (WINAPI *pCPGetUserKey)(HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey);
BOOL (WINAPI *pCPHashData)(HCRYPTPROV hProv, HCRYPTHASH hHash, CONST BYTE *pbData, DWORD dwDataLen, DWORD dwFlags);
BOOL (WINAPI *pCPHashSessionKey)(HCRYPTPROV hProv, HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags);
BOOL (WINAPI *pCPImportKey)(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey);
BOOL (WINAPI *pCPReleaseContext)(HCRYPTPROV hProv, DWORD dwFlags);
BOOL (WINAPI *pCPSetHashParam)(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD dwFlags);
BOOL (WINAPI *pCPSetKeyParam)(HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD dwFlags);
BOOL (WINAPI *pCPSetProvParam)(HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD dwFlags);
BOOL (WINAPI *pCPSignHash)(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription, DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen);
BOOL (WINAPI *pCPVerifySignature)(HCRYPTPROV hProv, HCRYPTHASH hHash, CONST BYTE *pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags);
} PROVFUNCS, *PPROVFUNCS;
typedef struct tagCRYPTPROV
{
UINT refcount;
HMODULE hModule;
PPROVFUNCS pFuncs;
HCRYPTPROV hPrivate; /*CSP's handle - Should not be given to application under any circumstances!*/
PVTableProvStruc pVTable;
} CRYPTPROV, *PCRYPTPROV;
typedef struct tagCRYPTKEY
{
PCRYPTPROV pProvider;
HCRYPTKEY hPrivate; /*CSP's handle - Should not be given to application under any circumstances!*/
} CRYPTKEY, *PCRYPTKEY;
typedef struct tagCRYPTHASH
{
PCRYPTPROV pProvider;
HCRYPTHASH hPrivate; /*CSP's handle - Should not be given to application under any circumstances!*/
} CRYPTHASH, *PCRYPTHASH;
#define MAXPROVTYPES 999
extern unsigned char *CRYPT_DESkey8to7( unsigned char *dst, const unsigned char *key );
extern unsigned char *CRYPT_DEShash( unsigned char *dst, const unsigned char *key,
const unsigned char *src );
#endif /* __WINE_CRYPT_H_ */
+290
View File
@@ -0,0 +1,290 @@
/*
* Copyright 2004 Hans Leidekker
*
* Based on DES.c from libcifs
*
* Copyright (C) 2003, 2004 by Christopher R. Hertel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "windef.h"
#include "crypt.h"
static const unsigned char InitialPermuteMap[64] =
{
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7,
56, 48, 40, 32, 24, 16, 8, 0,
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6
};
static const unsigned char KeyPermuteMap[56] =
{
49, 42, 35, 28, 21, 14, 7, 0,
50, 43, 36, 29, 22, 15, 8, 1,
51, 44, 37, 30, 23, 16, 9, 2,
52, 45, 38, 31, 55, 48, 41, 34,
27, 20, 13, 6, 54, 47, 40, 33,
26, 19, 12, 5, 53, 46, 39, 32,
25, 18, 11, 4, 24, 17, 10, 3,
};
static const unsigned char KeyRotation[16] =
{ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 };
static const unsigned char KeyCompression[48] =
{
13, 16, 10, 23, 0, 4, 2, 27,
14, 5, 20, 9, 22, 18, 11, 3,
25, 7, 15, 6, 26, 19, 12, 1,
40, 51, 30, 36, 46, 54, 29, 39,
50, 44, 32, 47, 43, 48, 38, 55,
33, 52, 45, 41, 49, 35, 28, 31
};
static const unsigned char DataExpansion[48] =
{
31, 0, 1, 2, 3, 4, 3, 4,
5, 6, 7, 8, 7, 8, 9, 10,
11, 12, 11, 12, 13, 14, 15, 16,
15, 16, 17, 18, 19, 20, 19, 20,
21, 22, 23, 24, 23, 24, 25, 26,
27, 28, 27, 28, 29, 30, 31, 0
};
static const unsigned char SBox[8][64] =
{
{ /* S0 */
14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1,
3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8,
4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7,
15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13
},
{ /* S1 */
15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14,
9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5,
0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2,
5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9
},
{ /* S2 */
10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10,
1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1,
13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7,
11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12
},
{ /* S3 */
7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3,
1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9,
10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8,
15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14
},
{ /* S4 */
2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1,
8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6,
4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13,
15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3
},
{ /* S5 */
12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5,
0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8,
9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10,
7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13
},
{ /* S6 */
4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10,
3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6,
1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7,
10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12
},
{ /* S7 */
13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4,
10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2,
7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13,
0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11
}
};
static const unsigned char PBox[32] =
{
15, 6, 19, 20, 28, 11, 27, 16,
0, 14, 22, 25, 4, 17, 30, 9,
1, 7, 23, 13, 31, 26, 2, 8,
18, 12, 29, 5, 21, 10, 3, 24
};
static const unsigned char FinalPermuteMap[64] =
{
7, 39, 15, 47, 23, 55, 31, 63,
6, 38, 14, 46, 22, 54, 30, 62,
5, 37, 13, 45, 21, 53, 29, 61,
4, 36, 12, 44, 20, 52, 28, 60,
3, 35, 11, 43, 19, 51, 27, 59,
2, 34, 10, 42, 18, 50, 26, 58,
1, 33, 9, 41, 17, 49, 25, 57,
0, 32, 8, 40, 16, 48, 24, 56
};
#define CLRBIT( STR, IDX ) ( (STR)[(IDX)/8] &= ~(0x01 << (7 - ((IDX)%8))) )
#define SETBIT( STR, IDX ) ( (STR)[(IDX)/8] |= (0x01 << (7 - ((IDX)%8))) )
#define GETBIT( STR, IDX ) (( ((STR)[(IDX)/8]) >> (7 - ((IDX)%8)) ) & 0x01)
static void Permute( unsigned char *dst, const unsigned char *src, const unsigned char *map, const int mapsize )
{
int bitcount, i;
for (i = 0; i < mapsize; i++)
dst[i] = 0;
bitcount = mapsize * 8;
for (i = 0; i < bitcount; i++)
{
if (GETBIT( src, map[i] ))
SETBIT( dst, i );
}
}
static void KeyShift( unsigned char *key, const int numbits )
{
int i;
unsigned char keep = key[0];
for (i = 0; i < numbits; i++)
{
int j;
for (j = 0; j < 7; j++)
{
if (j && (key[j] & 0x80))
key[j-1] |= 0x01;
key[j] <<= 1;
}
if (GETBIT( key, 27 ))
{
CLRBIT( key, 27 );
SETBIT( key, 55 );
}
if (keep & 0x80)
SETBIT( key, 27 );
keep <<= 1;
}
}
static void sbox( unsigned char *dst, const unsigned char *src )
{
int i;
for (i = 0; i < 4; i++)
dst[i] = 0;
for (i = 0; i < 8; i++)
{
int j, Snum, bitnum;
for (Snum = j = 0, bitnum = (i * 6); j < 6; j++, bitnum++)
{
Snum <<= 1;
Snum |= GETBIT( src, bitnum );
}
if (0 == (i%2))
dst[i/2] |= ((SBox[i][Snum]) << 4);
else
dst[i/2] |= SBox[i][Snum];
}
}
static void xor( unsigned char *dst, const unsigned char *a, const unsigned char *b, const int count )
{
int i;
for (i = 0; i < count; i++)
dst[i] = a[i] ^ b[i];
}
unsigned char *CRYPT_DESkey8to7( unsigned char *dst, const unsigned char *key )
{
int i;
unsigned char tmp[7];
static const unsigned char map8to7[56] =
{
0, 1, 2, 3, 4, 5, 6,
8, 9, 10, 11, 12, 13, 14,
16, 17, 18, 19, 20, 21, 22,
24, 25, 26, 27, 28, 29, 30,
32, 33, 34, 35, 36, 37, 38,
40, 41, 42, 43, 44, 45, 46,
48, 49, 50, 51, 52, 53, 54,
56, 57, 58, 59, 60, 61, 62
};
if ((dst == NULL) || (key == NULL))
return NULL;
Permute( tmp, key, map8to7, 7 );
for (i = 0; i < 7; i++)
dst[i] = tmp[i];
return dst;
}
unsigned char *CRYPT_DEShash( unsigned char *dst, const unsigned char *key, const unsigned char *src )
{
int i;
unsigned char K[7];
unsigned char D[8];
Permute( K, key, KeyPermuteMap, 7 );
Permute( D, src, InitialPermuteMap, 8 );
for (i = 0; i < 16; i++)
{
int j;
unsigned char *L = D;
unsigned char *R = &(D[4]);
unsigned char Rexp[6];
unsigned char Rn[4];
unsigned char SubK[6];
KeyShift( K, KeyRotation[i] );
Permute( SubK, K, KeyCompression, 6 );
Permute( Rexp, R, DataExpansion, 6 );
xor( Rexp, Rexp, SubK, 6 );
sbox( Rn, Rexp );
Permute( Rexp, Rn, PBox, 4 );
xor( Rn, L, Rexp, 4 );
for (j = 0; j < 4; j++)
{
L[j] = R[j];
R[j] = Rn[j];
}
}
Permute( dst, D, FinalPermuteMap, 8 );
return dst;
}
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright 2004 Hans Leidekker
*
* Based on LMHash.c from libcifs
*
* Copyright (C) 2004 by Christopher R. Hertel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
typedef LONG (CALLBACK *PVECTORED_EXCEPTION_HANDLER)(
struct _EXCEPTION_POINTERS *ExceptionInfo
);
#include "wine/winternl.h"
#include "wine/ntstatus.h"
#include "crypt.h"
static const unsigned char CRYPT_LMhash_Magic[8] =
{ 'K', 'G', 'S', '!', '@', '#', '$', '%' };
static void CRYPT_LMhash( unsigned char *dst, const unsigned char *pwd, const int len )
{
int i, max = 14;
unsigned char tmp_pwd[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
max = len > max ? max : len;
for (i = 0; i < max; i++)
tmp_pwd[i] = pwd[i];
CRYPT_DEShash( dst, tmp_pwd, CRYPT_LMhash_Magic );
CRYPT_DEShash( &dst[8], &tmp_pwd[7], CRYPT_LMhash_Magic );
}
NTSTATUS WINAPI SystemFunction006( LPCSTR password, LPSTR hash )
{
CRYPT_LMhash( hash, password, strlen(password) );
return STATUS_SUCCESS;
}
+270
View File
@@ -0,0 +1,270 @@
/*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <stdarg.h>
#include "windef.h"
#include "winbase.h"
typedef struct
{
unsigned int buf[4];
unsigned int i[2];
unsigned char in[64];
unsigned char digest[16];
} MD4_CTX;
static void MD4Transform( unsigned int buf[4], unsigned int const in[16] );
/*
* Note: this code is harmless on little-endian machines.
*/
static 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);
}
/*
* 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 + ((unsigned int)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;
}
+280
View File
@@ -0,0 +1,280 @@
/*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <stdarg.h>
#include "windef.h"
#include "winbase.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] );
/*
* Note: this code is harmless on little-endian machines.
*/
static 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);
}
/*
* 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 + ((unsigned int)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;
}
+188
View File
@@ -0,0 +1,188 @@
/*
* Copyright 2004 Filip Navara
* Based on public domain SHA code by Steve Reid <[email protected]>
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.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. */
void SHA1Transform(ULONG State[5], CHAR 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.
*/
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.
*/
VOID WINAPI
A_SHAUpdate(PSHA_CTX Context, PCHAR 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.
*/
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);
}
+13 -3
View File
@@ -1,4 +1,4 @@
# $Id: makefile,v 1.42 2004/08/15 17:03:14 chorns Exp $
# $Id: makefile,v 1.43 2004/12/11 00:21:33 weiden Exp $
PATH_TO_TOP = ../..
@@ -13,10 +13,18 @@ TARGET_CFLAGS = -Wall -Werror -fno-builtin -D__USE_W32API
TARGET_LFLAGS = -nostartfiles -nostdlib
TARGET_SDKLIBS = ntdll.a kernel32.a
TARGET_SDKLIBS = wine.a ntdll.a kernel32.a
TARGET_BASE = $(TARGET_BASE_LIB_ADVAPI32)
CRYPT_OBJECTS = \
crypt/crypt_des.o \
crypt/crypt_lmhash.o \
crypt/crypt_md4.o \
crypt/crypt_md5.o \
crypt/crypt_sha.o \
crypt/crypt.o
MISC_OBJECTS = \
misc/dllmain.o \
misc/hwprofiles.o \
@@ -33,7 +41,8 @@ SECURITY_OBJECTS = \
sec/lsa.o \
sec/misc.o \
sec/sec.o \
sec/sid.o
sec/sid.o \
sec/trustee.o
SERVICE_OBJECTS = \
service/eventlog.o \
@@ -46,6 +55,7 @@ TOKEN_OBJECTS = \
token/token.o
TARGET_OBJECTS = \
$(CRYPT_OBJECTS) \
$(MISC_OBJECTS) \
$(REGISTRY_OBJECTS) \
$(SECURITY_OBJECTS) \
+1 -15
View File
@@ -1,4 +1,4 @@
/* $Id: sysfunc.c,v 1.8 2004/08/15 17:03:14 chorns Exp $
/* $Id: sysfunc.c,v 1.9 2004/12/11 00:21:33 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@@ -77,20 +77,6 @@ SystemFunction005(INT a, INT b, INT c)
return 5;
}
/**********************************************************************
*
* @unimplemented
*/
INT
STDCALL
SystemFunction006(INT a, INT b)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 6;
}
/**********************************************************************
*
* @unimplemented
+68
View File
@@ -0,0 +1,68 @@
/* $Id: trustee.c,v 1.1 2004/12/11 00:21:33 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/advapi32/sec/ac.c
* PURPOSE: ACL/ACE functions
*/
#include "advapi32.h"
#include "wine/debug.h"
/******************************************************************************
* BuildTrusteeWithSidA [ADVAPI32.@]
*/
VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
{
DPRINT("%p %p\n", pTrustee, pSid);
pTrustee->pMultipleTrustee = NULL;
pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
pTrustee->TrusteeForm = TRUSTEE_IS_SID;
pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
pTrustee->ptstrName = (LPSTR) pSid;
}
/******************************************************************************
* BuildTrusteeWithSidW [ADVAPI32.@]
*/
VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
{
DPRINT("%p %p\n", pTrustee, pSid);
pTrustee->pMultipleTrustee = NULL;
pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
pTrustee->TrusteeForm = TRUSTEE_IS_SID;
pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
pTrustee->ptstrName = (LPWSTR) pSid;
}
/******************************************************************************
* BuildTrusteeWithNameA [ADVAPI32.@]
*/
VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
{
DPRINT("%p %s\n", pTrustee, debugstr_a(name) );
pTrustee->pMultipleTrustee = NULL;
pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
pTrustee->ptstrName = name;
}
/******************************************************************************
* BuildTrusteeWithNameW [ADVAPI32.@]
*/
VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
{
DPRINT("%p %s\n", pTrustee, debugstr_w(name) );
pTrustee->pMultipleTrustee = NULL;
pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
pTrustee->ptstrName = name;
}
+3 -9
View File
@@ -1,4 +1,4 @@
/* $Id: token.c,v 1.15 2004/12/10 16:50:37 navaraf Exp $
/* $Id: token.c,v 1.16 2004/12/11 00:21:33 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@@ -259,15 +259,9 @@ DuplicateTokenEx (HANDLE ExistingTokenHandle,
PHANDLE DuplicateTokenHandle)
{
OBJECT_ATTRIBUTES ObjectAttributes;
SECURITY_QUALITY_OF_SERVICE Qos;
HANDLE NewToken;
NTSTATUS Status;
Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
Qos.ImpersonationLevel = ImpersonationLevel;
Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
Qos.EffectiveOnly = FALSE;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
@@ -277,12 +271,12 @@ DuplicateTokenEx (HANDLE ExistingTokenHandle,
ObjectAttributes.Attributes |= OBJ_INHERIT;
}
ObjectAttributes.SecurityDescriptor = lpTokenAttributes->lpSecurityDescriptor;
ObjectAttributes.SecurityQualityOfService = &Qos;
ObjectAttributes.SecurityQualityOfService = NULL;
Status = NtDuplicateToken (ExistingTokenHandle,
dwDesiredAccess,
&ObjectAttributes,
FALSE,
ImpersonationLevel,
TokenType,
&NewToken);
if (!NT_SUCCESS(Status))