ReactOS 0.4.17-dev-934-g091855f
checksum.c File Reference
Include dependency graph for checksum.c:

Go to the source code of this file.

Classes

struct  md5_ctx
 

Macros

#define DXBC_CHECKSUM_BLOCK_SIZE   64
 
#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))
 
#define MD5STEP(f, w, x, y, z, data, s)    (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)
 

Functions

 STATIC_ASSERT (sizeof(unsigned int)==4)
 
static void md5_transform (unsigned int buf[4], const unsigned int in[16])
 
static void byte_reverse (unsigned char *buf, unsigned longs)
 
static void md5_init (struct md5_ctx *ctx)
 
static void md5_update (struct md5_ctx *ctx, const unsigned char *buf, unsigned int len)
 
static void md5_final (struct md5_ctx *ctx, enum vkd3d_md5_variant variant)
 
void vkd3d_compute_md5 (const void *data, size_t size, uint32_t checksum[4], enum vkd3d_md5_variant variant)
 

Macro Definition Documentation

◆ DXBC_CHECKSUM_BLOCK_SIZE

#define DXBC_CHECKSUM_BLOCK_SIZE   64

Definition at line 43 of file checksum.c.

◆ F1

#define F1 (   x,
  y,
  z 
)    (z ^ (x & (y ^ z)))

Definition at line 58 of file checksum.c.

◆ F2

#define F2 (   x,
  y,
  z 
)    F1(z, x, y)

Definition at line 59 of file checksum.c.

◆ F3

#define F3 (   x,
  y,
  z 
)    (x ^ y ^ z)

Definition at line 60 of file checksum.c.

◆ F4

#define F4 (   x,
  y,
  z 
)    (y ^ (x | ~z))

Definition at line 61 of file checksum.c.

◆ MD5STEP

#define MD5STEP (   f,
  w,
  x,
  y,
  z,
  data,
  s 
)     (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)

Definition at line 64 of file checksum.c.

Function Documentation

◆ byte_reverse()

static void byte_reverse ( unsigned char *  buf,
unsigned  longs 
)
static

Definition at line 158 of file checksum.c.

159{
160 unsigned int t;
161
162 do
163 {
165 *(unsigned int *)buf = t;
166 buf += 4;
167 } while (--longs);
168}
GLdouble GLdouble t
Definition: gl.h:2047
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static uint16_t vkd3d_make_u16(uint8_t low, uint8_t high)
Definition: vkd3d_common.h:376
static uint32_t vkd3d_make_u32(uint16_t low, uint16_t high)
Definition: vkd3d_common.h:381

Referenced by md5_final(), and md5_update().

◆ md5_final()

static void md5_final ( struct md5_ctx *  ctx,
enum vkd3d_md5_variant  variant 
)
static

Definition at line 238 of file checksum.c.

239{
240 unsigned int padding;
241 unsigned int count;
242 unsigned char *p;
243
244 /* Compute number of bytes mod 64 */
245 count = (ctx->i[0] >> 3) & 0x3F;
246
247 /* Set the first char of padding to 0x80. This is safe since there is
248 always at least one byte free */
249 p = ctx->in + count;
250 *p++ = 0x80;
251 ++count;
252
253 /* Bytes of padding needed to make 64 bytes */
255
256 /* Pad out to 56 mod 64 */
257 if (padding < 8)
258 {
259 /* Two lots of padding: Pad the first block to 64 bytes */
260 memset(p, 0, padding);
261 byte_reverse(ctx->in, 16);
262 md5_transform(ctx->buf, (unsigned int *)ctx->in);
263
264 /* Now fill the next block */
266 }
267 else if (variant == VKD3D_MD5_DXBC)
268 {
269 /* Make place for bitcount at the beginning of the block */
270 memmove(&ctx->in[4], ctx->in, count);
271
272 /* Pad block to 60 bytes */
273 memset(p + 4, 0, padding - 4);
274 }
275 else
276 {
277 /* Pad block to 56 bytes */
278 memset(p, 0, padding - 8);
279 }
280
281 /* Append length in bits and transform */
282 if (variant == VKD3D_MD5_DXBC)
283 {
284 unsigned int length;
285
286 length = ctx->i[0];
287 memcpy(&ctx->in[0], &length, sizeof(length));
288 byte_reverse(&ctx->in[4], 14);
289 length = ctx->i[0] >> 2 | 0x1;
290 memcpy(&ctx->in[DXBC_CHECKSUM_BLOCK_SIZE - 4], &length, sizeof(length));
291 }
292 else
293 {
294 byte_reverse(ctx->in, 14);
295
296 ((unsigned int *)ctx->in)[14] = ctx->i[0];
297 ((unsigned int *)ctx->in)[15] = ctx->i[1];
298 }
299
300 md5_transform(ctx->buf, (unsigned int *)ctx->in);
301 byte_reverse((unsigned char *)ctx->buf, 4);
302 memcpy(ctx->digest, ctx->buf, 16);
303}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLfloat GLfloat p
Definition: glext.h:8902
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static const DWORD padding[]
Definition: mciwnd.c:88
#define memset(x, y, z)
Definition: compat.h:39
static void md5_transform(unsigned int buf[4], const unsigned int in[16])
Definition: checksum.c:72
#define DXBC_CHECKSUM_BLOCK_SIZE
Definition: checksum.c:43
static void byte_reverse(unsigned char *buf, unsigned longs)
Definition: checksum.c:158
@ VKD3D_MD5_DXBC

Referenced by rdssl_sign_ok(), and vkd3d_compute_md5().

◆ md5_init()

static void md5_init ( struct md5_ctx *  ctx)
static

Definition at line 174 of file checksum.c.

175{
176 ctx->buf[0] = 0x67452301;
177 ctx->buf[1] = 0xefcdab89;
178 ctx->buf[2] = 0x98badcfe;
179 ctx->buf[3] = 0x10325476;
180
181 ctx->i[0] = ctx->i[1] = 0;
182}

◆ md5_transform()

static void md5_transform ( unsigned int  buf[4],
const unsigned int  in[16] 
)
static

Definition at line 72 of file checksum.c.

73{
74 unsigned int a, b, c, d;
75
76 a = buf[0];
77 b = buf[1];
78 c = buf[2];
79 d = buf[3];
80
81 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
82 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
83 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
84 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
85 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
86 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
87 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
88 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
89 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
90 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
91 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
92 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
93 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
94 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
95 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
96 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
97
98 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
99 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
100 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
101 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
102 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
103 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
104 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
105 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
106 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
107 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
108 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
109 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
110 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
111 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
112 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
113 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
114
115 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
116 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
117 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
118 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
119 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
120 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
121 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
122 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
123 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
124 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
125 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
126 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
127 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
128 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
129 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
130 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
131
132 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
133 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
134 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
135 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
136 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
137 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
138 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
139 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
140 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
141 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
142 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
143 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
144 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
145 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
146 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
147 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
148
149 buf[0] += a;
150 buf[1] += b;
151 buf[2] += c;
152 buf[3] += d;
153}
const GLubyte * c
Definition: glext.h:8905
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLuint in
Definition: glext.h:9616
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
#define a
Definition: ke_i.h:78
#define c
Definition: ke_i.h:80
#define b
Definition: ke_i.h:79
#define MD5STEP(f, w, x, y, z, data, s)
Definition: checksum.c:64
#define F1(x, y, z)
Definition: checksum.c:58
#define F4(x, y, z)
Definition: checksum.c:61
#define F3(x, y, z)
Definition: checksum.c:60
#define F2(x, y, z)
Definition: checksum.c:59

Referenced by md5_final(), and md5_update().

◆ md5_update()

static void md5_update ( struct md5_ctx *  ctx,
const unsigned char *  buf,
unsigned int  len 
)
static

Definition at line 188 of file checksum.c.

189{
190 unsigned int t;
191
192 /* Update bitcount */
193 t = ctx->i[0];
194
195 if ((ctx->i[0] = t + (len << 3)) < t)
196 ctx->i[1]++; /* Carry from low to high */
197
198 ctx->i[1] += len >> 29;
199 t = (t >> 3) & 0x3f;
200
201 /* Handle any leading odd-sized chunks */
202 if (t)
203 {
204 unsigned char *p = (unsigned char *)ctx->in + t;
206
207 if (len < t)
208 {
209 memcpy(p, buf, len);
210 return;
211 }
212
213 memcpy(p, buf, t);
214 byte_reverse(ctx->in, 16);
215
216 md5_transform(ctx->buf, (unsigned int *)ctx->in);
217
218 buf += t;
219 len -= t;
220 }
221
222 /* Process data in 64-byte chunks */
224 {
226 byte_reverse(ctx->in, 16);
227
228 md5_transform(ctx->buf, (unsigned int *)ctx->in);
229
232 }
233
234 /* Handle any remaining bytes of data. */
235 memcpy(ctx->in, buf, len);
236}
GLenum GLsizei len
Definition: glext.h:6722
if(dx< 0)
Definition: linetemp.h:194

◆ STATIC_ASSERT()

STATIC_ASSERT ( sizeof(unsigned int)  = =4)

◆ vkd3d_compute_md5()

void vkd3d_compute_md5 ( const void *  data,
size_t  size,
uint32_t  checksum[4],
enum vkd3d_md5_variant  variant 
)

Definition at line 305 of file checksum.c.

306{
307 const uint8_t *ptr = data;
308 struct md5_ctx ctx;
309
310 md5_init(&ctx);
312 md5_final(&ctx, variant);
313
314 memcpy(checksum, ctx.digest, sizeof(ctx.digest));
315}
#define md5_update
Definition: compat-1.3.h:2043
#define md5_init
Definition: compat-1.3.h:2039
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
Definition: fdi.c:353
unsigned char uint8_t
Definition: stdint.h:33
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
static PVOID ptr
Definition: dispmode.c:27
static void md5_final(struct md5_ctx *ctx, enum vkd3d_md5_variant variant)
Definition: checksum.c:238
Definition: msi.c:4007

Referenced by compute_dxbc_checksum(), and fill_shader_dump_data().