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 -purN btpd-0.13/configure.ac btpd-0.13-hack/configure.ac
70 --- btpd-0.13/configure.ac 2007-05-18 19:31:59.000000000 +0400
71 +++ btpd-0.13-hack/configure.ac 2007-09-04 15:09:17.000000000 +0400
72 @@ -10,14 +10,6 @@ AC_PROG_RANLIB
73 CFLAGS="$CFLAGS -std=c99"
74 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64"
77 -[ --with-openssl=dir use openssl installed in dir],
79 - AC_SUBST(openssl_LDFLAGS,["-L${withval}/lib -Wl,-rpath=${withval}/lib"])
80 - AC_SUBST(openssl_CPPFLAGS,"-I${withval}/include")
85 [ --with-warn=level select warning preset (no,all,allerr)],
87 @@ -38,11 +30,6 @@ AC_ARG_WITH(warn,
91 -old_LDFLAGS="$LDFLAGS"
92 -LDFLAGS="$LDFLAGS $openssl_LDFLAGS"
93 -AC_CHECK_LIB(crypto, SHA1_Final, :, echo Must have openssl; exit 1)
96 AC_CONFIG_SUBDIRS([libevent])
99 diff -purN btpd-0.13/libevent/evdns.c btpd-0.13-hack/libevent/evdns.c
100 --- btpd-0.13/libevent/evdns.c 2007-05-18 19:32:01.000000000 +0400
101 +++ btpd-0.13-hack/libevent/evdns.c 2007-09-04 15:12:38.000000000 +0400
104 #ifndef DNS_USE_CPU_CLOCK_FOR_ID
105 #ifndef DNS_USE_GETTIMEOFDAY_FOR_ID
106 -#ifndef DNS_USE_OPENSSL_FOR_ID
107 #error Must configure at least one id generation method.
108 #error Please see the documentation.
113 // #define _POSIX_C_SOURCE 200507
116 #ifdef DNS_USE_CPU_CLOCK_FOR_ID
117 -#ifdef DNS_USE_OPENSSL_FOR_ID
118 -#error Multiple id options selected
120 #ifdef DNS_USE_GETTIMEOFDAY_FOR_ID
121 #error Multiple id options selected
126 -#ifdef DNS_USE_OPENSSL_FOR_ID
127 -#ifdef DNS_USE_GETTIMEOFDAY_FOR_ID
128 -#error Multiple id options selected
130 -#include <openssl/rand.h>
133 #define _FORTIFY_SOURCE 3
136 @@ -1026,18 +1014,6 @@ transaction_id_pick(void) {
137 trans_id = tv.tv_usec & 0xffff;
140 -#ifdef DNS_USE_OPENSSL_FOR_ID
142 - if (RAND_pseudo_bytes((u8 *) &trans_id, 2) == -1) {
143 - /* // in the case that the RAND call fails we back
144 - // down to using gettimeofday.
146 - gettimeofday(&tv, NULL);
147 - trans_id = tv.tv_usec & 0xffff; */
152 if (trans_id == 0xffff) continue;
153 // now check to see if that id is already inflight
154 req = started_at = req_head;
155 diff -purN btpd-0.13/misc/Makefile.am btpd-0.13-hack/misc/Makefile.am
156 --- btpd-0.13/misc/Makefile.am 2007-05-18 19:32:01.000000000 +0400
157 +++ btpd-0.13-hack/misc/Makefile.am 2007-09-04 14:57:39.000000000 +0400
158 @@ -8,5 +8,6 @@ libmisc_a_SOURCES=\
163 -libmisc_a_CPPFLAGS=-I$(top_srcdir)/libevent @openssl_CPPFLAGS@
166 +libmisc_a_CPPFLAGS=-I$(top_srcdir)/libevent
167 diff -purN btpd-0.13/misc/metainfo.c btpd-0.13-hack/misc/metainfo.c
168 --- btpd-0.13/misc/metainfo.c 2007-05-18 19:32:01.000000000 +0400
169 +++ btpd-0.13-hack/misc/metainfo.c 2007-09-04 14:58:20.000000000 +0400
174 -#include <openssl/sha.h>
178 #include "metainfo.h"
180 @@ -158,7 +157,7 @@ mi_info_hash(const char *p, uint8_t *has
182 if ((hash = malloc(20)) == NULL)
184 - return SHA1(info, benc_length(info), hash);
185 + return (uint8_t *)sha1_buffer(info, benc_length(info), hash);
189 diff -purN btpd-0.13/misc/sha1.c btpd-0.13-hack/misc/sha1.c
190 --- btpd-0.13/misc/sha1.c 1970-01-01 03:00:00.000000000 +0300
191 +++ btpd-0.13-hack/misc/sha1.c 2007-09-04 14:45:36.000000000 +0400
193 +/* sha1.c - Functions to compute SHA1 message digest of files or
194 + memory blocks according to the NIST specification FIPS-180-1.
196 + Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
198 + This program is free software; you can redistribute it and/or modify it
199 + under the terms of the GNU General Public License as published by the
200 + Free Software Foundation; either version 2, or (at your option) any
203 + This program is distributed in the hope that it will be useful,
204 + but WITHOUT ANY WARRANTY; without even the implied warranty of
205 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
206 + GNU General Public License for more details.
208 + You should have received a copy of the GNU General Public License
209 + along with this program; if not, write to the Free Software Foundation,
210 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
212 +/* Written by Scott G. Miller
214 + Robert Klep <robert@ilse.nl> -- Expansion function fix
217 +#ifdef HAVE_CONFIG_H
218 +# include <config.h>
227 +# include "unlocked-io.h"
230 +/* SWAP does an endian swap on architectures that are little-endian,
231 + as SHA1 needs some data in a big-endian form. */
233 +#ifdef WORDS_BIGENDIAN
234 +# define SWAP(n) (n)
237 + (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
240 +#define BLOCKSIZE 4096
241 +#if BLOCKSIZE % 64 != 0
242 +# error "invalid BLOCKSIZE"
245 +/* This array contains the bytes used to pad the buffer to the next
246 + 64-byte boundary. (RFC 1321, 3.1: Step 1) */
247 +static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
251 + Takes a pointer to a 160 bit block of data (five 32 bit ints) and
252 + intializes it to the start constants of the SHA1 algorithm. This
253 + must be called before using hash in the call to sha1_hash.
256 +sha1_init_ctx (struct sha1_ctx *ctx)
258 + ctx->A = 0x67452301;
259 + ctx->B = 0xefcdab89;
260 + ctx->C = 0x98badcfe;
261 + ctx->D = 0x10325476;
262 + ctx->E = 0xc3d2e1f0;
264 + ctx->total[0] = ctx->total[1] = 0;
268 +/* Put result from CTX in first 20 bytes following RESBUF. The result
269 + must be in little endian byte order.
271 + IMPORTANT: On some systems it is required that RESBUF is correctly
272 + aligned for a 32 bits value. */
274 +sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
276 + ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
277 + ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
278 + ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
279 + ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
280 + ((uint32_t *) resbuf)[4] = SWAP (ctx->E);
285 +/* Process the remaining bytes in the internal buffer and the usual
286 + prolog according to the standard and write the result to RESBUF.
288 + IMPORTANT: On some systems it is required that RESBUF is correctly
289 + aligned for a 32 bits value. */
291 +sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
293 + /* Take yet unprocessed bytes into account. */
294 + uint32_t bytes = ctx->buflen;
297 + /* Now count remaining bytes. */
298 + ctx->total[0] += bytes;
299 + if (ctx->total[0] < bytes)
302 + pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
303 + memcpy (&ctx->buffer[bytes], fillbuf, pad);
305 + /* Put the 64-bit file length in *bits* at the end of the buffer. */
306 + *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
307 + *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
308 + (ctx->total[0] >> 29));
310 + /* Process last bytes. */
311 + sha1_process_block (ctx->buffer, bytes + pad + 8, ctx);
313 + return sha1_read_ctx (ctx, resbuf);
316 +/* Compute SHA1 message digest for bytes read from STREAM. The
317 + resulting message digest number will be written into the 16 bytes
318 + beginning at RESBLOCK. */
320 +sha1_stream (FILE *stream, void *resblock)
322 + struct sha1_ctx ctx;
323 + char buffer[BLOCKSIZE + 72];
326 + /* Initialize the computation context. */
327 + sha1_init_ctx (&ctx);
329 + /* Iterate over full file contents. */
332 + /* We read the file in blocks of BLOCKSIZE bytes. One call of the
333 + computation function processes the whole buffer so that with the
334 + next round of the loop another block can be read. */
338 + /* Read block. Take care for partial reads. */
341 + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
345 + if (sum == BLOCKSIZE)
350 + /* Check for the error flag IFF N == 0, so that we don't
351 + exit the loop after a partial read due to e.g., EAGAIN
353 + if (ferror (stream))
355 + goto process_partial_block;
358 + /* We've read at least one byte, so ignore errors. But always
359 + check for EOF, since feof may be true even though N > 0.
360 + Otherwise, we could end up calling fread after EOF. */
362 + goto process_partial_block;
365 + /* Process buffer with BLOCKSIZE bytes. Note that
366 + BLOCKSIZE % 64 == 0
368 + sha1_process_block (buffer, BLOCKSIZE, &ctx);
371 + process_partial_block:;
373 + /* Process any remaining bytes. */
375 + sha1_process_bytes (buffer, sum, &ctx);
377 + /* Construct result in desired memory. */
378 + sha1_finish_ctx (&ctx, resblock);
382 +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
383 + result is always in little endian byte order, so that a byte-wise
384 + output yields to the wanted ASCII representation of the message
387 +sha1_buffer (const char *buffer, size_t len, void *resblock)
389 + struct sha1_ctx ctx;
391 + /* Initialize the computation context. */
392 + sha1_init_ctx (&ctx);
394 + /* Process whole buffer but last len % 64 bytes. */
395 + sha1_process_bytes (buffer, len, &ctx);
397 + /* Put result in desired memory area. */
398 + return sha1_finish_ctx (&ctx, resblock);
402 +sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
404 + /* When we already have some bits in our internal buffer concatenate
405 + both inputs first. */
406 + if (ctx->buflen != 0)
408 + size_t left_over = ctx->buflen;
409 + size_t add = 128 - left_over > len ? len : 128 - left_over;
411 + memcpy (&ctx->buffer[left_over], buffer, add);
412 + ctx->buflen += add;
414 + if (ctx->buflen > 64)
416 + sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
419 + /* The regions in the following copy operation cannot overlap. */
420 + memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
424 + buffer = (const char *) buffer + add;
428 + /* Process available complete blocks. */
431 +#if !_STRING_ARCH_unaligned
432 +# define alignof(type) offsetof (struct { char c; type x; }, x)
433 +# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
434 + if (UNALIGNED_P (buffer))
437 + sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
438 + buffer = (const char *) buffer + 64;
444 + sha1_process_block (buffer, len & ~63, ctx);
445 + buffer = (const char *) buffer + (len & ~63);
450 + /* Move remaining bytes in internal buffer. */
453 + size_t left_over = ctx->buflen;
455 + memcpy (&ctx->buffer[left_over], buffer, len);
457 + if (left_over >= 64)
459 + sha1_process_block (ctx->buffer, 64, ctx);
461 + memcpy (ctx->buffer, &ctx->buffer[64], left_over);
463 + ctx->buflen = left_over;
467 +/* --- Code below is the primary difference between md5.c and sha1.c --- */
469 +/* SHA1 round constants */
470 +#define K1 0x5a827999L
471 +#define K2 0x6ed9eba1L
472 +#define K3 0x8f1bbcdcL
473 +#define K4 0xca62c1d6L
475 +/* Round functions. Note that F2 is the same as F4. */
476 +#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
477 +#define F2(B,C,D) (B ^ C ^ D)
478 +#define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
479 +#define F4(B,C,D) (B ^ C ^ D)
481 +/* Process LEN bytes of BUFFER, accumulating context into CTX.
482 + It is assumed that LEN % 64 == 0.
483 + Most of this code comes from GnuPG's cipher/sha1.c. */
486 +sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
488 + const uint32_t *words = buffer;
489 + size_t nwords = len / sizeof (uint32_t);
490 + const uint32_t *endp = words + nwords;
492 + uint32_t a = ctx->A;
493 + uint32_t b = ctx->B;
494 + uint32_t c = ctx->C;
495 + uint32_t d = ctx->D;
496 + uint32_t e = ctx->E;
498 + /* First increment the byte count. RFC 1321 specifies the possible
499 + length of the file up to 2^64 bits. Here we only compute the
500 + number of bytes. Do a double word increment. */
501 + ctx->total[0] += len;
502 + if (ctx->total[0] < len)
505 +#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
507 +#define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \
508 + ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
509 + , (x[I&0x0f] = rol(tm, 1)) )
511 +#define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \
515 + B = rol( B, 30 ); \
518 + while (words < endp)
522 + for (t = 0; t < 16; t++)
524 + x[t] = SWAP (*words);
528 + R( a, b, c, d, e, F1, K1, x[ 0] );
529 + R( e, a, b, c, d, F1, K1, x[ 1] );
530 + R( d, e, a, b, c, F1, K1, x[ 2] );
531 + R( c, d, e, a, b, F1, K1, x[ 3] );
532 + R( b, c, d, e, a, F1, K1, x[ 4] );
533 + R( a, b, c, d, e, F1, K1, x[ 5] );
534 + R( e, a, b, c, d, F1, K1, x[ 6] );
535 + R( d, e, a, b, c, F1, K1, x[ 7] );
536 + R( c, d, e, a, b, F1, K1, x[ 8] );
537 + R( b, c, d, e, a, F1, K1, x[ 9] );
538 + R( a, b, c, d, e, F1, K1, x[10] );
539 + R( e, a, b, c, d, F1, K1, x[11] );
540 + R( d, e, a, b, c, F1, K1, x[12] );
541 + R( c, d, e, a, b, F1, K1, x[13] );
542 + R( b, c, d, e, a, F1, K1, x[14] );
543 + R( a, b, c, d, e, F1, K1, x[15] );
544 + R( e, a, b, c, d, F1, K1, M(16) );
545 + R( d, e, a, b, c, F1, K1, M(17) );
546 + R( c, d, e, a, b, F1, K1, M(18) );
547 + R( b, c, d, e, a, F1, K1, M(19) );
548 + R( a, b, c, d, e, F2, K2, M(20) );
549 + R( e, a, b, c, d, F2, K2, M(21) );
550 + R( d, e, a, b, c, F2, K2, M(22) );
551 + R( c, d, e, a, b, F2, K2, M(23) );
552 + R( b, c, d, e, a, F2, K2, M(24) );
553 + R( a, b, c, d, e, F2, K2, M(25) );
554 + R( e, a, b, c, d, F2, K2, M(26) );
555 + R( d, e, a, b, c, F2, K2, M(27) );
556 + R( c, d, e, a, b, F2, K2, M(28) );
557 + R( b, c, d, e, a, F2, K2, M(29) );
558 + R( a, b, c, d, e, F2, K2, M(30) );
559 + R( e, a, b, c, d, F2, K2, M(31) );
560 + R( d, e, a, b, c, F2, K2, M(32) );
561 + R( c, d, e, a, b, F2, K2, M(33) );
562 + R( b, c, d, e, a, F2, K2, M(34) );
563 + R( a, b, c, d, e, F2, K2, M(35) );
564 + R( e, a, b, c, d, F2, K2, M(36) );
565 + R( d, e, a, b, c, F2, K2, M(37) );
566 + R( c, d, e, a, b, F2, K2, M(38) );
567 + R( b, c, d, e, a, F2, K2, M(39) );
568 + R( a, b, c, d, e, F3, K3, M(40) );
569 + R( e, a, b, c, d, F3, K3, M(41) );
570 + R( d, e, a, b, c, F3, K3, M(42) );
571 + R( c, d, e, a, b, F3, K3, M(43) );
572 + R( b, c, d, e, a, F3, K3, M(44) );
573 + R( a, b, c, d, e, F3, K3, M(45) );
574 + R( e, a, b, c, d, F3, K3, M(46) );
575 + R( d, e, a, b, c, F3, K3, M(47) );
576 + R( c, d, e, a, b, F3, K3, M(48) );
577 + R( b, c, d, e, a, F3, K3, M(49) );
578 + R( a, b, c, d, e, F3, K3, M(50) );
579 + R( e, a, b, c, d, F3, K3, M(51) );
580 + R( d, e, a, b, c, F3, K3, M(52) );
581 + R( c, d, e, a, b, F3, K3, M(53) );
582 + R( b, c, d, e, a, F3, K3, M(54) );
583 + R( a, b, c, d, e, F3, K3, M(55) );
584 + R( e, a, b, c, d, F3, K3, M(56) );
585 + R( d, e, a, b, c, F3, K3, M(57) );
586 + R( c, d, e, a, b, F3, K3, M(58) );
587 + R( b, c, d, e, a, F3, K3, M(59) );
588 + R( a, b, c, d, e, F4, K4, M(60) );
589 + R( e, a, b, c, d, F4, K4, M(61) );
590 + R( d, e, a, b, c, F4, K4, M(62) );
591 + R( c, d, e, a, b, F4, K4, M(63) );
592 + R( b, c, d, e, a, F4, K4, M(64) );
593 + R( a, b, c, d, e, F4, K4, M(65) );
594 + R( e, a, b, c, d, F4, K4, M(66) );
595 + R( d, e, a, b, c, F4, K4, M(67) );
596 + R( c, d, e, a, b, F4, K4, M(68) );
597 + R( b, c, d, e, a, F4, K4, M(69) );
598 + R( a, b, c, d, e, F4, K4, M(70) );
599 + R( e, a, b, c, d, F4, K4, M(71) );
600 + R( d, e, a, b, c, F4, K4, M(72) );
601 + R( c, d, e, a, b, F4, K4, M(73) );
602 + R( b, c, d, e, a, F4, K4, M(74) );
603 + R( a, b, c, d, e, F4, K4, M(75) );
604 + R( e, a, b, c, d, F4, K4, M(76) );
605 + R( d, e, a, b, c, F4, K4, M(77) );
606 + R( c, d, e, a, b, F4, K4, M(78) );
607 + R( b, c, d, e, a, F4, K4, M(79) );
616 diff -purN btpd-0.13/misc/sha1.h btpd-0.13-hack/misc/sha1.h
617 --- btpd-0.13/misc/sha1.h 1970-01-01 03:00:00.000000000 +0300
618 +++ btpd-0.13-hack/misc/sha1.h 2007-09-04 14:49:48.000000000 +0400
620 +/* Declarations of functions and data types used for SHA1 sum
622 + Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
624 + This program is free software; you can redistribute it and/or modify it
625 + under the terms of the GNU General Public License as published by the
626 + Free Software Foundation; either version 2, or (at your option) any
629 + This program is distributed in the hope that it will be useful,
630 + but WITHOUT ANY WARRANTY; without even the implied warranty of
631 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
632 + GNU General Public License for more details.
634 + You should have received a copy of the GNU General Public License
635 + along with this program; if not, write to the Free Software Foundation,
636 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
643 +#include <inttypes.h>
645 +#define SHA_DIGEST_LENGTH 20
647 +/* Structure to save state of computation between the single steps. */
662 +/* Initialize structure containing state of computation. */
663 +extern void sha1_init_ctx (struct sha1_ctx *ctx);
665 +/* Starting with the result of former calls of this function (or the
666 + initialization function update the context for the next LEN bytes
667 + starting at BUFFER.
668 + It is necessary that LEN is a multiple of 64!!! */
669 +extern void sha1_process_block (const void *buffer, size_t len,
670 + struct sha1_ctx *ctx);
672 +/* Starting with the result of former calls of this function (or the
673 + initialization function update the context for the next LEN bytes
674 + starting at BUFFER.
675 + It is NOT required that LEN is a multiple of 64. */
676 +extern void sha1_process_bytes (const void *buffer, size_t len,
677 + struct sha1_ctx *ctx);
679 +/* Process the remaining bytes in the buffer and put result from CTX
680 + in first 20 bytes following RESBUF. The result is always in little
681 + endian byte order, so that a byte-wise output yields to the wanted
682 + ASCII representation of the message digest.
684 + IMPORTANT: On some systems it is required that RESBUF be correctly
685 + aligned for a 32 bits value. */
686 +extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf);
689 +/* Put result from CTX in first 20 bytes following RESBUF. The result is
690 + always in little endian byte order, so that a byte-wise output yields
691 + to the wanted ASCII representation of the message digest.
693 + IMPORTANT: On some systems it is required that RESBUF is correctly
694 + aligned for a 32 bits value. */
695 +extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
698 +/* Compute SHA1 message digest for bytes read from STREAM. The
699 + resulting message digest number will be written into the 20 bytes
700 + beginning at RESBLOCK. */
701 +extern int sha1_stream (FILE *stream, void *resblock);
703 +/* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
704 + result is always in little endian byte order, so that a byte-wise
705 + output yields to the wanted ASCII representation of the message
707 +extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
710 diff -purN btpd-0.13/misc/stream.c btpd-0.13-hack/misc/stream.c
711 --- btpd-0.13/misc/stream.c 2007-05-18 19:32:01.000000000 +0400
712 +++ btpd-0.13-hack/misc/stream.c 2007-09-04 14:53:35.000000000 +0400
717 -#include <openssl/sha.h>
720 #include "metainfo.h"
722 @@ -161,21 +161,21 @@ bts_put(struct bt_stream *bts, off_t off
724 bts_sha(struct bt_stream *bts, off_t start, off_t length, uint8_t *hash)
727 + struct sha1_ctx ctx;
728 char buf[SHAFILEBUF];
733 + sha1_init_ctx(&ctx);
735 wantread = min(length, SHAFILEBUF);
736 if ((err = bts_get(bts, start, buf, wantread)) != 0)
740 - SHA1_Update(&ctx, buf, wantread);
741 + sha1_process_bytes(buf, wantread, &ctx);
743 - SHA1_Final(hash, &ctx);
744 + sha1_finish_ctx(&ctx, hash);