mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-14 05:18:31 +00:00
[Build-System] Update libsrtp to 2.4.0
This commit is contained in:
1 parent
641fcd2b26
commit
bddff9a2f1
95 files changed
+5998
-3870
No files matched your search
@@ -1,33 +0,0 @@
|
||||
AUTOMAKE_OPTIONS = gnu
|
||||
AM_CFLAGS = $(new_AM_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/crypto/include
|
||||
AM_CPPFLAGS = $(AM_CFLAGS)
|
||||
AM_LDFLAGS = $(new_AM_LDFLAGS) -L$(srcdir) -lsrtp
|
||||
|
||||
check_PROGRAMS = cipher_driver kernel_driver rdbx_driver srtp_driver roc_driver replay_driver \
|
||||
aes_calc datatypes_driver sha1_driver stat_driver rtpw
|
||||
|
||||
cipher_driver_SOURCES = crypto/cipher_driver.c
|
||||
kernel_driver_SOURCES = crypto/kernel_driver.c
|
||||
aes_calc_SOURCES = crypto/aes_calc.c
|
||||
datatypes_driver_SOURCES = crypto/datatypes_driver.c
|
||||
sha1_driver_SOURCES = crypto/sha1_driver.c
|
||||
stat_driver_SOURCES = crypto/stat_driver.c
|
||||
rdbx_driver_SOURCES = rdbx_driver.c
|
||||
srtp_driver_SOURCES = srtp_driver.c
|
||||
roc_driver_SOURCES = roc_driver.c
|
||||
replay_driver_SOURCES = replay_driver.c
|
||||
rtpw_SOURCES = rtpw.c rtp.c
|
||||
rtpw_LDADD = -lnsl -lsocket
|
||||
|
||||
check-local: cipher_driver
|
||||
./cipher_driver -v
|
||||
./kernel_driver -v
|
||||
./rdbx_driver -v
|
||||
./srtp_driver -v
|
||||
./roc_driver -v
|
||||
./replay_driver -v
|
||||
./datatypes_driver -v
|
||||
./stat_driver
|
||||
./sha1_driver -v
|
||||
./kernel_driver -v
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
/*
|
||||
* dtls_srtp_driver.c
|
||||
*
|
||||
* test driver for DTLS-SRTP functions
|
||||
*
|
||||
* David McGrew
|
||||
* 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
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include "getopt_s.h" /* for local getopt() */
|
||||
#include "srtp_priv.h"
|
||||
|
||||
srtp_err_status_t test_dtls_srtp(void);
|
||||
|
||||
srtp_hdr_t *srtp_create_test_packet(int pkt_octet_len, uint32_t ssrc);
|
||||
|
||||
void usage(char *prog_name)
|
||||
{
|
||||
printf("usage: %s [ -t ][ -c ][ -v ][-d <debug_module> ]* [ -l ]\n"
|
||||
" -d <mod> turn on debugging module <mod>\n"
|
||||
" -l list debugging modules\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned do_list_mods = 0;
|
||||
int q;
|
||||
srtp_err_status_t err;
|
||||
|
||||
printf("dtls_srtp_driver\n");
|
||||
|
||||
/* initialize srtp library */
|
||||
err = srtp_init();
|
||||
if (err) {
|
||||
printf("error: srtp init failed with error code %d\n", err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* process input arguments */
|
||||
while (1) {
|
||||
q = getopt_s(argc, argv, "ld:");
|
||||
if (q == -1)
|
||||
break;
|
||||
switch (q) {
|
||||
case 'l':
|
||||
do_list_mods = 1;
|
||||
break;
|
||||
case 'd':
|
||||
err = srtp_crypto_kernel_set_debug_module(optarg_s, 1);
|
||||
if (err) {
|
||||
printf("error: set debug module (%s) failed\n", optarg_s);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (do_list_mods) {
|
||||
err = srtp_crypto_kernel_list_debug_modules();
|
||||
if (err) {
|
||||
printf("error: list of debug modules failed\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
printf("testing dtls_srtp...");
|
||||
err = test_dtls_srtp();
|
||||
if (err) {
|
||||
printf("\nerror (code %d)\n", err);
|
||||
exit(1);
|
||||
}
|
||||
printf("passed\n");
|
||||
|
||||
/* shut down srtp library */
|
||||
err = srtp_shutdown();
|
||||
if (err) {
|
||||
printf("error: srtp shutdown failed with error code %d\n", err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
srtp_err_status_t test_dtls_srtp(void)
|
||||
{
|
||||
srtp_hdr_t *test_packet;
|
||||
int test_packet_len = 80;
|
||||
srtp_t s;
|
||||
srtp_policy_t policy;
|
||||
uint8_t key[SRTP_MAX_KEY_LEN];
|
||||
uint8_t salt[SRTP_MAX_KEY_LEN];
|
||||
unsigned int key_len, salt_len;
|
||||
srtp_profile_t profile;
|
||||
srtp_err_status_t err;
|
||||
|
||||
memset(&policy, 0x0, sizeof(srtp_policy_t));
|
||||
|
||||
/* create a 'null' SRTP session */
|
||||
err = srtp_create(&s, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/*
|
||||
* verify that packet-processing functions behave properly - we
|
||||
* expect that these functions will return srtp_err_status_no_ctx
|
||||
*/
|
||||
test_packet = srtp_create_test_packet(80, 0xa5a5a5a5);
|
||||
if (test_packet == NULL)
|
||||
return srtp_err_status_alloc_fail;
|
||||
|
||||
err = srtp_protect(s, test_packet, &test_packet_len);
|
||||
if (err != srtp_err_status_no_ctx) {
|
||||
printf("wrong return value from srtp_protect() (got code %d)\n", err);
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
err = srtp_unprotect(s, test_packet, &test_packet_len);
|
||||
if (err != srtp_err_status_no_ctx) {
|
||||
printf("wrong return value from srtp_unprotect() (got code %d)\n", err);
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
err = srtp_protect_rtcp(s, test_packet, &test_packet_len);
|
||||
if (err != srtp_err_status_no_ctx) {
|
||||
printf("wrong return value from srtp_protect_rtcp() (got code %d)\n",
|
||||
err);
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
err = srtp_unprotect_rtcp(s, test_packet, &test_packet_len);
|
||||
if (err != srtp_err_status_no_ctx) {
|
||||
printf("wrong return value from srtp_unprotect_rtcp() (got code %d)\n",
|
||||
err);
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* set keys to known values for testing
|
||||
*/
|
||||
profile = srtp_profile_aes128_cm_sha1_80;
|
||||
key_len = srtp_profile_get_master_key_length(profile);
|
||||
salt_len = srtp_profile_get_master_salt_length(profile);
|
||||
memset(key, 0xff, key_len);
|
||||
memset(salt, 0xee, salt_len);
|
||||
srtp_append_salt_to_key(key, key_len, salt, salt_len);
|
||||
policy.key = key;
|
||||
|
||||
/* initialize SRTP policy from profile */
|
||||
err = srtp_crypto_policy_set_from_profile_for_rtp(&policy.rtp, profile);
|
||||
if (err)
|
||||
return err;
|
||||
err = srtp_crypto_policy_set_from_profile_for_rtcp(&policy.rtcp, profile);
|
||||
if (err)
|
||||
return err;
|
||||
policy.ssrc.type = ssrc_any_inbound;
|
||||
policy.ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
|
||||
err = srtp_add_stream(s, &policy);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = srtp_dealloc(s);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
free(test_packet);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_create_test_packet(len, ssrc) returns a pointer to a
|
||||
* (malloced) example RTP packet whose data field has the length given
|
||||
* by pkt_octet_len and the SSRC value ssrc. The total length of the
|
||||
* packet is twelve octets longer, since the header is at the
|
||||
* beginning. There is room at the end of the packet for a trailer,
|
||||
* and the four octets following the packet are filled with 0xff
|
||||
* values to enable testing for overwrites.
|
||||
*
|
||||
* note that the location of the test packet can (and should) be
|
||||
* deallocated with the free() call once it is no longer needed.
|
||||
*/
|
||||
|
||||
srtp_hdr_t *srtp_create_test_packet(int pkt_octet_len, uint32_t ssrc)
|
||||
{
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
srtp_hdr_t *hdr;
|
||||
int bytes_in_hdr = 12;
|
||||
|
||||
/* allocate memory for test packet */
|
||||
hdr = malloc(pkt_octet_len + bytes_in_hdr + SRTP_MAX_TRAILER_LEN + 4);
|
||||
if (!hdr)
|
||||
return NULL;
|
||||
|
||||
hdr->version = 2; /* RTP version two */
|
||||
hdr->p = 0; /* no padding needed */
|
||||
hdr->x = 0; /* no header extension */
|
||||
hdr->cc = 0; /* no CSRCs */
|
||||
hdr->m = 0; /* marker bit */
|
||||
hdr->pt = 0xf; /* payload type */
|
||||
hdr->seq = htons(0x1234); /* sequence number */
|
||||
hdr->ts = htonl(0xdecafbad); /* timestamp */
|
||||
hdr->ssrc = htonl(ssrc); /* synch. source */
|
||||
|
||||
buffer = (uint8_t *)hdr;
|
||||
buffer += bytes_in_hdr;
|
||||
|
||||
/* set RTP data to 0xab */
|
||||
for (i = 0; i < pkt_octet_len; i++)
|
||||
*buffer++ = 0xab;
|
||||
|
||||
/* set post-data value to 0xffff to enable overrun checking */
|
||||
for (i = 0; i < SRTP_MAX_TRAILER_LEN + 4; i++)
|
||||
*buffer++ = 0xff;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
@@ -58,8 +58,9 @@ static int getopt_check_character(char c, const char *string)
|
||||
|
||||
while (*string != 0) {
|
||||
if (max_string_len == 0) {
|
||||
return '?';
|
||||
return GETOPT_NOT_FOUND;
|
||||
}
|
||||
max_string_len--;
|
||||
if (*string++ == c) {
|
||||
if (*string == ':') {
|
||||
return GETOPT_FOUND_WITH_ARGUMENT;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* getopt.h
|
||||
*
|
||||
* interface to a minimal implementation of the getopt() function,
|
||||
* written so that test applications that use that function can run on
|
||||
* non-POSIX platforms
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* 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
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GETOPT_S_H
|
||||
#define GETOPT_S_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* getopt_s(), optarg_s, and optind_s are small, locally defined
|
||||
* versions of the POSIX standard getopt() interface.
|
||||
*/
|
||||
|
||||
int getopt_s(int argc, char *const argv[], const char *optstring);
|
||||
|
||||
extern char *optarg_s; /* defined in getopt.c */
|
||||
|
||||
extern int optind_s; /* defined in getopt.c */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GETOPT_S_H */
|
||||
@@ -0,0 +1,77 @@
|
||||
# test suite
|
||||
|
||||
# XXX: Makefile only runs test_srtp and srtp_driver with valgrind
|
||||
add_test_setup('valgrind',
|
||||
exe_wrapper: ['valgrind', '--leak-check=full'],
|
||||
timeout_multiplier: 10)
|
||||
|
||||
test_apps = [
|
||||
['srtp_driver', {'extra_sources': 'util.c', 'run_args': '-v'}],
|
||||
['replay_driver', {'extra_sources': 'ut_sim.c', 'run_args': '-v'}],
|
||||
['roc_driver', {'extra_sources': 'ut_sim.c', 'run_args': '-v'}],
|
||||
['rdbx_driver', {'extra_sources': 'ut_sim.c', 'run_args': '-v'}],
|
||||
['test_srtp', {'run_args': '-v'}],
|
||||
['rtpw', {'extra_sources': ['rtp.c', 'util.c', '../crypto/math/datatypes.c'], 'define_test': false}],
|
||||
]
|
||||
|
||||
foreach t : test_apps
|
||||
test_name = t.get(0)
|
||||
test_dict = t.get(1, {})
|
||||
test_extra_sources = test_dict.get('extra_sources', [])
|
||||
test_run_args = test_dict.get('run_args', [])
|
||||
|
||||
test_exe = executable(test_name,
|
||||
'@0@.c'.format(test_name), 'getopt_s.c', test_extra_sources,
|
||||
include_directories: [config_incs, crypto_incs, srtp2_incs, test_incs],
|
||||
dependencies: [srtp2_deps, syslibs],
|
||||
link_with: libsrtp2_for_tests)
|
||||
|
||||
if test_dict.get('define_test', true)
|
||||
test(test_name, test_exe, args: test_run_args)
|
||||
else
|
||||
set_variable(test_name + '_exe', test_exe)
|
||||
endif
|
||||
endforeach
|
||||
|
||||
# rtpw test needs to be run using shell scripts
|
||||
can_run_rtpw = find_program('sh', 'bash', required: false).found()
|
||||
|
||||
# Meson only passes the exe_wrapper to shell scripts starting 0.55
|
||||
if meson.is_cross_build() and meson.version().version_compare('<0.55')
|
||||
can_run_rtpw = false
|
||||
endif
|
||||
|
||||
if can_run_rtpw
|
||||
words_txt = files('words.txt')
|
||||
|
||||
rtpw_test_sh = find_program('rtpw_test.sh', required: false)
|
||||
if rtpw_test_sh.found()
|
||||
test('rtpw_test', rtpw_test_sh,
|
||||
args: ['-w', words_txt],
|
||||
depends: rtpw_exe,
|
||||
is_parallel: false,
|
||||
workdir: meson.current_build_dir())
|
||||
endif
|
||||
|
||||
rtpw_test_gcm_sh = find_program('rtpw_test_gcm.sh', required: false)
|
||||
if (use_openssl or use_nss) and rtpw_test_gcm_sh.found()
|
||||
test('rtpw_test_gcm', rtpw_test_gcm_sh,
|
||||
args: ['-w', words_txt],
|
||||
depends: rtpw_exe,
|
||||
is_parallel: false,
|
||||
workdir: meson.current_build_dir())
|
||||
endif
|
||||
endif
|
||||
|
||||
# rtp_decoder
|
||||
pcap_dep = dependency('libpcap', required: get_option('pcap-tests'))
|
||||
|
||||
if pcap_dep.found()
|
||||
executable('rtp_decoder',
|
||||
'rtp_decoder.c', 'getopt_s.c', 'rtp.c', 'util.c', 'getopt_s.c',
|
||||
'../crypto/math/datatypes.c',
|
||||
include_directories: [config_incs, crypto_incs, srtp2_incs, test_incs],
|
||||
dependencies: [srtp2_deps, pcap_dep, syslibs],
|
||||
link_with: libsrtp2,
|
||||
install: false)
|
||||
endif
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "getopt_s.h" /* for local getopt() */
|
||||
|
||||
#include "rdbx.h"
|
||||
#include "cipher_priv.h"
|
||||
|
||||
#ifdef ROC_TEST
|
||||
#error "srtp_rdbx_t won't work with ROC_TEST - bitmask same size as seq_median"
|
||||
@@ -129,13 +130,6 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_rdbx(srtp_rdbx_t *rdbx)
|
||||
{
|
||||
char buf[2048];
|
||||
printf("rdbx: {%llu, %s}\n", (unsigned long long)(rdbx->index),
|
||||
bitvector_bit_string(&rdbx->bitmask, buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
/*
|
||||
* rdbx_check_add(rdbx, idx) checks a known-to-be-good idx against
|
||||
* rdbx, then adds it. if a failure is detected (i.e., the check
|
||||
@@ -305,7 +299,7 @@ srtp_err_status_t test_replay_dbx(int num_trials, unsigned long ws)
|
||||
*/
|
||||
printf("\ttesting insertion with large gaps...");
|
||||
for (idx = 0, ircvd = 0; (int)idx < num_trials;
|
||||
idx++, ircvd += (1 << (rand() % 12))) {
|
||||
idx++, ircvd += (1 << (srtp_cipher_rand_u32_for_tests() % 12))) {
|
||||
status = rdbx_check_add(&rdbx, ircvd);
|
||||
if (status)
|
||||
return status;
|
||||
@@ -320,8 +314,7 @@ srtp_err_status_t test_replay_dbx(int num_trials, unsigned long ws)
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
#include <time.h> /* for clock() */
|
||||
#include <stdlib.h> /* for random() */
|
||||
#include <time.h> /* for clock() */
|
||||
|
||||
double rdbx_check_adds_per_second(int num_trials, unsigned long ws)
|
||||
{
|
||||
@@ -348,6 +341,9 @@ double rdbx_check_adds_per_second(int num_trials, unsigned long ws)
|
||||
++failures;
|
||||
}
|
||||
timer = clock() - timer;
|
||||
if (timer < 1) {
|
||||
timer = 1;
|
||||
}
|
||||
|
||||
printf("number of failures: %d \n", failures);
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
#include "rdb.h"
|
||||
#include "ut_sim.h"
|
||||
|
||||
#include "cipher_priv.h"
|
||||
|
||||
/*
|
||||
* num_trials defines the number of trials that are used in the
|
||||
* validation functions below
|
||||
@@ -80,12 +82,6 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_rdb(srtp_rdb_t *rdb)
|
||||
{
|
||||
printf("rdb: {%u, %s}\n", rdb->window_start,
|
||||
v128_bit_string(&rdb->bitmask));
|
||||
}
|
||||
|
||||
srtp_err_status_t rdb_check_add(srtp_rdb_t *rdb, uint32_t idx)
|
||||
{
|
||||
if (srtp_rdb_check(rdb, idx) != srtp_err_status_ok) {
|
||||
@@ -189,7 +185,7 @@ srtp_err_status_t test_rdb_db()
|
||||
|
||||
/* test insertion with large gaps */
|
||||
for (idx = 0, ircvd = 0; idx < num_trials;
|
||||
idx++, ircvd += (1 << (rand() % 10))) {
|
||||
idx++, ircvd += (1 << (srtp_cipher_rand_u32_for_tests() % 10))) {
|
||||
err = rdb_check_add(&rdb, ircvd);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@@ -97,7 +97,7 @@ srtp_err_status_t roc_test(int num_trials)
|
||||
|
||||
printf("\n\ttesting sequential insertion...");
|
||||
for (i = 0; i < 2048; i++) {
|
||||
delta = srtp_index_guess(&local, &est, (uint16_t)ref);
|
||||
srtp_index_guess(&local, &est, (uint16_t)ref);
|
||||
#if ROC_VERBOSE
|
||||
printf("%lld, %lld, %d\n", ref, est, i);
|
||||
#endif
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include "cipher_priv.h"
|
||||
|
||||
#define PRINT_DEBUG 0 /* set to 1 to print out debugging data */
|
||||
#define VERBOSE_DEBUG 0 /* set to 1 to print out more data */
|
||||
|
||||
@@ -148,7 +150,7 @@ int rtp_sender_init(rtp_sender_t sender,
|
||||
/* set header values */
|
||||
sender->message.header.ssrc = htonl(ssrc);
|
||||
sender->message.header.ts = 0;
|
||||
sender->message.header.seq = (uint16_t)rand();
|
||||
sender->message.header.seq = (uint16_t)srtp_cipher_rand_u32_for_tests();
|
||||
sender->message.header.m = 0;
|
||||
sender->message.header.pt = 0x1;
|
||||
sender->message.header.version = 2;
|
||||
|
||||
+274
-78
@@ -83,23 +83,76 @@
|
||||
|
||||
#define MAX_KEY_LEN 96
|
||||
#define MAX_FILTER 256
|
||||
#define MAX_FILE 255
|
||||
|
||||
struct srtp_crypto_suite {
|
||||
const char *can_name;
|
||||
int gcm_on;
|
||||
int key_size;
|
||||
int tag_size;
|
||||
};
|
||||
|
||||
static struct srtp_crypto_suite srtp_crypto_suites[] = {
|
||||
{.can_name = "AES_CM_128_HMAC_SHA1_32", .key_size = 128, .tag_size = 4 },
|
||||
#if 0
|
||||
{.can_name = "F8_128_HMAC_SHA1_32", .key_size = 128, .tag_size = 4},
|
||||
{.can_name = "F8_128_HMAC_SHA1_32", .gcm_on = 0, .key_size = 128, .tag_size = 4},
|
||||
#endif
|
||||
{.can_name = "AES_CM_128_HMAC_SHA1_32", .key_size = 128, .tag_size = 4 },
|
||||
{.can_name = "AES_CM_128_HMAC_SHA1_80", .key_size = 128, .tag_size = 10 },
|
||||
{.can_name = "AES_CM_128_HMAC_SHA1_32",
|
||||
.gcm_on = 0,
|
||||
.key_size = 128,
|
||||
.tag_size = 4 },
|
||||
{.can_name = "AES_CM_128_HMAC_SHA1_80",
|
||||
.gcm_on = 0,
|
||||
.key_size = 128,
|
||||
.tag_size = 10 },
|
||||
{.can_name = "AES_192_CM_HMAC_SHA1_32",
|
||||
.gcm_on = 0,
|
||||
.key_size = 192,
|
||||
.tag_size = 4 },
|
||||
{.can_name = "AES_192_CM_HMAC_SHA1_80",
|
||||
.gcm_on = 0,
|
||||
.key_size = 192,
|
||||
.tag_size = 10 },
|
||||
{.can_name = "AES_256_CM_HMAC_SHA1_32",
|
||||
.gcm_on = 0,
|
||||
.key_size = 256,
|
||||
.tag_size = 4 },
|
||||
{.can_name = "AES_256_CM_HMAC_SHA1_80",
|
||||
.gcm_on = 0,
|
||||
.key_size = 256,
|
||||
.tag_size = 10 },
|
||||
{.can_name = "AEAD_AES_128_GCM",
|
||||
.gcm_on = 1,
|
||||
.key_size = 128,
|
||||
.tag_size = 16 },
|
||||
{.can_name = "AEAD_AES_256_GCM",
|
||||
.gcm_on = 1,
|
||||
.key_size = 256,
|
||||
.tag_size = 16 },
|
||||
{.can_name = NULL }
|
||||
};
|
||||
|
||||
void rtp_decoder_srtp_log_handler(srtp_log_level_t level,
|
||||
const char *msg,
|
||||
void *data)
|
||||
{
|
||||
char level_char = '?';
|
||||
switch (level) {
|
||||
case srtp_log_level_error:
|
||||
level_char = 'e';
|
||||
break;
|
||||
case srtp_log_level_warning:
|
||||
level_char = 'w';
|
||||
break;
|
||||
case srtp_log_level_info:
|
||||
level_char = 'i';
|
||||
break;
|
||||
case srtp_log_level_debug:
|
||||
level_char = 'd';
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "SRTP-LOG [%c]: %s\n", level_char, msg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
@@ -112,15 +165,18 @@ int main(int argc, char *argv[])
|
||||
int c;
|
||||
struct srtp_crypto_suite scs, *i_scsp;
|
||||
scs.key_size = 128;
|
||||
scs.tag_size = 8;
|
||||
scs.tag_size = 0;
|
||||
int gcm_on = 0;
|
||||
char *input_key = NULL;
|
||||
int b64_input = 0;
|
||||
char key[MAX_KEY_LEN];
|
||||
struct bpf_program fp;
|
||||
char filter_exp[MAX_FILTER] = "";
|
||||
char pcap_file[MAX_FILE] = "-";
|
||||
int rtp_packet_offset = DEFAULT_RTP_OFFSET;
|
||||
rtp_decoder_t dec;
|
||||
srtp_policy_t policy;
|
||||
srtp_policy_t policy = { { 0 } };
|
||||
rtp_decoder_mode_t mode = mode_rtp;
|
||||
srtp_err_status_t status;
|
||||
int len;
|
||||
int expected_len;
|
||||
@@ -138,9 +194,15 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
status = srtp_install_log_handler(rtp_decoder_srtp_log_handler, NULL);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: install log handler failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* check args */
|
||||
while (1) {
|
||||
c = getopt_s(argc, argv, "b:k:gt:ae:ld:f:s:");
|
||||
c = getopt_s(argc, argv, "b:k:gt:ae:ld:f:s:m:p:o:");
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
@@ -153,10 +215,12 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case 'e':
|
||||
scs.key_size = atoi(optarg_s);
|
||||
if (scs.key_size != 128 && scs.key_size != 256) {
|
||||
fprintf(stderr,
|
||||
"error: encryption key size must be 128 or 256 (%d)\n",
|
||||
scs.key_size);
|
||||
if (scs.key_size != 128 && scs.key_size != 192 &&
|
||||
scs.key_size != 256) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"error: encryption key size must be 128, 192 or 256 (%d)\n",
|
||||
scs.key_size);
|
||||
exit(1);
|
||||
}
|
||||
input_key = malloc(scs.key_size);
|
||||
@@ -173,7 +237,7 @@ int main(int argc, char *argv[])
|
||||
sec_servs |= sec_serv_auth;
|
||||
break;
|
||||
case 'd':
|
||||
status = srtp_crypto_kernel_set_debug_module(optarg_s, 1);
|
||||
status = srtp_set_debug_module(optarg_s, 1);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: set debug module (%s) failed\n",
|
||||
optarg_s);
|
||||
@@ -207,20 +271,59 @@ int main(int argc, char *argv[])
|
||||
scs = *i_scsp;
|
||||
input_key = malloc(scs.key_size);
|
||||
sec_servs |= sec_serv_conf | sec_serv_auth;
|
||||
gcm_on = scs.gcm_on;
|
||||
break;
|
||||
case 'm':
|
||||
if (strcasecmp("rtp", optarg_s) == 0) {
|
||||
mode = mode_rtp;
|
||||
} else if (strcasecmp("rtcp", optarg_s) == 0) {
|
||||
mode = mode_rtcp;
|
||||
} else if (strcasecmp("rtcp-mux", optarg_s) == 0) {
|
||||
mode = mode_rtcp_mux;
|
||||
} else {
|
||||
fprintf(stderr, "Unknown/unsupported mode %s\n", optarg_s);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if (strlen(optarg_s) > MAX_FILE) {
|
||||
fprintf(stderr,
|
||||
"error: pcap file path bigger than %d characters\n",
|
||||
MAX_FILE);
|
||||
exit(1);
|
||||
}
|
||||
strcpy(pcap_file, optarg_s);
|
||||
break;
|
||||
case 'o':
|
||||
rtp_packet_offset = atoi(optarg_s);
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (scs.tag_size == 0) {
|
||||
if (gcm_on) {
|
||||
scs.tag_size = 16;
|
||||
} else {
|
||||
scs.tag_size = 10;
|
||||
}
|
||||
}
|
||||
|
||||
if (gcm_on && scs.tag_size != 8 && scs.tag_size != 16) {
|
||||
fprintf(stderr, "error: GCM tag size must be 8 or 16 (%d)\n",
|
||||
scs.tag_size);
|
||||
// exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!gcm_on && scs.tag_size != 4 && scs.tag_size != 10) {
|
||||
fprintf(stderr, "error: non GCM tag size must be 4 or 10 (%d)\n",
|
||||
scs.tag_size);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (do_list_mods) {
|
||||
status = srtp_crypto_kernel_list_debug_modules();
|
||||
status = srtp_list_debug_modules();
|
||||
if (status) {
|
||||
fprintf(stderr, "error: list of debug modules failed\n");
|
||||
exit(1);
|
||||
@@ -266,12 +369,24 @@ int main(int argc, char *argv[])
|
||||
#ifdef OPENSSL
|
||||
switch (scs.key_size) {
|
||||
case 128:
|
||||
srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtcp);
|
||||
if (scs.tag_size == 16) {
|
||||
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_128_16_auth(
|
||||
&policy.rtcp);
|
||||
} else {
|
||||
srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtcp);
|
||||
}
|
||||
break;
|
||||
case 256:
|
||||
srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy.rtcp);
|
||||
if (scs.tag_size == 16) {
|
||||
srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_256_16_auth(
|
||||
&policy.rtcp);
|
||||
} else {
|
||||
srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy.rtcp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#else
|
||||
@@ -282,12 +397,51 @@ int main(int argc, char *argv[])
|
||||
} else {
|
||||
switch (scs.key_size) {
|
||||
case 128:
|
||||
srtp_crypto_policy_set_rtp_default(&policy.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
if (scs.tag_size == 4) {
|
||||
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(
|
||||
&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
} else {
|
||||
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
|
||||
&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
}
|
||||
break;
|
||||
case 192:
|
||||
#ifdef OPENSSL
|
||||
if (scs.tag_size == 4) {
|
||||
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(
|
||||
&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
} else {
|
||||
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
|
||||
&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
}
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"error: AES 192 mode only supported when using the "
|
||||
"OpenSSL crypto engine.\n");
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
break;
|
||||
case 256:
|
||||
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
if (scs.tag_size == 4) {
|
||||
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(
|
||||
&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
} else {
|
||||
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
|
||||
&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -302,11 +456,26 @@ int main(int argc, char *argv[])
|
||||
switch (scs.key_size) {
|
||||
case 128:
|
||||
srtp_crypto_policy_set_aes_cm_128_null_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
break;
|
||||
case 192:
|
||||
#ifdef OPENSSL
|
||||
srtp_crypto_policy_set_aes_cm_192_null_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
#else
|
||||
fprintf(stderr,
|
||||
"error: AES 192 mode only supported when using the "
|
||||
"OpenSSL crypto engine.\n");
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
break;
|
||||
case 256:
|
||||
srtp_crypto_policy_set_aes_cm_256_null_auth(&policy.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
|
||||
&policy.rtcp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -342,7 +511,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
policy.key = (uint8_t *)key;
|
||||
policy.ekt = NULL;
|
||||
policy.next = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
@@ -353,7 +521,7 @@ int main(int argc, char *argv[])
|
||||
policy.rtp.auth_tag_len = scs.tag_size;
|
||||
|
||||
if (gcm_on && scs.tag_size != 8) {
|
||||
fprintf(stderr, "setted tag len %d\n", scs.tag_size);
|
||||
fprintf(stderr, "set tag len %d\n", scs.tag_size);
|
||||
policy.rtp.auth_tag_len = scs.tag_size;
|
||||
}
|
||||
|
||||
@@ -365,11 +533,7 @@ int main(int argc, char *argv[])
|
||||
int pad;
|
||||
expected_len = policy.rtp.cipher_key_len * 4 / 3;
|
||||
len = base64_string_to_octet_string(key, &pad, input_key,
|
||||
expected_len);
|
||||
if (pad != 0) {
|
||||
fprintf(stderr, "error: padding in base64 unexpected\n");
|
||||
exit(1);
|
||||
}
|
||||
strlen(input_key));
|
||||
} else {
|
||||
expected_len = policy.rtp.cipher_key_len * 2;
|
||||
len = hex_string_to_octet_string(key, input_key, expected_len);
|
||||
@@ -388,17 +552,20 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int key_octets = (scs.key_size / 8);
|
||||
int salt_octets = policy.rtp.cipher_key_len - key_octets;
|
||||
fprintf(stderr, "set master key/salt to %s/",
|
||||
octet_string_hex_string(key, 16));
|
||||
fprintf(stderr, "%s\n", octet_string_hex_string(key + 16, 14));
|
||||
octet_string_hex_string(key, key_octets));
|
||||
fprintf(stderr, "%s\n",
|
||||
octet_string_hex_string(key + key_octets, salt_octets));
|
||||
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"error: neither encryption or authentication were selected");
|
||||
"error: neither encryption or authentication were selected\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pcap_handle = pcap_open_offline("-", errbuf);
|
||||
pcap_handle = pcap_open_offline(pcap_file, errbuf);
|
||||
|
||||
if (!pcap_handle) {
|
||||
fprintf(stderr, "libpcap failed to open file '%s'\n", errbuf);
|
||||
@@ -421,11 +588,22 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "Starting decoder\n");
|
||||
rtp_decoder_init(dec, policy);
|
||||
if (rtp_decoder_init(dec, policy, mode, rtp_packet_offset)) {
|
||||
fprintf(stderr, "error: init failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pcap_loop(pcap_handle, 0, rtp_decoder_handle_pkt, (u_char *)dec);
|
||||
|
||||
rtp_decoder_deinit_srtp(dec);
|
||||
if (dec->mode == mode_rtp || dec->mode == mode_rtcp_mux) {
|
||||
fprintf(stderr, "RTP packets decoded: %d\n", dec->rtp_cnt);
|
||||
}
|
||||
if (dec->mode == mode_rtcp || dec->mode == mode_rtcp_mux) {
|
||||
fprintf(stderr, "RTCP packets decoded: %d\n", dec->rtcp_cnt);
|
||||
}
|
||||
fprintf(stderr, "Packet decode errors: %d\n", dec->error_cnt);
|
||||
|
||||
rtp_decoder_deinit(dec);
|
||||
rtp_decoder_dealloc(dec);
|
||||
|
||||
status = srtp_shutdown();
|
||||
@@ -442,7 +620,8 @@ void usage(char *string)
|
||||
{
|
||||
fprintf(
|
||||
stderr,
|
||||
"usage: %s [-d <debug>]* [[-k][-b] <key> [-a][-e]]\n"
|
||||
"usage: %s [-d <debug>]* [[-k][-b] <key>] [-a][-t][-e] [-s "
|
||||
"<srtp-crypto-suite>] [-m <mode>]\n"
|
||||
"or %s -l\n"
|
||||
"where -a use message authentication\n"
|
||||
" -e <key size> use encryption (use 128 or 256 for key size)\n"
|
||||
@@ -454,7 +633,10 @@ void usage(char *string)
|
||||
" -f \"<pcap filter>\" to filter only the desired SRTP packets\n"
|
||||
" -d <debug> turn on debugging for module <debug>\n"
|
||||
" -s \"<srtp-crypto-suite>\" to set both key and tag size based\n"
|
||||
" on RFC4568-style crypto suite specification\n",
|
||||
" on RFC4568-style crypto suite specification\n"
|
||||
" -m <mode> set the mode to be one of [rtp]|rtcp|rtcp-mux\n"
|
||||
" -p <pcap file> path to pcap file (defaults to stdin)\n"
|
||||
" -o byte offset of RTP packet in capture (defaults to 42)\n",
|
||||
string, string);
|
||||
exit(1);
|
||||
}
|
||||
@@ -469,27 +651,34 @@ void rtp_decoder_dealloc(rtp_decoder_t rtp_ctx)
|
||||
free(rtp_ctx);
|
||||
}
|
||||
|
||||
srtp_err_status_t rtp_decoder_init_srtp(rtp_decoder_t decoder,
|
||||
unsigned int ssrc)
|
||||
int rtp_decoder_deinit(rtp_decoder_t decoder)
|
||||
{
|
||||
decoder->policy.ssrc.value = htonl(ssrc);
|
||||
return srtp_create(&decoder->srtp_ctx, &decoder->policy);
|
||||
if (decoder->srtp_ctx) {
|
||||
return srtp_dealloc(decoder->srtp_ctx);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtp_decoder_deinit_srtp(rtp_decoder_t decoder)
|
||||
int rtp_decoder_init(rtp_decoder_t dcdr,
|
||||
srtp_policy_t policy,
|
||||
rtp_decoder_mode_t mode,
|
||||
int rtp_packet_offset)
|
||||
{
|
||||
return srtp_dealloc(decoder->srtp_ctx);
|
||||
}
|
||||
|
||||
int rtp_decoder_init(rtp_decoder_t dcdr, srtp_policy_t policy)
|
||||
{
|
||||
dcdr->rtp_offset = DEFAULT_RTP_OFFSET;
|
||||
dcdr->rtp_offset = rtp_packet_offset;
|
||||
dcdr->srtp_ctx = NULL;
|
||||
dcdr->start_tv.tv_usec = 0;
|
||||
dcdr->start_tv.tv_sec = 0;
|
||||
dcdr->frame_nr = -1;
|
||||
dcdr->error_cnt = 0;
|
||||
dcdr->rtp_cnt = 0;
|
||||
dcdr->rtcp_cnt = 0;
|
||||
dcdr->mode = mode;
|
||||
dcdr->policy = policy;
|
||||
dcdr->policy.ssrc.type = ssrc_specific;
|
||||
dcdr->policy.ssrc.type = ssrc_any_inbound;
|
||||
|
||||
if (srtp_create(&dcdr->srtp_ctx, &dcdr->policy)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -516,6 +705,8 @@ void rtp_decoder_handle_pkt(u_char *arg,
|
||||
const u_char *bytes)
|
||||
{
|
||||
rtp_decoder_t dcdr = (rtp_decoder_t)arg;
|
||||
rtp_msg_t message;
|
||||
int rtp;
|
||||
int pktsize;
|
||||
struct timeval delta;
|
||||
int octets_recvd;
|
||||
@@ -531,7 +722,7 @@ void rtp_decoder_handle_pkt(u_char *arg,
|
||||
}
|
||||
const void *rtp_packet = bytes + dcdr->rtp_offset;
|
||||
|
||||
memcpy((void *)&dcdr->message, rtp_packet, hdr->caplen - dcdr->rtp_offset);
|
||||
memcpy((void *)&message, rtp_packet, hdr->caplen - dcdr->rtp_offset);
|
||||
pktsize = hdr->caplen - dcdr->rtp_offset;
|
||||
octets_recvd = pktsize;
|
||||
|
||||
@@ -539,36 +730,41 @@ void rtp_decoder_handle_pkt(u_char *arg,
|
||||
return;
|
||||
}
|
||||
|
||||
/* verify rtp header */
|
||||
if (dcdr->message.header.version != 2) {
|
||||
return;
|
||||
}
|
||||
if (dcdr->srtp_ctx == NULL) {
|
||||
status = rtp_decoder_init_srtp(dcdr, dcdr->message.header.ssrc);
|
||||
if (status) {
|
||||
exit(1);
|
||||
if (dcdr->mode == mode_rtp) {
|
||||
rtp = 1;
|
||||
} else if (dcdr->mode == mode_rtcp) {
|
||||
rtp = 0;
|
||||
} else {
|
||||
rtp = 1;
|
||||
if (octets_recvd >= 2) {
|
||||
/* rfc5761 */
|
||||
u_char payload_type = *(bytes + dcdr->rtp_offset + 1) & 0x7f;
|
||||
rtp = payload_type < 64 || payload_type > 95;
|
||||
}
|
||||
}
|
||||
status = srtp_unprotect(dcdr->srtp_ctx, &dcdr->message, &octets_recvd);
|
||||
if (status) {
|
||||
return;
|
||||
|
||||
if (rtp) {
|
||||
/* verify rtp header */
|
||||
if (message.header.version != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
status = srtp_unprotect(dcdr->srtp_ctx, &message, &octets_recvd);
|
||||
if (status) {
|
||||
dcdr->error_cnt++;
|
||||
return;
|
||||
}
|
||||
dcdr->rtp_cnt++;
|
||||
} else {
|
||||
status = srtp_unprotect_rtcp(dcdr->srtp_ctx, &message, &octets_recvd);
|
||||
if (status) {
|
||||
dcdr->error_cnt++;
|
||||
return;
|
||||
}
|
||||
dcdr->rtcp_cnt++;
|
||||
}
|
||||
timersub(&hdr->ts, &dcdr->start_tv, &delta);
|
||||
fprintf(stdout, "%02ld:%02ld.%06ld\n", delta.tv_sec / 60, delta.tv_sec % 60,
|
||||
(long)delta.tv_usec);
|
||||
hexdump(&dcdr->message, octets_recvd);
|
||||
}
|
||||
|
||||
void rtp_print_error(srtp_err_status_t status, char *message)
|
||||
{
|
||||
// clang-format off
|
||||
fprintf(stderr,
|
||||
"error: %s %d%s\n", message, status,
|
||||
status == srtp_err_status_replay_fail ? " (replay check failed)" :
|
||||
status == srtp_err_status_bad_param ? " (bad param)" :
|
||||
status == srtp_err_status_no_ctx ? " (no context)" :
|
||||
status == srtp_err_status_cipher_fail ? " (cipher failed)" :
|
||||
status == srtp_err_status_key_expired ? " (key expired)" :
|
||||
status == srtp_err_status_auth_fail ? " (auth check failed)" : "");
|
||||
// clang-format on
|
||||
hexdump(&message, octets_recvd);
|
||||
}
|
||||
@@ -52,22 +52,26 @@
|
||||
|
||||
#define DEFAULT_RTP_OFFSET 42
|
||||
|
||||
typedef enum {
|
||||
mode_rtp = 0,
|
||||
mode_rtcp,
|
||||
mode_rtcp_mux,
|
||||
} rtp_decoder_mode_t;
|
||||
|
||||
typedef struct rtp_decoder_ctx_t {
|
||||
srtp_policy_t policy;
|
||||
srtp_ctx_t *srtp_ctx;
|
||||
rtp_decoder_mode_t mode;
|
||||
int rtp_offset;
|
||||
struct timeval start_tv;
|
||||
int frame_nr;
|
||||
rtp_msg_t message;
|
||||
int error_cnt;
|
||||
int rtp_cnt;
|
||||
int rtcp_cnt;
|
||||
} rtp_decoder_ctx_t;
|
||||
|
||||
typedef struct rtp_decoder_ctx_t *rtp_decoder_t;
|
||||
|
||||
/*
|
||||
* error to string
|
||||
*/
|
||||
void rtp_print_error(srtp_err_status_t status, char *message);
|
||||
|
||||
/*
|
||||
* prints the output of a random buffer in hexadecimal
|
||||
*/
|
||||
@@ -95,11 +99,19 @@ rtp_decoder_t rtp_decoder_alloc(void);
|
||||
|
||||
void rtp_decoder_dealloc(rtp_decoder_t rtp_ctx);
|
||||
|
||||
int rtp_decoder_init(rtp_decoder_t dcdr, srtp_policy_t policy);
|
||||
int rtp_decoder_init(rtp_decoder_t dcdr,
|
||||
srtp_policy_t policy,
|
||||
rtp_decoder_mode_t mode,
|
||||
int rtp_packet_offset);
|
||||
|
||||
srtp_err_status_t rtp_decoder_init_srtp(rtp_decoder_t decoder,
|
||||
unsigned int ssrc);
|
||||
int rtp_decoder_deinit(rtp_decoder_t decoder);
|
||||
|
||||
int rtp_decoder_deinit_srtp(rtp_decoder_t decoder);
|
||||
void rtp_decoder_srtp_log_handler(srtp_log_level_t level,
|
||||
const char *msg,
|
||||
void *data);
|
||||
|
||||
void rtp_decoder_srtp_log_handler(srtp_log_level_t level,
|
||||
const char *msg,
|
||||
void *data);
|
||||
|
||||
#endif /* RTP_DECODER_H */
|
||||
@@ -96,7 +96,7 @@
|
||||
|
||||
#ifndef HAVE_USLEEP
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
#define usleep(us) Sleep((us) / 1000)
|
||||
#define usleep(us) Sleep(((DWORD)us) / 1000)
|
||||
#else
|
||||
#define usleep(us) sleep((us) / 1000000)
|
||||
#endif
|
||||
@@ -317,6 +317,7 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(&name, 0, sizeof(struct sockaddr_in));
|
||||
name.sin_addr = rcvr_addr;
|
||||
name.sin_family = PF_INET;
|
||||
name.sin_port = htons(port);
|
||||
@@ -364,7 +365,7 @@ int main(int argc, char *argv[])
|
||||
switch (sec_servs) {
|
||||
case sec_serv_conf_and_auth:
|
||||
if (gcm_on) {
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
switch (key_size) {
|
||||
case 128:
|
||||
srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
|
||||
@@ -377,7 +378,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#else
|
||||
printf("error: GCM mode only supported when using the OpenSSL "
|
||||
"crypto engine.\n");
|
||||
"or NSS crypto engine.\n");
|
||||
return 0;
|
||||
#endif
|
||||
} else {
|
||||
@@ -413,7 +414,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case sec_serv_auth:
|
||||
if (gcm_on) {
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
switch (key_size) {
|
||||
case 128:
|
||||
srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&policy.rtp);
|
||||
@@ -443,7 +444,6 @@ int main(int argc, char *argv[])
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = ssrc;
|
||||
policy.key = (uint8_t *)key;
|
||||
policy.ekt = NULL;
|
||||
policy.next = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
@@ -505,7 +505,6 @@ int main(int argc, char *argv[])
|
||||
policy.ssrc.value = ssrc;
|
||||
policy.window_size = 0;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.ekt = NULL;
|
||||
policy.next = NULL;
|
||||
}
|
||||
|
||||
@@ -670,7 +669,7 @@ void handle_signal(int signum)
|
||||
|
||||
int setup_signal_handler(char *name)
|
||||
{
|
||||
#if HAVE_SIGACTION
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
|
||||
|
||||
@@ -41,12 +41,24 @@ case $(uname -s) in
|
||||
*CYGWIN*|*MINGW*)
|
||||
EXE=".exe"
|
||||
;;
|
||||
*)
|
||||
*Linux*)
|
||||
EXE=""
|
||||
if [ -n "$CRYPTO_LIBDIR" ]
|
||||
then
|
||||
export LD_LIBRARY_PATH="$CRYPTO_LIBDIR"
|
||||
fi
|
||||
;;
|
||||
*Darwin*)
|
||||
EXE=""
|
||||
if [ -n "$CRYPTO_LIBDIR" ]
|
||||
then
|
||||
export DYLD_LIBRARY_PATH="$CRYPTO_LIBDIR"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
RTPW=./rtpw$EXE
|
||||
[ -n "$MESON_EXE_WRAPPER" ] && RTPW="$MESON_EXE_WRAPPER $RTPW"
|
||||
DEST_PORT=9999
|
||||
DURATION=3
|
||||
|
||||
@@ -62,7 +74,7 @@ ARGS="-b $key -a -e 128"
|
||||
|
||||
killall rtpw 2>/dev/null
|
||||
|
||||
if test -x $RTPW; then
|
||||
if test -n $MESON_EXE_WRAPPER || test -x $RTPW; then
|
||||
|
||||
echo $0 ": starting rtpw receiver process... "
|
||||
|
||||
|
||||
@@ -41,12 +41,24 @@ case $(uname -s) in
|
||||
*CYGWIN*|*MINGW*)
|
||||
EXE=".exe"
|
||||
;;
|
||||
*)
|
||||
*Linux*)
|
||||
EXE=""
|
||||
if [ -n "$CRYPTO_LIBDIR" ]
|
||||
then
|
||||
export LD_LIBRARY_PATH="$CRYPTO_LIBDIR"
|
||||
fi
|
||||
;;
|
||||
*Darwin*)
|
||||
EXE=""
|
||||
if [ -n "$CRYPTO_LIBDIR" ]
|
||||
then
|
||||
export DYLD_LIBRARY_PATH="$CRYPTO_LIBDIR"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
RTPW=./rtpw$EXE
|
||||
[ -n "$MESON_EXE_WRAPPER" ] && RTPW="$MESON_EXE_WRAPPER $RTPW"
|
||||
DEST_PORT=9999
|
||||
DURATION=3
|
||||
|
||||
@@ -58,7 +70,7 @@ DURATION=3
|
||||
|
||||
killall rtpw 2>/dev/null
|
||||
|
||||
if test -x $RTPW; then
|
||||
if test -n $MESON_EXE_WRAPPER || test -x $RTPW; then
|
||||
|
||||
GCMARGS128="-k 01234567890123456789012345678901234567890123456789012345 -g -e 128"
|
||||
echo $0 ": starting GCM mode 128-bit rtpw receiver process... "
|
||||
|
||||
@@ -61,13 +61,13 @@
|
||||
|
||||
srtp_err_status_t srtp_validate(void);
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
srtp_err_status_t srtp_validate_gcm(void);
|
||||
#endif
|
||||
|
||||
srtp_err_status_t srtp_validate_encrypted_extensions_headers(void);
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm(void);
|
||||
#endif
|
||||
|
||||
@@ -79,7 +79,7 @@ srtp_err_status_t srtp_dealloc_big_policy(srtp_policy_t *list);
|
||||
|
||||
srtp_err_status_t srtp_test_empty_payload(void);
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
srtp_err_status_t srtp_test_empty_payload_gcm(void);
|
||||
#endif
|
||||
|
||||
@@ -181,11 +181,12 @@ void log_handler(srtp_log_level_t level, const char *msg, void *data)
|
||||
}
|
||||
|
||||
/*
|
||||
* The policy_array is a null-terminated array of policy structs. it
|
||||
* is declared at the end of this file
|
||||
* The policy_array and invalid_policy_array are null-terminated arrays of
|
||||
* policy structs. They is declared at the end of this file.
|
||||
*/
|
||||
|
||||
extern const srtp_policy_t *policy_array[];
|
||||
extern const srtp_policy_t *invalid_policy_array[];
|
||||
|
||||
/* the wildcard_policy is declared below; it has a wildcard ssrc */
|
||||
|
||||
@@ -302,6 +303,7 @@ int main(int argc, char *argv[])
|
||||
if (do_validation) {
|
||||
const srtp_policy_t **policy = policy_array;
|
||||
srtp_policy_t *big_policy;
|
||||
srtp_t srtp_sender;
|
||||
|
||||
/* loop over policy array, testing srtp and srtcp for each policy */
|
||||
while (*policy != NULL) {
|
||||
@@ -364,6 +366,21 @@ int main(int argc, char *argv[])
|
||||
policy++;
|
||||
}
|
||||
|
||||
/* loop over invalid policy array, testing that an SRTP context cannot
|
||||
* be created with the policy */
|
||||
policy = invalid_policy_array;
|
||||
while (*policy != NULL) {
|
||||
printf("testing srtp_create fails with invalid policy\n");
|
||||
if (srtp_create(&srtp_sender, *policy) != srtp_err_status_ok) {
|
||||
printf("passed\n\n");
|
||||
} else {
|
||||
printf("failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
policy++;
|
||||
}
|
||||
|
||||
/* create a big policy list and run tests on it */
|
||||
status = srtp_create_big_policy(&big_policy);
|
||||
if (status) {
|
||||
@@ -422,7 +439,7 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
printf("testing srtp_protect and srtp_unprotect against "
|
||||
"reference packet using GCM\n");
|
||||
if (srtp_validate_gcm() == srtp_err_status_ok) {
|
||||
@@ -442,7 +459,7 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
printf("testing srtp_protect and srtp_unprotect against "
|
||||
"reference packet with encrypted extension headers (GCM)\n");
|
||||
if (srtp_validate_encrypted_extensions_headers_gcm() ==
|
||||
@@ -478,7 +495,7 @@ int main(int argc, char *argv[])
|
||||
printf("failed\n");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
printf("testing srtp_protect and srtp_unprotect against "
|
||||
"packet with empty payload (GCM)\n");
|
||||
if (srtp_test_empty_payload_gcm() == srtp_err_status_ok) {
|
||||
@@ -589,7 +606,7 @@ int main(int argc, char *argv[])
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xdecafbad;
|
||||
policy.key = test_key;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -928,12 +945,10 @@ double srtp_rejections_per_second(int msg_len_octets,
|
||||
|
||||
void err_check(srtp_err_status_t s)
|
||||
{
|
||||
if (s == srtp_err_status_ok) {
|
||||
return;
|
||||
} else {
|
||||
if (s != srtp_err_status_ok) {
|
||||
fprintf(stderr, "error: unexpected srtp failure (code %d)\n", s);
|
||||
exit(1);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_test_call_protect(srtp_t srtp_sender,
|
||||
@@ -1341,6 +1356,8 @@ srtp_err_status_t srtcp_test(const srtp_policy_t *policy, int mki_index)
|
||||
*/
|
||||
rcvr_policy = (srtp_policy_t *)malloc(sizeof(srtp_policy_t));
|
||||
if (rcvr_policy == NULL) {
|
||||
free(hdr);
|
||||
free(hdr2);
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
memcpy(rcvr_policy, policy, sizeof(srtp_policy_t));
|
||||
@@ -1606,6 +1623,9 @@ double mips_estimate(int num_trials, int *ignore)
|
||||
sum += i;
|
||||
}
|
||||
t = clock() - t;
|
||||
if (t < 1) {
|
||||
t = 1;
|
||||
}
|
||||
|
||||
/* printf("%d\n", sum); */
|
||||
*ignore = sum;
|
||||
@@ -1678,7 +1698,7 @@ srtp_err_status_t srtp_validate()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = test_key;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -1702,7 +1722,7 @@ srtp_err_status_t srtp_validate()
|
||||
debug_print(mod_driver, "ciphertext reference:\n %s",
|
||||
octet_string_hex_string(srtp_ciphertext, len));
|
||||
|
||||
if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
|
||||
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -1720,7 +1740,7 @@ srtp_err_status_t srtp_validate()
|
||||
debug_print(mod_driver, "srtcp ciphertext reference:\n %s",
|
||||
octet_string_hex_string(srtcp_ciphertext, len));
|
||||
|
||||
if (octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
|
||||
if (srtp_octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -1742,7 +1762,7 @@ srtp_err_status_t srtp_validate()
|
||||
return status;
|
||||
}
|
||||
|
||||
if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
|
||||
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -1755,7 +1775,7 @@ srtp_err_status_t srtp_validate()
|
||||
return status;
|
||||
}
|
||||
|
||||
if (octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
|
||||
if (srtp_octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -1772,7 +1792,7 @@ srtp_err_status_t srtp_validate()
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
/*
|
||||
* srtp_validate_gcm() verifies the correctness of libsrtp by comparing
|
||||
* an computed packet against the known ciphertext for the plaintext.
|
||||
@@ -1846,7 +1866,7 @@ srtp_err_status_t srtp_validate_gcm()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = test_key_gcm;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -1870,7 +1890,7 @@ srtp_err_status_t srtp_validate_gcm()
|
||||
debug_print(mod_driver, "srtp ciphertext reference:\n %s",
|
||||
octet_string_hex_string(srtp_ciphertext, len));
|
||||
|
||||
if (octet_string_is_eq(rtp_plaintext, srtp_ciphertext, len)) {
|
||||
if (srtp_octet_string_is_eq(rtp_plaintext, srtp_ciphertext, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -1888,7 +1908,7 @@ srtp_err_status_t srtp_validate_gcm()
|
||||
debug_print(mod_driver, "srtcp ciphertext reference:\n %s",
|
||||
octet_string_hex_string(srtcp_ciphertext, len));
|
||||
|
||||
if (octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
|
||||
if (srtp_octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -1911,7 +1931,7 @@ srtp_err_status_t srtp_validate_gcm()
|
||||
return status;
|
||||
}
|
||||
|
||||
if (octet_string_is_eq(srtp_ciphertext, rtp_plaintext_ref, len)) {
|
||||
if (srtp_octet_string_is_eq(srtp_ciphertext, rtp_plaintext_ref, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -1924,7 +1944,7 @@ srtp_err_status_t srtp_validate_gcm()
|
||||
return status;
|
||||
}
|
||||
|
||||
if (octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
|
||||
if (srtp_octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -2003,7 +2023,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = test_key_ext_headers;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.enc_xtn_hdr = headers;
|
||||
@@ -2027,7 +2047,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers()
|
||||
debug_print(mod_driver, "ciphertext reference:\n %s",
|
||||
srtp_octet_string_hex_string(srtp_ciphertext, len));
|
||||
|
||||
if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
|
||||
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
|
||||
return srtp_err_status_fail;
|
||||
|
||||
/*
|
||||
@@ -2049,7 +2069,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers()
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
|
||||
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
|
||||
return srtp_err_status_fail;
|
||||
|
||||
status = srtp_dealloc(srtp_snd);
|
||||
@@ -2063,7 +2083,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers()
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
|
||||
/*
|
||||
* Headers of test vectors taken from RFC 6904, Appendix A
|
||||
@@ -2124,7 +2144,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = test_key_ext_headers;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.enc_xtn_hdr = headers;
|
||||
@@ -2148,7 +2168,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm()
|
||||
debug_print(mod_driver, "ciphertext reference:\n %s",
|
||||
srtp_octet_string_hex_string(srtp_ciphertext, len));
|
||||
|
||||
if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
|
||||
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
|
||||
return srtp_err_status_fail;
|
||||
|
||||
/*
|
||||
@@ -2170,7 +2190,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm()
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
|
||||
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
|
||||
return srtp_err_status_fail;
|
||||
|
||||
status = srtp_dealloc(srtp_snd);
|
||||
@@ -2240,7 +2260,7 @@ srtp_err_status_t srtp_validate_aes_256()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = aes_256_test_key;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -2264,7 +2284,7 @@ srtp_err_status_t srtp_validate_aes_256()
|
||||
debug_print(mod_driver, "ciphertext reference:\n %s",
|
||||
octet_string_hex_string(srtp_ciphertext, len));
|
||||
|
||||
if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
|
||||
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -2286,7 +2306,7 @@ srtp_err_status_t srtp_validate_aes_256()
|
||||
return status;
|
||||
}
|
||||
|
||||
if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
|
||||
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
@@ -2306,7 +2326,8 @@ srtp_err_status_t srtp_validate_aes_256()
|
||||
srtp_err_status_t srtp_create_big_policy(srtp_policy_t **list)
|
||||
{
|
||||
extern const srtp_policy_t *policy_array[];
|
||||
srtp_policy_t *p, *tmp;
|
||||
srtp_policy_t *p = NULL;
|
||||
srtp_policy_t *tmp;
|
||||
int i = 0;
|
||||
uint32_t ssrc = 0;
|
||||
|
||||
@@ -2367,7 +2388,7 @@ srtp_err_status_t srtp_test_empty_payload()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = test_key;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -2424,7 +2445,7 @@ srtp_err_status_t srtp_test_empty_payload()
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
srtp_err_status_t srtp_test_empty_payload_gcm()
|
||||
{
|
||||
srtp_t srtp_snd, srtp_recv;
|
||||
@@ -2443,7 +2464,7 @@ srtp_err_status_t srtp_test_empty_payload_gcm()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = test_key;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -2499,7 +2520,7 @@ srtp_err_status_t srtp_test_empty_payload_gcm()
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
#endif // OPENSSL
|
||||
#endif // GCM
|
||||
|
||||
srtp_err_status_t srtp_test_remove_stream()
|
||||
{
|
||||
@@ -2568,7 +2589,7 @@ srtp_err_status_t srtp_test_remove_stream()
|
||||
policy.ssrc.type = ssrc_specific;
|
||||
policy.ssrc.value = 0xcafebabe;
|
||||
policy.key = test_key;
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -2627,7 +2648,7 @@ srtp_err_status_t srtp_test_update()
|
||||
memset(&policy, 0, sizeof(policy));
|
||||
srtp_crypto_policy_set_rtp_default(&policy.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -2783,15 +2804,15 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams(
|
||||
srtp_policy_t policy;
|
||||
srtp_policy_t policy_mki;
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
srtp_policy_t policy_aes_gcm;
|
||||
srtp_policy_t policy_aes_gcm_mki;
|
||||
#endif // OPENSSL
|
||||
#endif // GCM
|
||||
|
||||
memset(&policy, 0, sizeof(policy));
|
||||
srtp_crypto_policy_set_rtp_default(&policy.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
policy.ekt = NULL;
|
||||
policy.deprecated_ekt = NULL;
|
||||
policy.window_size = 128;
|
||||
policy.allow_repeat_tx = 0;
|
||||
policy.next = NULL;
|
||||
@@ -2801,7 +2822,7 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams(
|
||||
memset(&policy_mki, 0, sizeof(policy_mki));
|
||||
srtp_crypto_policy_set_rtp_default(&policy_mki.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy_mki.rtcp);
|
||||
policy_mki.ekt = NULL;
|
||||
policy_mki.deprecated_ekt = NULL;
|
||||
policy_mki.window_size = 128;
|
||||
policy_mki.allow_repeat_tx = 0;
|
||||
policy_mki.next = NULL;
|
||||
@@ -2810,11 +2831,11 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams(
|
||||
policy_mki.keys = test_keys;
|
||||
policy_mki.num_master_keys = 2;
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
memset(&policy_aes_gcm, 0, sizeof(policy_aes_gcm));
|
||||
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm.rtcp);
|
||||
policy_aes_gcm.ekt = NULL;
|
||||
policy_aes_gcm.deprecated_ekt = NULL;
|
||||
policy_aes_gcm.window_size = 128;
|
||||
policy_aes_gcm.allow_repeat_tx = 0;
|
||||
policy_aes_gcm.next = NULL;
|
||||
@@ -2824,7 +2845,7 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams(
|
||||
memset(&policy_aes_gcm_mki, 0, sizeof(policy_aes_gcm_mki));
|
||||
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm_mki.rtp);
|
||||
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm_mki.rtcp);
|
||||
policy_aes_gcm_mki.ekt = NULL;
|
||||
policy_aes_gcm_mki.deprecated_ekt = NULL;
|
||||
policy_aes_gcm_mki.window_size = 128;
|
||||
policy_aes_gcm_mki.allow_repeat_tx = 0;
|
||||
policy_aes_gcm_mki.next = NULL;
|
||||
@@ -2832,7 +2853,7 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams(
|
||||
policy_aes_gcm_mki.key = NULL;
|
||||
policy_aes_gcm_mki.keys = test_keys;
|
||||
policy_aes_gcm_mki.num_master_keys = 2;
|
||||
#endif
|
||||
#endif // GCM
|
||||
|
||||
/* create a send ctx with defualt profile and test_key */
|
||||
status = srtp_create(srtp_send, &policy);
|
||||
@@ -2843,7 +2864,7 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams(
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
status = srtp_create(srtp_send_aes_gcm, &policy_aes_gcm);
|
||||
if (status)
|
||||
return status;
|
||||
@@ -2851,7 +2872,7 @@ srtp_err_status_t srtp_test_setup_protect_trailer_streams(
|
||||
status = srtp_create(srtp_send_aes_gcm_mki, &policy_aes_gcm_mki);
|
||||
if (status)
|
||||
return status;
|
||||
#endif // OPENSSL
|
||||
#endif // GCM
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
@@ -2884,7 +2905,7 @@ srtp_err_status_t srtp_test_protect_trailer_length()
|
||||
if (length != 14)
|
||||
return srtp_err_status_fail;
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
status = srtp_get_protect_trailer_length(srtp_send_aes_gcm, 0, 0, &length);
|
||||
if (status)
|
||||
return status;
|
||||
@@ -2901,11 +2922,11 @@ srtp_err_status_t srtp_test_protect_trailer_length()
|
||||
/* TAG Length: 16 bytes + MKI length: 4 bytes*/
|
||||
if (length != 20)
|
||||
return srtp_err_status_fail;
|
||||
#endif // OPENSSL
|
||||
#endif // GCM
|
||||
|
||||
srtp_dealloc(srtp_send);
|
||||
srtp_dealloc(srtp_send_mki);
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
srtp_dealloc(srtp_send_aes_gcm);
|
||||
srtp_dealloc(srtp_send_aes_gcm_mki);
|
||||
#endif
|
||||
@@ -2941,7 +2962,7 @@ srtp_err_status_t srtp_test_protect_rtcp_trailer_length()
|
||||
if (length != 18)
|
||||
return srtp_err_status_fail;
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
status =
|
||||
srtp_get_protect_rtcp_trailer_length(srtp_send_aes_gcm, 0, 0, &length);
|
||||
if (status)
|
||||
@@ -2959,11 +2980,11 @@ srtp_err_status_t srtp_test_protect_rtcp_trailer_length()
|
||||
/* TAG Length: 16 bytes + SRTCP Trailer 4 bytes + MKI 4 bytes*/
|
||||
if (length != 24)
|
||||
return srtp_err_status_fail;
|
||||
#endif // OPENSSL
|
||||
#endif // GCM
|
||||
|
||||
srtp_dealloc(srtp_send);
|
||||
srtp_dealloc(srtp_send_mki);
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
srtp_dealloc(srtp_send_aes_gcm);
|
||||
srtp_dealloc(srtp_send_aes_gcm_mki);
|
||||
#endif
|
||||
@@ -3088,6 +3109,7 @@ static srtp_err_status_t test_set_receiver_roc(uint32_t packets,
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
seq++;
|
||||
ts++;
|
||||
}
|
||||
@@ -3500,7 +3522,7 @@ const srtp_policy_t hmac_only_policy = {
|
||||
NULL
|
||||
};
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
const srtp_policy_t aes128_gcm_8_policy = {
|
||||
{ ssrc_any_outbound, 0 }, /* SSRC */
|
||||
{
|
||||
@@ -3724,23 +3746,7 @@ const srtp_policy_t aes_256_hmac_policy = {
|
||||
NULL
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
uint8_t ekt_test_key[16] = {
|
||||
0x77, 0x26, 0x9d, 0xac, 0x16, 0xa3, 0x28, 0xca,
|
||||
0x8e, 0xc9, 0x68, 0x4b, 0xcc, 0xc4, 0xd2, 0x1b
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
#include "ekt.h"
|
||||
|
||||
// clang-format off
|
||||
srtp_ekt_policy_ctx_t ekt_test_policy = {
|
||||
0xa5a5, /* SPI */
|
||||
SRTP_EKT_CIPHER_AES_128_ECB,
|
||||
ekt_test_key,
|
||||
NULL
|
||||
};
|
||||
// clang-format on
|
||||
char ekt_test_policy = 'x';
|
||||
|
||||
const srtp_policy_t hmac_only_with_ekt_policy = {
|
||||
{ ssrc_any_outbound, 0 }, /* SSRC */
|
||||
@@ -3763,7 +3769,7 @@ const srtp_policy_t hmac_only_with_ekt_policy = {
|
||||
NULL,
|
||||
(srtp_master_key_t **)test_keys,
|
||||
2, /* indicates the number of Master keys */
|
||||
&ekt_test_policy, /* indicates that EKT is not in use */
|
||||
&ekt_test_policy, /* requests deprecated EKT functionality */
|
||||
128, /* replay window size */
|
||||
0, /* retransmission not allowed */
|
||||
NULL, /* no encrypted extension headers */
|
||||
@@ -3786,7 +3792,7 @@ const srtp_policy_t *policy_array[] = {
|
||||
&hmac_only_policy,
|
||||
&aes_only_policy,
|
||||
&default_policy,
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
&aes128_gcm_8_policy,
|
||||
&aes128_gcm_8_cauth_policy,
|
||||
&aes256_gcm_8_policy,
|
||||
@@ -3794,6 +3800,12 @@ const srtp_policy_t *policy_array[] = {
|
||||
#endif
|
||||
&null_policy,
|
||||
&aes_256_hmac_policy,
|
||||
NULL
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// clang-format off
|
||||
const srtp_policy_t *invalid_policy_array[] = {
|
||||
&hmac_only_with_ekt_policy,
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -43,16 +43,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Test specific.
|
||||
*/
|
||||
#include "cutest.h"
|
||||
|
||||
/*
|
||||
* libSRTP specific.
|
||||
*/
|
||||
#include "../srtp/srtp.c" // Get access to static functions
|
||||
|
||||
/*
|
||||
* Test specific.
|
||||
*/
|
||||
#include "cutest.h"
|
||||
|
||||
/*
|
||||
* Standard library.
|
||||
*/
|
||||
@@ -152,14 +152,15 @@ void srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number()
|
||||
srtp_session_keys_t session_keys;
|
||||
srtcp_hdr_t header;
|
||||
v128_t output_iv[SAMPLE_COUNT];
|
||||
memset(&output_iv, 0, SAMPLE_COUNT * sizeof(v128_t));
|
||||
uint32_t sequence_num[SAMPLE_COUNT];
|
||||
v128_t final_iv[SAMPLE_COUNT];
|
||||
size_t i = 0;
|
||||
memset(&output_iv, 0, SAMPLE_COUNT * sizeof(v128_t));
|
||||
sequence_num[0] = 0xFF;
|
||||
sequence_num[1] = 0xFF00;
|
||||
sequence_num[2] = 0xFF0000;
|
||||
|
||||
// Postconditions
|
||||
v128_t final_iv[SAMPLE_COUNT];
|
||||
memset(&final_iv, 0, SAMPLE_COUNT * sizeof(v128_t));
|
||||
final_iv[0].v8[11] = 0xFF;
|
||||
final_iv[1].v8[10] = 0xFF;
|
||||
@@ -170,7 +171,6 @@ void srtp_calc_aead_iv_srtcp_distinct_iv_per_sequence_number()
|
||||
memset(&header, 0, sizeof(srtcp_hdr_t));
|
||||
|
||||
// When
|
||||
size_t i = 0;
|
||||
for (i = 0; i < SAMPLE_COUNT; i++) {
|
||||
TEST_CHECK(srtp_calc_aead_iv_srtcp(&session_keys, &output_iv[i],
|
||||
sequence_num[i],
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* ut_sim.c
|
||||
*
|
||||
* an unreliable transport simulator
|
||||
* (for testing replay databases and suchlike)
|
||||
*
|
||||
* David A. McGrew
|
||||
* 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
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ut_sim.h"
|
||||
#include "cipher_priv.h"
|
||||
|
||||
int ut_compar(const void *a, const void *b)
|
||||
{
|
||||
uint8_t r;
|
||||
srtp_cipher_rand_for_tests(&r, sizeof(r));
|
||||
return r > (UINT8_MAX / 2) ? -1 : 1;
|
||||
}
|
||||
|
||||
void ut_init(ut_connection *utc)
|
||||
{
|
||||
int i;
|
||||
utc->index = 0;
|
||||
|
||||
for (i = 0; i < UT_BUF; i++)
|
||||
utc->buffer[i] = i;
|
||||
|
||||
qsort(utc->buffer, UT_BUF, sizeof(uint32_t), ut_compar);
|
||||
|
||||
utc->index = UT_BUF - 1;
|
||||
}
|
||||
|
||||
uint32_t ut_next_index(ut_connection *utc)
|
||||
{
|
||||
uint32_t tmp;
|
||||
|
||||
tmp = utc->buffer[0];
|
||||
utc->index++;
|
||||
utc->buffer[0] = utc->index;
|
||||
|
||||
qsort(utc->buffer, UT_BUF, sizeof(uint32_t), ut_compar);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
#ifdef UT_TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
uint32_t i, irecvd, idiff;
|
||||
ut_connection utc;
|
||||
|
||||
ut_init(&utc);
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
irecvd = ut_next_index(&utc);
|
||||
idiff = i - irecvd;
|
||||
printf("%lu\t%lu\t%d\n", i, irecvd, idiff);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* ut-sim.h
|
||||
*
|
||||
* an unreliable transport simulator
|
||||
* (for testing replay databases and suchlike)
|
||||
*
|
||||
* David A. McGrew
|
||||
* 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
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UT_SIM_H
|
||||
#define UT_SIM_H
|
||||
|
||||
#include "integers.h" /* for uint32_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UT_BUF 160 /* maximum amount of packet reorder */
|
||||
|
||||
typedef struct {
|
||||
uint32_t index;
|
||||
uint32_t buffer[UT_BUF];
|
||||
} ut_connection;
|
||||
|
||||
/*
|
||||
* ut_init(&u) initializes the ut_connection
|
||||
*
|
||||
* this function should always be the first one called on a new
|
||||
* ut_connection
|
||||
*/
|
||||
|
||||
void ut_init(ut_connection *utc);
|
||||
|
||||
/*
|
||||
* ut_next_index(&u) returns the next index from the simulated
|
||||
* unreliable connection
|
||||
*/
|
||||
|
||||
uint32_t ut_next_index(ut_connection *utc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UT_SIM_H */
|
||||
@@ -42,12 +42,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
char bit_string[MAX_PRINT_STRING_LEN];
|
||||
/* include space for null terminator */
|
||||
static char bit_string[MAX_PRINT_STRING_LEN + 1];
|
||||
|
||||
static inline int hex_char_to_nibble(uint8_t c)
|
||||
{
|
||||
@@ -151,7 +153,7 @@ char *octet_string_hex_string(const void *s, int length)
|
||||
|
||||
/* truncate string if it would be too long */
|
||||
if (length > MAX_PRINT_STRING_LEN) {
|
||||
length = MAX_PRINT_STRING_LEN - 1;
|
||||
length = MAX_PRINT_STRING_LEN;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i += 2) {
|
||||
|
||||
Reference in new issue
Block a user