Changeset 4785:60919d1fa9af in roaraudio


Ignore:
Timestamp:
03/11/11 01:43:46 (9 years ago)
Author:
phi
Branch:
default
Message:

added roar_random_uint{16,32}()

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/random.h

    r4708 r4785  
    5252int roar_random_salt_nonce (void * salt, size_t len); 
    5353 
     54uint16_t roar_random_uint16(void); 
     55uint32_t roar_random_uint32(void); 
     56 
    5457int roar_random_gen(void * buffer, size_t len, int quality); 
    5558 
  • libroar/random.c

    r4755 r4785  
    5757static size_t roar_nonce_salt_len = 0; 
    5858static void * roar_nonce_salt     = NULL; 
     59 
     60static unsigned char roar_nonce_pool[TIGER_DIGESTLEN]; 
     61static size_t        roar_nonce_pool_len = 0; 
    5962 
    6063int roar_random_gen_nonce(void * buffer, size_t len) { 
     
    138141} 
    139142 
     143uint16_t roar_random_uint16(void) { 
     144 uint16_t ret; 
     145 
     146 if ( roar_nonce_pool_len < 2 ) { 
     147  roar_random_gen_nonce(roar_nonce_pool, sizeof(roar_nonce_pool)); 
     148  roar_nonce_pool_len = sizeof(roar_nonce_pool); 
     149 } 
     150 
     151 ret  = roar_nonce_pool[sizeof(roar_nonce_pool)-roar_nonce_pool_len+0] <<  0; 
     152 ret |= roar_nonce_pool[sizeof(roar_nonce_pool)-roar_nonce_pool_len+1] <<  8; 
     153 
     154 roar_nonce_pool_len -= 2; 
     155 
     156 return ret; 
     157} 
     158 
     159uint32_t roar_random_uint32(void) { 
     160 uint32_t ret; 
     161 
     162 if ( roar_nonce_pool_len < 4 ) { 
     163  roar_random_gen_nonce(roar_nonce_pool, sizeof(roar_nonce_pool)); 
     164  roar_nonce_pool_len = sizeof(roar_nonce_pool); 
     165 } 
     166 
     167 ret  = roar_nonce_pool[sizeof(roar_nonce_pool)-roar_nonce_pool_len+0] <<  0; 
     168 ret |= roar_nonce_pool[sizeof(roar_nonce_pool)-roar_nonce_pool_len+1] <<  8; 
     169 ret |= roar_nonce_pool[sizeof(roar_nonce_pool)-roar_nonce_pool_len+2] << 16; 
     170 ret |= roar_nonce_pool[sizeof(roar_nonce_pool)-roar_nonce_pool_len+3] << 24; 
     171 
     172 roar_nonce_pool_len -= 4; 
     173 
     174 return ret; 
     175} 
     176 
    140177int roar_random_gen(void * buffer, size_t len, int quality) { 
    141178 if ( len == 0 ) 
Note: See TracChangeset for help on using the changeset viewer.