1 diff -purN btpd-0.13/btpd/content.c btpd-0.13-hack/btpd/content.c
2 --- btpd-0.13/btpd/content.c 2007-05-18 19:32:01.000000000 +0400
3 +++ btpd-0.13-hack/btpd/content.c 2007-09-04 14:59:06.000000000 +0400
8 -#include <openssl/sha.h>
13 diff -purN btpd-0.13/btpd/download_subr.c btpd-0.13-hack/btpd/download_subr.c
14 --- btpd-0.13/btpd/download_subr.c 2007-05-18 19:32:01.000000000 +0400
15 +++ btpd-0.13-hack/btpd/download_subr.c 2007-09-04 15:13:35.000000000 +0400
20 -#include <openssl/sha.h>
25 diff -purN btpd-0.13/btpd/Makefile.am btpd-0.13-hack/btpd/Makefile.am
26 --- btpd-0.13/btpd/Makefile.am 2007-05-18 19:32:01.000000000 +0400
27 +++ btpd-0.13-hack/btpd/Makefile.am 2007-09-04 15:15:17.000000000 +0400
28 @@ -16,5 +16,5 @@ btpd_SOURCES=\
31 btpd_LDADD=../misc/libmisc.a ../libevent/libevent.a
32 -btpd_CPPFLAGS=-I$(top_srcdir)/misc -I$(top_srcdir)/libevent @openssl_CPPFLAGS@
33 -btpd_LDFLAGS=@openssl_LDFLAGS@ -lcrypto -lm
34 +btpd_CPPFLAGS=-I$(top_srcdir)/misc -I$(top_srcdir)/libevent
36 diff -purN btpd-0.13/btpd/torrent.c btpd-0.13-hack/btpd/torrent.c
37 --- btpd-0.13/btpd/torrent.c 2007-05-19 12:41:32.000000000 +0400
38 +++ btpd-0.13-hack/btpd/torrent.c 2007-09-04 15:14:06.000000000 +0400
43 -#include <openssl/sha.h>
46 #include "tracker_req.h"
48 diff -purN btpd-0.13/cli/Makefile.am btpd-0.13-hack/cli/Makefile.am
49 --- btpd-0.13/cli/Makefile.am 2007-05-18 19:32:00.000000000 +0400
50 +++ btpd-0.13-hack/cli/Makefile.am 2007-09-04 15:14:46.000000000 +0400
52 bin_PROGRAMS=btinfo btcli
54 btinfo_SOURCES=btinfo.c
55 -btinfo_LDADD=../misc/libmisc.a -lcrypto -lm
56 -btinfo_CPPFLAGS=-I$(top_srcdir)/misc @openssl_CPPFLAGS@
57 -btinfo_LDFLAGS=@openssl_LDFLAGS@
58 +btinfo_LDADD=../misc/libmisc.a -lm
59 +btinfo_CPPFLAGS=-I$(top_srcdir)/misc
62 btcli_SOURCES=btcli.c btcli.h add.c del.c list.c kill.c start.c stop.c stat.c
63 -btcli_LDADD=../misc/libmisc.a -lcrypto -lm
64 -btcli_CPPFLAGS=-I$(top_srcdir)/misc @openssl_CPPFLAGS@
65 -btcli_LDFLAGS=@openssl_LDFLAGS@
66 +btcli_LDADD=../misc/libmisc.a -lm
67 +btcli_CPPFLAGS=-I$(top_srcdir)/misc
69 diff -urN btpd-0.13.orig/configure btpd-0.13/configure
70 --- btpd-0.13.orig/configure 2007-05-19 13:55:14.000000000 -0700
71 +++ btpd-0.13/configure 2008-06-14 23:04:33.000000000 -0700
72 @@ -2939,80 +2939,6 @@
75 old_LDFLAGS="$LDFLAGS"
76 -LDFLAGS="$LDFLAGS $openssl_LDFLAGS"
78 -echo "$as_me:$LINENO: checking for SHA1_Final in -lcrypto" >&5
79 -echo $ECHO_N "checking for SHA1_Final in -lcrypto... $ECHO_C" >&6
80 -if test "${ac_cv_lib_crypto_SHA1_Final+set}" = set; then
81 - echo $ECHO_N "(cached) $ECHO_C" >&6
83 - ac_check_lib_save_LIBS=$LIBS
84 -LIBS="-lcrypto $LIBS"
85 -cat >conftest.$ac_ext <<_ACEOF
88 -cat confdefs.h >>conftest.$ac_ext
89 -cat >>conftest.$ac_ext <<_ACEOF
90 -/* end confdefs.h. */
92 -/* Override any gcc2 internal prototype to avoid an error. */
96 -/* We use char because int might match the return type of a gcc2
97 - builtin and then its argument prototype would still apply. */
107 -rm -f conftest.$ac_objext conftest$ac_exeext
108 -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
109 - (eval $ac_link) 2>conftest.er1
111 - grep -v '^ *+' conftest.er1 >conftest.err
113 - cat conftest.err >&5
114 - echo "$as_me:$LINENO: \$? = $ac_status" >&5
115 - (exit $ac_status); } &&
116 - { ac_try='test -z "$ac_c_werror_flag"
117 - || test ! -s conftest.err'
118 - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
119 - (eval $ac_try) 2>&5
121 - echo "$as_me:$LINENO: \$? = $ac_status" >&5
122 - (exit $ac_status); }; } &&
123 - { ac_try='test -s conftest$ac_exeext'
124 - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
125 - (eval $ac_try) 2>&5
127 - echo "$as_me:$LINENO: \$? = $ac_status" >&5
128 - (exit $ac_status); }; }; then
129 - ac_cv_lib_crypto_SHA1_Final=yes
131 - echo "$as_me: failed program was:" >&5
132 -sed 's/^/| /' conftest.$ac_ext >&5
134 -ac_cv_lib_crypto_SHA1_Final=no
136 -rm -f conftest.err conftest.$ac_objext \
137 - conftest$ac_exeext conftest.$ac_ext
138 -LIBS=$ac_check_lib_save_LIBS
140 -echo "$as_me:$LINENO: result: $ac_cv_lib_crypto_SHA1_Final" >&5
141 -echo "${ECHO_T}$ac_cv_lib_crypto_SHA1_Final" >&6
142 -if test $ac_cv_lib_crypto_SHA1_Final = yes; then
145 - echo Must have openssl; exit 1
148 -LDFLAGS=$old_LDFLAGS
152 subdirs="$subdirs libevent"
153 diff -purN btpd-0.13/configure.ac btpd-0.13-hack/configure.ac
154 --- btpd-0.13/configure.ac 2007-05-18 19:31:59.000000000 +0400
155 +++ btpd-0.13-hack/configure.ac 2007-09-04 15:09:17.000000000 +0400
156 @@ -10,14 +10,6 @@ AC_PROG_RANLIB
157 CFLAGS="$CFLAGS -std=c99"
158 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64"
160 -AC_ARG_WITH(openssl,
161 -[ --with-openssl=dir use openssl installed in dir],
163 - AC_SUBST(openssl_LDFLAGS,["-L${withval}/lib -Wl,-rpath=${withval}/lib"])
164 - AC_SUBST(openssl_CPPFLAGS,"-I${withval}/include")
169 [ --with-warn=level select warning preset (no,all,allerr)],
171 @@ -38,11 +30,6 @@ AC_ARG_WITH(warn,
175 -old_LDFLAGS="$LDFLAGS"
176 -LDFLAGS="$LDFLAGS $openssl_LDFLAGS"
177 -AC_CHECK_LIB(crypto, SHA1_Final, :, echo Must have openssl; exit 1)
178 -LDFLAGS=$old_LDFLAGS
180 AC_CONFIG_SUBDIRS([libevent])
183 diff -purN btpd-0.13/libevent/evdns.c btpd-0.13-hack/libevent/evdns.c
184 --- btpd-0.13/libevent/evdns.c 2007-05-18 19:32:01.000000000 +0400
185 +++ btpd-0.13-hack/libevent/evdns.c 2007-09-04 15:12:38.000000000 +0400
188 #ifndef DNS_USE_CPU_CLOCK_FOR_ID
189 #ifndef DNS_USE_GETTIMEOFDAY_FOR_ID
190 -#ifndef DNS_USE_OPENSSL_FOR_ID
191 #error Must configure at least one id generation method.
192 #error Please see the documentation.
197 // #define _POSIX_C_SOURCE 200507
200 #ifdef DNS_USE_CPU_CLOCK_FOR_ID
201 -#ifdef DNS_USE_OPENSSL_FOR_ID
202 -#error Multiple id options selected
204 #ifdef DNS_USE_GETTIMEOFDAY_FOR_ID
205 #error Multiple id options selected
210 -#ifdef DNS_USE_OPENSSL_FOR_ID
211 -#ifdef DNS_USE_GETTIMEOFDAY_FOR_ID
212 -#error Multiple id options selected
214 -#include <openssl/rand.h>
217 #define _FORTIFY_SOURCE 3
220 @@ -1026,18 +1014,6 @@ transaction_id_pick(void) {
221 trans_id = tv.tv_usec & 0xffff;
224 -#ifdef DNS_USE_OPENSSL_FOR_ID
226 - if (RAND_pseudo_bytes((u8 *) &trans_id, 2) == -1) {
227 - /* // in the case that the RAND call fails we back
228 - // down to using gettimeofday.
230 - gettimeofday(&tv, NULL);
231 - trans_id = tv.tv_usec & 0xffff; */
236 if (trans_id == 0xffff) continue;
237 // now check to see if that id is already inflight
238 req = started_at = req_head;
239 diff -purN btpd-0.13/misc/Makefile.am btpd-0.13-hack/misc/Makefile.am
240 --- btpd-0.13/misc/Makefile.am 2007-05-18 19:32:01.000000000 +0400
241 +++ btpd-0.13-hack/misc/Makefile.am 2007-09-04 14:57:39.000000000 +0400
242 @@ -8,5 +8,6 @@ libmisc_a_SOURCES=\
247 -libmisc_a_CPPFLAGS=-I$(top_srcdir)/libevent @openssl_CPPFLAGS@
250 +libmisc_a_CPPFLAGS=-I$(top_srcdir)/libevent
251 diff -purN btpd-0.13/misc/metainfo.c btpd-0.13-hack/misc/metainfo.c
252 --- btpd-0.13/misc/metainfo.c 2007-05-18 19:32:01.000000000 +0400
253 +++ btpd-0.13-hack/misc/metainfo.c 2007-09-04 14:58:20.000000000 +0400
258 -#include <openssl/sha.h>
262 #include "metainfo.h"
264 @@ -158,7 +157,7 @@ mi_info_hash(const char *p, uint8_t *has
266 if ((hash = malloc(20)) == NULL)
268 - return SHA1(info, benc_length(info), hash);
269 + return (uint8_t *)sha1_buffer(info, benc_length(info), hash);
273 diff -purN btpd-0.13/misc/sha1.c btpd-0.13-hack/misc/sha1.c
274 --- btpd-0.13/misc/sha1.c 1970-01-01 03:00:00.000000000 +0300
275 +++ btpd-0.13-hack/misc/sha1.c 2007-09-04 14:45:36.000000000 +0400
277 +/* sha1.c - Functions to compute SHA1 message digest of files or
278 + memory blocks according to the NIST specification FIPS-180-1.
280 + Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
282 + This program is free software; you can redistribute it and/or modify it
283 + under the terms of the GNU General Public License as published by the
284 + Free Software Foundation; either version 2, or (at your option) any
287 + This program is distributed in the hope that it will be useful,
288 + but WITHOUT ANY WARRANTY; without even the implied warranty of
289 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
290 + GNU General Public License for more details.
292 + You should have received a copy of the GNU General Public License
293 + along with this program; if not, write to the Free Software Foundation,
294 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
296 +/* Written by Scott G. Miller
298 + Robert Klep <robert@ilse.nl> -- Expansion function fix
301 +#ifdef HAVE_CONFIG_H
302 +# include <config.h>
311 +# include "unlocked-io.h"
314 +/* SWAP does an endian swap on architectures that are little-endian,
315 + as SHA1 needs some data in a big-endian form. */
317 +#ifdef WORDS_BIGENDIAN
318 +# define SWAP(n) (n)
321 + (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
324 +#define BLOCKSIZE 4096
325 +#if BLOCKSIZE % 64 != 0
326 +# error "invalid BLOCKSIZE"
329 +/* This array contains the bytes used to pad the buffer to the next
330 + 64-byte boundary. (RFC 1321, 3.1: Step 1) */
331 +static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
335 + Takes a pointer to a 160 bit block of data (five 32 bit ints) and
336 + intializes it to the start constants of the SHA1 algorithm. This
337 + must be called before using hash in the call to sha1_hash.
340 +sha1_init_ctx (struct sha1_ctx *ctx)
342 + ctx->A = 0x67452301;
343 + ctx->B = 0xefcdab89;
344 + ctx->C = 0x98badcfe;
345 + ctx->D = 0x10325476;
346 + ctx->E = 0xc3d2e1f0;
348 + ctx->total[0] = ctx->total[1] = 0;
352 +/* Put result from CTX in first 20 bytes following RESBUF. The result
353 + must be in little endian byte order.
355 + IMPORTANT: On some systems it is required that RESBUF is correctly
356 + aligned for a 32 bits value. */
358 +sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
360 + ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
361 + ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
362 + ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
363 + ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
364 + ((uint32_t *) resbuf)[4] = SWAP (ctx->E);
369 +/* Process the remaining bytes in the internal buffer and the usual
370 + prolog according to the standard and write the result to RESBUF.
372 + IMPORTANT: On some systems it is required that RESBUF is correctly
373 + aligned for a 32 bits value. */
375 +sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
377 + /* Take yet unprocessed bytes into account. */
378 + uint32_t bytes = ctx->buflen;
381 + /* Now count remaining bytes. */
382 + ctx->total[0] += bytes;
383 + if (ctx->total[0] < bytes)
386 + pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
387 + memcpy (&ctx->buffer[bytes], fillbuf, pad);
389 + /* Put the 64-bit file length in *bits* at the end of the buffer. */
390 + *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
391 + *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
392 + (ctx->total[0] >> 29));
394 + /* Process last bytes. */
395 + sha1_process_block (ctx->buffer, bytes + pad + 8, ctx);
397 + return sha1_read_ctx (ctx, resbuf);
400 +/* Compute SHA1 message digest for bytes read from STREAM. The
401 + resulting message digest number will be written into the 16 bytes
402 + beginning at RESBLOCK. */
404 +sha1_stream (FILE *stream, void *resblock)
406 + struct sha1_ctx ctx;
407 + char buffer[BLOCKSIZE + 72];
410 + /* Initialize the computation context. */
411 + sha1_init_ctx (&ctx);
413 + /* Iterate over full file contents. */
416 + /* We read the file in blocks of BLOCKSIZE bytes. One call of the
417 + computation function processes the whole buffer so that with the
418 + next round of the loop another block can be read. */
422 + /* Read block. Take care for partial reads. */
425 + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
429 + if (sum == BLOCKSIZE)
434 + /* Check for the error flag IFF N == 0, so that we don't
435 + exit the loop after a partial read due to e.g., EAGAIN
437 + if (ferror (stream))
439 + goto process_partial_block;
442 + /* We've read at least one byte, so ignore errors. But always
443 + check for EOF, since feof may be true even though N > 0.
444 + Otherwise, we could end up calling fread after EOF. */
446 + goto process_partial_block;
449 + /* Process buffer with BLOCKSIZE bytes. Note that
450 + BLOCKSIZE % 64 == 0
452 + sha1_process_block (buffer, BLOCKSIZE, &ctx);
455 + process_partial_block:;
457 + /* Process any remaining bytes. */
459 + sha1_process_bytes (buffer, sum, &ctx);
461 + /* Construct result in desired memory. */
462 + sha1_finish_ctx (&ctx, resblock);
466 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
467 + result is always in little endian byte order, so that a byte-wise
468 + output yields to the wanted ASCII representation of the message
471 +sha1_buffer (const char *buffer, size_t len, void *resblock)
473 + struct sha1_ctx ctx;
475 + /* Initialize the computation context. */
476 + sha1_init_ctx (&ctx);
478 + /* Process whole buffer but last len % 64 bytes. */
479 + sha1_process_bytes (buffer, len, &ctx);
481 + /* Put result in desired memory area. */
482 + return sha1_finish_ctx (&ctx, resblock);
486 +sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
488 + /* When we already have some bits in our internal buffer concatenate
489 + both inputs first. */
490 + if (ctx->buflen != 0)
492 + size_t left_over = ctx->buflen;
493 + size_t add = 128 - left_over > len ? len : 128 - left_over;
495 + memcpy (&ctx->buffer[left_over], buffer, add);
496 + ctx->buflen += add;
498 + if (ctx->buflen > 64)
500 + sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
503 + /* The regions in the following copy operation cannot overlap. */
504 + memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
508 + buffer = (const char *) buffer + add;
512 + /* Process available complete blocks. */
515 +#if !_STRING_ARCH_unaligned
516 +# define alignof(type) offsetof (struct { char c; type x; }, x)
517 +# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
518 + if (UNALIGNED_P (buffer))
521 + sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
522 + buffer = (const char *) buffer + 64;
528 + sha1_process_block (buffer, len & ~63, ctx);
529 + buffer = (const char *) buffer + (len & ~63);
534 + /* Move remaining bytes in internal buffer. */
537 + size_t left_over = ctx->buflen;
539 + memcpy (&ctx->buffer[left_over], buffer, len);
541 + if (left_over >= 64)
543 + sha1_process_block (ctx->buffer, 64, ctx);
545 + memcpy (ctx->buffer, &ctx->buffer[64], left_over);
547 + ctx->buflen = left_over;
551 +/* --- Code below is the primary difference between md5.c and sha1.c --- */
553 +/* SHA1 round constants */
554 +#define K1 0x5a827999L
555 +#define K2 0x6ed9eba1L
556 +#define K3 0x8f1bbcdcL
557 +#define K4 0xca62c1d6L
559 +/* Round functions. Note that F2 is the same as F4. */
560 +#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
561 +#define F2(B,C,D) (B ^ C ^ D)
562 +#define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
563 +#define F4(B,C,D) (B ^ C ^ D)
565 +/* Process LEN bytes of BUFFER, accumulating context into CTX.
566 + It is assumed that LEN % 64 == 0.
567 + Most of this code comes from GnuPG's cipher/sha1.c. */
570 +sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
572 + const uint32_t *words = buffer;
573 + size_t nwords = len / sizeof (uint32_t);
574 + const uint32_t *endp = words + nwords;
576 + uint32_t a = ctx->A;
577 + uint32_t b = ctx->B;
578 + uint32_t c = ctx->C;
579 + uint32_t d = ctx->D;
580 + uint32_t e = ctx->E;
582 + /* First increment the byte count. RFC 1321 specifies the possible
583 + length of the file up to 2^64 bits. Here we only compute the
584 + number of bytes. Do a double word increment. */
585 + ctx->total[0] += len;
586 + if (ctx->total[0] < len)
589 +#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
591 +#define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \
592 + ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
593 + , (x[I&0x0f] = rol(tm, 1)) )
595 +#define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \
599 + B = rol( B, 30 ); \
602 + while (words < endp)
606 + for (t = 0; t < 16; t++)
608 + x[t] = SWAP (*words);
612 + R( a, b, c, d, e, F1, K1, x[ 0] );
613 + R( e, a, b, c, d, F1, K1, x[ 1] );
614 + R( d, e, a, b, c, F1, K1, x[ 2] );
615 + R( c, d, e, a, b, F1, K1, x[ 3] );
616 + R( b, c, d, e, a, F1, K1, x[ 4] );
617 + R( a, b, c, d, e, F1, K1, x[ 5] );
618 + R( e, a, b, c, d, F1, K1, x[ 6] );
619 + R( d, e, a, b, c, F1, K1, x[ 7] );
620 + R( c, d, e, a, b, F1, K1, x[ 8] );
621 + R( b, c, d, e, a, F1, K1, x[ 9] );
622 + R( a, b, c, d, e, F1, K1, x[10] );
623 + R( e, a, b, c, d, F1, K1, x[11] );
624 + R( d, e, a, b, c, F1, K1, x[12] );
625 + R( c, d, e, a, b, F1, K1, x[13] );
626 + R( b, c, d, e, a, F1, K1, x[14] );
627 + R( a, b, c, d, e, F1, K1, x[15] );
628 + R( e, a, b, c, d, F1, K1, M(16) );
629 + R( d, e, a, b, c, F1, K1, M(17) );
630 + R( c, d, e, a, b, F1, K1, M(18) );
631 + R( b, c, d, e, a, F1, K1, M(19) );
632 + R( a, b, c, d, e, F2, K2, M(20) );
633 + R( e, a, b, c, d, F2, K2, M(21) );
634 + R( d, e, a, b, c, F2, K2, M(22) );
635 + R( c, d, e, a, b, F2, K2, M(23) );
636 + R( b, c, d, e, a, F2, K2, M(24) );
637 + R( a, b, c, d, e, F2, K2, M(25) );
638 + R( e, a, b, c, d, F2, K2, M(26) );
639 + R( d, e, a, b, c, F2, K2, M(27) );
640 + R( c, d, e, a, b, F2, K2, M(28) );
641 + R( b, c, d, e, a, F2, K2, M(29) );
642 + R( a, b, c, d, e, F2, K2, M(30) );
643 + R( e, a, b, c, d, F2, K2, M(31) );
644 + R( d, e, a, b, c, F2, K2, M(32) );
645 + R( c, d, e, a, b, F2, K2, M(33) );
646 + R( b, c, d, e, a, F2, K2, M(34) );
647 + R( a, b, c, d, e, F2, K2, M(35) );
648 + R( e, a, b, c, d, F2, K2, M(36) );
649 + R( d, e, a, b, c, F2, K2, M(37) );
650 + R( c, d, e, a, b, F2, K2, M(38) );
651 + R( b, c, d, e, a, F2, K2, M(39) );
652 + R( a, b, c, d, e, F3, K3, M(40) );
653 + R( e, a, b, c, d, F3, K3, M(41) );
654 + R( d, e, a, b, c, F3, K3, M(42) );
655 + R( c, d, e, a, b, F3, K3, M(43) );
656 + R( b, c, d, e, a, F3, K3, M(44) );
657 + R( a, b, c, d, e, F3, K3, M(45) );
658 + R( e, a, b, c, d, F3, K3, M(46) );
659 + R( d, e, a, b, c, F3, K3, M(47) );
660 + R( c, d, e, a, b, F3, K3, M(48) );
661 + R( b, c, d, e, a, F3, K3, M(49) );
662 + R( a, b, c, d, e, F3, K3, M(50) );
663 + R( e, a, b, c, d, F3, K3, M(51) );
664 + R( d, e, a, b, c, F3, K3, M(52) );
665 + R( c, d, e, a, b, F3, K3, M(53) );
666 + R( b, c, d, e, a, F3, K3, M(54) );
667 + R( a, b, c, d, e, F3, K3, M(55) );
668 + R( e, a, b, c, d, F3, K3, M(56) );
669 + R( d, e, a, b, c, F3, K3, M(57) );
670 + R( c, d, e, a, b, F3, K3, M(58) );
671 + R( b, c, d, e, a, F3, K3, M(59) );
672 + R( a, b, c, d, e, F4, K4, M(60) );
673 + R( e, a, b, c, d, F4, K4, M(61) );
674 + R( d, e, a, b, c, F4, K4, M(62) );
675 + R( c, d, e, a, b, F4, K4, M(63) );
676 + R( b, c, d, e, a, F4, K4, M(64) );
677 + R( a, b, c, d, e, F4, K4, M(65) );
678 + R( e, a, b, c, d, F4, K4, M(66) );
679 + R( d, e, a, b, c, F4, K4, M(67) );
680 + R( c, d, e, a, b, F4, K4, M(68) );
681 + R( b, c, d, e, a, F4, K4, M(69) );
682 + R( a, b, c, d, e, F4, K4, M(70) );
683 + R( e, a, b, c, d, F4, K4, M(71) );
684 + R( d, e, a, b, c, F4, K4, M(72) );
685 + R( c, d, e, a, b, F4, K4, M(73) );
686 + R( b, c, d, e, a, F4, K4, M(74) );
687 + R( a, b, c, d, e, F4, K4, M(75) );
688 + R( e, a, b, c, d, F4, K4, M(76) );
689 + R( d, e, a, b, c, F4, K4, M(77) );
690 + R( c, d, e, a, b, F4, K4, M(78) );
691 + R( b, c, d, e, a, F4, K4, M(79) );
700 diff -purN btpd-0.13/misc/sha1.h btpd-0.13-hack/misc/sha1.h
701 --- btpd-0.13/misc/sha1.h 1970-01-01 03:00:00.000000000 +0300
702 +++ btpd-0.13-hack/misc/sha1.h 2007-09-04 14:49:48.000000000 +0400
704 +/* Declarations of functions and data types used for SHA1 sum
706 + Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
708 + This program is free software; you can redistribute it and/or modify it
709 + under the terms of the GNU General Public License as published by the
710 + Free Software Foundation; either version 2, or (at your option) any
713 + This program is distributed in the hope that it will be useful,
714 + but WITHOUT ANY WARRANTY; without even the implied warranty of
715 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
716 + GNU General Public License for more details.
718 + You should have received a copy of the GNU General Public License
719 + along with this program; if not, write to the Free Software Foundation,
720 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
727 +#include <inttypes.h>
729 +#define SHA_DIGEST_LENGTH 20
731 +/* Structure to save state of computation between the single steps. */
746 +/* Initialize structure containing state of computation. */
747 +extern void sha1_init_ctx (struct sha1_ctx *ctx);
749 +/* Starting with the result of former calls of this function (or the
750 + initialization function update the context for the next LEN bytes
751 + starting at BUFFER.
752 + It is necessary that LEN is a multiple of 64!!! */
753 +extern void sha1_process_block (const void *buffer, size_t len,
754 + struct sha1_ctx *ctx);
756 +/* Starting with the result of former calls of this function (or the
757 + initialization function update the context for the next LEN bytes
758 + starting at BUFFER.
759 + It is NOT required that LEN is a multiple of 64. */
760 +extern void sha1_process_bytes (const void *buffer, size_t len,
761 + struct sha1_ctx *ctx);
763 +/* Process the remaining bytes in the buffer and put result from CTX
764 + in first 20 bytes following RESBUF. The result is always in little
765 + endian byte order, so that a byte-wise output yields to the wanted
766 + ASCII representation of the message digest.
768 + IMPORTANT: On some systems it is required that RESBUF be correctly
769 + aligned for a 32 bits value. */
770 +extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
773 +/* Put result from CTX in first 20 bytes following RESBUF. The result is
774 + always in little endian byte order, so that a byte-wise output yields
775 + to the wanted ASCII representation of the message digest.
777 + IMPORTANT: On some systems it is required that RESBUF is correctly
778 + aligned for a 32 bits value. */
779 +extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
782 +/* Compute SHA1 message digest for bytes read from STREAM. The
783 + resulting message digest number will be written into the 20 bytes
784 + beginning at RESBLOCK. */
785 +extern int sha1_stream (FILE *stream, void *resblock);
787 +/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
788 + result is always in little endian byte order, so that a byte-wise
789 + output yields to the wanted ASCII representation of the message
791 +extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
794 diff -purN btpd-0.13/misc/stream.c btpd-0.13-hack/misc/stream.c
795 --- btpd-0.13/misc/stream.c 2007-05-18 19:32:01.000000000 +0400
796 +++ btpd-0.13-hack/misc/stream.c 2007-09-04 14:53:35.000000000 +0400
801 -#include <openssl/sha.h>
804 #include "metainfo.h"
806 @@ -161,21 +161,21 @@ bts_put(struct bt_stream *bts, off_t off
808 bts_sha(struct bt_stream *bts, off_t start, off_t length, uint8_t *hash)
811 + struct sha1_ctx ctx;
812 char buf[SHAFILEBUF];
817 + sha1_init_ctx(&ctx);
819 wantread = min(length, SHAFILEBUF);
820 if ((err = bts_get(bts, start, buf, wantread)) != 0)
824 - SHA1_Update(&ctx, buf, wantread);
825 + sha1_process_bytes(buf, wantread, &ctx);
827 - SHA1_Final(hash, &ctx);
828 + sha1_finish_ctx(&ctx, hash);