Changeset 2557


Ignore:
Timestamp:
Jul 30, 2007, 7:55:10 PM (15 years ago)
Author:
charles
Message:

(libT) not all libT source files need to #include sha1/openssl, just three of them. Also, no need to compile a local sha1 implementation if we're using openssl's.

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r2555 r2557  
    2121#include "fdlimit.h"
    2222#include "inout.h"
     23#include "sha1.h"
    2324#include "utils.h"
    2425
  • trunk/libtransmission/internal.h

    r2555 r2557  
    3434#endif
    3535
    36 #ifndef __AMIGAOS4__
    37 #include <sys/types.h>
    38 #include <sys/resource.h>
    39 #endif
    40 
    4136#ifdef SYS_BEOS
    4237#  define socklen_t uint32_t
     
    6358#  define UNUSED
    6459#  define PRINTF( fmt, args )
    65 #endif
    66 
    67 /* We use OpenSSL whenever possible, since it is likely to be more
    68    optimized and it is ok to use it with a MIT-licensed application.
    69    Otherwise, we use the included implementation by vi@nwr.jp. */
    70 #if defined(HAVE_OPENSSL) || defined(HAVE_LIBSSL)
    71 #  undef SHA_DIGEST_LENGTH
    72 #  include <openssl/sha.h>
    73 #else
    74 #  include "sha1.h"
    75 #  define SHA1(p,i,h) \
    76    { \
    77      sha1_state_s pms; \
    78      sha1_init( &pms ); \
    79      sha1_update( &pms, (sha1_byte_t *) p, i ); \
    80      sha1_finish( &pms, (sha1_byte_t *) h ); \
    81    }
    8260#endif
    8361
  • trunk/libtransmission/makemeta.c

    r2555 r2557  
    2727#include "platform.h" /* threads, locks */
    2828#include "shared.h" /* shared lock */
     29#include "sha1.h"
    2930#include "utils.h" /* buildpath */
    3031#include "version.h"
  • trunk/libtransmission/metainfo.c

    r2555 r2557  
    3636#include "http.h" /* tr_httpParseUrl */
    3737#include "metainfo.h"
     38#include "sha1.h"
    3839#include "utils.h"
    3940
  • trunk/libtransmission/sha1.c

    r261 r2557  
    3030   <ghost@aladdin.com>. Thank him since I'm not a good speaker of English. :)
    3131 */
     32
    3233#include <string.h>
    3334#include "sha1.h"
    3435
     36#if !defined(HAVE_OPENSSL) && !defined(HAVE_LIBSSL)
     37
     38#define BITS 8
    3539#define INLINE  inline
     40
     41struct sha1_state_s
     42{
     43  sha1_byte_t   sha1_buf[64];   /* 512 bits */
     44  int           sha1_count;     /* How many bytes are used */
     45  sha1_word_t   sha1_size1;             /* Length counter Lower Word */
     46  sha1_word_t   sha1_size2;             /* Length counter Upper Word */
     47  sha1_word_t   sha1_h[5];              /* Hash output */
     48};
     49
    3650/*
    3751 * Packing bytes to a word
     
    6175 * Processing a block
    6276 */
    63 static inline void sha1_update_now(sha1_state_s *pms, sha1_byte_t *bp)
     77static inline void sha1_update_now(sha1_state_t *pms, sha1_byte_t *bp)
    6478{
    6579  sha1_word_t   tmp, a, b, c, d, e, w[16+16];
     
    132146
    133147/*
    134  * Increment sha1_size1, sha1_size2 field of sha1_state_s
    135  */
    136 static INLINE void incr(sha1_state_s *pms, int v)
     148 * Increment sha1_size1, sha1_size2 field of sha1_state_t
     149 */
     150static INLINE void incr(sha1_state_t *pms, int v)
    137151{
    138152  sha1_word_t   q;
     
    146160
    147161/*
    148  * Initialize sha1_state_s as FIPS specifies
    149  */
    150 void    sha1_init(sha1_state_s *pms)
     162 * Initialize sha1_state_t as FIPS specifies
     163 */
     164void    sha1_init(sha1_state_t *pms)
    151165{
    152166  memset(pms, 0, sizeof(*pms));
     
    161175 * Fill block and update output when needed
    162176 */
    163 void    sha1_update(sha1_state_s *pms, sha1_byte_t *bufp, int length)
     177void    sha1_update(sha1_state_t *pms, sha1_byte_t *bufp, int length)
    164178{
    165179  /* Is the buffer partially filled? */
     
    199213}
    200214
    201 void    sha1_finish(sha1_state_s *pms, sha1_byte_t output[SHA1_OUTPUT_SIZE])
     215void    sha1_finish(sha1_state_t *pms, sha1_byte_t output[SHA1_OUTPUT_SIZE])
    202216{
    203217  int i;
     
    234248  }
    235249}
     250
     251void
     252tr_sha1( const void * input_buffer, int length, unsigned char * output)
     253{
     254    sha1_state_t pms;
     255    sha1_init( &pms );
     256    sha1_update( &pms, (sha1_byte_t *) input_buffer, length );
     257    sha1_finish( &pms, (sha1_byte_t *) output );
     258}
     259
     260#endif
  • trunk/libtransmission/sha1.h

    r261 r2557  
    3030   <ghost@aladdin.com>. Thank him since I'm not a good speaker of English. :)
    3131 */
    32 #ifndef SHA1_H
    33 #define SHA1_H
     32#ifndef SHA1_H
     33#define SHA1_H
    3434
    35 typedef unsigned int    sha1_word_t;    /* 32bits unsigned integer */
    36 typedef unsigned char   sha1_byte_t;    /* 8bits unsigned integer */
    37 #define BITS            8
     35/* We use OpenSSL whenever possible, since it is likely to be more
     36   optimized and it is ok to use it with a MIT-licensed application.
     37   Otherwise, we use the included implementation by vi@nwr.jp. */
     38#if defined(HAVE_OPENSSL) || defined(HAVE_LIBSSL)
    3839
    39 /* Define the state of SHA-1 algorithm */
    40 typedef struct {
    41   sha1_byte_t   sha1_buf[64];   /* 512 bits */
    42   int           sha1_count;     /* How many bytes are used */
    43   sha1_word_t   sha1_size1;             /* Length counter Lower Word */
    44   sha1_word_t   sha1_size2;             /* Length counter Upper Word */
    45   sha1_word_t   sha1_h[5];              /* Hash output */
    46 } sha1_state_s;
    47 #define SHA1_OUTPUT_SIZE        20      /* in bytes */
     40    #undef SHA_DIGEST_LENGTH
     41    #include <openssl/sha.h>
    4842
    49 /* External Functions */
     43#else
    5044
    51 #ifdef  __cplusplus
    52 extern "C" {
    53 #endif
     45    #include <stdint.h>
     46    #define SHA1_OUTPUT_SIZE 20 /* in bytes */
    5447
    55 /* Initialize SHA-1 algorithm */
    56 void    sha1_init(sha1_state_s *pms);
     48    typedef struct sha1_state_s sha1_state_t;
     49    typedef uint32_t sha1_word_t;  /* 32bits unsigned integer */
     50    typedef uint8_t sha1_byte_t;   /* 8bits unsigned integer */
    5751
    58 /* Append a string to SHA-1 algorithm */
    59 void    sha1_update(sha1_state_s *pms, sha1_byte_t *input_buffer, int length);
     52    /* Initialize SHA-1 algorithm */
     53    void sha1_init(sha1_state_t *pms);
    6054
    61 /* Finish the SHA-1 algorithm and return the hash */
    62 void    sha1_finish(sha1_state_s *pms, sha1_byte_t output[SHA1_OUTPUT_SIZE]);
     55    /* Append a string to SHA-1 algorithm */
     56    void sha1_update(sha1_state_t *pms, sha1_byte_t *input_buffer, int length);
    6357
    64 #ifdef  __cplusplus
    65 }
    66 #endif
     58    /* Finish the SHA-1 algorithm and return the hash */
     59    void sha1_finish(sha1_state_t *pms, sha1_byte_t output[SHA1_OUTPUT_SIZE]);
    6760
    68 #endif
     61    /* Convenience version of the above */
     62    void tr_sha1( const void * input_buffer, int length, unsigned char * output);
     63
     64    #define SHA1(in,inlen,out) tr_sha1(in,inlen,out)
     65
     66#endif /* ifndef HAVE_OPENSSL, HAVE_LIBSSL */
     67
     68#endif /* #ifndef SHA1_H */
Note: See TracChangeset for help on using the changeset viewer.