libmspack 0.0.5 → 0.10.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rake.yml +37 -0
- data/.gitignore +2 -0
- data/.yardopts +1 -1
- data/README.md +1 -1
- data/Rakefile +11 -5
- data/ext/Rakefile +1 -1
- data/ext/libmspack/AUTHORS +1 -0
- data/ext/libmspack/ChangeLog +321 -4
- data/ext/libmspack/INSTALL +368 -0
- data/ext/libmspack/Makefile.am +86 -95
- data/ext/libmspack/Makefile.in +1729 -0
- data/ext/libmspack/README +30 -30
- data/ext/libmspack/acinclude.m4 +99 -0
- data/ext/libmspack/aclocal.m4 +1218 -0
- data/ext/libmspack/ar-lib +270 -0
- data/ext/libmspack/compile +347 -0
- data/ext/libmspack/config.guess +1480 -0
- data/ext/libmspack/config.h.in +129 -0
- data/ext/libmspack/config.sub +1801 -0
- data/ext/libmspack/configure +15487 -0
- data/ext/libmspack/configure.ac +11 -13
- data/ext/libmspack/depcomp +791 -0
- data/ext/libmspack/install-sh +508 -0
- data/ext/libmspack/libmscabd.la +41 -0
- data/ext/libmspack/libmschmd.la +41 -0
- data/ext/libmspack/libmspack.la +41 -0
- data/ext/libmspack/ltmain.sh +11156 -0
- data/ext/libmspack/m4/libtool.m4 +8387 -0
- data/ext/libmspack/m4/ltoptions.m4 +437 -0
- data/ext/libmspack/m4/ltsugar.m4 +124 -0
- data/ext/libmspack/m4/ltversion.m4 +23 -0
- data/ext/libmspack/m4/lt~obsolete.m4 +99 -0
- data/ext/libmspack/missing +215 -0
- data/ext/libmspack/mspack/cab.h +20 -7
- data/ext/libmspack/mspack/cabd.c +301 -236
- data/ext/libmspack/mspack/chmd.c +304 -319
- data/ext/libmspack/mspack/crc32.c +52 -52
- data/ext/libmspack/mspack/crc32.h +1 -1
- data/ext/libmspack/mspack/kwajd.c +178 -172
- data/ext/libmspack/mspack/lzss.h +4 -4
- data/ext/libmspack/mspack/lzssd.c +42 -42
- data/ext/libmspack/mspack/lzx.h +11 -11
- data/ext/libmspack/mspack/lzxd.c +370 -361
- data/ext/libmspack/mspack/mspack.h +109 -77
- data/ext/libmspack/mspack/mszip.h +6 -6
- data/ext/libmspack/mspack/mszipd.c +140 -139
- data/ext/libmspack/mspack/oab.h +1 -0
- data/ext/libmspack/mspack/oabd.c +71 -73
- data/ext/libmspack/mspack/qtm.h +4 -4
- data/ext/libmspack/mspack/qtmd.c +118 -117
- data/ext/libmspack/mspack/readbits.h +52 -52
- data/ext/libmspack/mspack/readhuff.h +61 -61
- data/ext/libmspack/mspack/system.c +15 -9
- data/ext/libmspack/mspack/system.h +38 -50
- data/ext/libmspack/mspack/szddd.c +35 -35
- data/ext/libmspack/test-driver +148 -0
- data/ext/x86_64-linux/libmspack.so +0 -0
- data/ext/x86_64-windows/mspack.dll +0 -0
- data/lib/libmspack/version.rb +2 -1
- data/lib/libmspack.rb +1 -1
- data/libmspack.gemspec +4 -4
- data/spec/libmspack_spec.rb +5 -4
- metadata +38 -105
- data/.travis.yml +0 -5
- data/ext/i386-windows/libmspack.dll +0 -0
- data/ext/libmspack/cleanup.sh +0 -9
- data/ext/libmspack/debian/changelog +0 -6
- data/ext/libmspack/debian/control +0 -14
- data/ext/libmspack/debian/rules +0 -101
- data/ext/libmspack/doc/Doxyfile.in +0 -22
- data/ext/libmspack/doc/Makefile.in +0 -14
- data/ext/libmspack/doc/szdd_kwaj_format.html +0 -331
- data/ext/libmspack/mspack/mspack.def +0 -28
- data/ext/libmspack/mspack/qtmc.c +0 -18
- data/ext/libmspack/rebuild.sh +0 -8
- data/ext/libmspack/test/cabd_c10 +0 -19
- data/ext/libmspack/test/cabd_compare +0 -34
- data/ext/libmspack/test/cabd_md5.c +0 -161
- data/ext/libmspack/test/cabd_memory.c +0 -179
- data/ext/libmspack/test/cabd_test.c +0 -386
- data/ext/libmspack/test/cabrip.c +0 -81
- data/ext/libmspack/test/chmd_compare +0 -38
- data/ext/libmspack/test/chmd_find.c +0 -95
- data/ext/libmspack/test/chmd_md5.c +0 -67
- data/ext/libmspack/test/chmd_order.c +0 -144
- data/ext/libmspack/test/chminfo.c +0 -284
- data/ext/libmspack/test/chmx.c +0 -216
- data/ext/libmspack/test/error.h +0 -22
- data/ext/libmspack/test/expand.c +0 -79
- data/ext/libmspack/test/md5.c +0 -457
- data/ext/libmspack/test/md5.h +0 -165
- data/ext/libmspack/test/md5_fh.h +0 -123
- data/ext/libmspack/test/msdecompile_md5 +0 -24
- data/ext/libmspack/test/msexpand_md5 +0 -39
- data/ext/libmspack/test/multifh.c +0 -435
- data/ext/libmspack/test/oabx.c +0 -41
- data/ext/libmspack/test/test_files/cabd/1.pl +0 -84
- data/ext/libmspack/test/test_files/cabd/2.pl +0 -75
- data/ext/libmspack/test/test_files/cabd/bad_folderindex.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/bad_nofiles.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/bad_nofolders.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/bad_signature.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/multi_basic_pt1.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/multi_basic_pt2.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/multi_basic_pt3.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/multi_basic_pt4.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/multi_basic_pt5.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/normal_255c_filename.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/normal_2files_1folder.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_nodata.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_nofiles.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_nofolder.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_shortextheader.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_shortfile1.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_shortfile2.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_shortfolder.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_shortheader.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_nofname.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_noninfo.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_nonname.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_nopinfo.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_nopname.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_shortfname.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_shortninfo.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_shortnname.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_shortpinfo.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/partial_str_shortpname.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_---.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_--D.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_-F-.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_-FD.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_H--.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_H-D.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_HF-.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/reserve_HFD.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/search_basic.cab +0 -0
- data/ext/libmspack/test/test_files/cabd/search_tricky1.cab +0 -0
- data/ext/libmspack/winbuild.sh +0 -26
- data/ext/libmspack.h +0 -259
- data/ext/x86_64-windows/libmspack.dll +0 -0
data/ext/libmspack/test/md5.c
DELETED
@@ -1,457 +0,0 @@
|
|
1
|
-
/* md5.c - Functions to compute MD5 message digest of files or memory blocks
|
2
|
-
according to the definition of MD5 in RFC 1321 from April 1992.
|
3
|
-
Copyright (C) 1995, 1996, 2001, 2003 Free Software Foundation, Inc.
|
4
|
-
NOTE: The canonical source of this file is maintained with the GNU C
|
5
|
-
Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
6
|
-
|
7
|
-
This program is free software; you can redistribute it and/or modify it
|
8
|
-
under the terms of the GNU General Public License as published by the
|
9
|
-
Free Software Foundation; either version 2, or (at your option) any
|
10
|
-
later version.
|
11
|
-
|
12
|
-
This program is distributed in the hope that it will be useful,
|
13
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
GNU General Public License for more details.
|
16
|
-
|
17
|
-
You should have received a copy of the GNU General Public License
|
18
|
-
along with this program; if not, write to the Free Software Foundation,
|
19
|
-
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
20
|
-
|
21
|
-
/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */
|
22
|
-
|
23
|
-
#ifdef HAVE_CONFIG_H
|
24
|
-
# include <config.h>
|
25
|
-
#endif
|
26
|
-
|
27
|
-
#include <sys/types.h>
|
28
|
-
|
29
|
-
#if STDC_HEADERS || defined _LIBC
|
30
|
-
# include <stdlib.h>
|
31
|
-
# include <string.h>
|
32
|
-
#else
|
33
|
-
# ifndef HAVE_MEMCPY
|
34
|
-
# define memcpy(d, s, n) bcopy ((s), (d), (n))
|
35
|
-
# endif
|
36
|
-
#endif
|
37
|
-
|
38
|
-
#include <md5.h>
|
39
|
-
|
40
|
-
#ifdef _LIBC
|
41
|
-
# include <endian.h>
|
42
|
-
# if __BYTE_ORDER == __BIG_ENDIAN
|
43
|
-
# define WORDS_BIGENDIAN 1
|
44
|
-
# endif
|
45
|
-
/* We need to keep the namespace clean so define the MD5 function
|
46
|
-
protected using leading __ . */
|
47
|
-
# define md5_init_ctx __md5_init_ctx
|
48
|
-
# define md5_process_block __md5_process_block
|
49
|
-
# define md5_process_bytes __md5_process_bytes
|
50
|
-
# define md5_finish_ctx __md5_finish_ctx
|
51
|
-
# define md5_read_ctx __md5_read_ctx
|
52
|
-
# define md5_stream __md5_stream
|
53
|
-
# define md5_buffer __md5_buffer
|
54
|
-
#endif
|
55
|
-
|
56
|
-
#ifdef WORDS_BIGENDIAN
|
57
|
-
# define SWAP(n) \
|
58
|
-
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
|
59
|
-
#else
|
60
|
-
# define SWAP(n) (n)
|
61
|
-
#endif
|
62
|
-
|
63
|
-
#define BLOCKSIZE 4096
|
64
|
-
/* Ensure that BLOCKSIZE is a multiple of 64. */
|
65
|
-
#if BLOCKSIZE % 64 != 0
|
66
|
-
/* FIXME-someday (soon?): use #error instead of this kludge. */
|
67
|
-
"invalid BLOCKSIZE"
|
68
|
-
#endif
|
69
|
-
|
70
|
-
/* This array contains the bytes used to pad the buffer to the next
|
71
|
-
64-byte boundary. (RFC 1321, 3.1: Step 1) */
|
72
|
-
static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
|
73
|
-
|
74
|
-
|
75
|
-
/* Initialize structure containing state of computation.
|
76
|
-
(RFC 1321, 3.3: Step 3) */
|
77
|
-
void
|
78
|
-
md5_init_ctx (struct md5_ctx *ctx)
|
79
|
-
{
|
80
|
-
ctx->A = 0x67452301;
|
81
|
-
ctx->B = 0xefcdab89;
|
82
|
-
ctx->C = 0x98badcfe;
|
83
|
-
ctx->D = 0x10325476;
|
84
|
-
|
85
|
-
ctx->total[0] = ctx->total[1] = 0;
|
86
|
-
ctx->buflen = 0;
|
87
|
-
}
|
88
|
-
|
89
|
-
/* Put result from CTX in first 16 bytes following RESBUF. The result
|
90
|
-
must be in little endian byte order.
|
91
|
-
|
92
|
-
IMPORTANT: On some systems it is required that RESBUF is correctly
|
93
|
-
aligned for a 32 bits value. */
|
94
|
-
void *
|
95
|
-
md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
|
96
|
-
{
|
97
|
-
((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
|
98
|
-
((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
|
99
|
-
((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
|
100
|
-
((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
|
101
|
-
|
102
|
-
return resbuf;
|
103
|
-
}
|
104
|
-
|
105
|
-
/* Process the remaining bytes in the internal buffer and the usual
|
106
|
-
prolog according to the standard and write the result to RESBUF.
|
107
|
-
|
108
|
-
IMPORTANT: On some systems it is required that RESBUF is correctly
|
109
|
-
aligned for a 32 bits value. */
|
110
|
-
void *
|
111
|
-
md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
|
112
|
-
{
|
113
|
-
/* Take yet unprocessed bytes into account. */
|
114
|
-
md5_uint32 bytes = ctx->buflen;
|
115
|
-
size_t pad;
|
116
|
-
|
117
|
-
/* Now count remaining bytes. */
|
118
|
-
ctx->total[0] += bytes;
|
119
|
-
if (ctx->total[0] < bytes)
|
120
|
-
++ctx->total[1];
|
121
|
-
|
122
|
-
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
|
123
|
-
memcpy (&ctx->buffer[bytes], fillbuf, pad);
|
124
|
-
|
125
|
-
/* Put the 64-bit file length in *bits* at the end of the buffer. */
|
126
|
-
*(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
|
127
|
-
*(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
|
128
|
-
(ctx->total[0] >> 29));
|
129
|
-
|
130
|
-
/* Process last bytes. */
|
131
|
-
md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
|
132
|
-
|
133
|
-
return md5_read_ctx (ctx, resbuf);
|
134
|
-
}
|
135
|
-
|
136
|
-
/* Compute MD5 message digest for bytes read from STREAM. The
|
137
|
-
resulting message digest number will be written into the 16 bytes
|
138
|
-
beginning at RESBLOCK. */
|
139
|
-
int
|
140
|
-
md5_stream (FILE *stream, void *resblock)
|
141
|
-
{
|
142
|
-
struct md5_ctx ctx;
|
143
|
-
char buffer[BLOCKSIZE + 72];
|
144
|
-
size_t sum;
|
145
|
-
|
146
|
-
/* Initialize the computation context. */
|
147
|
-
md5_init_ctx (&ctx);
|
148
|
-
|
149
|
-
/* Iterate over full file contents. */
|
150
|
-
while (1)
|
151
|
-
{
|
152
|
-
/* We read the file in blocks of BLOCKSIZE bytes. One call of the
|
153
|
-
computation function processes the whole buffer so that with the
|
154
|
-
next round of the loop another block can be read. */
|
155
|
-
size_t n;
|
156
|
-
sum = 0;
|
157
|
-
|
158
|
-
/* Read block. Take care for partial reads. */
|
159
|
-
while (1)
|
160
|
-
{
|
161
|
-
n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
|
162
|
-
|
163
|
-
sum += n;
|
164
|
-
|
165
|
-
if (sum == BLOCKSIZE)
|
166
|
-
break;
|
167
|
-
|
168
|
-
if (n == 0)
|
169
|
-
{
|
170
|
-
/* Check for the error flag IFF N == 0, so that we don't
|
171
|
-
exit the loop after a partial read due to e.g., EAGAIN
|
172
|
-
or EWOULDBLOCK. */
|
173
|
-
if (ferror (stream))
|
174
|
-
return 1;
|
175
|
-
goto process_partial_block;
|
176
|
-
}
|
177
|
-
|
178
|
-
/* We've read at least one byte, so ignore errors. But always
|
179
|
-
check for EOF, since feof may be true even though N > 0.
|
180
|
-
Otherwise, we could end up calling fread after EOF. */
|
181
|
-
if (feof (stream))
|
182
|
-
goto process_partial_block;
|
183
|
-
}
|
184
|
-
|
185
|
-
/* Process buffer with BLOCKSIZE bytes. Note that
|
186
|
-
BLOCKSIZE % 64 == 0
|
187
|
-
*/
|
188
|
-
md5_process_block (buffer, BLOCKSIZE, &ctx);
|
189
|
-
}
|
190
|
-
|
191
|
-
process_partial_block:;
|
192
|
-
|
193
|
-
/* Process any remaining bytes. */
|
194
|
-
if (sum > 0)
|
195
|
-
md5_process_bytes (buffer, sum, &ctx);
|
196
|
-
|
197
|
-
/* Construct result in desired memory. */
|
198
|
-
md5_finish_ctx (&ctx, resblock);
|
199
|
-
return 0;
|
200
|
-
}
|
201
|
-
|
202
|
-
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
|
203
|
-
result is always in little endian byte order, so that a byte-wise
|
204
|
-
output yields to the wanted ASCII representation of the message
|
205
|
-
digest. */
|
206
|
-
void *
|
207
|
-
md5_buffer (const char *buffer, size_t len, void *resblock)
|
208
|
-
{
|
209
|
-
struct md5_ctx ctx;
|
210
|
-
|
211
|
-
/* Initialize the computation context. */
|
212
|
-
md5_init_ctx (&ctx);
|
213
|
-
|
214
|
-
/* Process whole buffer but last len % 64 bytes. */
|
215
|
-
md5_process_bytes (buffer, len, &ctx);
|
216
|
-
|
217
|
-
/* Put result in desired memory area. */
|
218
|
-
return md5_finish_ctx (&ctx, resblock);
|
219
|
-
}
|
220
|
-
|
221
|
-
|
222
|
-
void
|
223
|
-
md5_process_bytes ( const void *buffer, size_t len, struct md5_ctx *ctx)
|
224
|
-
{
|
225
|
-
/* When we already have some bits in our internal buffer concatenate
|
226
|
-
both inputs first. */
|
227
|
-
if (ctx->buflen != 0)
|
228
|
-
{
|
229
|
-
size_t left_over = ctx->buflen;
|
230
|
-
size_t add = 128 - left_over > len ? len : 128 - left_over;
|
231
|
-
|
232
|
-
memcpy (&ctx->buffer[left_over], buffer, add);
|
233
|
-
ctx->buflen += add;
|
234
|
-
|
235
|
-
if (ctx->buflen > 64)
|
236
|
-
{
|
237
|
-
md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
|
238
|
-
|
239
|
-
ctx->buflen &= 63;
|
240
|
-
/* The regions in the following copy operation cannot overlap. */
|
241
|
-
memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
|
242
|
-
ctx->buflen);
|
243
|
-
}
|
244
|
-
|
245
|
-
buffer = (const char *) buffer + add;
|
246
|
-
len -= add;
|
247
|
-
}
|
248
|
-
|
249
|
-
/* Process available complete blocks. */
|
250
|
-
if (len >= 64)
|
251
|
-
{
|
252
|
-
#if !_STRING_ARCH_unaligned
|
253
|
-
/* To check alignment gcc has an appropriate operator. Other
|
254
|
-
compilers don't. */
|
255
|
-
# if __GNUC__ >= 2
|
256
|
-
# define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32) != 0)
|
257
|
-
# else
|
258
|
-
# define UNALIGNED_P(p) (((md5_uintptr) p) % sizeof (md5_uint32) != 0)
|
259
|
-
# endif
|
260
|
-
if (UNALIGNED_P (buffer))
|
261
|
-
while (len > 64)
|
262
|
-
{
|
263
|
-
memcpy (ctx->buffer, buffer, 64);
|
264
|
-
md5_process_block (ctx->buffer, 64, ctx);
|
265
|
-
buffer = (const char *) buffer + 64;
|
266
|
-
len -= 64;
|
267
|
-
}
|
268
|
-
else
|
269
|
-
#endif
|
270
|
-
{
|
271
|
-
md5_process_block (buffer, len & ~63, ctx);
|
272
|
-
buffer = (const char *) buffer + (len & ~63);
|
273
|
-
len &= 63;
|
274
|
-
}
|
275
|
-
}
|
276
|
-
|
277
|
-
/* Move remaining bytes in internal buffer. */
|
278
|
-
if (len > 0)
|
279
|
-
{
|
280
|
-
size_t left_over = ctx->buflen;
|
281
|
-
|
282
|
-
memcpy (&ctx->buffer[left_over], buffer, len);
|
283
|
-
left_over += len;
|
284
|
-
if (left_over >= 64)
|
285
|
-
{
|
286
|
-
md5_process_block (ctx->buffer, 64, ctx);
|
287
|
-
left_over -= 64;
|
288
|
-
memcpy (ctx->buffer, &ctx->buffer[64], left_over);
|
289
|
-
}
|
290
|
-
ctx->buflen = left_over;
|
291
|
-
}
|
292
|
-
}
|
293
|
-
|
294
|
-
|
295
|
-
/* These are the four functions used in the four steps of the MD5 algorithm
|
296
|
-
and defined in the RFC 1321. The first function is a little bit optimized
|
297
|
-
(as found in Colin Plumbs public domain implementation). */
|
298
|
-
/* #define FF(b, c, d) ((b & c) | (~b & d)) */
|
299
|
-
#define FF(b, c, d) (d ^ (b & (c ^ d)))
|
300
|
-
#define FG(b, c, d) FF (d, b, c)
|
301
|
-
#define FH(b, c, d) (b ^ c ^ d)
|
302
|
-
#define FI(b, c, d) (c ^ (b | ~d))
|
303
|
-
|
304
|
-
/* Process LEN bytes of BUFFER, accumulating context into CTX.
|
305
|
-
It is assumed that LEN % 64 == 0. */
|
306
|
-
|
307
|
-
void
|
308
|
-
md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
|
309
|
-
{
|
310
|
-
md5_uint32 correct_words[16];
|
311
|
-
const md5_uint32 *words = (const md5_uint32 *) buffer;
|
312
|
-
size_t nwords = len / sizeof (md5_uint32);
|
313
|
-
const md5_uint32 *endp = words + nwords;
|
314
|
-
md5_uint32 A = ctx->A;
|
315
|
-
md5_uint32 B = ctx->B;
|
316
|
-
md5_uint32 C = ctx->C;
|
317
|
-
md5_uint32 D = ctx->D;
|
318
|
-
|
319
|
-
/* First increment the byte count. RFC 1321 specifies the possible
|
320
|
-
length of the file up to 2^64 bits. Here we only compute the
|
321
|
-
number of bytes. Do a double word increment. */
|
322
|
-
ctx->total[0] += len;
|
323
|
-
if (ctx->total[0] < len)
|
324
|
-
++ctx->total[1];
|
325
|
-
|
326
|
-
/* Process all bytes in the buffer with 64 bytes in each round of
|
327
|
-
the loop. */
|
328
|
-
while (words < endp)
|
329
|
-
{
|
330
|
-
md5_uint32 *cwp = correct_words;
|
331
|
-
md5_uint32 A_save = A;
|
332
|
-
md5_uint32 B_save = B;
|
333
|
-
md5_uint32 C_save = C;
|
334
|
-
md5_uint32 D_save = D;
|
335
|
-
|
336
|
-
/* First round: using the given function, the context and a constant
|
337
|
-
the next context is computed. Because the algorithms processing
|
338
|
-
unit is a 32-bit word and it is determined to work on words in
|
339
|
-
little endian byte order we perhaps have to change the byte order
|
340
|
-
before the computation. To reduce the work for the next steps
|
341
|
-
we store the swapped words in the array CORRECT_WORDS. */
|
342
|
-
|
343
|
-
#define OP(a, b, c, d, s, T) \
|
344
|
-
do \
|
345
|
-
{ \
|
346
|
-
a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \
|
347
|
-
++words; \
|
348
|
-
a = rol (a, s); \
|
349
|
-
a += b; \
|
350
|
-
} \
|
351
|
-
while (0)
|
352
|
-
|
353
|
-
/* Before we start, one word to the strange constants.
|
354
|
-
They are defined in RFC 1321 as
|
355
|
-
|
356
|
-
T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64, or
|
357
|
-
perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin $_))}'
|
358
|
-
*/
|
359
|
-
|
360
|
-
/* Round 1. */
|
361
|
-
OP (A, B, C, D, 7, 0xd76aa478);
|
362
|
-
OP (D, A, B, C, 12, 0xe8c7b756);
|
363
|
-
OP (C, D, A, B, 17, 0x242070db);
|
364
|
-
OP (B, C, D, A, 22, 0xc1bdceee);
|
365
|
-
OP (A, B, C, D, 7, 0xf57c0faf);
|
366
|
-
OP (D, A, B, C, 12, 0x4787c62a);
|
367
|
-
OP (C, D, A, B, 17, 0xa8304613);
|
368
|
-
OP (B, C, D, A, 22, 0xfd469501);
|
369
|
-
OP (A, B, C, D, 7, 0x698098d8);
|
370
|
-
OP (D, A, B, C, 12, 0x8b44f7af);
|
371
|
-
OP (C, D, A, B, 17, 0xffff5bb1);
|
372
|
-
OP (B, C, D, A, 22, 0x895cd7be);
|
373
|
-
OP (A, B, C, D, 7, 0x6b901122);
|
374
|
-
OP (D, A, B, C, 12, 0xfd987193);
|
375
|
-
OP (C, D, A, B, 17, 0xa679438e);
|
376
|
-
OP (B, C, D, A, 22, 0x49b40821);
|
377
|
-
|
378
|
-
/* For the second to fourth round we have the possibly swapped words
|
379
|
-
in CORRECT_WORDS. Redefine the macro to take an additional first
|
380
|
-
argument specifying the function to use. */
|
381
|
-
#undef OP
|
382
|
-
#define OP(f, a, b, c, d, k, s, T) \
|
383
|
-
do \
|
384
|
-
{ \
|
385
|
-
a += f (b, c, d) + correct_words[k] + T; \
|
386
|
-
a = rol (a, s); \
|
387
|
-
a += b; \
|
388
|
-
} \
|
389
|
-
while (0)
|
390
|
-
|
391
|
-
/* Round 2. */
|
392
|
-
OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
|
393
|
-
OP (FG, D, A, B, C, 6, 9, 0xc040b340);
|
394
|
-
OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
|
395
|
-
OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
|
396
|
-
OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
|
397
|
-
OP (FG, D, A, B, C, 10, 9, 0x02441453);
|
398
|
-
OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
|
399
|
-
OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
|
400
|
-
OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
|
401
|
-
OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
|
402
|
-
OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
|
403
|
-
OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
|
404
|
-
OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
|
405
|
-
OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
|
406
|
-
OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
|
407
|
-
OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
|
408
|
-
|
409
|
-
/* Round 3. */
|
410
|
-
OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
|
411
|
-
OP (FH, D, A, B, C, 8, 11, 0x8771f681);
|
412
|
-
OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
|
413
|
-
OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
|
414
|
-
OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
|
415
|
-
OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
|
416
|
-
OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
|
417
|
-
OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
|
418
|
-
OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
|
419
|
-
OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
|
420
|
-
OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
|
421
|
-
OP (FH, B, C, D, A, 6, 23, 0x04881d05);
|
422
|
-
OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
|
423
|
-
OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
|
424
|
-
OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
|
425
|
-
OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
|
426
|
-
|
427
|
-
/* Round 4. */
|
428
|
-
OP (FI, A, B, C, D, 0, 6, 0xf4292244);
|
429
|
-
OP (FI, D, A, B, C, 7, 10, 0x432aff97);
|
430
|
-
OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
|
431
|
-
OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
|
432
|
-
OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
|
433
|
-
OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
|
434
|
-
OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
|
435
|
-
OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
|
436
|
-
OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
|
437
|
-
OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
|
438
|
-
OP (FI, C, D, A, B, 6, 15, 0xa3014314);
|
439
|
-
OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
|
440
|
-
OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
|
441
|
-
OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
|
442
|
-
OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
|
443
|
-
OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
|
444
|
-
|
445
|
-
/* Add the starting values of the context. */
|
446
|
-
A += A_save;
|
447
|
-
B += B_save;
|
448
|
-
C += C_save;
|
449
|
-
D += D_save;
|
450
|
-
}
|
451
|
-
|
452
|
-
/* Put checksum in context given as argument. */
|
453
|
-
ctx->A = A;
|
454
|
-
ctx->B = B;
|
455
|
-
ctx->C = C;
|
456
|
-
ctx->D = D;
|
457
|
-
}
|
data/ext/libmspack/test/md5.h
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
/* md5.h - Declaration of functions and data types used for MD5 sum
|
2
|
-
computing library functions.
|
3
|
-
Copyright (C) 1995, 1996, 1999 Free Software Foundation, Inc.
|
4
|
-
NOTE: The canonical source of this file is maintained with the GNU C
|
5
|
-
Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
6
|
-
|
7
|
-
This program is free software; you can redistribute it and/or modify it
|
8
|
-
under the terms of the GNU General Public License as published by the
|
9
|
-
Free Software Foundation; either version 2, or (at your option) any
|
10
|
-
later version.
|
11
|
-
|
12
|
-
This program is distributed in the hope that it will be useful,
|
13
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
GNU General Public License for more details.
|
16
|
-
|
17
|
-
You should have received a copy of the GNU General Public License
|
18
|
-
along with this program; if not, write to the Free Software Foundation,
|
19
|
-
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
20
|
-
|
21
|
-
#ifndef _MD5_H
|
22
|
-
#define _MD5_H 1
|
23
|
-
|
24
|
-
#include <stdio.h>
|
25
|
-
|
26
|
-
#if defined HAVE_LIMITS_H || _LIBC
|
27
|
-
# include <limits.h>
|
28
|
-
#endif
|
29
|
-
|
30
|
-
/* The following contortions are an attempt to use the C preprocessor
|
31
|
-
to determine an unsigned integral type that is 32 bits wide. An
|
32
|
-
alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
|
33
|
-
doing that would require that the configure script compile and *run*
|
34
|
-
the resulting executable. Locally running cross-compiled executables
|
35
|
-
is usually not possible. */
|
36
|
-
|
37
|
-
#ifdef _LIBC
|
38
|
-
# include <stdint.h>
|
39
|
-
typedef uint32_t md5_uint32;
|
40
|
-
typedef uintptr_t md5_uintptr;
|
41
|
-
#else
|
42
|
-
# if defined __STDC__ && __STDC__
|
43
|
-
# define UINT_MAX_32_BITS 4294967295U
|
44
|
-
# else
|
45
|
-
# define UINT_MAX_32_BITS 0xFFFFFFFF
|
46
|
-
# endif
|
47
|
-
|
48
|
-
/* If UINT_MAX isn't defined, assume it's a 32-bit type.
|
49
|
-
This should be valid for all systems GNU cares about because
|
50
|
-
that doesn't include 16-bit systems, and only modern systems
|
51
|
-
(that certainly have <limits.h>) have 64+-bit integral types. */
|
52
|
-
|
53
|
-
# ifndef UINT_MAX
|
54
|
-
# define UINT_MAX UINT_MAX_32_BITS
|
55
|
-
# endif
|
56
|
-
|
57
|
-
# if UINT_MAX == UINT_MAX_32_BITS
|
58
|
-
typedef unsigned int md5_uint32;
|
59
|
-
# else
|
60
|
-
# if USHRT_MAX == UINT_MAX_32_BITS
|
61
|
-
typedef unsigned short md5_uint32;
|
62
|
-
# else
|
63
|
-
# if ULONG_MAX == UINT_MAX_32_BITS
|
64
|
-
typedef unsigned long md5_uint32;
|
65
|
-
# else
|
66
|
-
/* The following line is intended to evoke an error.
|
67
|
-
Using #error is not portable enough. */
|
68
|
-
"Cannot determine unsigned 32-bit data type."
|
69
|
-
# endif
|
70
|
-
# endif
|
71
|
-
# endif
|
72
|
-
/* We have to make a guess about the integer type equivalent in size
|
73
|
-
to pointers which should always be correct. */
|
74
|
-
typedef unsigned long int md5_uintptr;
|
75
|
-
#endif
|
76
|
-
|
77
|
-
#undef __P
|
78
|
-
#if defined (__STDC__) && __STDC__
|
79
|
-
#define __P(x) x
|
80
|
-
#else
|
81
|
-
#define __P(x) ()
|
82
|
-
#endif
|
83
|
-
|
84
|
-
/* Structure to save state of computation between the single steps. */
|
85
|
-
struct md5_ctx
|
86
|
-
{
|
87
|
-
md5_uint32 A;
|
88
|
-
md5_uint32 B;
|
89
|
-
md5_uint32 C;
|
90
|
-
md5_uint32 D;
|
91
|
-
|
92
|
-
md5_uint32 total[2];
|
93
|
-
md5_uint32 buflen;
|
94
|
-
char buffer[128];
|
95
|
-
};
|
96
|
-
|
97
|
-
/*
|
98
|
-
* The following three functions are build up the low level used in
|
99
|
-
* the functions `md5_stream' and `md5_buffer'.
|
100
|
-
*/
|
101
|
-
|
102
|
-
/* Initialize structure containing state of computation.
|
103
|
-
(RFC 1321, 3.3: Step 3) */
|
104
|
-
extern void md5_init_ctx __P ((struct md5_ctx *ctx));
|
105
|
-
|
106
|
-
/* Starting with the result of former calls of this function (or the
|
107
|
-
initialization function update the context for the next LEN bytes
|
108
|
-
starting at BUFFER.
|
109
|
-
It is necessary that LEN is a multiple of 64!!! */
|
110
|
-
extern void md5_process_block __P ((const void *buffer, size_t len,
|
111
|
-
struct md5_ctx *ctx));
|
112
|
-
|
113
|
-
/* Starting with the result of former calls of this function (or the
|
114
|
-
initialization function update the context for the next LEN bytes
|
115
|
-
starting at BUFFER.
|
116
|
-
It is NOT required that LEN is a multiple of 64. */
|
117
|
-
extern void md5_process_bytes __P ((const void *buffer, size_t len,
|
118
|
-
struct md5_ctx *ctx));
|
119
|
-
|
120
|
-
/* Process the remaining bytes in the buffer and put result from CTX
|
121
|
-
in first 16 bytes following RESBUF. The result is always in little
|
122
|
-
endian byte order, so that a byte-wise output yields to the wanted
|
123
|
-
ASCII representation of the message digest.
|
124
|
-
|
125
|
-
IMPORTANT: On some systems it is required that RESBUF be correctly
|
126
|
-
aligned for a 32 bits value. */
|
127
|
-
extern void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
|
128
|
-
|
129
|
-
|
130
|
-
/* Put result from CTX in first 16 bytes following RESBUF. The result is
|
131
|
-
always in little endian byte order, so that a byte-wise output yields
|
132
|
-
to the wanted ASCII representation of the message digest.
|
133
|
-
|
134
|
-
IMPORTANT: On some systems it is required that RESBUF is correctly
|
135
|
-
aligned for a 32 bits value. */
|
136
|
-
extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
|
137
|
-
|
138
|
-
|
139
|
-
/* Compute MD5 message digest for bytes read from STREAM. The
|
140
|
-
resulting message digest number will be written into the 16 bytes
|
141
|
-
beginning at RESBLOCK. */
|
142
|
-
extern int md5_stream __P ((FILE *stream, void *resblock));
|
143
|
-
|
144
|
-
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
|
145
|
-
result is always in little endian byte order, so that a byte-wise
|
146
|
-
output yields to the wanted ASCII representation of the message
|
147
|
-
digest. */
|
148
|
-
extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
|
149
|
-
|
150
|
-
/* The following is from gnupg-1.0.2's cipher/bithelp.h. */
|
151
|
-
/* Rotate a 32 bit integer by n bytes */
|
152
|
-
#if defined __GNUC__ && defined __i386__
|
153
|
-
static inline md5_uint32
|
154
|
-
rol(md5_uint32 x, int n)
|
155
|
-
{
|
156
|
-
__asm__("roll %%cl,%0"
|
157
|
-
:"=r" (x)
|
158
|
-
:"0" (x),"c" (n));
|
159
|
-
return x;
|
160
|
-
}
|
161
|
-
#else
|
162
|
-
# define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
|
163
|
-
#endif
|
164
|
-
|
165
|
-
#endif
|