Changeset 1738


Ignore:
Timestamp:
Jan 24, 2008 3:27:30 PM (16 years ago)
Author:
bennylp
Message:

More ticket #61: SRTP will try to use /dev/urandom as RNG if fcntl.h and unistd.h is present. If it fails, it will fallback to using rand()

Location:
pjproject/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/aconfigure

    r1729 r1738  
    55105510esac 
    55115511 
     5512if test "${ac_cv_header_fcntl_h+set}" = set; then 
     5513  { echo "$as_me:$LINENO: checking for fcntl.h" >&5 
     5514echo $ECHO_N "checking for fcntl.h... $ECHO_C" >&6; } 
     5515if test "${ac_cv_header_fcntl_h+set}" = set; then 
     5516  echo $ECHO_N "(cached) $ECHO_C" >&6 
     5517fi 
     5518{ echo "$as_me:$LINENO: result: $ac_cv_header_fcntl_h" >&5 
     5519echo "${ECHO_T}$ac_cv_header_fcntl_h" >&6; } 
     5520else 
     5521  # Is the header compilable? 
     5522{ echo "$as_me:$LINENO: checking fcntl.h usability" >&5 
     5523echo $ECHO_N "checking fcntl.h usability... $ECHO_C" >&6; } 
     5524cat >conftest.$ac_ext <<_ACEOF 
     5525/* confdefs.h.  */ 
     5526_ACEOF 
     5527cat confdefs.h >>conftest.$ac_ext 
     5528cat >>conftest.$ac_ext <<_ACEOF 
     5529/* end confdefs.h.  */ 
     5530$ac_includes_default 
     5531#include <fcntl.h> 
     5532_ACEOF 
     5533rm -f conftest.$ac_objext 
     5534if { (ac_try="$ac_compile" 
     5535case "(($ac_try" in 
     5536  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; 
     5537  *) ac_try_echo=$ac_try;; 
     5538esac 
     5539eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 
     5540  (eval "$ac_compile") 2>conftest.er1 
     5541  ac_status=$? 
     5542  grep -v '^ *+' conftest.er1 >conftest.err 
     5543  rm -f conftest.er1 
     5544  cat conftest.err >&5 
     5545  echo "$as_me:$LINENO: \$? = $ac_status" >&5 
     5546  (exit $ac_status); } && { 
     5547         test -z "$ac_c_werror_flag" || 
     5548         test ! -s conftest.err 
     5549       } && test -s conftest.$ac_objext; then 
     5550  ac_header_compiler=yes 
     5551else 
     5552  echo "$as_me: failed program was:" >&5 
     5553sed 's/^/| /' conftest.$ac_ext >&5 
     5554 
     5555        ac_header_compiler=no 
     5556fi 
     5557 
     5558rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext 
     5559{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 
     5560echo "${ECHO_T}$ac_header_compiler" >&6; } 
     5561 
     5562# Is the header present? 
     5563{ echo "$as_me:$LINENO: checking fcntl.h presence" >&5 
     5564echo $ECHO_N "checking fcntl.h presence... $ECHO_C" >&6; } 
     5565cat >conftest.$ac_ext <<_ACEOF 
     5566/* confdefs.h.  */ 
     5567_ACEOF 
     5568cat confdefs.h >>conftest.$ac_ext 
     5569cat >>conftest.$ac_ext <<_ACEOF 
     5570/* end confdefs.h.  */ 
     5571#include <fcntl.h> 
     5572_ACEOF 
     5573if { (ac_try="$ac_cpp conftest.$ac_ext" 
     5574case "(($ac_try" in 
     5575  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; 
     5576  *) ac_try_echo=$ac_try;; 
     5577esac 
     5578eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 
     5579  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 
     5580  ac_status=$? 
     5581  grep -v '^ *+' conftest.er1 >conftest.err 
     5582  rm -f conftest.er1 
     5583  cat conftest.err >&5 
     5584  echo "$as_me:$LINENO: \$? = $ac_status" >&5 
     5585  (exit $ac_status); } >/dev/null && { 
     5586         test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || 
     5587         test ! -s conftest.err 
     5588       }; then 
     5589  ac_header_preproc=yes 
     5590else 
     5591  echo "$as_me: failed program was:" >&5 
     5592sed 's/^/| /' conftest.$ac_ext >&5 
     5593 
     5594  ac_header_preproc=no 
     5595fi 
     5596 
     5597rm -f conftest.err conftest.$ac_ext 
     5598{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 
     5599echo "${ECHO_T}$ac_header_preproc" >&6; } 
     5600 
     5601# So?  What about this header? 
     5602case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in 
     5603  yes:no: ) 
     5604    { echo "$as_me:$LINENO: WARNING: fcntl.h: accepted by the compiler, rejected by the preprocessor!" >&5 
     5605echo "$as_me: WARNING: fcntl.h: accepted by the compiler, rejected by the preprocessor!" >&2;} 
     5606    { echo "$as_me:$LINENO: WARNING: fcntl.h: proceeding with the compiler's result" >&5 
     5607echo "$as_me: WARNING: fcntl.h: proceeding with the compiler's result" >&2;} 
     5608    ac_header_preproc=yes 
     5609    ;; 
     5610  no:yes:* ) 
     5611    { echo "$as_me:$LINENO: WARNING: fcntl.h: present but cannot be compiled" >&5 
     5612echo "$as_me: WARNING: fcntl.h: present but cannot be compiled" >&2;} 
     5613    { echo "$as_me:$LINENO: WARNING: fcntl.h:     check for missing prerequisite headers?" >&5 
     5614echo "$as_me: WARNING: fcntl.h:     check for missing prerequisite headers?" >&2;} 
     5615    { echo "$as_me:$LINENO: WARNING: fcntl.h: see the Autoconf documentation" >&5 
     5616echo "$as_me: WARNING: fcntl.h: see the Autoconf documentation" >&2;} 
     5617    { echo "$as_me:$LINENO: WARNING: fcntl.h:     section \"Present But Cannot Be Compiled\"" >&5 
     5618echo "$as_me: WARNING: fcntl.h:     section \"Present But Cannot Be Compiled\"" >&2;} 
     5619    { echo "$as_me:$LINENO: WARNING: fcntl.h: proceeding with the preprocessor's result" >&5 
     5620echo "$as_me: WARNING: fcntl.h: proceeding with the preprocessor's result" >&2;} 
     5621    { echo "$as_me:$LINENO: WARNING: fcntl.h: in the future, the compiler will take precedence" >&5 
     5622echo "$as_me: WARNING: fcntl.h: in the future, the compiler will take precedence" >&2;} 
     5623 
     5624    ;; 
     5625esac 
     5626{ echo "$as_me:$LINENO: checking for fcntl.h" >&5 
     5627echo $ECHO_N "checking for fcntl.h... $ECHO_C" >&6; } 
     5628if test "${ac_cv_header_fcntl_h+set}" = set; then 
     5629  echo $ECHO_N "(cached) $ECHO_C" >&6 
     5630else 
     5631  ac_cv_header_fcntl_h=$ac_header_preproc 
     5632fi 
     5633{ echo "$as_me:$LINENO: result: $ac_cv_header_fcntl_h" >&5 
     5634echo "${ECHO_T}$ac_cv_header_fcntl_h" >&6; } 
     5635 
     5636fi 
     5637if test $ac_cv_header_fcntl_h = yes; then 
     5638  cat >>confdefs.h <<\_ACEOF 
     5639#define PJ_HAS_FCNTL_H 1 
     5640_ACEOF 
     5641 
     5642fi 
     5643 
     5644 
    55125645if test "${ac_cv_header_linux_socket_h+set}" = set; then 
    55135646  { echo "$as_me:$LINENO: checking for linux/socket.h" >&5 
  • pjproject/trunk/aconfigure.ac

    r1729 r1738  
    139139esac 
    140140 
     141AC_CHECK_HEADER(fcntl.h,[AC_DEFINE(PJ_HAS_FCNTL_H,1)]) 
    141142AC_CHECK_HEADER(linux/socket.h,[AC_DEFINE(PJ_HAS_LINUX_SOCKET_H,1)]) 
    142143AC_CHECK_HEADER(malloc.h,[AC_DEFINE(PJ_HAS_MALLOC_H,1)]) 
  • pjproject/trunk/pjlib/include/pj/compat/os_auto.h.in

    r1729 r1738  
    4747#undef PJ_HAS_CTYPE_H 
    4848#undef PJ_HAS_ERRNO_H 
     49#undef PJ_HAS_FCNTL_H 
    4950#undef PJ_HAS_LINUX_SOCKET_H 
    5051#undef PJ_HAS_MALLOC_H 
  • pjproject/trunk/third_party/build/srtp/srtp_config.h

    r1736 r1738  
    2727    (defined(PJ_M_IA64) && PJ_M_IA64!=0) 
    2828#   define CPU_CISC         1 
    29 #   define HAVE_X86         1   /* use X86 inlined assembly code */ 
     29/* #   define HAVE_X86      1  use X86 inlined assembly code */ 
    3030#else 
    3131#   define CPU_RISC         1 
     
    114114#endif 
    115115 
    116 #define SIZEOF_UNSIGNED_LONG        (sizeof(unsigned long)) 
     116#define SIZEOF_UNSIGNED_LONG        8 
    117117#define SIZEOF_UNSIGNED_LONG_LONG   8 
    118118 
     
    156156/* #define DEV_URANDOM "/dev/urandom" */ 
    157157 
     158/* Only with PJSIP: 
     159 * Try to open PJ_DEV_URANDOM if present 
     160 */ 
     161#if defined(PJ_HAS_FCNTL_H) && defined(PJ_HAS_UNISTD_H) 
     162#   define PJ_DEV_URANDOM       "/dev/urandom" 
     163#endif 
     164 
    158165/* We have overridden libsrtp error mechanism, so these are not used. */ 
    159166/* #undef ERR_REPORTING_FILE */ 
  • pjproject/trunk/third_party/srtp/crypto/rng/rand_source.c

    r1730 r1738  
    4545#include "srtp_config.h" 
    4646 
    47 #ifdef DEV_URANDOM 
     47#if defined(DEV_URANDOM) || defined(PJ_DEV_URANDOM) 
    4848# include <fcntl.h>          /* for open()  */ 
    4949# include <unistd.h>         /* for close() */ 
     
    8888  if (dev_random_fdes < 0) 
    8989    return err_status_init_fail; 
     90#elif defined(PJ_DEV_URANDOM) 
     91  /* open random source for reading */ 
     92  dev_random_fdes = open(PJ_DEV_URANDOM, O_RDONLY); 
     93  if (dev_random_fdes < 0) { 
     94    err_report(3,"Ugh: /dev/urandom not present, using rand() instead"); 
     95    return err_status_ok;  /* it's ok, it'll fallback to using rand() */ 
     96  } 
    9097#elif (_MSC_VER >= 1400) 
    9198  dev_random_fdes = RAND_SOURCE_READY; 
     
    124131  } 
    125132#else 
     133  uint8_t *dst = (uint8_t *)dest; 
     134 
     135  /* First try with /dev/urandom, if it's opened */ 
     136  if (dev_random_fdes >= 0) { 
     137    if (read(dev_random_fdes, dest, len) == len) 
     138        return err_status_ok;   /* success */ 
     139  } 
     140 
    126141  /* Generic C-library (rand()) version */ 
    127142  /* This is a random source of last resort */ 
    128   uint8_t *dst = (uint8_t *)dest; 
    129143  while (len) 
    130144  { 
     
    142156err_status_t 
    143157rand_source_deinit(void) { 
     158#ifndef PJ_DEV_URANDOM 
    144159  if (dev_random_fdes < 0) 
    145160    return err_status_dealloc_fail;  /* well, we haven't really failed, * 
    146161                                      * but there is something wrong    */ 
    147 #ifdef DEV_URANDOM 
    148   close(dev_random_fdes);   
    149162#endif 
     163 
     164  if (dev_random_fdes >= 0) 
     165    close(dev_random_fdes);   
     166 
    150167  dev_random_fdes = RAND_SOURCE_NOT_READY; 
    151168   
    152169  return err_status_ok;   
    153170} 
     171 
Note: See TracChangeset for help on using the changeset viewer.