ReactOS 0.4.15-dev-5672-gf73ac17
util.c File Reference
#include "precomp.h"
#include <wine/debug.h>
Include dependency graph for util.c:

Go to the source code of this file.

Classes

struct  MD4_CTX
 
struct  MD5_CTX
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (ntlm)
 
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 WINAPI MD5Init (MD5_CTX *ctx)
 
VOID WINAPI MD5Update (MD5_CTX *ctx, const unsigned char *buf, unsigned int len)
 
VOID WINAPI MD5Final (MD5_CTX *ctx)
 
ULONG ComputeCrc32 (const BYTE *pData, INT iLen, ULONG initial_crc)
 
SECURITY_STATUS SECUR32_CreateNTLM1SessionKey (PBYTE password, int len, PBYTE session_key)
 
static void SECUR32_CalcNTLM2Subkey (const BYTE *session_key, const char *magic, PBYTE subkey)
 
SECURITY_STATUS SECUR32_CreateNTLM2SubKeys (PNegoHelper helper)
 
arc4_infoSECUR32_arc4Alloc (void)
 
void SECUR32_arc4Init (arc4_info *a4i, const BYTE *key, unsigned int keyLen)
 
void SECUR32_arc4Process (arc4_info *a4i, BYTE *inoutString, unsigned int length)
 
void SECUR32_arc4Cleanup (arc4_info *a4i)
 

Variables

static const ULONG CRC_table [256]
 
static const char client_to_server_sign_constant [] = "session key to client-to-server signing key magic constant"
 
static const char client_to_server_seal_constant [] = "session key to client-to-server sealing key magic constant"
 
static const char server_to_client_sign_constant [] = "session key to server-to-client signing key magic constant"
 
static const char server_to_client_seal_constant [] = "session key to server-to-client sealing key magic constant"
 

Function Documentation

◆ ComputeCrc32()

ULONG ComputeCrc32 ( const BYTE pData,
INT  iLen,
ULONG  initial_crc 
)

Definition at line 109 of file util.c.

110{
111 ULONG crc = ~initial_crc;
112
113 while (iLen > 0)
114 {
115 crc = CRC_table[(crc ^ *pData) & 0xff] ^ (crc >> 8);
116 pData++;
117 iLen--;
118 }
119 return ~crc;
120}
static const ULONG CRC_table[256]
Definition: util.c:29
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ntlm_CreateSignature().

◆ MD4Final()

VOID WINAPI MD4Final ( MD4_CTX ctx)

Definition at line 113 of file md4.c.

114{
115 unsigned int count;
116 unsigned char *p;
117
118 /* Compute number of bytes mod 64 */
119 count = (ctx->i[0] >> 3) & 0x3F;
120
121 /* Set the first char of padding to 0x80. This is safe since there is
122 always at least one byte free */
123 p = ctx->in + count;
124 *p++ = 0x80;
125
126 /* Bytes of padding needed to make 64 bytes */
127 count = 64 - 1 - count;
128
129 /* Pad out to 56 mod 64 */
130 if (count < 8)
131 {
132 /* Two lots of padding: Pad the first block to 64 bytes */
133 memset( p, 0, count );
134 byteReverse( ctx->in, 16 );
135 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
136
137 /* Now fill the next block with 56 bytes */
138 memset( ctx->in, 0, 56 );
139 }
140 else
141 {
142 /* Pad block to 56 bytes */
143 memset( p, 0, count - 8 );
144 }
145
146 byteReverse( ctx->in, 14 );
147
148 /* Append length in bits and transform */
149 ((unsigned int *)ctx->in)[14] = ctx->i[0];
150 ((unsigned int *)ctx->in)[15] = ctx->i[1];
151
152 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
153 byteReverse( (unsigned char *)ctx->buf, 4 );
154 memcpy( ctx->digest, ctx->buf, 16 );
155}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void MD4Transform(unsigned int buf[4], unsigned int const in[16])
Definition: md4.c:181
#define byteReverse(buf, long)
Definition: util.h:5
#define memset(x, y, z)
Definition: compat.h:39

Referenced by SECUR32_CreateNTLM1SessionKey().

◆ MD4Init()

VOID WINAPI MD4Init ( MD4_CTX ctx)

Definition at line 45 of file md4.c.

46{
47 ctx->buf[0] = 0x67452301;
48 ctx->buf[1] = 0xefcdab89;
49 ctx->buf[2] = 0x98badcfe;
50 ctx->buf[3] = 0x10325476;
51
52 ctx->i[0] = ctx->i[1] = 0;
53}

Referenced by SECUR32_CreateNTLM1SessionKey().

◆ MD4Update()

VOID WINAPI MD4Update ( MD4_CTX ctx,
const unsigned char buf,
unsigned int  len 
)

Definition at line 59 of file md4.c.

60{
61 register unsigned int t;
62
63 /* Update bitcount */
64 t = ctx->i[0];
65
66 if ((ctx->i[0] = t + (len << 3)) < t)
67 ctx->i[1]++; /* Carry from low to high */
68
69 ctx->i[1] += len >> 29;
70 t = (t >> 3) & 0x3f;
71
72 /* Handle any leading odd-sized chunks */
73 if (t)
74 {
75 unsigned char *p = (unsigned char *)ctx->in + t;
76 t = 64 - t;
77
78 if (len < t)
79 {
80 memcpy( p, buf, len );
81 return;
82 }
83
84 memcpy( p, buf, t );
85 byteReverse( ctx->in, 16 );
86
87 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
88
89 buf += t;
90 len -= t;
91 }
92
93 /* Process data in 64-byte chunks */
94 while (len >= 64)
95 {
96 memcpy( ctx->in, buf, 64 );
97 byteReverse( ctx->in, 16 );
98
99 MD4Transform( ctx->buf, (unsigned int *)ctx->in );
100
101 buf += 64;
102 len -= 64;
103 }
104
105 /* Handle any remaining bytes of data. */
106 memcpy( ctx->in, buf, len );
107}
GLdouble GLdouble t
Definition: gl.h:2047
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
if(dx< 0)
Definition: linetemp.h:194

Referenced by SECUR32_CreateNTLM1SessionKey().

◆ MD5Final()

VOID WINAPI MD5Final ( MD5_CTX ctx)

Definition at line 113 of file md5.c.

114{
115 unsigned int count;
116 unsigned char *p;
117
118 /* Compute number of bytes mod 64 */
119 count = (ctx->i[0] >> 3) & 0x3F;
120
121 /* Set the first char of padding to 0x80. This is safe since there is
122 always at least one byte free */
123 p = ctx->in + count;
124 *p++ = 0x80;
125
126 /* Bytes of padding needed to make 64 bytes */
127 count = 64 - 1 - count;
128
129 /* Pad out to 56 mod 64 */
130 if (count < 8)
131 {
132 /* Two lots of padding: Pad the first block to 64 bytes */
133 memset( p, 0, count );
134 byteReverse( ctx->in, 16 );
135 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
136
137 /* Now fill the next block with 56 bytes */
138 memset( ctx->in, 0, 56 );
139 }
140 else
141 {
142 /* Pad block to 56 bytes */
143 memset( p, 0, count - 8 );
144 }
145
146 byteReverse( ctx->in, 14 );
147
148 /* Append length in bits and transform */
149 ((unsigned int *)ctx->in)[14] = ctx->i[0];
150 ((unsigned int *)ctx->in)[15] = ctx->i[1];
151
152 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
153 byteReverse( (unsigned char *)ctx->buf, 4 );
154 memcpy( ctx->digest, ctx->buf, 16 );
155}
static void MD5Transform(unsigned int buf[4], const unsigned int in[16])
Definition: md5.c:174

Referenced by SECUR32_CalcNTLM2Subkey().

◆ MD5Init()

VOID WINAPI MD5Init ( MD5_CTX ctx)

Definition at line 45 of file md5.c.

46{
47 ctx->buf[0] = 0x67452301;
48 ctx->buf[1] = 0xefcdab89;
49 ctx->buf[2] = 0x98badcfe;
50 ctx->buf[3] = 0x10325476;
51
52 ctx->i[0] = ctx->i[1] = 0;
53}

Referenced by SECUR32_CalcNTLM2Subkey().

◆ MD5Update()

VOID WINAPI MD5Update ( MD5_CTX ctx,
const unsigned char buf,
unsigned int  len 
)

Definition at line 59 of file md5.c.

60{
61 register unsigned int t;
62
63 /* Update bitcount */
64 t = ctx->i[0];
65
66 if ((ctx->i[0] = t + (len << 3)) < t)
67 ctx->i[1]++; /* Carry from low to high */
68
69 ctx->i[1] += len >> 29;
70 t = (t >> 3) & 0x3f;
71
72 /* Handle any leading odd-sized chunks */
73 if (t)
74 {
75 unsigned char *p = (unsigned char *)ctx->in + t;
76 t = 64 - t;
77
78 if (len < t)
79 {
80 memcpy( p, buf, len );
81 return;
82 }
83
84 memcpy( p, buf, t );
85 byteReverse( ctx->in, 16 );
86
87 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
88
89 buf += t;
90 len -= t;
91 }
92
93 /* Process data in 64-byte chunks */
94 while (len >= 64)
95 {
96 memcpy( ctx->in, buf, 64 );
97 byteReverse( ctx->in, 16 );
98
99 MD5Transform( ctx->buf, (unsigned int *)ctx->in );
100
101 buf += 64;
102 len -= 64;
103 }
104
105 /* Handle any remaining bytes of data. */
106 memcpy( ctx->in, buf, len );
107}

Referenced by SECUR32_CalcNTLM2Subkey().

◆ SECUR32_arc4Alloc()

arc4_info * SECUR32_arc4Alloc ( void  )

Definition at line 189 of file util.c.

190{
191 arc4_info *a4i = HeapAlloc(GetProcessHeap(), 0, sizeof(arc4_info));
192 return a4i;
193}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733

Referenced by ntlm_AcceptSecurityContext(), and ntlm_InitializeSecurityContextW().

◆ SECUR32_arc4Cleanup()

void SECUR32_arc4Cleanup ( arc4_info a4i)

Definition at line 246 of file util.c.

247{
248 HeapFree(GetProcessHeap(), 0, a4i);
249}
#define HeapFree(x, y, z)
Definition: compat.h:735

Referenced by ntlm_DeleteSecurityContext().

◆ SECUR32_arc4Init()

void SECUR32_arc4Init ( arc4_info a4i,
const BYTE key,
unsigned int  keyLen 
)

Definition at line 199 of file util.c.

200{
201 unsigned int keyIndex = 0, stateIndex = 0;
202 unsigned int i, a;
203
204 TRACE("(%p, %p, %d)\n", a4i, key, keyLen);
205
206 a4i->x = a4i->y = 0;
207
208 for (i=0; i<256; i++)
209 a4i->state[i] = i;
210
211 for (i=0; i<256; i++)
212 {
213 a = a4i->state[i];
214 stateIndex += key[keyIndex] + a;
215 stateIndex &= 0xff;
216 a4i->state[i] = a4i->state[stateIndex];
217 a4i->state[stateIndex] = a;
218 if (++keyIndex >= keyLen)
219 keyIndex = 0;
220 }
221
222}
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define a
Definition: ke_i.h:78
#define for
Definition: utility.h:88
#define TRACE(s)
Definition: solgame.cpp:4
Definition: copy.c:22
unsigned char x
Definition: ntlm.h:17
unsigned char y
Definition: ntlm.h:17
unsigned char state[256]
Definition: ntlm.h:18

Referenced by ntlm_AcceptSecurityContext(), and ntlm_InitializeSecurityContextW().

◆ SECUR32_arc4Process()

void SECUR32_arc4Process ( arc4_info a4i,
BYTE inoutString,
unsigned int  length 
)

Definition at line 224 of file util.c.

225{
226 BYTE *const s=a4i->state;
227 unsigned int x = a4i->x;
228 unsigned int y = a4i->y;
229 unsigned int a, b;
230
231 while(length--)
232 {
233 x = (x+1) & 0xff;
234 a = s[x];
235 y = (y+a) & 0xff;
236 b = s[y];
237 s[x] = b;
238 s[y] = a;
239 *inoutString++ ^= s[(a+b) & 0xff];
240 }
241
242 a4i->x = x;
243 a4i->y = y;
244}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define b
Definition: ke_i.h:79
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ntlm_CreateSignature(), ntlm_DecryptMessage(), and ntlm_EncryptMessage().

◆ SECUR32_CalcNTLM2Subkey()

static void SECUR32_CalcNTLM2Subkey ( const BYTE session_key,
const char magic,
PBYTE  subkey 
)
static

Definition at line 144 of file util.c.

145{
146 MD5_CTX ctx;
147
148 MD5Init(&ctx);
149 MD5Update(&ctx, session_key, 16);
150 MD5Update(&ctx, (const unsigned char*)magic, lstrlenA(magic)+1);
151 MD5Final(&ctx);
152 memcpy(subkey, ctx.digest, 16);
153}
VOID WINAPI MD5Final(MD5_CTX *ctx)
Definition: md5.c:113
VOID WINAPI MD5Update(MD5_CTX *ctx, const unsigned char *buf, unsigned int len)
Definition: md5.c:59
VOID WINAPI MD5Init(MD5_CTX *ctx)
Definition: md5.c:45
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
u32_t magic(void)
Definition: msi.c:4013

Referenced by SECUR32_CreateNTLM2SubKeys().

◆ SECUR32_CreateNTLM1SessionKey()

SECURITY_STATUS SECUR32_CreateNTLM1SessionKey ( PBYTE  password,
int  len,
PBYTE  session_key 
)

Definition at line 122 of file util.c.

123{
124 MD4_CTX ctx;
125 BYTE ntlm_hash[16];
126
127 TRACE("(%p, %p)\n", password, session_key);
128
129 MD4Init(&ctx);
131 MD4Final(&ctx);
132
133 memcpy(ntlm_hash, ctx.digest, 0x10);
134
135 MD4Init(&ctx);
136 MD4Update(&ctx, ntlm_hash, 0x10u);
137 MD4Final(&ctx);
138
139 memcpy(session_key, ctx.digest, 0x10);
140
141 return SEC_E_OK;
142}
VOID WINAPI MD4Final(MD4_CTX *ctx)
Definition: md4.c:113
VOID WINAPI MD4Update(MD4_CTX *ctx, const unsigned char *buf, unsigned int len)
Definition: md4.c:59
VOID WINAPI MD4Init(MD4_CTX *ctx)
Definition: md4.c:45
static WCHAR password[]
Definition: url.c:33
Definition: util.c:82
#define SEC_E_OK
Definition: winerror.h:2356

Referenced by ntlm_InitializeSecurityContextW().

◆ SECUR32_CreateNTLM2SubKeys()

SECURITY_STATUS SECUR32_CreateNTLM2SubKeys ( PNegoHelper  helper)

Definition at line 156 of file util.c.

157{
158 helper->crypt.ntlm2.send_sign_key = HeapAlloc(GetProcessHeap(), 0, 16);
159 helper->crypt.ntlm2.send_seal_key = HeapAlloc(GetProcessHeap(), 0, 16);
160 helper->crypt.ntlm2.recv_sign_key = HeapAlloc(GetProcessHeap(), 0, 16);
161 helper->crypt.ntlm2.recv_seal_key = HeapAlloc(GetProcessHeap(), 0, 16);
162
163 if(helper->mode == NTLM_CLIENT)
164 {
166 helper->crypt.ntlm2.send_sign_key);
168 helper->crypt.ntlm2.send_seal_key);
170 helper->crypt.ntlm2.recv_sign_key);
172 helper->crypt.ntlm2.recv_seal_key);
173 }
174 else
175 {
177 helper->crypt.ntlm2.send_sign_key);
179 helper->crypt.ntlm2.send_seal_key);
181 helper->crypt.ntlm2.recv_sign_key);
183 helper->crypt.ntlm2.recv_seal_key);
184 }
185
186 return SEC_E_OK;
187}
static void SECUR32_CalcNTLM2Subkey(const BYTE *session_key, const char *magic, PBYTE subkey)
Definition: util.c:144
static const char client_to_server_seal_constant[]
Definition: util.c:77
static const char server_to_client_seal_constant[]
Definition: util.c:79
static const char client_to_server_sign_constant[]
Definition: util.c:76
static const char server_to_client_sign_constant[]
Definition: util.c:78
@ NTLM_CLIENT
Definition: ntlm.h:12
struct _NegoHelper::@536 crypt
BYTE * session_key
Definition: ntlm.h:36
HelperMode mode
Definition: ntlm.h:27

Referenced by ntlm_InitializeSecurityContextW().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( ntlm  )

Variable Documentation

◆ client_to_server_seal_constant

const char client_to_server_seal_constant[] = "session key to client-to-server sealing key magic constant"
static

Definition at line 77 of file util.c.

Referenced by SECUR32_CreateNTLM2SubKeys().

◆ client_to_server_sign_constant

const char client_to_server_sign_constant[] = "session key to client-to-server signing key magic constant"
static

Definition at line 76 of file util.c.

Referenced by SECUR32_CreateNTLM2SubKeys().

◆ CRC_table

const ULONG CRC_table[256]
static

Definition at line 29 of file util.c.

Referenced by ComputeCrc32().

◆ server_to_client_seal_constant

const char server_to_client_seal_constant[] = "session key to server-to-client sealing key magic constant"
static

Definition at line 79 of file util.c.

Referenced by SECUR32_CreateNTLM2SubKeys().

◆ server_to_client_sign_constant

const char server_to_client_sign_constant[] = "session key to server-to-client signing key magic constant"
static

Definition at line 78 of file util.c.

Referenced by SECUR32_CreateNTLM2SubKeys().