Changeset 3405
- Timestamp:
- Oct 13, 2007, 11:15:43 PM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/crypto.c
r3360 r3405 77 77 struct tr_crypto 78 78 { 79 DH * dh;80 79 RC4_KEY dec_key; 81 80 RC4_KEY enc_key; … … 86 85 uint8_t myPublicKey[KEY_LEN]; 87 86 uint8_t mySecret[KEY_LEN]; 88 89 87 }; 90 88 91 static void 92 ensureKeyExists( tr_crypto * crypto ) 93 { 94 if( crypto->dh == NULL ) 89 /** 90 *** 91 **/ 92 93 static DH* 94 getSharedDH( void ) 95 { 96 static DH * dh = NULL; 97 98 if( dh == NULL ) 95 99 { 96 int len, offset; 97 98 crypto->dh = DH_new( ); 99 crypto->dh->p = BN_bin2bn( dh_P, sizeof(dh_P), NULL ); 100 crypto->dh->g = BN_bin2bn( dh_G, sizeof(dh_G), NULL ); 101 DH_generate_key( crypto->dh ); 102 103 /* DH can generate key sizes that are smaller than the size of 104 P with exponentially decreasing probability, in which case 105 the msb's of myPublicKey need to be zeroed appropriately. */ 106 len = DH_size( crypto->dh ); 107 offset = KEY_LEN - len; 108 assert( len <= KEY_LEN ); 109 memset( crypto->myPublicKey, 0, offset ); 110 BN_bn2bin( crypto->dh->pub_key, crypto->myPublicKey + offset ); 100 dh = DH_new( ); 101 dh->p = BN_bin2bn( dh_P, sizeof(dh_P), NULL ); 102 dh->g = BN_bin2bn( dh_G, sizeof(dh_G), NULL ); 103 DH_generate_key( dh ); 111 104 } 112 } 113 114 /** 115 *** 116 **/ 105 106 return dh; 107 } 117 108 118 109 tr_crypto * … … 120 111 int isIncoming ) 121 112 { 113 int len, offset; 122 114 tr_crypto * crypto; 115 DH * dh = getSharedDH( ); 123 116 124 117 crypto = tr_new0( tr_crypto, 1 ); 125 118 crypto->isIncoming = isIncoming ? 1 : 0; 126 crypto->dh = NULL;127 119 tr_cryptoSetTorrentHash( crypto, torrentHash ); 120 121 /* DH can generate key sizes that are smaller than the size of 122 P with exponentially decreasing probability, in which case 123 the msb's of myPublicKey need to be zeroed appropriately. */ 124 len = DH_size( dh ); 125 offset = KEY_LEN - len; 126 assert( len <= KEY_LEN ); 127 memset( crypto->myPublicKey, 0, offset ); 128 BN_bn2bin( dh->pub_key, crypto->myPublicKey + offset ); 129 128 130 return crypto; 129 131 } … … 132 134 tr_cryptoFree( tr_crypto * crypto ) 133 135 { 134 assert( crypto != NULL );135 if( crypto->dh != NULL )136 DH_free( crypto->dh );137 136 tr_free( crypto ); 138 137 } … … 149 148 uint8_t secret[KEY_LEN]; 150 149 BIGNUM * bn = BN_bin2bn( peerPublicKey, KEY_LEN, NULL ); 151 152 ensureKeyExists( crypto ); 153 assert( DH_size( crypto->dh ) == KEY_LEN ); 154 155 len = DH_compute_key( secret, bn, crypto->dh ); 150 DH * dh = getSharedDH( ); 151 assert( DH_size(dh) == KEY_LEN ); 152 153 len = DH_compute_key( secret, bn, dh ); 156 154 assert( len <= KEY_LEN ); 157 155 offset = KEY_LEN - len; … … 168 166 tr_cryptoGetMyPublicKey( const tr_crypto * crypto, int * setme_len ) 169 167 { 170 ensureKeyExists( (tr_crypto*) crypto );171 168 *setme_len = KEY_LEN; 172 169 return crypto->myPublicKey; -
trunk/libtransmission/peer-msgs.c
r3393 r3405 70 70 KEEPALIVE_INTERVAL_SECS = 90, /* idle seconds before we send a keepalive */ 71 71 PEX_INTERVAL = (60 * 1000), /* msec between calls to sendPex() */ 72 PEER_PULSE_INTERVAL = ( 66), /* msec between calls to pulse() */72 PEER_PULSE_INTERVAL = (20), /* msec between calls to pulse() */ 73 73 RATE_PULSE_INTERVAL = (333), /* msec between calls to ratePulse() */ 74 74 };
Note: See TracChangeset
for help on using the changeset viewer.