Ignore:
Timestamp:
Feb 21, 2008 9:36:34 PM (17 years ago)
Author:
bennylp
Message:

Ticket #412: increased randomness of guid_simple.c to 192-bits, and seed random number generator in pjsua_core.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r1735 r1815  
    512512 
    513513 
     514/* Init random seed */ 
     515static void init_random_seed(void) 
     516{ 
     517    pj_sockaddr addr; 
     518    const pj_str_t *hostname; 
     519    pj_uint32_t pid; 
     520    pj_time_val t; 
     521    unsigned seed=0; 
     522 
     523    /* Add hostname */ 
     524    hostname = pj_gethostname(); 
     525    seed = pj_hash_calc(seed, hostname->ptr, (int)hostname->slen); 
     526 
     527    /* Add primary IP address */ 
     528    if (pj_gethostip(pj_AF_INET(), &addr)==PJ_SUCCESS) 
     529        seed = pj_hash_calc(seed, &addr.ipv4.sin_addr, 4); 
     530 
     531    /* Get timeofday */ 
     532    pj_gettimeofday(&t); 
     533    seed = pj_hash_calc(seed, &t, sizeof(t)); 
     534 
     535    /* Add PID */ 
     536    pid = pj_getpid(); 
     537    seed = pj_hash_calc(seed, &pid, sizeof(pid)); 
     538 
     539    /* Init random seed */ 
     540    pj_srand(seed); 
     541} 
     542 
    514543/* 
    515544 * Instantiate pjsua application. 
     
    529558    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
    530559 
     560    /* Init random seed */ 
     561    init_random_seed(); 
    531562 
    532563    /* Init PJLIB-UTIL: */ 
Note: See TracChangeset for help on using the changeset viewer.