Ignore:
Timestamp:
Feb 11, 2009, 4:07:45 PM (13 years ago)
Author:
charles
Message:

(1.5x libT) backport r7870 and r7866 to the 1.5x branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.5x/libtransmission/crypto.c

    r7863 r7873  
    307307
    308308int
    309 tr_cryptoRandInt( int sup )
    310 {
    311     int r;
    312 
    313     RAND_pseudo_bytes ( (unsigned char *) &r, sizeof r );
    314 
    315     return (int) ( sup * ( abs( r ) / ( INT_MAX + 1.0 ) ) );
     309tr_cryptoRandInt( int upperBound )
     310{
     311    int noise;
     312    int val;
     313
     314    if( RAND_pseudo_bytes ( (unsigned char *) &noise, sizeof noise ) >= 0 )
     315    {
     316        val = abs( noise ) % upperBound;
     317    }
     318    else /* fall back to a weaker implementation... */
     319    {
     320        val = tr_cryptoWeakRandInt( upperBound );
     321    }
     322
     323    assert( val >= 0 );
     324    assert( val < upperBound );
     325    return val;
    316326}
    317327
    318328int
    319 tr_cryptoWeakRandInt( int sup )
     329tr_cryptoWeakRandInt( int upperBound )
    320330{
    321331    static int init = 0;
    322332
    323     assert( sup > 0 );
     333    assert( upperBound > 0 );
    324334
    325335    if( !init )
     
    329339    }
    330340
    331     return rand( ) % sup;
     341    return rand( ) % upperBound;
    332342}
    333343
Note: See TracChangeset for help on using the changeset viewer.