Commit 37b81a11 authored by Simon Morlat's avatar Simon Morlat

merge patches for openBSD, for using arc4random() and fix compilation when...

merge patches for openBSD, for using arc4random() and fix compilation when char is unsigned by default.
parent 123ef1a5
Copyright (c) 2010-2013 Belledonne Communications SARL <sales@belledonne-communications.com>
Simon MORLAT (simon dot morlat at linphone dot org) is the author the oRTP library.
Contributors:
Lovadina Nicola < lovadina dot nicola dot 10272 at unimo dot it > worked on RTCP support.
* Copyright (c) 2013 Vadim Zhukov <persgray@gmail.com>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- support of arc4random()
- bugfix in b64.c for platforms where char is unsigned.
* Lovadina Nicola < lovadina dot nicola dot 10272 at unimo dot it > worked on RTCP support.
......@@ -176,6 +176,9 @@ build_scheduler=yes
dnl Check if we have seteuid system call
AC_CHECK_FUNCS(seteuid)
dnl Check if we have arc4random family routines available
AC_CHECK_FUNCS(arc4random)
dnl check if we can use the pthread_library
AC_CHECK_LIB(pthread, pthread_mutex_init, [pthread_enabled=yes], [pthread_enabled=no])
......
......@@ -181,7 +181,7 @@ static size_t b64_encode_( unsigned char const *src
for(; NUM_PLAIN_DATA_BYTES <= srcSize; srcSize -= NUM_PLAIN_DATA_BYTES)
{
char characters[NUM_ENCODED_DATA_BYTES];
unsigned char characters[NUM_ENCODED_DATA_BYTES];
/*
*
......@@ -197,38 +197,38 @@ static size_t b64_encode_( unsigned char const *src
*/
/* characters[0] is the 6 left-most bits of src[0] */
characters[0] = (char)((src[0] & 0xfc) >> 2);
characters[0] = ((src[0] & 0xfc) >> 2);
/* characters[0] is the right-most 2 bits of src[0] and the left-most 4 bits of src[1] */
characters[1] = (char)(((src[0] & 0x03) << 4) + ((src[1] & 0xf0) >> 4));
characters[1] = (((src[0] & 0x03) << 4) + ((src[1] & 0xf0) >> 4));
/* characters[0] is the right-most 4 bits of src[1] and the 2 left-most bits of src[2] */
characters[2] = (char)(((src[1] & 0x0f) << 2) + ((src[2] & 0xc0) >> 6));
characters[2] = (((src[1] & 0x0f) << 2) + ((src[2] & 0xc0) >> 6));
/* characters[3] is the right-most 6 bits of src[2] */
characters[3] = (char)(src[2] & 0x3f);
characters[3] = (src[2] & 0x3f);
#ifndef __WATCOMC__
assert(characters[0] >= 0 && characters[0] < 64);
assert(characters[1] >= 0 && characters[1] < 64);
assert(characters[2] >= 0 && characters[2] < 64);
assert(characters[3] >= 0 && characters[3] < 64);
assert(characters[0] < 64);
assert(characters[1] < 64);
assert(characters[2] < 64);
assert(characters[3] < 64);
#endif /* __WATCOMC__ */
src += NUM_PLAIN_DATA_BYTES;
*p++ = b64_chars[(unsigned char)characters[0]];
*p++ = b64_chars[characters[0]];
assert(NULL != strchr(b64_chars, *(p-1)));
++len;
assert(len != lineLen);
*p++ = b64_chars[(unsigned char)characters[1]];
*p++ = b64_chars[characters[1]];
assert(NULL != strchr(b64_chars, *(p-1)));
++len;
assert(len != lineLen);
*p++ = b64_chars[(unsigned char)characters[2]];
*p++ = b64_chars[characters[2]];
assert(NULL != strchr(b64_chars, *(p-1)));
++len;
assert(len != lineLen);
*p++ = b64_chars[(unsigned char)characters[3]];
*p++ = b64_chars[characters[3]];
assert(NULL != strchr(b64_chars, *(p-1)));
if( ++len == lineLen &&
......
......@@ -115,7 +115,13 @@ static mblk_t *simulate_bandwidth_limit(RtpSession *session, mblk_t *input){
}
static mblk_t *simulate_loss_rate(RtpSession *session, mblk_t *input, int rate){
if((rand() % 101) >= rate) {
int rrate;
#ifdef HAVE_ARC4RANDOM
rrate = arc4random_uniform(101);
#else
rrate = rand() % 101;
#endif
if(rrate >= rate) {
return input;
}
freemsg(input);
......
......@@ -49,9 +49,11 @@ RtpScheduler *__ortp_scheduler;
extern void av_profile_init(RtpProfile *profile);
static void init_random_number_generator(){
#ifndef HAVE_ARC4RANDOM
struct timeval t;
ortp_gettimeofday(&t,NULL);
srandom(t.tv_usec+t.tv_sec);
#endif
}
......
......@@ -98,7 +98,11 @@ extern void rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_ts,
static uint32_t uint32_t_random(){
#ifdef HAVE_ARC4RANDOM
return arc4random();
#else
return random();
#endif
}
......
......@@ -23,7 +23,7 @@
#if defined(WIN32) || defined(_WIN32_WCE)
#include "ortp-config-win32.h"
#elif HAVE_CONFIG_H
#include "ortp-config.h" /*needed for HAVE_SYS_UIO_H */
#include "ortp-config.h" /*needed for HAVE_SYS_UIO_H and HAVE_ARC4RANDOM */
#endif
#include "ortp/ortp.h"
#include "utils.h"
......@@ -278,11 +278,16 @@ static ortp_socket_t create_and_bind_random(const char *localip, int *sock_famil
for (retry=0;retry<100;retry++)
{
int localport;
#ifdef HAVE_ARC4RANDOM
localport = 5000 + (int)arc4random_uniform(0x10000 - 5000);
localport &= 0xfffe;
#else
do
{
localport = (rand () + 5000) & 0xfffe;
}
while ((localport < 5000) || (localport > 0xffff));
#endif
/*do not set REUSEADDR in case of random allocation */
sock = create_and_bind(localip, localport, sock_family,FALSE);
if (sock!=-1) {
......
......@@ -1159,6 +1159,9 @@ stunEncodeMessage( const StunMessage *msg,
int
stunRand(void)
{
#if defined(HAVE_ARC4RANDOM)
return (int)arc4random();
#else
/* return 32 bits of random stuff */
/* assert( sizeof(int) == 4 ); */
static bool_t init=FALSE;
......@@ -1251,6 +1254,7 @@ stunRand(void)
#else
return random();
#endif
#endif /* HAVE_ARC4RANDOM */
}
......@@ -1260,10 +1264,15 @@ randomPort()
{
int min=0x4000;
int max=0x7FFF;
int ret = stunRand();
int ret;
#ifdef HAVE_ARC4RANDOM
ret = min + (int)arc4random_uniform(max - min);
#else
ret = stunRand();
ret = ret|min;
ret = ret&max;
#endif
return ret;
}
......
......@@ -775,7 +775,11 @@ static OrtpZrtpContext* createUserData(ZrtpContext *context) {
userData->zrtpContext=context;
userData->timerWillTriggerAt=0;
userData->last_recv_zrtp_seq_number=0;
#ifdef HAVE_ARC4RANDOM
userData->last_sent_zrtp_seq_number=arc4random_uniform(0xffff) + 1;
#else
userData->last_sent_zrtp_seq_number=rand()+1; // INT_MAX+1 (signed)
#endif
userData->srtpRecv=NULL;
userData->srtpSend=NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment