(trunk libT) #3638 "fewer crypto calls when creating peer-ids, session ids, announcer keys, etc" -- fixed.

This commit is contained in:
Charles Kerr 2010-10-17 18:32:55 +00:00
parent 97d992bba0
commit ad613b05f7
4 changed files with 15 additions and 12 deletions

View File

@ -315,7 +315,7 @@ typedef struct
* to verify us if our IP address changes.
* This is immutable for the life of the tracker object.
* The +1 is for '\0' */
char key_param[KEYLEN + 1];
unsigned char key_param[KEYLEN + 1];
}
tr_tracker_item;
@ -334,15 +334,16 @@ trackerItemCopyAttributes( tr_tracker_item * t, const tr_tracker_item * o )
}
static void
generateKeyParam( char * msg, size_t msglen )
generateKeyParam( unsigned char * msg, size_t msglen )
{
size_t i;
const char * pool = "abcdefghijklmnopqrstuvwxyz0123456789";
const int poolSize = 36;
tr_cryptoRandBuf( msg, msglen );
for( i=0; i<msglen; ++i )
*msg++ = pool[tr_cryptoRandInt( poolSize )];
*msg = '\0';
msg[i] = pool[ msg[i] % poolSize ];
msg[msglen] = '\0';
}
static tr_tracker_item*

View File

@ -376,12 +376,13 @@ tr_ssha1( const void * plaintext )
"./";
size_t i;
char salt[saltval_len];
unsigned char salt[saltval_len];
uint8_t sha[SHA_DIGEST_LENGTH];
char buf[2*SHA_DIGEST_LENGTH + saltval_len + 2];
tr_cryptoRandBuf( salt, saltval_len );
for( i=0; i<saltval_len; ++i )
salt[i] = salter[ tr_cryptoRandInt( salter_len ) ];
salt[i] = salter[ salt[i] % salter_len ];
tr_sha1( sha, plaintext, strlen( plaintext ), salt, saltval_len, NULL );
tr_sha1_to_hex( &buf[1], sha );

View File

@ -100,14 +100,15 @@ get_current_session_id( struct tr_rpc_server * server )
const int n = 48;
const char * pool = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const size_t pool_size = strlen( pool );
char * buf = tr_new( char, n+1 );
unsigned char * buf = tr_new( unsigned char, n+1 );
tr_cryptoRandBuf( buf, n );
for( i=0; i<n; ++i )
buf[i] = pool[ tr_cryptoRandInt( pool_size ) ];
buf[i] = pool[ buf[i] % pool_size ];
buf[n] = '\0';
tr_free( server->sessionId );
server->sessionId = buf;
server->sessionId = (char*) buf;
server->sessionIdExpiresAt = now + (60*60); /* expire in an hour */
}

View File

@ -87,9 +87,9 @@ tr_peerIdNew( void )
memcpy( buf, PEERID_PREFIX, 8 );
for( i = 8; i < 19; ++i )
{
val = tr_cryptoRandInt( base );
tr_cryptoRandBuf( buf+8, 11 );
for( i=8; i<19; ++i ) {
val = buf[i] % base;
total += val;
buf[i] = pool[val];
}