Changeset 2938


Ignore:
Timestamp:
Aug 29, 2007, 12:24:34 PM (15 years ago)
Author:
charles
Message:

make things a little less prolix - s/tr_encryption/tr_crypto/

Location:
branches/encryption/libtransmission
Files:
8 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/Makefile.am

    r2936 r2938  
    1313    clients.c \
    1414    completion.c \
     15    crypto.c \
    1516    dirname.c \
    16     encryption.c \
    1717    fastresume.c \
    1818    fdlimit.c \
     
    5050    choking.h \
    5151    clients.h \
     52    crypto.h \
    5253    completion.h \
    53     encryption.h \
    5454    fastresume.h \
    5555    fdlimit.h \
  • branches/encryption/libtransmission/crypto.c

    r2936 r2938  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
     
    2222
    2323#include <event.h>
    24 #include "encryption.h"
     24#include "crypto.h"
    2525#include "utils.h"
    2626
     
    5050    }
    5151    SHA1_Final( setme, &sha );
    52  
    53 
    54 }
    55 
    56 void
    57 tr_sha1_buf( struct evbuffer  * outbuf,
    58              const void       * content1,
    59              int                content1_len,
    60              ... )
    61 {
    62     uint8_t shabuf[SHA_DIGEST_LENGTH];
    63     va_list vl;
    64     SHA_CTX sha;
    65 
    66     SHA1_Init( &sha );
    67     SHA1_Update( &sha, content1, content1_len );
    68 
    69     va_start( vl, content1_len );
    70     for( ;; ) {
    71         const void * content = (const void*) va_arg( vl, const void* );
    72         const int content_len = content ? (int) va_arg( vl, int ) : -1;
    73         if( content==NULL || content_len<1 )
    74             break;
    75         SHA1_Update( &sha, content, content_len );
    76     }
    77     SHA1_Final( shabuf, &sha );
    78 
    79     evbuffer_add( outbuf, shabuf, SHA_DIGEST_LENGTH );
    8052}
    8153
     
    10274static const uint8_t dh_G[] = { 2 };
    10375
    104 struct tr_encryption
     76struct tr_crypto
    10577{
    10678    DH * dh;
     
    12092**/
    12193
    122 tr_encryption *
    123 tr_encryptionNew( const uint8_t * torrentHash,
    124                   int             isIncoming )
     94tr_crypto *
     95tr_cryptoNew( const uint8_t * torrentHash,
     96              int             isIncoming )
    12597{
    12698    int len, offset;
    127     tr_encryption * e;
    128 
    129     e = tr_new0( tr_encryption, 1 );
    130     e->isIncoming = isIncoming ? 1 : 0;
    131     tr_encryptionSetTorrentHash( e, torrentHash );
    132 
    133     e->dh = DH_new( );
    134     e->dh->p = BN_bin2bn( dh_P, sizeof(dh_P), NULL );
    135     e->dh->g = BN_bin2bn( dh_G, sizeof(dh_G), NULL );
    136     DH_generate_key( e->dh );
     99    tr_crypto * crypto;
     100
     101    crypto = tr_new0( tr_crypto, 1 );
     102    crypto->isIncoming = isIncoming ? 1 : 0;
     103    tr_cryptoSetTorrentHash( crypto, torrentHash );
     104
     105    crypto->dh = DH_new( );
     106    crypto->dh->p = BN_bin2bn( dh_P, sizeof(dh_P), NULL );
     107    crypto->dh->g = BN_bin2bn( dh_G, sizeof(dh_G), NULL );
     108    DH_generate_key( crypto->dh );
    137109
    138110    // DH can generate key sizes that are smaller than the size of
    139111    // P with exponentially decreasing probability, in which case
    140112    // the msb's of myPublicKey need to be zeroed appropriately.
    141     len = DH_size( e->dh );
     113    len = DH_size( crypto->dh );
    142114    offset = KEY_LEN - len;
    143115    assert( len <= KEY_LEN );
    144     memset( e->myPublicKey, 0, offset );
    145     BN_bn2bin( e->dh->pub_key, e->myPublicKey + offset );
    146 
    147     return e;
    148 }
    149 
    150 void
    151 tr_encryptionFree( tr_encryption * e )
    152 {
    153     assert( e != NULL );
    154     assert( e->dh != NULL );
    155 
    156     DH_free( e->dh );
    157     tr_free( e );
     116    memset( crypto->myPublicKey, 0, offset );
     117    BN_bn2bin( crypto->dh->pub_key, crypto->myPublicKey + offset );
     118
     119    return crypto;
     120}
     121
     122void
     123tr_cryptoFree( tr_crypto * crypto )
     124{
     125    assert( crypto != NULL );
     126    assert( crypto->dh != NULL );
     127
     128    DH_free( crypto->dh );
     129    tr_free( crypto );
    158130}
    159131
     
    163135
    164136const uint8_t*
    165 tr_encryptionComputeSecret( tr_encryption * e,
    166                             const uint8_t * peerPublicKey )
     137tr_cryptoComputeSecret( tr_crypto      * crypto,
     138                        const uint8_t * peerPublicKey )
    167139{
    168140    int len, offset;
    169141    uint8_t secret[KEY_LEN];
    170142    BIGNUM * bn = BN_bin2bn( peerPublicKey, KEY_LEN, NULL );
    171     assert( DH_size(e->dh) == KEY_LEN );
    172 
    173     len = DH_compute_key( secret, bn, e->dh );
     143    assert( DH_size(crypto->dh) == KEY_LEN );
     144
     145    len = DH_compute_key( secret, bn, crypto->dh );
    174146    assert( len <= KEY_LEN );
    175147    offset = KEY_LEN - len;
    176     memset( e->mySecret, 0, offset );
    177     memcpy( e->mySecret + offset, secret, len );
    178     e->mySecretIsSet = 1;
     148    memset( crypto->mySecret, 0, offset );
     149    memcpy( crypto->mySecret + offset, secret, len );
     150    crypto->mySecretIsSet = 1;
    179151   
    180152    BN_free( bn );
    181153
    182     return e->mySecret;
     154    return crypto->mySecret;
    183155}
    184156
    185157const uint8_t*
    186 tr_encryptionGetMyPublicKey( const tr_encryption * e, int * setme_len )
     158tr_cryptoGetMyPublicKey( const tr_crypto * crypto, int * setme_len )
    187159{
    188160    *setme_len = KEY_LEN;
    189     return e->myPublicKey;
     161    return crypto->myPublicKey;
    190162}
    191163
     
    195167
    196168static void
    197 initRC4( tr_encryption * e, RC4_KEY * setme, const char * key )
     169initRC4( tr_crypto * crypto, RC4_KEY * setme, const char * key )
    198170{
    199171    SHA_CTX sha;
    200172    uint8_t buf[SHA_DIGEST_LENGTH];
    201173
    202     assert( e->torrentHashIsSet );
    203     assert( e->mySecretIsSet );
     174    assert( crypto->torrentHashIsSet );
     175    assert( crypto->mySecretIsSet );
    204176
    205177    SHA1_Init( &sha );
    206178    SHA1_Update( &sha, key, 4 );
    207     SHA1_Update( &sha, e->mySecret, KEY_LEN );
    208     SHA1_Update( &sha, e->torrentHash, SHA_DIGEST_LENGTH );
     179    SHA1_Update( &sha, crypto->mySecret, KEY_LEN );
     180    SHA1_Update( &sha, crypto->torrentHash, SHA_DIGEST_LENGTH );
    209181    SHA1_Final( buf, &sha );
    210182    RC4_set_key( setme, SHA_DIGEST_LENGTH, buf );
     
    212184
    213185void
    214 tr_encryptionDecryptInit( tr_encryption * encryption )
     186tr_cryptoDecryptInit( tr_crypto * crypto )
    215187{
    216188    unsigned char discard[1024];
    217     const char * txt = encryption->isIncoming ? "keyA" : "keyB";
    218     initRC4( encryption, &encryption->dec_key, txt );
    219     RC4( &encryption->dec_key, sizeof(discard), discard, discard );
    220 }
    221 
    222 void
    223 tr_encryptionDecrypt( tr_encryption * encryption,
    224                       size_t          buf_len,
    225                       const void    * buf_in,
    226                       void          * buf_out )
    227 {
    228     RC4( &encryption->dec_key, buf_len,
     189    const char * txt = crypto->isIncoming ? "keyA" : "keyB";
     190    initRC4( crypto, &crypto->dec_key, txt );
     191    RC4( &crypto->dec_key, sizeof(discard), discard, discard );
     192}
     193
     194void
     195tr_cryptoDecrypt( tr_crypto  * crypto,
     196                  size_t       buf_len,
     197                  const void * buf_in,
     198                  void       * buf_out )
     199{
     200    RC4( &crypto->dec_key, buf_len,
    229201         (const unsigned char*)buf_in,
    230202         (unsigned char*)buf_out );
     
    232204
    233205void
    234 tr_encryptionEncryptInit( tr_encryption * encryption )
     206tr_cryptoEncryptInit( tr_crypto * crypto )
    235207{
    236208    unsigned char discard[1024];
    237     const char * txt = encryption->isIncoming ? "keyB" : "keyA";
    238     initRC4( encryption, &encryption->enc_key, txt );
    239     RC4( &encryption->enc_key, sizeof(discard), discard, discard );
    240 }
    241 
    242 void
    243 tr_encryptionEncrypt( tr_encryption * encryption,
    244                       size_t          buf_len,
    245                       const void    * buf_in,
    246                       void          * buf_out )
    247 {
    248     RC4( &encryption->enc_key, buf_len,
     209    const char * txt = crypto->isIncoming ? "keyB" : "keyA";
     210    initRC4( crypto, &crypto->enc_key, txt );
     211    RC4( &crypto->enc_key, sizeof(discard), discard, discard );
     212}
     213
     214void
     215tr_cryptoEncrypt( tr_crypto  * crypto,
     216                  size_t       buf_len,
     217                  const void * buf_in,
     218                  void       * buf_out )
     219{
     220    RC4( &crypto->enc_key, buf_len,
    249221         (const unsigned char*)buf_in,
    250222         (unsigned char*)buf_out );
     
    256228
    257229void
    258 tr_encryptionSetTorrentHash( tr_encryption * e,
    259                              const uint8_t * hash )
    260 {
    261     e->torrentHashIsSet = hash ? 1 : 0;
     230tr_cryptoSetTorrentHash( tr_crypto     * crypto,
     231                         const uint8_t * hash )
     232{
     233    crypto->torrentHashIsSet = hash ? 1 : 0;
    262234
    263235    if( hash != NULL )
    264         memcpy( e->torrentHash, hash, SHA_DIGEST_LENGTH );
     236        memcpy( crypto->torrentHash, hash, SHA_DIGEST_LENGTH );
    265237    else
    266         memset( e->torrentHash, 0, SHA_DIGEST_LENGTH );
     238        memset( crypto->torrentHash, 0, SHA_DIGEST_LENGTH );
    267239}
    268240
    269241const uint8_t*
    270 tr_encryptionGetTorrentHash( const tr_encryption * e )
    271 {
    272     assert( e->torrentHashIsSet );
    273 
    274     return e->torrentHash;
    275 }
     242tr_cryptoGetTorrentHash( const tr_crypto * crypto )
     243{
     244    assert( crypto->torrentHashIsSet );
     245
     246    return crypto->torrentHash;
     247}
  • branches/encryption/libtransmission/crypto.h

    r2936 r2938  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
     
    2121
    2222struct evbuffer;
    23 typedef struct tr_encryption tr_encryption;
     23typedef struct tr_crypto tr_crypto;
    2424
    2525/**
     
    2727**/
    2828
    29 tr_encryption*  tr_encryptionNew ( const uint8_t * torrentHash,
    30                                    int             isIncoming );
     29tr_crypto*  tr_cryptoNew ( const uint8_t * torrentHash,
     30                           int             isIncoming );
    3131
    32 void            tr_encryptionFree( tr_encryption * encryption );
     32void            tr_cryptoFree( tr_crypto * crypto );
    3333
    3434/**
     
    3636**/
    3737
    38 void            tr_encryptionSetTorrentHash( tr_encryption * encryption,
    39                                              const uint8_t * torrentHash );
     38void            tr_cryptoSetTorrentHash( tr_crypto     * crypto,
     39                                         const uint8_t * torrentHash );
    4040
    41 const uint8_t*  tr_encryptionGetTorrentHash( const tr_encryption * encryption );
     41const uint8_t*  tr_cryptoGetTorrentHash( const tr_crypto * crypto );
    4242
    4343/**
     
    4545**/
    4646
    47 const uint8_t*  tr_encryptionComputeSecret   ( tr_encryption * encryption,
    48                                                const uint8_t * peerPublicKey );
     47const uint8_t*  tr_cryptoComputeSecret   ( tr_crypto     * crypto,
     48                                           const uint8_t * peerPublicKey );
    4949
    50 const uint8_t*  tr_encryptionGetMyPublicKey ( const tr_encryption * encryption,
    51                                               int                 * setme_len );
     50const uint8_t*  tr_cryptoGetMyPublicKey ( const tr_crypto * crypto,
     51                                          int             * setme_len );
    5252
    53 void            tr_encryptionDecryptInit( tr_encryption * encryption );
     53void            tr_cryptoDecryptInit( tr_crypto   * crypto );
    5454
    55 void            tr_encryptionDecrypt    ( tr_encryption  * encryption,
    56                                           size_t           buflen,
    57                                           const void     * buf_in,
    58                                           void           * buf_out );
     55void            tr_cryptoDecrypt    ( tr_crypto   * crypto,
     56                                      size_t        buflen,
     57                                      const void  * buf_in,
     58                                      void        * buf_out );
    5959
    60 void            tr_encryptionEncryptInit( tr_encryption * encryption );
     60void            tr_cryptoEncryptInit( tr_crypto   * crypto );
    6161
    62 void            tr_encryptionEncrypt    ( tr_encryption  * encryption,
    63                                           size_t           buflen,
    64                                           const void     * buf_in,
    65                                           void           * buf_out );
     62void            tr_cryptoEncrypt    ( tr_crypto   * crypto,
     63                                      size_t        buflen,
     64                                      const void  * buf_in,
     65                                      void        * buf_out );
    6666
    6767/**
     
    6969**/
    7070
    71 
    72 
    73 void            tr_sha1( uint8_t* setme,
    74                          const void * content1, int content1_len,
    75                          ... );
    76 
    77 void            tr_sha1_buf( struct evbuffer* outbuf,
    78                              const void * content1, int content1_len,
    79                              ... );
     71void  tr_sha1( uint8_t* setme,
     72               const void * content1, int content1_len,
     73               ... );
    8074
    8175/**
  • branches/encryption/libtransmission/handshake.c

    r2936 r2938  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
     
    2424#include <event.h>
    2525
    26 #include "transmission.h"
    27 #include "encryption.h"
    28 #include "handshake.h"
    29 #include "peer-connection.h"
    30 #include "utils.h"
     26#include <libtransmission/transmission.h>
     27#include <libtransmission/crypto.h>
     28#include <libtransmission/handshake.h>
     29#include <libtransmission/peer-connection.h>
     30#include <libtransmission/utils.h>
    3131
    3232/***
     
    7878{
    7979    tr_peerConnection * connection;
    80     tr_encryption * encryption;
     80    tr_crypto * crypto;
    8181    struct tr_handle * handle;
    8282    uint8_t myPublicKey[96];
     
    180180
    181181    /* add our public key (Ya) */
    182     public_key = tr_encryptionGetMyPublicKey( handshake->encryption, &len );
     182    public_key = tr_cryptoGetMyPublicKey( handshake->crypto, &len );
    183183    assert( len == KEY_LEN );
    184184    assert( public_key != NULL );
     
    203203{
    204204    uint8_t *walk = buf;
    205     const uint8_t * torrentHash = tr_encryptionGetTorrentHash( handshake->encryption );
     205    const uint8_t * torrentHash = tr_cryptoGetTorrentHash( handshake->crypto );
    206206
    207207    memcpy( walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN );
     
    259259    /* read the incoming peer's public key */
    260260    evbuffer_remove( inbuf, ya, KEY_LEN );
    261     secret = tr_encryptionComputeSecret( handshake->encryption, ya );
     261    secret = tr_cryptoComputeSecret( handshake->crypto, ya );
    262262    memcpy( handshake->mySecret, secret, KEY_LEN );
    263263    tr_sha1( handshake->myReq1, "req1", 4, secret, KEY_LEN, NULL );
     
    265265    /* send our public key to the peer */
    266266    walk = outbuf;
    267     myKey = tr_encryptionGetMyPublicKey( handshake->encryption, &len );
     267    myKey = tr_cryptoGetMyPublicKey( handshake->crypto, &len );
    268268    memcpy( walk, myKey, len );
    269269    len = tr_rand( 512 );
     
    340340    /* next part: ENCRYPT(VC, crypto_provide, len(PadC), */
    341341
    342     tr_encryptionDecryptInit( handshake->encryption );
     342    tr_cryptoDecryptInit( handshake->crypto );
    343343
    344344    evbuffer_remove( inbuf, vc_in, VC_LENGTH );
    345     tr_encryptionDecrypt( handshake->encryption, VC_LENGTH, vc_in, vc_in );
     345    tr_cryptoDecrypt( handshake->crypto, VC_LENGTH, vc_in, vc_in );
    346346    fprintf( stderr, "read vc -> %d %d %d %d %d %d %d %d\n",
    347347        (int)vc_in[0], (int)vc_in[1], (int)vc_in[2], (int)vc_in[3],
     
    349349
    350350    evbuffer_remove( inbuf, &crypto_provide, sizeof(crypto_provide) );
    351     tr_encryptionDecrypt( handshake->encryption, sizeof(crypto_provide),
     351    tr_cryptoDecrypt( handshake->crypto, sizeof(crypto_provide),
    352352                          &crypto_provide, &crypto_provide );
    353353    crypto_provide = ntohl( crypto_provide );
     
    355355
    356356    evbuffer_remove( inbuf, &padc_len, sizeof(padc_len) );
    357     tr_encryptionDecrypt( handshake->encryption, sizeof(padc_len), &padc_len, &padc_len );
     357    tr_cryptoDecrypt( handshake->crypto, sizeof(padc_len), &padc_len, &padc_len );
    358358    padc_len = ntohs( padc_len );
    359359    fprintf( stderr, "padc is %d\n", (int)padc_len );
     
    393393    ia = tr_new( uint8_t, handshake->ia_len );
    394394    evbuffer_remove( inbuf, ia, handshake->ia_len );
    395     tr_encryptionDecrypt( handshake->encryption, handshake->ia_len, ia, ia );
     395    tr_cryptoDecrypt( handshake->crypto, handshake->ia_len, ia, ia );
    396396    fprintf( stderr, "got their payload ia: [%*.*s]\n", (int)needlen, (int)needlen, ia );
    397397
     
    425425    /* compute the secret */
    426426    evbuffer_remove( inbuf, yb, KEY_LEN );
    427     secret = tr_encryptionComputeSecret( handshake->encryption, yb );
     427    secret = tr_cryptoComputeSecret( handshake->crypto, yb );
    428428    memcpy( handshake->mySecret, secret, KEY_LEN );
    429429
     
    445445        uint8_t req3[SHA_DIGEST_LENGTH];
    446446        uint8_t buf[SHA_DIGEST_LENGTH];
    447         tr_sha1( req2, "req2", 4, tr_encryptionGetTorrentHash(handshake->encryption), SHA_DIGEST_LENGTH, NULL );
     447        tr_sha1( req2, "req2", 4, tr_cryptoGetTorrentHash(handshake->crypto), SHA_DIGEST_LENGTH, NULL );
    448448        tr_sha1( req3, "req3", 4, secret, KEY_LEN, NULL );
    449449        for( i=0; i<SHA_DIGEST_LENGTH; ++i )
     
    459459        uint32_t crypto_provide;
    460460
    461         tr_encryptionEncryptInit( handshake->encryption );
     461        tr_cryptoEncryptInit( handshake->crypto );
    462462       
    463463        /* vc */
    464         tr_encryptionEncrypt( handshake->encryption, VC_LENGTH, vc, vc );
     464        tr_cryptoEncrypt( handshake->crypto, VC_LENGTH, vc, vc );
    465465        evbuffer_add( outbuf, vc, VC_LENGTH );
    466466
     
    473473        assert( 1<=crypto_provide && crypto_provide<=3 );
    474474        crypto_provide = htonl( crypto_provide );
    475         tr_encryptionEncrypt( handshake->encryption, sizeof(crypto_provide), &crypto_provide, &crypto_provide );
     475        tr_cryptoEncrypt( handshake->crypto, sizeof(crypto_provide), &crypto_provide, &crypto_provide );
    476476fprintf( stderr, "crypto_provide is [%d]\n", crypto_provide );
    477477        evbuffer_add( outbuf, &crypto_provide, sizeof(crypto_provide) );
     
    480480        i = len = tr_rand( 512 );
    481481        i = htons( i );
    482         tr_encryptionEncrypt( handshake->encryption, sizeof(i), &i, &i );
     482        tr_cryptoEncrypt( handshake->crypto, sizeof(i), &i, &i );
    483483        evbuffer_add( outbuf, &i, sizeof(i) );
    484484
     
    495495
    496496        i = htons( HANDSHAKE_SIZE );
    497         tr_encryptionEncrypt( handshake->encryption, sizeof(uint16_t), &i, &i );
     497        tr_cryptoEncrypt( handshake->crypto, sizeof(uint16_t), &i, &i );
    498498        evbuffer_add( outbuf, &i, sizeof(uint16_t) );
    499499
    500         tr_encryptionEncrypt( handshake->encryption, HANDSHAKE_SIZE, msg, msg );
     500        tr_cryptoEncrypt( handshake->crypto, HANDSHAKE_SIZE, msg, msg );
    501501        evbuffer_add( outbuf, msg, HANDSHAKE_SIZE );
    502502    }
    503503
    504504    /* send it */
    505     tr_encryptionDecryptInit( handshake->encryption );
     505    tr_cryptoDecryptInit( handshake->crypto );
    506506    setState( handshake, SENDING_CRYPTO_PROVIDE );
    507507    tr_peerConnectionWriteBuf( handshake->connection, outbuf );
     
    528528
    529529        memcpy( tmp, EVBUFFER_DATA(inbuf), key_len );
    530         tr_encryptionDecryptInit( handshake->encryption );
    531         tr_encryptionDecrypt( handshake->encryption, key_len, tmp, tmp );
     530        tr_cryptoDecryptInit( handshake->crypto );
     531        tr_cryptoDecrypt( handshake->crypto, key_len, tmp, tmp );
    532532        if( !memcmp( tmp, key, key_len ) )
    533533            break;
     
    552552        return READ_MORE;
    553553
    554  //   tr_encryptionDecryptInit( handshake->encryption );
     554 //   tr_cryptoDecryptInit( handshake->crypto );
    555555
    556556    evbuffer_remove( inbuf, &crypto_select, sizeof(uint32_t) );
    557     tr_encryptionDecrypt( handshake->encryption, sizeof(uint32_t), &crypto_select, &crypto_select );
     557    tr_cryptoDecrypt( handshake->crypto, sizeof(uint32_t), &crypto_select, &crypto_select );
    558558    fprintf( stderr, "crypto select 1 is %d\n", crypto_select );
    559559    crypto_select = ntohl( crypto_select );
     
    563563
    564564    evbuffer_remove( inbuf, &pad_d_len, sizeof(uint16_t) );
    565     tr_encryptionDecrypt( handshake->encryption, sizeof(uint16_t), &pad_d_len, &pad_d_len );
     565    tr_cryptoDecrypt( handshake->crypto, sizeof(uint16_t), &pad_d_len, &pad_d_len );
    566566    pad_d_len = ntohs( pad_d_len );
    567567    fprintf( stderr, "pad_d_len is %d\n", (int)pad_d_len );
     
    585585    buf = tr_new( uint8_t, needlen );
    586586    evbuffer_remove( inbuf, buf, needlen );
    587     tr_encryptionDecrypt( handshake->encryption, needlen, buf, buf );
     587    tr_cryptoDecrypt( handshake->crypto, needlen, buf, buf );
    588588    tr_free( buf );
    589589
     
    617617    if( encrypted ) {
    618618        fprintf( stderr, "clearly it's encrypted...\n" );
    619         //tr_encryptionDecryptInit( handshake->encryption );
    620         tr_encryptionDecrypt( handshake->encryption, 1, &pstrlen, &pstrlen );
     619        //tr_cryptoDecryptInit( handshake->crypto );
     620        tr_cryptoDecrypt( handshake->crypto, 1, &pstrlen, &pstrlen );
    621621    }
    622622    fprintf( stderr, "pstrlen is %d [%c]\n", (int)pstrlen, pstrlen );
     
    627627    evbuffer_remove( inbuf, pstr, pstrlen );
    628628    if( encrypted )
    629         tr_encryptionDecrypt( handshake->encryption, pstrlen, pstr, pstr );
     629        tr_cryptoDecrypt( handshake->crypto, pstrlen, pstr, pstr );
    630630    pstr[pstrlen] = '\0';
    631631    fprintf( stderr, "pstrlen is [%s]\n", pstr );
     
    635635    evbuffer_remove( inbuf, reserved, sizeof(reserved) );
    636636    if( encrypted )
    637         tr_encryptionDecrypt( handshake->encryption, sizeof(reserved), reserved, reserved );
     637        tr_cryptoDecrypt( handshake->crypto, sizeof(reserved), reserved, reserved );
    638638
    639639    /* torrent hash */
    640640    evbuffer_remove( inbuf, hash, sizeof(hash) );
    641641    if( encrypted )
    642         tr_encryptionDecrypt( handshake->encryption, sizeof(hash), hash, hash );
     642        tr_cryptoDecrypt( handshake->crypto, sizeof(hash), hash, hash );
    643643    assert( !memcmp( hash, tr_peerConnectionGetTorrent(handshake->connection)->info.hash, SHA_DIGEST_LENGTH ) );
    644644
     
    647647    evbuffer_remove( inbuf, peer_id, sizeof(peer_id) );
    648648    if( encrypted )
    649         tr_encryptionDecrypt( handshake->encryption, sizeof(peer_id), peer_id, peer_id );
     649        tr_cryptoDecrypt( handshake->crypto, sizeof(peer_id), peer_id, peer_id );
    650650    fprintf( stderr, "peer_id: " );
    651651    for( i=0; i<20; ++i ) fprintf( stderr, "[%c]", peer_id[i] );
     
    790790    handshake = tr_new0( tr_handshake, 1 );
    791791    handshake->connection = connection;
    792     handshake->encryption = tr_peerConnectionGetEncryption( connection );
     792    handshake->crypto = tr_peerConnectionGetCrypto( connection );
    793793    handshake->encryptionPreference = encryptionPreference;
    794794    handshake->doneCB = doneCB;
  • branches/encryption/libtransmission/inout.c

    r2936 r2938  
    2121#include "transmission.h"
    2222#include "completion.h"
    23 #include "encryption.h"
     23#include "crypto.h"
    2424#include "fdlimit.h"
    2525#include "inout.h"
  • branches/encryption/libtransmission/makemeta.c

    r2936 r2938  
    2222#include <dirent.h>
    2323
    24 #include "encryption.h" /* tr_sha1 */
     24#include "crypto.h" /* tr_sha1 */
    2525#include "trcompat.h" /* strlcpy */
    2626#include "transmission.h"
  • branches/encryption/libtransmission/metainfo.c

    r2936 r2938  
    3434#include "transmission.h"
    3535#include "bencode.h"
    36 #include "encryption.h" /* tr_sha1 */
     36#include "crypto.h" /* tr_sha1 */
    3737#include "http.h" /* tr_httpParseUrl */
    3838#include "metainfo.h"
  • branches/encryption/libtransmission/peer-connection.c

    r2936 r2938  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
     
    1818#include <event.h>
    1919#include "transmission.h"
    20 #include "encryption.h"
     20#include "crypto.h"
    2121#include "net.h"
    2222#include "peer-connection.h"
     
    4949    void             * userData;
    5050
    51     tr_encryption * encryption;
     51    tr_crypto * crypto;
    5252};
    5353
     
    103103    c = tr_new0( tr_peerConnection, 1 );
    104104    c->torrent = torrent;
    105     c->encryption = tr_encryptionNew( torrent ? torrent->info.hash : NULL, isIncoming );
     105    c->crypto = tr_cryptoNew( torrent ? torrent->info.hash : NULL, isIncoming );
    106106    c->handle = handle;
    107107    c->in_addr = *in_addr;
     
    150150    bufferevent_free( c->bufev );
    151151    tr_netClose( c->socket );
    152     tr_encryptionFree( c->encryption );
     152    tr_cryptoFree( c->crypto );
    153153    tr_free( c );
    154154}
     
    203203
    204204
    205 tr_encryption*
    206 tr_peerConnectionGetEncryption( tr_peerConnection * c )
    207 {
    208     return c->encryption;
     205tr_crypto*
     206tr_peerConnectionGetCrypto( tr_peerConnection * c )
     207{
     208    return c->crypto;
    209209}
    210210
     
    243243    connection->torrent = torrent;
    244244
    245     tr_encryptionSetTorrentHash( connection->encryption, torrent->info.hash );
     245    tr_cryptoSetTorrentHash( connection->crypto, torrent->info.hash );
    246246}
    247247
  • branches/encryption/libtransmission/peer-connection.h

    r2936 r2938  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
     
    2222struct bufferevent;
    2323struct tr_handle;
    24 struct tr_encryption;
     24struct tr_crypto;
    2525struct tr_torrent;
    2626typedef struct tr_peerConnection tr_peerConnection;
     
    100100**/
    101101
    102 struct tr_encryption*
    103       tr_peerConnectionGetEncryption( tr_peerConnection * connection );
     102struct tr_crypto*
     103      tr_peerConnectionGetCrypto( tr_peerConnection * connection );
    104104
    105105/**
  • branches/encryption/libtransmission/torrent.c

    r2936 r2938  
    3232#include "transmission.h"
    3333#include "completion.h"
    34 #include "encryption.h"
     34#include "crypto.h" /* for tr_sha1 */
    3535#include "fastresume.h"
    3636#include "handshake.h"
Note: See TracChangeset for help on using the changeset viewer.