(trunk libT) avoid an extra malloc/free when sending the opening handshake message
This commit is contained in:
parent
837186679d
commit
13cac341cd
|
@ -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( );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue