[package] update btpd to 0.15 (#5404)
[openwrt/svn-archive/archive.git] / net / btpd / patches / 000-sha1.diff
1 diff -urN btpd-0.15/btpd/content.c btpd-0.15-new/btpd/content.c
2 --- btpd-0.15/btpd/content.c 2009-02-03 10:15:01.000000000 -0500
3 +++ btpd-0.15-new/btpd/content.c 2009-06-19 15:02:48.000000000 -0400
4 @@ -1,6 +1,6 @@
5 #include "btpd.h"
6
7 -#include <openssl/sha.h>
8 +#include "sha1.h"
9 #include <stream.h>
10
11 struct content {
12 diff -urN btpd-0.15/btpd/download_subr.c btpd-0.15-new/btpd/download_subr.c
13 --- btpd-0.15/btpd/download_subr.c 2009-02-07 16:45:36.000000000 -0500
14 +++ btpd-0.15-new/btpd/download_subr.c 2009-06-19 15:03:06.000000000 -0400
15 @@ -21,7 +21,6 @@
16
17 #include "btpd.h"
18
19 -#include <openssl/sha.h>
20 #include <stream.h>
21
22 static void
23 diff -urN btpd-0.15/btpd/torrent.c btpd-0.15-new/btpd/torrent.c
24 --- btpd-0.15/btpd/torrent.c 2009-01-26 16:15:10.000000000 -0500
25 +++ btpd-0.15-new/btpd/torrent.c 2009-06-19 15:03:24.000000000 -0400
26 @@ -1,7 +1,5 @@
27 #include "btpd.h"
28
29 -#include <openssl/sha.h>
30 -
31 #define SAVE_INTERVAL 300
32
33 static unsigned m_nghosts;
34 diff -urN btpd-0.15/configure.ac btpd-0.15-new/configure.ac
35 --- btpd-0.15/configure.ac 2009-02-09 16:04:53.000000000 -0500
36 +++ btpd-0.15-new/configure.ac 2009-06-19 15:04:12.000000000 -0400
37 @@ -29,13 +29,6 @@
38 rm -f conftest.c conftest.$OBJEXT
39 [$3]))
40
41 -AC_ARG_WITH(openssl,
42 -[ --with-openssl=dir use openssl installed in dir],
43 -[
44 - AC_SUBST(openssl_LDFLAGS,["-L${withval}/lib -Wl,-R,${withval}/lib"])
45 - AC_SUBST(openssl_CPPFLAGS,"-I${withval}/include")
46 -])
47 -
48 AC_ARG_WITH(evloop-method,
49 [ --with-evloop-method select evloop method (epoll,poll,kqueue)],
50 evloop_methods=$withval,
51 @@ -76,11 +69,6 @@
52 ,
53 AC_MSG_RESULT(no))
54
55 -old_LDFLAGS="$LDFLAGS"
56 -LDFLAGS="$LDFLAGS $openssl_LDFLAGS"
57 -AC_CHECK_LIB(crypto, SHA1_Final,:,AC_MSG_FAILURE(btpd needs openssl's libraries and headers))
58 -LDFLAGS=$old_LDFLAGS
59 -
60 for m in $evloop_methods; do
61 case $m in
62 epoll)
63 diff -urN btpd-0.15/Makefile.in btpd-0.15-new/Makefile.in
64 --- btpd-0.15/Makefile.in 2009-02-09 16:08:59.000000000 -0500
65 +++ btpd-0.15-new/Makefile.in 2009-06-19 15:21:05.000000000 -0400
66 @@ -58,7 +58,8 @@
67 am_misc_libmisc_a_OBJECTS = misc/benc.$(OBJEXT) misc/btpd_if.$(OBJEXT) \
68 misc/metainfo.$(OBJEXT) misc/hashtable.$(OBJEXT) \
69 misc/http_client.$(OBJEXT) misc/iobuf.$(OBJEXT) \
70 - misc/stream.$(OBJEXT) misc/subr.$(OBJEXT)
71 + misc/stream.$(OBJEXT) misc/subr.$(OBJEXT) \
72 + misc/sha1.$(OBJEXT)
73 misc_libmisc_a_OBJECTS = $(am_misc_libmisc_a_OBJECTS)
74 am__installdirs = "$(DESTDIR)$(bindir)"
75 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
76 @@ -213,8 +214,8 @@
77 top_builddir = @top_builddir@
78 top_srcdir = @top_srcdir@
79 AM_CFLAGS = -std=c99 -Wall @WARNNPS@
80 -AM_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D@EVLOOP_METHOD@ -I$(top_srcdir)/misc -I$(top_srcdir)/evloop @openssl_CPPFLAGS@
81 -AM_LDFLAGS = @openssl_LDFLAGS@
82 +AM_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D@EVLOOP_METHOD@ -I$(top_srcdir)/misc -I$(top_srcdir)/evloop
83 +AM_LDFLAGS =
84 noinst_LIBRARIES = misc/libmisc.a evloop/libevloop.a
85 EXTRA_DIST = COPYRIGHT CHANGES
86
87 @@ -256,7 +257,8 @@
88 misc/iobuf.c misc/iobuf.h\
89 misc/queue.h\
90 misc/stream.c misc/stream.h\
91 - misc/subr.c misc/subr.h
92 + misc/subr.c misc/subr.h\
93 + misc/sha1.c misc/sha1.h
94
95
96 # evloop
97 @@ -349,6 +351,8 @@
98 misc/$(DEPDIR)/$(am__dirstamp)
99 misc/subr.$(OBJEXT): misc/$(am__dirstamp) \
100 misc/$(DEPDIR)/$(am__dirstamp)
101 +misc/sha1.$(OBJEXT): misc/$(am__dirstamp) \
102 + misc/$(DIPDIR)/$(am__dirstamp)
103 misc/libmisc.a: $(misc_libmisc_a_OBJECTS) $(misc_libmisc_a_DEPENDENCIES) misc/$(am__dirstamp)
104 -rm -f misc/libmisc.a
105 $(misc_libmisc_a_AR) misc/libmisc.a $(misc_libmisc_a_OBJECTS) $(misc_libmisc_a_LIBADD)
106 @@ -492,6 +496,7 @@
107 -rm -f misc/metainfo.$(OBJEXT)
108 -rm -f misc/stream.$(OBJEXT)
109 -rm -f misc/subr.$(OBJEXT)
110 + -rm -f misc/sha1.$(OBJEXT)
111
112 distclean-compile:
113 -rm -f *.tab.c
114 @@ -538,6 +543,7 @@
115 @AMDEP_TRUE@@am__include@ @am__quote@misc/$(DEPDIR)/metainfo.Po@am__quote@
116 @AMDEP_TRUE@@am__include@ @am__quote@misc/$(DEPDIR)/stream.Po@am__quote@
117 @AMDEP_TRUE@@am__include@ @am__quote@misc/$(DEPDIR)/subr.Po@am__quote@
118 +@AMDEP_TRUE@@am__include@ @am__quote@misc/$(DEPDIR)/sha1.Po@am__quote@
119
120 .c.o:
121 @am__fastdepCC_TRUE@ depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
122 diff -urN btpd-0.15/misc/metainfo.c btpd-0.15-new/misc/metainfo.c
123 --- btpd-0.15/misc/metainfo.c 2009-01-12 17:43:18.000000000 -0500
124 +++ btpd-0.15-new/misc/metainfo.c 2009-06-19 15:02:20.000000000 -0400
125 @@ -6,8 +6,7 @@
126 #include <string.h>
127 #include <strings.h>
128
129 -#include <openssl/sha.h>
130 -
131 +#include "sha1.h"
132 #include "benc.h"
133 #include "metainfo.h"
134 #include "subr.h"
135 @@ -159,7 +158,7 @@
136 if (hash == NULL)
137 if ((hash = malloc(20)) == NULL)
138 return NULL;
139 - return SHA1(info, benc_length(info), hash);
140 + return (uint8_t *)sha1_buffer(info, benc_length(info), hash);
141 }
142
143 char *
144 diff -urN btpd-0.15/misc/sha1.c btpd-0.15-new/misc/sha1.c
145 --- btpd-0.15/misc/sha1.c 1969-12-31 19:00:00.000000000 -0500
146 +++ btpd-0.15-new/misc/sha1.c 2009-06-19 15:02:20.000000000 -0400
147 @@ -0,0 +1,423 @@
148 +/* sha1.c - Functions to compute SHA1 message digest of files or
149 + memory blocks according to the NIST specification FIPS-180-1.
150 +
151 + Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
152 +
153 + This program is free software; you can redistribute it and/or modify it
154 + under the terms of the GNU General Public License as published by the
155 + Free Software Foundation; either version 2, or (at your option) any
156 + later version.
157 +
158 + This program is distributed in the hope that it will be useful,
159 + but WITHOUT ANY WARRANTY; without even the implied warranty of
160 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161 + GNU General Public License for more details.
162 +
163 + You should have received a copy of the GNU General Public License
164 + along with this program; if not, write to the Free Software Foundation,
165 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
166 +
167 +/* Written by Scott G. Miller
168 + Credits:
169 + Robert Klep <robert@ilse.nl> -- Expansion function fix
170 +*/
171 +
172 +#ifdef HAVE_CONFIG_H
173 +# include <config.h>
174 +#endif
175 +
176 +#include "sha1.h"
177 +
178 +#include <stddef.h>
179 +#include <string.h>
180 +
181 +#if USE_UNLOCKED_IO
182 +# include "unlocked-io.h"
183 +#endif
184 +
185 +/* SWAP does an endian swap on architectures that are little-endian,
186 + as SHA1 needs some data in a big-endian form. */
187 +
188 +#ifdef WORDS_BIGENDIAN
189 +# define SWAP(n) (n)
190 +#else
191 +# define SWAP(n) \
192 + (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
193 +#endif
194 +
195 +#define BLOCKSIZE 4096
196 +#if BLOCKSIZE % 64 != 0
197 +# error "invalid BLOCKSIZE"
198 +#endif
199 +
200 +/* This array contains the bytes used to pad the buffer to the next
201 + 64-byte boundary. (RFC 1321, 3.1: Step 1) */
202 +static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
203 +
204 +
205 +/*
206 + Takes a pointer to a 160 bit block of data (five 32 bit ints) and
207 + intializes it to the start constants of the SHA1 algorithm. This
208 + must be called before using hash in the call to sha1_hash.
209 +*/
210 +void
211 +sha1_init_ctx (struct sha1_ctx *ctx)
212 +{
213 + ctx->A = 0x67452301;
214 + ctx->B = 0xefcdab89;
215 + ctx->C = 0x98badcfe;
216 + ctx->D = 0x10325476;
217 + ctx->E = 0xc3d2e1f0;
218 +
219 + ctx->total[0] = ctx->total[1] = 0;
220 + ctx->buflen = 0;
221 +}
222 +
223 +/* Put result from CTX in first 20 bytes following RESBUF. The result
224 + must be in little endian byte order.
225 +
226 + IMPORTANT: On some systems it is required that RESBUF is correctly
227 + aligned for a 32 bits value. */
228 +void *
229 +sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
230 +{
231 + ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
232 + ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
233 + ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
234 + ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
235 + ((uint32_t *) resbuf)[4] = SWAP (ctx->E);
236 +
237 + return resbuf;
238 +}
239 +
240 +/* Process the remaining bytes in the internal buffer and the usual
241 + prolog according to the standard and write the result to RESBUF.
242 +
243 + IMPORTANT: On some systems it is required that RESBUF is correctly
244 + aligned for a 32 bits value. */
245 +void *
246 +sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
247 +{
248 + /* Take yet unprocessed bytes into account. */
249 + uint32_t bytes = ctx->buflen;
250 + size_t pad;
251 +
252 + /* Now count remaining bytes. */
253 + ctx->total[0] += bytes;
254 + if (ctx->total[0] < bytes)
255 + ++ctx->total[1];
256 +
257 + pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
258 + memcpy (&ctx->buffer[bytes], fillbuf, pad);
259 +
260 + /* Put the 64-bit file length in *bits* at the end of the buffer. */
261 + *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
262 + *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
263 + (ctx->total[0] >> 29));
264 +
265 + /* Process last bytes. */
266 + sha1_process_block (ctx->buffer, bytes + pad + 8, ctx);
267 +
268 + return sha1_read_ctx (ctx, resbuf);
269 +}
270 +
271 +/* Compute SHA1 message digest for bytes read from STREAM. The
272 + resulting message digest number will be written into the 16 bytes
273 + beginning at RESBLOCK. */
274 +int
275 +sha1_stream (FILE *stream, void *resblock)
276 +{
277 + struct sha1_ctx ctx;
278 + char buffer[BLOCKSIZE + 72];
279 + size_t sum;
280 +
281 + /* Initialize the computation context. */
282 + sha1_init_ctx (&ctx);
283 +
284 + /* Iterate over full file contents. */
285 + while (1)
286 + {
287 + /* We read the file in blocks of BLOCKSIZE bytes. One call of the
288 + computation function processes the whole buffer so that with the
289 + next round of the loop another block can be read. */
290 + size_t n;
291 + sum = 0;
292 +
293 + /* Read block. Take care for partial reads. */
294 + while (1)
295 + {
296 + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
297 +
298 + sum += n;
299 +
300 + if (sum == BLOCKSIZE)
301 + break;
302 +
303 + if (n == 0)
304 + {
305 + /* Check for the error flag IFF N == 0, so that we don't
306 + exit the loop after a partial read due to e.g., EAGAIN
307 + or EWOULDBLOCK. */
308 + if (ferror (stream))
309 + return 1;
310 + goto process_partial_block;
311 + }
312 +
313 + /* We've read at least one byte, so ignore errors. But always
314 + check for EOF, since feof may be true even though N > 0.
315 + Otherwise, we could end up calling fread after EOF. */
316 + if (feof (stream))
317 + goto process_partial_block;
318 + }
319 +
320 + /* Process buffer with BLOCKSIZE bytes. Note that
321 + BLOCKSIZE % 64 == 0
322 + */
323 + sha1_process_block (buffer, BLOCKSIZE, &ctx);
324 + }
325 +
326 + process_partial_block:;
327 +
328 + /* Process any remaining bytes. */
329 + if (sum > 0)
330 + sha1_process_bytes (buffer, sum, &ctx);
331 +
332 + /* Construct result in desired memory. */
333 + sha1_finish_ctx (&ctx, resblock);
334 + return 0;
335 +}
336 +
337 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
338 + result is always in little endian byte order, so that a byte-wise
339 + output yields to the wanted ASCII representation of the message
340 + digest. */
341 +void *
342 +sha1_buffer (const char *buffer, size_t len, void *resblock)
343 +{
344 + struct sha1_ctx ctx;
345 +
346 + /* Initialize the computation context. */
347 + sha1_init_ctx (&ctx);
348 +
349 + /* Process whole buffer but last len % 64 bytes. */
350 + sha1_process_bytes (buffer, len, &ctx);
351 +
352 + /* Put result in desired memory area. */
353 + return sha1_finish_ctx (&ctx, resblock);
354 +}
355 +
356 +void
357 +sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
358 +{
359 + /* When we already have some bits in our internal buffer concatenate
360 + both inputs first. */
361 + if (ctx->buflen != 0)
362 + {
363 + size_t left_over = ctx->buflen;
364 + size_t add = 128 - left_over > len ? len : 128 - left_over;
365 +
366 + memcpy (&ctx->buffer[left_over], buffer, add);
367 + ctx->buflen += add;
368 +
369 + if (ctx->buflen > 64)
370 + {
371 + sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
372 +
373 + ctx->buflen &= 63;
374 + /* The regions in the following copy operation cannot overlap. */
375 + memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
376 + ctx->buflen);
377 + }
378 +
379 + buffer = (const char *) buffer + add;
380 + len -= add;
381 + }
382 +
383 + /* Process available complete blocks. */
384 + if (len >= 64)
385 + {
386 +#if !_STRING_ARCH_unaligned
387 +# define alignof(type) offsetof (struct { char c; type x; }, x)
388 +# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
389 + if (UNALIGNED_P (buffer))
390 + while (len > 64)
391 + {
392 + sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
393 + buffer = (const char *) buffer + 64;
394 + len -= 64;
395 + }
396 + else
397 +#endif
398 + {
399 + sha1_process_block (buffer, len & ~63, ctx);
400 + buffer = (const char *) buffer + (len & ~63);
401 + len &= 63;
402 + }
403 + }
404 +
405 + /* Move remaining bytes in internal buffer. */
406 + if (len > 0)
407 + {
408 + size_t left_over = ctx->buflen;
409 +
410 + memcpy (&ctx->buffer[left_over], buffer, len);
411 + left_over += len;
412 + if (left_over >= 64)
413 + {
414 + sha1_process_block (ctx->buffer, 64, ctx);
415 + left_over -= 64;
416 + memcpy (ctx->buffer, &ctx->buffer[64], left_over);
417 + }
418 + ctx->buflen = left_over;
419 + }
420 +}
421 +
422 +/* --- Code below is the primary difference between md5.c and sha1.c --- */
423 +
424 +/* SHA1 round constants */
425 +#define K1 0x5a827999L
426 +#define K2 0x6ed9eba1L
427 +#define K3 0x8f1bbcdcL
428 +#define K4 0xca62c1d6L
429 +
430 +/* Round functions. Note that F2 is the same as F4. */
431 +#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
432 +#define F2(B,C,D) (B ^ C ^ D)
433 +#define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
434 +#define F4(B,C,D) (B ^ C ^ D)
435 +
436 +/* Process LEN bytes of BUFFER, accumulating context into CTX.
437 + It is assumed that LEN % 64 == 0.
438 + Most of this code comes from GnuPG's cipher/sha1.c. */
439 +
440 +void
441 +sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
442 +{
443 + const uint32_t *words = buffer;
444 + size_t nwords = len / sizeof (uint32_t);
445 + const uint32_t *endp = words + nwords;
446 + uint32_t x[16];
447 + uint32_t a = ctx->A;
448 + uint32_t b = ctx->B;
449 + uint32_t c = ctx->C;
450 + uint32_t d = ctx->D;
451 + uint32_t e = ctx->E;
452 +
453 + /* First increment the byte count. RFC 1321 specifies the possible
454 + length of the file up to 2^64 bits. Here we only compute the
455 + number of bytes. Do a double word increment. */
456 + ctx->total[0] += len;
457 + if (ctx->total[0] < len)
458 + ++ctx->total[1];
459 +
460 +#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
461 +
462 +#define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \
463 + ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
464 + , (x[I&0x0f] = rol(tm, 1)) )
465 +
466 +#define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \
467 + + F( B, C, D ) \
468 + + K \
469 + + M; \
470 + B = rol( B, 30 ); \
471 + } while(0)
472 +
473 + while (words < endp)
474 + {
475 + uint32_t tm;
476 + int t;
477 + for (t = 0; t < 16; t++)
478 + {
479 + x[t] = SWAP (*words);
480 + words++;
481 + }
482 +
483 + R( a, b, c, d, e, F1, K1, x[ 0] );
484 + R( e, a, b, c, d, F1, K1, x[ 1] );
485 + R( d, e, a, b, c, F1, K1, x[ 2] );
486 + R( c, d, e, a, b, F1, K1, x[ 3] );
487 + R( b, c, d, e, a, F1, K1, x[ 4] );
488 + R( a, b, c, d, e, F1, K1, x[ 5] );
489 + R( e, a, b, c, d, F1, K1, x[ 6] );
490 + R( d, e, a, b, c, F1, K1, x[ 7] );
491 + R( c, d, e, a, b, F1, K1, x[ 8] );
492 + R( b, c, d, e, a, F1, K1, x[ 9] );
493 + R( a, b, c, d, e, F1, K1, x[10] );
494 + R( e, a, b, c, d, F1, K1, x[11] );
495 + R( d, e, a, b, c, F1, K1, x[12] );
496 + R( c, d, e, a, b, F1, K1, x[13] );
497 + R( b, c, d, e, a, F1, K1, x[14] );
498 + R( a, b, c, d, e, F1, K1, x[15] );
499 + R( e, a, b, c, d, F1, K1, M(16) );
500 + R( d, e, a, b, c, F1, K1, M(17) );
501 + R( c, d, e, a, b, F1, K1, M(18) );
502 + R( b, c, d, e, a, F1, K1, M(19) );
503 + R( a, b, c, d, e, F2, K2, M(20) );
504 + R( e, a, b, c, d, F2, K2, M(21) );
505 + R( d, e, a, b, c, F2, K2, M(22) );
506 + R( c, d, e, a, b, F2, K2, M(23) );
507 + R( b, c, d, e, a, F2, K2, M(24) );
508 + R( a, b, c, d, e, F2, K2, M(25) );
509 + R( e, a, b, c, d, F2, K2, M(26) );
510 + R( d, e, a, b, c, F2, K2, M(27) );
511 + R( c, d, e, a, b, F2, K2, M(28) );
512 + R( b, c, d, e, a, F2, K2, M(29) );
513 + R( a, b, c, d, e, F2, K2, M(30) );
514 + R( e, a, b, c, d, F2, K2, M(31) );
515 + R( d, e, a, b, c, F2, K2, M(32) );
516 + R( c, d, e, a, b, F2, K2, M(33) );
517 + R( b, c, d, e, a, F2, K2, M(34) );
518 + R( a, b, c, d, e, F2, K2, M(35) );
519 + R( e, a, b, c, d, F2, K2, M(36) );
520 + R( d, e, a, b, c, F2, K2, M(37) );
521 + R( c, d, e, a, b, F2, K2, M(38) );
522 + R( b, c, d, e, a, F2, K2, M(39) );
523 + R( a, b, c, d, e, F3, K3, M(40) );
524 + R( e, a, b, c, d, F3, K3, M(41) );
525 + R( d, e, a, b, c, F3, K3, M(42) );
526 + R( c, d, e, a, b, F3, K3, M(43) );
527 + R( b, c, d, e, a, F3, K3, M(44) );
528 + R( a, b, c, d, e, F3, K3, M(45) );
529 + R( e, a, b, c, d, F3, K3, M(46) );
530 + R( d, e, a, b, c, F3, K3, M(47) );
531 + R( c, d, e, a, b, F3, K3, M(48) );
532 + R( b, c, d, e, a, F3, K3, M(49) );
533 + R( a, b, c, d, e, F3, K3, M(50) );
534 + R( e, a, b, c, d, F3, K3, M(51) );
535 + R( d, e, a, b, c, F3, K3, M(52) );
536 + R( c, d, e, a, b, F3, K3, M(53) );
537 + R( b, c, d, e, a, F3, K3, M(54) );
538 + R( a, b, c, d, e, F3, K3, M(55) );
539 + R( e, a, b, c, d, F3, K3, M(56) );
540 + R( d, e, a, b, c, F3, K3, M(57) );
541 + R( c, d, e, a, b, F3, K3, M(58) );
542 + R( b, c, d, e, a, F3, K3, M(59) );
543 + R( a, b, c, d, e, F4, K4, M(60) );
544 + R( e, a, b, c, d, F4, K4, M(61) );
545 + R( d, e, a, b, c, F4, K4, M(62) );
546 + R( c, d, e, a, b, F4, K4, M(63) );
547 + R( b, c, d, e, a, F4, K4, M(64) );
548 + R( a, b, c, d, e, F4, K4, M(65) );
549 + R( e, a, b, c, d, F4, K4, M(66) );
550 + R( d, e, a, b, c, F4, K4, M(67) );
551 + R( c, d, e, a, b, F4, K4, M(68) );
552 + R( b, c, d, e, a, F4, K4, M(69) );
553 + R( a, b, c, d, e, F4, K4, M(70) );
554 + R( e, a, b, c, d, F4, K4, M(71) );
555 + R( d, e, a, b, c, F4, K4, M(72) );
556 + R( c, d, e, a, b, F4, K4, M(73) );
557 + R( b, c, d, e, a, F4, K4, M(74) );
558 + R( a, b, c, d, e, F4, K4, M(75) );
559 + R( e, a, b, c, d, F4, K4, M(76) );
560 + R( d, e, a, b, c, F4, K4, M(77) );
561 + R( c, d, e, a, b, F4, K4, M(78) );
562 + R( b, c, d, e, a, F4, K4, M(79) );
563 +
564 + a = ctx->A += a;
565 + b = ctx->B += b;
566 + c = ctx->C += c;
567 + d = ctx->D += d;
568 + e = ctx->E += e;
569 + }
570 +}
571 diff -urN btpd-0.15/misc/sha1.h btpd-0.15-new/misc/sha1.h
572 --- btpd-0.15/misc/sha1.h 1969-12-31 19:00:00.000000000 -0500
573 +++ btpd-0.15-new/misc/sha1.h 2009-06-19 15:02:20.000000000 -0400
574 @@ -0,0 +1,90 @@
575 +/* Declarations of functions and data types used for SHA1 sum
576 + library functions.
577 + Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
578 +
579 + This program is free software; you can redistribute it and/or modify it
580 + under the terms of the GNU General Public License as published by the
581 + Free Software Foundation; either version 2, or (at your option) any
582 + later version.
583 +
584 + This program is distributed in the hope that it will be useful,
585 + but WITHOUT ANY WARRANTY; without even the implied warranty of
586 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
587 + GNU General Public License for more details.
588 +
589 + You should have received a copy of the GNU General Public License
590 + along with this program; if not, write to the Free Software Foundation,
591 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
592 +
593 +#ifndef SHA1_H
594 +# define SHA1_H 1
595 +
596 +#include <stdio.h>
597 +
598 +#include <inttypes.h>
599 +
600 +#define SHA_DIGEST_LENGTH 20
601 +
602 +/* Structure to save state of computation between the single steps. */
603 +struct sha1_ctx
604 +{
605 + uint32_t A;
606 + uint32_t B;
607 + uint32_t C;
608 + uint32_t D;
609 + uint32_t E;
610 +
611 + uint32_t total[2];
612 + uint32_t buflen;
613 + char buffer[128];
614 +};
615 +
616 +
617 +/* Initialize structure containing state of computation. */
618 +extern void sha1_init_ctx (struct sha1_ctx *ctx);
619 +
620 +/* Starting with the result of former calls of this function (or the
621 + initialization function update the context for the next LEN bytes
622 + starting at BUFFER.
623 + It is necessary that LEN is a multiple of 64!!! */
624 +extern void sha1_process_block (const void *buffer, size_t len,
625 + struct sha1_ctx *ctx);
626 +
627 +/* Starting with the result of former calls of this function (or the
628 + initialization function update the context for the next LEN bytes
629 + starting at BUFFER.
630 + It is NOT required that LEN is a multiple of 64. */
631 +extern void sha1_process_bytes (const void *buffer, size_t len,
632 + struct sha1_ctx *ctx);
633 +
634 +/* Process the remaining bytes in the buffer and put result from CTX
635 + in first 20 bytes following RESBUF. The result is always in little
636 + endian byte order, so that a byte-wise output yields to the wanted
637 + ASCII representation of the message digest.
638 +
639 + IMPORTANT: On some systems it is required that RESBUF be correctly
640 + aligned for a 32 bits value. */
641 +extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
642 +
643 +
644 +/* Put result from CTX in first 20 bytes following RESBUF. The result is
645 + always in little endian byte order, so that a byte-wise output yields
646 + to the wanted ASCII representation of the message digest.
647 +
648 + IMPORTANT: On some systems it is required that RESBUF is correctly
649 + aligned for a 32 bits value. */
650 +extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
651 +
652 +
653 +/* Compute SHA1 message digest for bytes read from STREAM. The
654 + resulting message digest number will be written into the 20 bytes
655 + beginning at RESBLOCK. */
656 +extern int sha1_stream (FILE *stream, void *resblock);
657 +
658 +/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
659 + result is always in little endian byte order, so that a byte-wise
660 + output yields to the wanted ASCII representation of the message
661 + digest. */
662 +extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
663 +
664 +#endif
665 diff -urN btpd-0.15/misc/stream.c btpd-0.15-new/misc/stream.c
666 --- btpd-0.15/misc/stream.c 2008-12-22 17:25:36.000000000 -0500
667 +++ btpd-0.15-new/misc/stream.c 2009-06-19 15:02:20.000000000 -0400
668 @@ -5,7 +5,7 @@
669 #include <stdlib.h>
670 #include <unistd.h>
671
672 -#include <openssl/sha.h>
673 +#include "sha1.h"
674
675 #include "metainfo.h"
676 #include "subr.h"
677 @@ -161,21 +161,21 @@
678 int
679 bts_sha(struct bt_stream *bts, off_t start, off_t length, uint8_t *hash)
680 {
681 - SHA_CTX ctx;
682 + struct sha1_ctx ctx;
683 char buf[SHAFILEBUF];
684 size_t wantread;
685 int err = 0;
686
687 - SHA1_Init(&ctx);
688 + sha1_init_ctx(&ctx);
689 while (length > 0) {
690 wantread = min(length, SHAFILEBUF);
691 if ((err = bts_get(bts, start, buf, wantread)) != 0)
692 break;
693 length -= wantread;
694 start += wantread;
695 - SHA1_Update(&ctx, buf, wantread);
696 + sha1_process_bytes(buf, wantread, &ctx);
697 }
698 - SHA1_Final(hash, &ctx);
699 + sha1_finish_ctx(&ctx, hash);
700 return err;
701 }
702
703 diff -urN btpd-0.15/.pc/.version btpd-0.15-new/.pc/.version
704 --- btpd-0.15/.pc/.version 1969-12-31 19:00:00.000000000 -0500
705 +++ btpd-0.15-new/.pc/.version 2009-06-19 15:00:46.000000000 -0400
706 @@ -0,0 +1 @@
707 +2
708 diff -urN btpd-0.15/Makefile.am btpd-0.15.new/Makefile.am
709 --- btpd-0.15/Makefile.am 2009-02-03 12:09:25.000000000 +0100
710 +++ btpd-0.15.new/Makefile.am 2009-07-02 17:39:47.000000000 +0200
711 @@ -1,6 +1,6 @@
712 AM_CFLAGS=-std=c99 -Wall @WARNNPS@
713 -AM_CPPFLAGS=-D_FILE_OFFSET_BITS=64 -D@EVLOOP_METHOD@ -I$(top_srcdir)/misc -I$(top_srcdir)/evloop @openssl_CPPFLAGS@
714 -AM_LDFLAGS=@openssl_LDFLAGS@
715 +AM_CPPFLAGS=-D_FILE_OFFSET_BITS=64 -D@EVLOOP_METHOD@ -I$(top_srcdir)/misc -I$(top_srcdir)/evloop
716 +AM_LDFLAGS=
717
718 bin_PROGRAMS=btpd/btpd cli/btcli cli/btinfo
719 noinst_LIBRARIES=misc/libmisc.a evloop/libevloop.a
720 @@ -44,7 +44,8 @@
721 misc/iobuf.c misc/iobuf.h\
722 misc/queue.h\
723 misc/stream.c misc/stream.h\
724 - misc/subr.c misc/subr.h
725 + misc/subr.c misc/subr.h\
726 + misc/sha1.c misc/sha1.h
727
728 # evloop
729 EXTRA_evloop_libevloop_a_SOURCES=evloop/epoll.c evloop/kqueue.c evloop/poll.c