mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-15 22:08:33 +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
@@ -67,7 +67,7 @@
|
||||
|
||||
void usage(char *prog_name)
|
||||
{
|
||||
printf("usage: %s <key> <plaintext> [-v]\n", prog_name);
|
||||
printf("usage: %s <key> <plaintext> [<ciphertext>] [-v]\n", prog_name);
|
||||
exit(255);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ void usage(char *prog_name)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *expected_ciphertext = NULL;
|
||||
const char *ciphertext = NULL;
|
||||
v128_t data;
|
||||
uint8_t key[AES_MAX_KEY_LEN];
|
||||
srtp_aes_expanded_key_t exp_key;
|
||||
@@ -82,22 +84,26 @@ int main(int argc, char *argv[])
|
||||
int verbose = 0;
|
||||
srtp_err_status_t status;
|
||||
|
||||
if (argc == 3) {
|
||||
/* we're not in verbose mode */
|
||||
verbose = 0;
|
||||
} else if (argc == 4) {
|
||||
if (strncmp(argv[3], "-v", 2) == 0) {
|
||||
/* we're in verbose mode */
|
||||
verbose = 1;
|
||||
} else {
|
||||
/* unrecognized flag, complain and exit */
|
||||
usage(argv[0]);
|
||||
}
|
||||
} else {
|
||||
/* -v must be last if it's passed */
|
||||
if (argc > 0 && strncmp(argv[argc - 1], "-v", 2) == 0) {
|
||||
/* we're in verbose mode */
|
||||
verbose = 1;
|
||||
--argc;
|
||||
}
|
||||
|
||||
if (argc < 3 || argc > 4) {
|
||||
/* we've been fed the wrong number of arguments - compain and exit */
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
/* we're being passed the ciphertext to check (in unit test mode) */
|
||||
expected_ciphertext = argv[3];
|
||||
if (strlen(expected_ciphertext) != 16 * 2) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/* read in key, checking length */
|
||||
if (strlen(argv[1]) > AES_MAX_KEY_LEN * 2) {
|
||||
fprintf(stderr, "error: too many digits in key "
|
||||
@@ -151,7 +157,16 @@ int main(int argc, char *argv[])
|
||||
printf("key:\t\t%s\n", octet_string_hex_string(key, key_len));
|
||||
printf("ciphertext:\t");
|
||||
}
|
||||
printf("%s\n", v128_hex_string(&data));
|
||||
|
||||
ciphertext = v128_hex_string(&data);
|
||||
printf("%s\n", ciphertext);
|
||||
|
||||
if (expected_ciphertext && strcmp(ciphertext, expected_ciphertext) != 0) {
|
||||
fprintf(stderr, "error: calculated ciphertext %s does not match "
|
||||
"expected ciphertext %s\n",
|
||||
ciphertext, expected_ciphertext);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -47,16 +47,11 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include <stdlib.h> /* for rand() */
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include "getopt_s.h"
|
||||
#include "cipher.h"
|
||||
#ifdef OPENSSL
|
||||
#include "aes_icm_ossl.h"
|
||||
#include "aes_gcm_ossl.h"
|
||||
#else
|
||||
#include "aes_icm.h"
|
||||
#endif
|
||||
#include "cipher_priv.h"
|
||||
#include "datatypes.h"
|
||||
|
||||
#define PRINT_DEBUG 0
|
||||
|
||||
@@ -118,10 +113,10 @@ void check_status(srtp_err_status_t s)
|
||||
extern srtp_cipher_type_t srtp_null_cipher;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_128;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_256;
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
extern srtp_cipher_type_t srtp_aes_icm_192;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_128_openssl;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_256_openssl;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_128;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_256;
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -187,21 +182,19 @@ int main(int argc, char *argv[])
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_256, SRTP_AES_ICM_256_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_192, SRTP_AES_ICM_192_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
|
||||
cipher_driver_test_array_throughput(&srtp_aes_gcm_128_openssl,
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT,
|
||||
num_cipher);
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_gcm_128, SRTP_AES_GCM_128_KEY_LEN_WSALT, num_cipher);
|
||||
}
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
|
||||
cipher_driver_test_array_throughput(&srtp_aes_gcm_256_openssl,
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT,
|
||||
num_cipher);
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_gcm_256, SRTP_AES_GCM_256_KEY_LEN_WSALT, num_cipher);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -210,10 +203,10 @@ int main(int argc, char *argv[])
|
||||
cipher_driver_self_test(&srtp_null_cipher);
|
||||
cipher_driver_self_test(&srtp_aes_icm_128);
|
||||
cipher_driver_self_test(&srtp_aes_icm_256);
|
||||
#ifdef OPENSSL
|
||||
#ifdef GCM
|
||||
cipher_driver_self_test(&srtp_aes_icm_192);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_128_openssl);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_256_openssl);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_128);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_256);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -277,9 +270,9 @@ int main(int argc, char *argv[])
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
#ifdef OPENSSL
|
||||
/* run the throughput test on the aes_gcm_128_openssl cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_128_openssl, &c,
|
||||
#ifdef GCM
|
||||
/* run the throughput test on the aes_gcm_128 cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_128, &c,
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, 8);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate GCM 128 cipher\n");
|
||||
@@ -291,15 +284,13 @@ int main(int argc, char *argv[])
|
||||
cipher_driver_test_throughput(c);
|
||||
}
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
// GCM ciphers don't do buffering; they're "one shot"
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
/* run the throughput test on the aes_gcm_256_openssl cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_256_openssl, &c,
|
||||
/* run the throughput test on the aes_gcm_256 cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_256, &c,
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, 16);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate GCM 256 cipher\n");
|
||||
@@ -311,10 +302,8 @@ int main(int argc, char *argv[])
|
||||
cipher_driver_test_throughput(c);
|
||||
}
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
// GCM ciphers don't do buffering; they're "one shot"
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
#endif
|
||||
@@ -396,7 +385,7 @@ srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c)
|
||||
end = buffer1 + buflen;
|
||||
while (current < end) {
|
||||
/* choose a short length */
|
||||
len = rand() & 0x01f;
|
||||
len = srtp_cipher_rand_u32_for_tests() & 0x01f;
|
||||
|
||||
/* make sure that len doesn't cause us to overreach the buffer */
|
||||
if (current + len > end)
|
||||
@@ -479,9 +468,8 @@ srtp_err_status_t cipher_array_alloc_init(srtp_cipher_t ***ca,
|
||||
return status;
|
||||
|
||||
/* generate random key and initialize cipher */
|
||||
for (j = 0; j < klen; j++)
|
||||
key[j] = (uint8_t)rand();
|
||||
for (; j < klen_pad; j++)
|
||||
srtp_cipher_rand_for_tests(key, klen);
|
||||
for (j = klen; j < klen_pad; j++)
|
||||
key[j] = 0;
|
||||
status = srtp_cipher_init(*cipher_array, key);
|
||||
if (status)
|
||||
@@ -535,7 +523,7 @@ uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[],
|
||||
v128_t nonce;
|
||||
clock_t timer;
|
||||
unsigned char *enc_buf;
|
||||
int cipher_index = rand() % num_cipher;
|
||||
int cipher_index = srtp_cipher_rand_u32_for_tests() % num_cipher;
|
||||
|
||||
/* Over-alloc, for NIST CBC padding */
|
||||
enc_buf = srtp_crypto_alloc(octets_in_buffer + 17);
|
||||
|
||||
@@ -60,6 +60,8 @@ void print_string(char *s);
|
||||
|
||||
void test_bswap(void);
|
||||
|
||||
void test_set_to_zero(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/*
|
||||
@@ -98,13 +100,6 @@ int main(void)
|
||||
}
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
v128_set_bit(&x, 0);
|
||||
for (i = 0; i < 128; i++) {
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
v128_right_shift(&x, 1);
|
||||
}
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
v128_set_bit(&x, 127);
|
||||
@@ -135,6 +130,7 @@ int main(void)
|
||||
printf(" } \n");
|
||||
|
||||
test_bswap();
|
||||
test_set_to_zero();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -145,33 +141,6 @@ void byte_order(void)
|
||||
{
|
||||
int i;
|
||||
v128_t e;
|
||||
#if 0
|
||||
v16_t b;
|
||||
v32_t c;
|
||||
v64_t d;
|
||||
|
||||
for (i=0; i < sizeof(b); i++)
|
||||
b.octet[i] = i;
|
||||
for (i=0; i < sizeof(c); i++)
|
||||
c.octet[i] = i;
|
||||
for (i=0; i < sizeof(d); i++)
|
||||
d.octet[i] = i;
|
||||
|
||||
printf("v128_t:\t%s\n", v128_hex_string(&e));
|
||||
printf("v64_t:\t%s\n", v64_hex_string(&d));
|
||||
printf("v32_t:\t%s\n", v32_hex_string(c));
|
||||
printf("v16_t:\t%s\n", v16_hex_string(b));
|
||||
|
||||
c.value = 0x01020304;
|
||||
printf("v32_t:\t%s\n", v32_hex_string(c));
|
||||
b.value = 0x0102;
|
||||
printf("v16_t:\t%s\n", v16_hex_string(b));
|
||||
|
||||
printf("uint16_t ordering:\n");
|
||||
|
||||
c.value = 0x00010002;
|
||||
printf("v32_t:\t%x%x\n", c.v16[0], c.v16[1]);
|
||||
#endif
|
||||
|
||||
printf("byte ordering of crypto/math datatypes:\n");
|
||||
for (i = 0; i < sizeof(e); i++)
|
||||
@@ -228,3 +197,26 @@ void test_bswap(void)
|
||||
printf("bswapped octet string: %s\n",
|
||||
octet_string_hex_string((uint8_t *)&y, 8));
|
||||
}
|
||||
|
||||
void test_set_to_zero(void)
|
||||
{
|
||||
#define BUFFER_SIZE (16)
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < BUFFER_SIZE; i++) {
|
||||
buffer[i] = i & 0xff;
|
||||
}
|
||||
printf("Buffer before: %s\n", octet_string_hex_string(buffer, BUFFER_SIZE));
|
||||
octet_string_set_to_zero(buffer, BUFFER_SIZE);
|
||||
printf("Buffer after: %s\n", octet_string_hex_string(buffer, BUFFER_SIZE));
|
||||
for (i = 0; i < BUFFER_SIZE; i++) {
|
||||
if (buffer[i]) {
|
||||
fprintf(stderr,
|
||||
"Buffer contents not zero at position %zu (is %d)\n", i,
|
||||
buffer[i]);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#undef BUFFER_SIZE
|
||||
}
|
||||
@@ -113,15 +113,3 @@ int main(int argc, char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* crypto_kernel_cipher_test() is a test of the cipher interface
|
||||
* of the crypto_kernel
|
||||
*/
|
||||
|
||||
srtp_err_status_t crypto_kernel_cipher_test(void)
|
||||
{
|
||||
/* not implemented yet! */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# crypto test suite
|
||||
|
||||
test_apps = [
|
||||
'cipher_driver',
|
||||
'datatypes_driver',
|
||||
'kernel_driver',
|
||||
'env',
|
||||
]
|
||||
|
||||
if not use_openssl and not use_nss
|
||||
test_apps += ['sha1_driver']
|
||||
endif
|
||||
|
||||
foreach test_name : test_apps
|
||||
test_exe = executable(test_name,
|
||||
'@0@.c'.format(test_name), '../../test/getopt_s.c', '../../test/util.c',
|
||||
include_directories: [config_incs, crypto_incs, srtp2_incs, test_incs],
|
||||
dependencies: [srtp2_deps, syslibs],
|
||||
link_with: libsrtp2_for_tests)
|
||||
test(test_name, test_exe, args: ['-v'])
|
||||
endforeach
|
||||
|
||||
if not use_openssl and not use_nss
|
||||
test_exe = executable('aes_calc',
|
||||
'aes_calc.c', '../../test/getopt_s.c', '../../test/util.c',
|
||||
include_directories: [config_incs, crypto_incs, srtp2_incs, test_incs],
|
||||
dependencies: [srtp2_deps, syslibs],
|
||||
link_with: libsrtp2_for_tests)
|
||||
|
||||
# data values used to test the aes_calc application for AES-128
|
||||
k128 = '000102030405060708090a0b0c0d0e0f'
|
||||
p128 = '00112233445566778899aabbccddeeff'
|
||||
c128 = '69c4e0d86a7b0430d8cdb78070b4c55a'
|
||||
test('aes_calc_128', test_exe, args: [k128, p128, c128])
|
||||
|
||||
# data values used to test the aes_calc application for AES-256
|
||||
k256 = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
|
||||
p256 = '00112233445566778899aabbccddeeff'
|
||||
c256 = '8ea2b7ca516745bfeafc49904b496089'
|
||||
test('aes_calc_256', test_exe, args: [k256, p256, c256])
|
||||
endif
|
||||
@@ -1,258 +0,0 @@
|
||||
/*
|
||||
* stat-driver.c
|
||||
*
|
||||
* test driver for the stat_test functions
|
||||
*
|
||||
* 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 <stdio.h> /* for printf() */
|
||||
|
||||
#include "err.h"
|
||||
#include "stat.h"
|
||||
#include "srtp.h"
|
||||
|
||||
#include "cipher.h"
|
||||
|
||||
typedef struct {
|
||||
void *state;
|
||||
} random_source_t;
|
||||
|
||||
srtp_err_status_t random_source_alloc(void);
|
||||
|
||||
void err_check(srtp_err_status_t s)
|
||||
{
|
||||
if (s) {
|
||||
printf("error (code %d)\n", s);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint8_t buffer[2532];
|
||||
unsigned int buf_len = 2500;
|
||||
int i, j;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_128;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_256;
|
||||
#ifdef OPENSSL
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_128_openssl;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_256_openssl;
|
||||
#endif
|
||||
srtp_cipher_t *c;
|
||||
/* clang-format off */
|
||||
uint8_t key[46] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05
|
||||
};
|
||||
/* clang-format on */
|
||||
v128_t nonce;
|
||||
int num_trials = 500;
|
||||
int num_fail;
|
||||
|
||||
printf("statistical tests driver\n");
|
||||
|
||||
v128_set_to_zero(&nonce);
|
||||
for (i = 0; i < 2500; i++)
|
||||
buffer[i] = 0;
|
||||
|
||||
/* run tests */
|
||||
printf("running stat_tests on all-null buffer, expecting failure\n");
|
||||
printf("monobit %d\n", stat_test_monobit(buffer));
|
||||
printf("poker %d\n", stat_test_poker(buffer));
|
||||
printf("runs %d\n", stat_test_runs(buffer));
|
||||
|
||||
for (i = 0; i < 2500; i++)
|
||||
buffer[i] = rand();
|
||||
printf("running stat_tests on rand(), expecting success\n");
|
||||
printf("monobit %d\n", stat_test_monobit(buffer));
|
||||
printf("poker %d\n", stat_test_poker(buffer));
|
||||
printf("runs %d\n", stat_test_runs(buffer));
|
||||
|
||||
printf("running stat_tests on AES-128-ICM, expecting success\n");
|
||||
/* set buffer to cipher output */
|
||||
for (i = 0; i < 2500; i++)
|
||||
buffer[i] = 0;
|
||||
err_check(srtp_cipher_type_alloc(&srtp_aes_icm_128, &c,
|
||||
SRTP_AES_ICM_128_KEY_LEN_WSALT, 0));
|
||||
err_check(srtp_cipher_init(c, key));
|
||||
err_check(srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
/* run tests on cipher outout */
|
||||
printf("monobit %d\n", stat_test_monobit(buffer));
|
||||
printf("poker %d\n", stat_test_poker(buffer));
|
||||
printf("runs %d\n", stat_test_runs(buffer));
|
||||
|
||||
printf("runs test (please be patient): ");
|
||||
fflush(stdout);
|
||||
num_fail = 0;
|
||||
v128_set_to_zero(&nonce);
|
||||
for (j = 0; j < num_trials; j++) {
|
||||
for (i = 0; i < 2500; i++)
|
||||
buffer[i] = 0;
|
||||
nonce.v32[3] = i;
|
||||
err_check(
|
||||
srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
if (stat_test_runs(buffer)) {
|
||||
num_fail++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d failures in %d tests\n", num_fail, num_trials);
|
||||
printf("(nota bene: a small fraction of stat_test failures does not \n"
|
||||
"indicate that the random source is invalid)\n");
|
||||
|
||||
err_check(srtp_cipher_dealloc(c));
|
||||
|
||||
printf("running stat_tests on AES-256-ICM, expecting success\n");
|
||||
/* set buffer to cipher output */
|
||||
for (i = 0; i < 2500; i++)
|
||||
buffer[i] = 0;
|
||||
err_check(srtp_cipher_type_alloc(&srtp_aes_icm_256, &c,
|
||||
SRTP_AES_ICM_256_KEY_LEN_WSALT, 0));
|
||||
err_check(srtp_cipher_init(c, key));
|
||||
err_check(srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
/* run tests on cipher outout */
|
||||
printf("monobit %d\n", stat_test_monobit(buffer));
|
||||
printf("poker %d\n", stat_test_poker(buffer));
|
||||
printf("runs %d\n", stat_test_runs(buffer));
|
||||
|
||||
printf("runs test (please be patient): ");
|
||||
fflush(stdout);
|
||||
num_fail = 0;
|
||||
v128_set_to_zero(&nonce);
|
||||
for (j = 0; j < num_trials; j++) {
|
||||
for (i = 0; i < 2500; i++)
|
||||
buffer[i] = 0;
|
||||
nonce.v32[3] = i;
|
||||
err_check(
|
||||
srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
if (stat_test_runs(buffer)) {
|
||||
num_fail++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPENSSL
|
||||
{
|
||||
printf("running stat_tests on AES-128-GCM, expecting success\n");
|
||||
/* set buffer to cipher output */
|
||||
for (i = 0; i < 2500; i++) {
|
||||
buffer[i] = 0;
|
||||
}
|
||||
err_check(srtp_cipher_type_alloc(&srtp_aes_gcm_128_openssl, &c,
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, 8));
|
||||
err_check(srtp_cipher_init(c, key));
|
||||
err_check(
|
||||
srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
/* run tests on cipher outout */
|
||||
printf("monobit %d\n", stat_test_monobit(buffer));
|
||||
printf("poker %d\n", stat_test_poker(buffer));
|
||||
printf("runs %d\n", stat_test_runs(buffer));
|
||||
fflush(stdout);
|
||||
num_fail = 0;
|
||||
v128_set_to_zero(&nonce);
|
||||
for (j = 0; j < num_trials; j++) {
|
||||
for (i = 0; i < 2500; i++) {
|
||||
buffer[i] = 0;
|
||||
}
|
||||
nonce.v32[3] = i;
|
||||
err_check(srtp_cipher_set_iv(c, (uint8_t *)&nonce,
|
||||
srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
buf_len = 2500;
|
||||
if (stat_test_runs(buffer)) {
|
||||
num_fail++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("running stat_tests on AES-256-GCM, expecting success\n");
|
||||
/* set buffer to cipher output */
|
||||
for (i = 0; i < 2500; i++) {
|
||||
buffer[i] = 0;
|
||||
}
|
||||
err_check(srtp_cipher_type_alloc(&srtp_aes_gcm_256_openssl, &c,
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, 16));
|
||||
err_check(srtp_cipher_init(c, key));
|
||||
err_check(
|
||||
srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
/* run tests on cipher outout */
|
||||
printf("monobit %d\n", stat_test_monobit(buffer));
|
||||
printf("poker %d\n", stat_test_poker(buffer));
|
||||
printf("runs %d\n", stat_test_runs(buffer));
|
||||
fflush(stdout);
|
||||
num_fail = 0;
|
||||
v128_set_to_zero(&nonce);
|
||||
for (j = 0; j < num_trials; j++) {
|
||||
for (i = 0; i < 2500; i++) {
|
||||
buffer[i] = 0;
|
||||
}
|
||||
nonce.v32[3] = i;
|
||||
err_check(srtp_cipher_set_iv(c, (uint8_t *)&nonce,
|
||||
srtp_direction_encrypt));
|
||||
err_check(srtp_cipher_encrypt(c, buffer, &buf_len));
|
||||
buf_len = 2500;
|
||||
if (stat_test_runs(buffer)) {
|
||||
num_fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("%d failures in %d tests\n", num_fail, num_trials);
|
||||
printf("(nota bene: a small fraction of stat_test failures does not \n"
|
||||
"indicate that the random source is invalid)\n");
|
||||
|
||||
err_check(srtp_cipher_dealloc(c));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user