FS-9785: upgrade libsrtp to 2.1

This commit is contained in:
Mike Jerris committed 2017-06-26 14:14:36 -05:00
1 parent 19e8621682
commit 3bcf5b7ff8
129 files changed
+21084 -21652

No files matched your search

+13 -38
View File
@@ -8,7 +8,7 @@
*/
/*
*
* Copyright (c) 2001-2006 Cisco Systems, Inc.
* Copyright (c) 2001-2017 Cisco Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -42,35 +42,36 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "alloc.h"
#include "crypto_kernel.h"
/* the debug module for memory allocation */
debug_module_t mod_alloc = {
srtp_debug_module_t mod_alloc = {
0, /* debugging is off by default */
"alloc" /* printable name for module */
};
/*
* Nota bene: the debugging statements for crypto_alloc() and
* crypto_free() have identical prefixes, which include the addresses
* Nota bene: the debugging statements for srtp_crypto_alloc() and
* srtp_crypto_free() have identical prefixes, which include the addresses
* of the memory locations on which they are operating. This fact can
* be used to locate memory leaks, by turning on memory debugging,
* grepping for 'alloc', then matching alloc and free calls by
* address.
*/
#ifdef SRTP_KERNEL_LINUX
#if defined(HAVE_STDLIB_H)
#include <linux/interrupt.h>
void *
crypto_alloc(size_t size) {
void * srtp_crypto_alloc(size_t size) {
void *ptr;
ptr = kmalloc(size, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
ptr = malloc(size);
if (ptr) {
debug_print(mod_alloc, "(location: %p) allocated", ptr);
} else {
@@ -80,33 +81,7 @@ crypto_alloc(size_t size) {
return ptr;
}
void
crypto_free(void *ptr) {
debug_print(mod_alloc, "(location: %p) freed", ptr);
kfree(ptr);
}
#elif defined(HAVE_STDLIB_H)
void *
crypto_alloc(size_t size) {
void *ptr;
ptr = malloc(size);
if (ptr) {
debug_print(mod_alloc, "(location: %p) allocated", ptr);
} else
debug_print(mod_alloc, "allocation failed (asked for %d bytes)\n", size);
return ptr;
}
void
crypto_free(void *ptr) {
void srtp_crypto_free(void *ptr) {
debug_print(mod_alloc, "(location: %p) freed", ptr);
File diff suppressed because it is too large. Load diff
+60 -102
View File
@@ -7,26 +7,26 @@
* Cisco Systems, Inc.
*/
/*
*
* Copyright(c) 2001-2006 Cisco Systems, Inc.
*
* Copyright(c) 2001-2017 Cisco Systems, Inc.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
*
* Neither the name of the Cisco Systems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -42,107 +42,65 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "err.h"
#include "datatypes.h"
#include <string.h>
#ifdef ERR_REPORTING_SYSLOG
# ifdef HAVE_SYSLOG_H
# include <syslog.h>
# endif
#endif
/* srtp_err_file is the FILE to which errors are reported */
static FILE *srtp_err_file = NULL;
/* err_level reflects the level of errors that are reported */
err_reporting_level_t err_level = err_level_none;
#ifdef SRTP_KERNEL_LINUX
err_status_t
err_reporting_init(char *ident) {
return err_status_ok;
}
#else /* SRTP_KERNEL_LINUX */
/* err_file is the FILE to which errors are reported */
static FILE *err_file = NULL;
err_status_t
err_reporting_init(char *ident) {
#ifdef ERR_REPORTING_SYSLOG
openlog(ident, LOG_PID, LOG_AUTHPRIV);
#endif
/*
* Believe it or not, openlog doesn't return an error on failure.
* But then, neither does the syslog() call...
*/
srtp_err_status_t srtp_err_reporting_init ()
{
#ifdef ERR_REPORTING_STDOUT
err_file = stdout;
#elif defined(USE_ERR_REPORTING_FILE)
/* open file for error reporting */
err_file = fopen(ERR_REPORTING_FILE, "w");
if (err_file == NULL)
return err_status_init_fail;
#endif
return err_status_ok;
}
void
err_report(int priority, char *format, ...) {
va_list args;
if (priority <= err_level) {
va_start(args, format);
if (err_file != NULL) {
vfprintf(err_file, format, args);
/* fprintf(err_file, "\n"); */
srtp_err_file = stdout;
#elif defined(ERR_REPORTING_FILE)
/* open file for error reporting */
srtp_err_file = fopen(ERR_REPORTING_FILE, "w");
if (srtp_err_file == NULL) {
return srtp_err_status_init_fail;
}
#ifdef ERR_REPORTING_SYSLOG
if (1) { /* FIXME: Make this a runtime option. */
int syslogpri;
switch (priority) {
case err_level_emergency:
syslogpri = LOG_EMERG;
break;
case err_level_alert:
syslogpri = LOG_ALERT;
break;
case err_level_critical:
syslogpri = LOG_CRIT;
break;
case err_level_error:
syslogpri = LOG_ERR;
break;
case err_level_warning:
syslogpri = LOG_WARNING;
break;
case err_level_notice:
syslogpri = LOG_NOTICE;
break;
case err_level_info:
syslogpri = LOG_INFO;
break;
case err_level_debug:
case err_level_none:
default:
syslogpri = LOG_DEBUG;
break;
}
vsyslog(syslogpri, format, args);
#endif
va_end(args);
}
}
#endif /* SRTP_KERNEL_LINUX */
void
err_reporting_set_level(err_reporting_level_t lvl) {
err_level = lvl;
return srtp_err_status_ok;
}
static srtp_err_report_handler_func_t * srtp_err_report_handler = NULL;
srtp_err_status_t srtp_install_err_report_handler(srtp_err_report_handler_func_t func)
{
srtp_err_report_handler = func;
return srtp_err_status_ok;
}
void srtp_err_report (srtp_err_reporting_level_t level, const char *format, ...)
{
va_list args;
if (srtp_err_file != NULL) {
va_start(args, format);
vfprintf(srtp_err_file, format, args);
va_end(args);
}
if (srtp_err_report_handler != NULL) {
va_start(args, format);
char msg[512];
if (vsnprintf(msg, sizeof(msg), format, args) > 0) {
/* strip trailing \n, callback should not have one */
size_t l = strlen(msg);
if (l && msg[l-1] == '\n') {
msg[l-1] = '\0';
}
srtp_err_report_handler(level, msg);
/*
* NOTE, need to be carefull, there is a potential that octet_string_set_to_zero() could
* call srtp_err_report() in the future, leading to recursion
*/
octet_string_set_to_zero(msg, sizeof(msg));
}
va_end(args);
}
}
+63 -58
View File
@@ -2,31 +2,31 @@
* key.c
*
* key usage limits enforcement
*
*
* David A. Mcgrew
* Cisco Systems, Inc.
*/
/*
*
* Copyright (c) 2001-2006 Cisco Systems, Inc.
*
* Copyright (c) 2001-2017 Cisco Systems, Inc.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
*
* Neither the name of the Cisco Systems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -42,74 +42,79 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "key.h"
#define soft_limit 0x10000
err_status_t
key_limit_set(key_limit_t key, const xtd_seq_num_t s) {
srtp_err_status_t srtp_key_limit_set (srtp_key_limit_t key, const srtp_xtd_seq_num_t s)
{
#ifdef NO_64BIT_MATH
if (high32(s) == 0 && low32(s) < soft_limit)
return err_status_bad_param;
if (high32(s) == 0 && low32(s) < soft_limit) {
return srtp_err_status_bad_param;
}
#else
if (s < soft_limit)
return err_status_bad_param;
if (s < soft_limit) {
return srtp_err_status_bad_param;
}
#endif
key->num_left = s;
key->state = key_state_normal;
return err_status_ok;
key->num_left = s;
key->state = srtp_key_state_normal;
return srtp_err_status_ok;
}
err_status_t
key_limit_clone(key_limit_t original, key_limit_t *new_key) {
if (original == NULL)
return err_status_bad_param;
*new_key = original;
return err_status_ok;
srtp_err_status_t srtp_key_limit_clone (srtp_key_limit_t original, srtp_key_limit_t *new_key)
{
if (original == NULL) {
return srtp_err_status_bad_param;
}
*new_key = original;
return srtp_err_status_ok;
}
err_status_t
key_limit_check(const key_limit_t key) {
if (key->state == key_state_expired)
return err_status_key_expired;
return err_status_ok;
srtp_err_status_t srtp_key_limit_check (const srtp_key_limit_t key)
{
if (key->state == srtp_key_state_expired) {
return srtp_err_status_key_expired;
}
return srtp_err_status_ok;
}
key_event_t
key_limit_update(key_limit_t key) {
srtp_key_event_t srtp_key_limit_update (srtp_key_limit_t key)
{
#ifdef NO_64BIT_MATH
if (low32(key->num_left) == 0)
{
// carry
key->num_left = make64(high32(key->num_left)-1,low32(key->num_left) - 1);
}
else
{
// no carry
key->num_left = make64(high32(key->num_left),low32(key->num_left) - 1);
}
if (high32(key->num_left) != 0 || low32(key->num_left) >= soft_limit) {
return key_event_normal; /* we're above the soft limit */
}
if (low32(key->num_left) == 0) {
// carry
key->num_left = make64(high32(key->num_left) - 1, low32(key->num_left) - 1);
}else {
// no carry
key->num_left = make64(high32(key->num_left), low32(key->num_left) - 1);
}
if (high32(key->num_left) != 0 || low32(key->num_left) >= soft_limit) {
return srtp_key_event_normal; /* we're above the soft limit */
}
#else
key->num_left--;
if (key->num_left >= soft_limit) {
return key_event_normal; /* we're above the soft limit */
}
key->num_left--;
if (key->num_left >= soft_limit) {
return srtp_key_event_normal; /* we're above the soft limit */
}
#endif
if (key->state == key_state_normal) {
/* we just passed the soft limit, so change the state */
key->state = key_state_past_soft_limit;
}
if (key->state == srtp_key_state_normal) {
/* we just passed the soft limit, so change the state */
key->state = srtp_key_state_past_soft_limit;
}
#ifdef NO_64BIT_MATH
if (low32(key->num_left) == 0 && high32(key->num_left == 0))
if (low32(key->num_left) == 0 && high32(key->num_left == 0))
#else
if (key->num_left < 1)
if (key->num_left < 1)
#endif
{ /* we just hit the hard limit */
key->state = key_state_expired;
return key_event_hard_limit;
}
return key_event_soft_limit;
{ /* we just hit the hard limit */
key->state = srtp_key_state_expired;
return srtp_key_event_hard_limit;
}
return srtp_key_event_soft_limit;
}