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
7 -#include <openssl/sha.h>
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
19 -#include <openssl/sha.h>
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
29 -#include <openssl/sha.h>
31 #define SAVE_INTERVAL 300
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
38 rm -f conftest.c conftest.$OBJEXT
42 -[ --with-openssl=dir use openssl installed in dir],
44 - AC_SUBST(openssl_LDFLAGS,["-L${withval}/lib -Wl,-R,${withval}/lib"])
45 - AC_SUBST(openssl_CPPFLAGS,"-I${withval}/include")
48 AC_ARG_WITH(evloop-method,
49 [ --with-evloop-method select evloop method (epoll,poll,kqueue)],
50 evloop_methods=$withval,
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))
60 for m in $evloop_methods; do
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
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) \
73 misc_libmisc_a_OBJECTS = $(am_misc_libmisc_a_OBJECTS)
74 am__installdirs = "$(DESTDIR)$(bindir)"
75 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
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
84 noinst_LIBRARIES = misc/libmisc.a evloop/libevloop.a
85 EXTRA_DIST = COPYRIGHT CHANGES
88 misc/iobuf.c misc/iobuf.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
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)
107 -rm -f misc/metainfo.$(OBJEXT)
108 -rm -f misc/stream.$(OBJEXT)
109 -rm -f misc/subr.$(OBJEXT)
110 + -rm -f misc/sha1.$(OBJEXT)
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@
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
129 -#include <openssl/sha.h>
133 #include "metainfo.h"
137 if ((hash = malloc(20)) == NULL)
139 - return SHA1(info, benc_length(info), hash);
140 + return (uint8_t *)sha1_buffer(info, benc_length(info), hash);
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
148 +/* sha1.c - Functions to compute SHA1 message digest of files or
149 + memory blocks according to the NIST specification FIPS-180-1.
151 + Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
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
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.
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. */
167 +/* Written by Scott G. Miller
169 + Robert Klep <robert@ilse.nl> -- Expansion function fix
172 +#ifdef HAVE_CONFIG_H
173 +# include <config.h>
182 +# include "unlocked-io.h"
185 +/* SWAP does an endian swap on architectures that are little-endian,
186 + as SHA1 needs some data in a big-endian form. */
188 +#ifdef WORDS_BIGENDIAN
189 +# define SWAP(n) (n)
192 + (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
195 +#define BLOCKSIZE 4096
196 +#if BLOCKSIZE % 64 != 0
197 +# error "invalid BLOCKSIZE"
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, ... */ };
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.
211 +sha1_init_ctx (struct sha1_ctx *ctx)
213 + ctx->A = 0x67452301;
214 + ctx->B = 0xefcdab89;
215 + ctx->C = 0x98badcfe;
216 + ctx->D = 0x10325476;
217 + ctx->E = 0xc3d2e1f0;
219 + ctx->total[0] = ctx->total[1] = 0;
223 +/* Put result from CTX in first 20 bytes following RESBUF. The result
224 + must be in little endian byte order.
226 + IMPORTANT: On some systems it is required that RESBUF is correctly
227 + aligned for a 32 bits value. */
229 +sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
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);
240 +/* Process the remaining bytes in the internal buffer and the usual
241 + prolog according to the standard and write the result to RESBUF.
243 + IMPORTANT: On some systems it is required that RESBUF is correctly
244 + aligned for a 32 bits value. */
246 +sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
248 + /* Take yet unprocessed bytes into account. */
249 + uint32_t bytes = ctx->buflen;
252 + /* Now count remaining bytes. */
253 + ctx->total[0] += bytes;
254 + if (ctx->total[0] < bytes)
257 + pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
258 + memcpy (&ctx->buffer[bytes], fillbuf, pad);
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));
265 + /* Process last bytes. */
266 + sha1_process_block (ctx->buffer, bytes + pad + 8, ctx);
268 + return sha1_read_ctx (ctx, resbuf);
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. */
275 +sha1_stream (FILE *stream, void *resblock)
277 + struct sha1_ctx ctx;
278 + char buffer[BLOCKSIZE + 72];
281 + /* Initialize the computation context. */
282 + sha1_init_ctx (&ctx);
284 + /* Iterate over full file contents. */
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. */
293 + /* Read block. Take care for partial reads. */
296 + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
300 + if (sum == BLOCKSIZE)
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
308 + if (ferror (stream))
310 + goto process_partial_block;
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. */
317 + goto process_partial_block;
320 + /* Process buffer with BLOCKSIZE bytes. Note that
321 + BLOCKSIZE % 64 == 0
323 + sha1_process_block (buffer, BLOCKSIZE, &ctx);
326 + process_partial_block:;
328 + /* Process any remaining bytes. */
330 + sha1_process_bytes (buffer, sum, &ctx);
332 + /* Construct result in desired memory. */
333 + sha1_finish_ctx (&ctx, resblock);
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
342 +sha1_buffer (const char *buffer, size_t len, void *resblock)
344 + struct sha1_ctx ctx;
346 + /* Initialize the computation context. */
347 + sha1_init_ctx (&ctx);
349 + /* Process whole buffer but last len % 64 bytes. */
350 + sha1_process_bytes (buffer, len, &ctx);
352 + /* Put result in desired memory area. */
353 + return sha1_finish_ctx (&ctx, resblock);
357 +sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
359 + /* When we already have some bits in our internal buffer concatenate
360 + both inputs first. */
361 + if (ctx->buflen != 0)
363 + size_t left_over = ctx->buflen;
364 + size_t add = 128 - left_over > len ? len : 128 - left_over;
366 + memcpy (&ctx->buffer[left_over], buffer, add);
367 + ctx->buflen += add;
369 + if (ctx->buflen > 64)
371 + sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
374 + /* The regions in the following copy operation cannot overlap. */
375 + memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
379 + buffer = (const char *) buffer + add;
383 + /* Process available complete blocks. */
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))
392 + sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
393 + buffer = (const char *) buffer + 64;
399 + sha1_process_block (buffer, len & ~63, ctx);
400 + buffer = (const char *) buffer + (len & ~63);
405 + /* Move remaining bytes in internal buffer. */
408 + size_t left_over = ctx->buflen;
410 + memcpy (&ctx->buffer[left_over], buffer, len);
412 + if (left_over >= 64)
414 + sha1_process_block (ctx->buffer, 64, ctx);
416 + memcpy (ctx->buffer, &ctx->buffer[64], left_over);
418 + ctx->buflen = left_over;
422 +/* --- Code below is the primary difference between md5.c and sha1.c --- */
424 +/* SHA1 round constants */
425 +#define K1 0x5a827999L
426 +#define K2 0x6ed9eba1L
427 +#define K3 0x8f1bbcdcL
428 +#define K4 0xca62c1d6L
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)
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. */
441 +sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
443 + const uint32_t *words = buffer;
444 + size_t nwords = len / sizeof (uint32_t);
445 + const uint32_t *endp = words + nwords;
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;
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)
460 +#define rol(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
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)) )
466 +#define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \
470 + B = rol( B, 30 ); \
473 + while (words < endp)
477 + for (t = 0; t < 16; t++)
479 + x[t] = SWAP (*words);
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) );
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
575 +/* Declarations of functions and data types used for SHA1 sum
577 + Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
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
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.
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. */
598 +#include <inttypes.h>
600 +#define SHA_DIGEST_LENGTH 20
602 +/* Structure to save state of computation between the single steps. */
617 +/* Initialize structure containing state of computation. */
618 +extern void sha1_init_ctx (struct sha1_ctx *ctx);
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);
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);
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.
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);
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.
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);
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);
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
662 +extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
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
672 -#include <openssl/sha.h>
675 #include "metainfo.h"
677 @@ -161,21 +161,21 @@
679 bts_sha(struct bt_stream *bts, off_t start, off_t length, uint8_t *hash)
682 + struct sha1_ctx ctx;
683 char buf[SHAFILEBUF];
688 + sha1_init_ctx(&ctx);
690 wantread = min(length, SHAFILEBUF);
691 if ((err = bts_get(bts, start, buf, wantread)) != 0)
695 - SHA1_Update(&ctx, buf, wantread);
696 + sha1_process_bytes(buf, wantread, &ctx);
698 - SHA1_Final(hash, &ctx);
699 + sha1_finish_ctx(&ctx, hash);
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
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
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
718 bin_PROGRAMS=btpd/btpd cli/btcli cli/btinfo
719 noinst_LIBRARIES=misc/libmisc.a evloop/libevloop.a
721 misc/iobuf.c misc/iobuf.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
729 EXTRA_evloop_libevloop_a_SOURCES=evloop/epoll.c evloop/kqueue.c evloop/poll.c