(trunk libT) avoid an extra malloc/free when sending the opening handshake message

This commit is contained in:
Charles Kerr 2009-06-14 14:39:51 +00:00
parent 837186679d
commit 13cac341cd
4 changed files with 10 additions and 15 deletions

View File

@ -349,10 +349,9 @@ tr_cryptoWeakRandInt( int upperBound )
}
void
tr_cryptoRandBuf( unsigned char *buf,
size_t len )
tr_cryptoRandBuf( void * buf, size_t len )
{
if( RAND_pseudo_bytes ( buf, len ) != 1 )
if( RAND_pseudo_bytes ( (unsigned char*)buf, len ) != 1 )
logErrorFromSSL( );
}

View File

@ -98,8 +98,7 @@ int tr_cryptoRandInt( int n );
int tr_cryptoWeakRandInt( int n );
/** Fills a buffer with random bytes */
void tr_cryptoRandBuf( unsigned char *buf,
size_t len );
void tr_cryptoRandBuf( void * buf, size_t len );
char* tr_ssha1( const void * plaintext );

View File

@ -332,26 +332,23 @@ sendYa( tr_handshake * handshake )
{
int len;
const uint8_t * public_key;
struct evbuffer * outbuf = evbuffer_new( );
uint8_t pad_a[PadA_MAXLEN];
char outbuf[ KEY_LEN + PadA_MAXLEN ], *walk=outbuf;
/* add our public key (Ya) */
public_key = tr_cryptoGetMyPublicKey( handshake->crypto, &len );
assert( len == KEY_LEN );
assert( public_key );
evbuffer_add( outbuf, public_key, len );
memcpy( walk, public_key, len );
walk += len;
/* add some bullshit padding */
len = tr_cryptoRandInt( PadA_MAXLEN );
tr_cryptoRandBuf( pad_a, len );
evbuffer_add( outbuf, pad_a, len );
tr_cryptoRandBuf( walk, len );
walk += len;
/* send it */
setReadState( handshake, AWAITING_YB );
tr_peerIoWriteBuf( handshake->io, outbuf, FALSE );
/* cleanup */
evbuffer_free( outbuf );
tr_peerIoWrite( handshake->io, outbuf, walk-outbuf, FALSE );
}
static uint32_t

View File

@ -243,7 +243,7 @@ announceToScrape( const char * announce )
memcpy( walk, "scrape", 6 ); walk += 6;
memcpy( walk, suffix, suffix_len ); walk += suffix_len;
*walk++ = '\0';
assert( walk - scrape == alloc_len );
assert( walk - scrape == (int)alloc_len );
}
return scrape;