Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: crypto/test/cipher_driver.c

Issue 2344973002: Update libsrtp to version 2.0 (Closed)
Patch Set: Add '.' back to include_dirs Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/test/auth_driver.c ('k') | crypto/test/datatypes_driver.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/test/cipher_driver.c
diff --git a/srtp/crypto/test/cipher_driver.c b/crypto/test/cipher_driver.c
similarity index 70%
rename from srtp/crypto/test/cipher_driver.c
rename to crypto/test/cipher_driver.c
index 9c9c2203a1976494e0cb667307e171fcd553a71b..c8b3f055e9de8c3f9d167b535e675625c239e20f 100644
--- a/srtp/crypto/test/cipher_driver.c
+++ b/crypto/test/cipher_driver.c
@@ -58,15 +58,14 @@
#else
#include "aes_icm.h"
#endif
-#include "null_cipher.h"
#define PRINT_DEBUG 0
void
-cipher_driver_test_throughput(cipher_t *c);
+cipher_driver_test_throughput(srtp_cipher_t *c);
-err_status_t
-cipher_driver_self_test(cipher_type_t *ct);
+srtp_err_status_t
+cipher_driver_self_test(srtp_cipher_type_t *ct);
/*
@@ -75,30 +74,30 @@ cipher_driver_self_test(cipher_type_t *ct);
* calls
*/
-err_status_t
-cipher_driver_test_buffering(cipher_t *c);
+srtp_err_status_t
+cipher_driver_test_buffering(srtp_cipher_t *c);
/*
* functions for testing cipher cache thrash
*/
-err_status_t
-cipher_driver_test_array_throughput(cipher_type_t *ct,
+srtp_err_status_t
+cipher_driver_test_array_throughput(srtp_cipher_type_t *ct,
int klen, int num_cipher);
void
-cipher_array_test_throughput(cipher_t *ca[], int num_cipher);
+cipher_array_test_throughput(srtp_cipher_t *ca[], int num_cipher);
uint64_t
-cipher_array_bits_per_second(cipher_t *cipher_array[], int num_cipher,
+cipher_array_bits_per_second(srtp_cipher_t *cipher_array[], int num_cipher,
unsigned octets_in_buffer, int num_trials);
-err_status_t
-cipher_array_delete(cipher_t *cipher_array[], int num_cipher);
+srtp_err_status_t
+cipher_array_delete(srtp_cipher_t *cipher_array[], int num_cipher);
-err_status_t
-cipher_array_alloc_init(cipher_t ***cipher_array, int num_ciphers,
- cipher_type_t *ctype, int klen);
+srtp_err_status_t
+cipher_array_alloc_init(srtp_cipher_t ***cipher_array, int num_ciphers,
+ srtp_cipher_type_t *ctype, int klen);
void
usage(char *prog_name) {
@@ -107,7 +106,7 @@ usage(char *prog_name) {
}
void
-check_status(err_status_t s) {
+check_status(srtp_err_status_t s) {
if (s) {
printf("error (code %d)\n", s);
exit(s);
@@ -116,28 +115,24 @@ check_status(err_status_t s) {
}
/*
- * null_cipher, aes_icm, and aes_cbc are the cipher meta-objects
+ * null_cipher and srtp_aes_icm are the cipher meta-objects
* defined in the files in crypto/cipher subdirectory. these are
* declared external so that we can use these cipher types here
*/
-extern cipher_type_t null_cipher;
-extern cipher_type_t aes_icm;
-#ifndef OPENSSL
-extern cipher_type_t aes_cbc;
-#else
-#ifndef SRTP_NO_AES192
-extern cipher_type_t aes_icm_192;
-#endif
-extern cipher_type_t aes_icm_256;
-extern cipher_type_t aes_gcm_128_openssl;
-extern cipher_type_t aes_gcm_256_openssl;
+extern srtp_cipher_type_t srtp_null_cipher;
+extern srtp_cipher_type_t srtp_aes_icm;
+#ifdef OPENSSL
+extern srtp_cipher_type_t srtp_aes_icm_192;
+extern srtp_cipher_type_t srtp_aes_icm_256;
+extern srtp_cipher_type_t srtp_aes_gcm_128_openssl;
+extern srtp_cipher_type_t srtp_aes_gcm_256_openssl;
#endif
int
main(int argc, char *argv[]) {
- cipher_t *c = NULL;
- err_status_t status;
+ srtp_cipher_t *c = NULL;
+ srtp_err_status_t status;
unsigned char test_key[48] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -170,7 +165,7 @@ main(int argc, char *argv[]) {
usage(argv[0]);
}
}
-
+
printf("cipher test driver\n"
"David A. McGrew\n"
"Cisco Systems, Inc.\n");
@@ -184,58 +179,47 @@ main(int argc, char *argv[]) {
int num_cipher;
for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
- cipher_driver_test_array_throughput(&null_cipher, 0, num_cipher);
+ cipher_driver_test_array_throughput(&srtp_null_cipher, 0, num_cipher);
for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
- cipher_driver_test_array_throughput(&aes_icm, 30, num_cipher);
+ cipher_driver_test_array_throughput(&srtp_aes_icm, 30, num_cipher);
#ifndef OPENSSL
for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
- cipher_driver_test_array_throughput(&aes_icm, 46, num_cipher);
-
- for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
- cipher_driver_test_array_throughput(&aes_cbc, 16, num_cipher);
-
- for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
- cipher_driver_test_array_throughput(&aes_cbc, 32, num_cipher);
+ cipher_driver_test_array_throughput(&srtp_aes_icm, 46, num_cipher);
#else
-#ifndef SRTP_NO_AES192
for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
- cipher_driver_test_array_throughput(&aes_icm_192, 38, num_cipher);
-#endif
+ cipher_driver_test_array_throughput(&srtp_aes_icm_192, 38, num_cipher);
+
for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
- cipher_driver_test_array_throughput(&aes_icm_256, 46, num_cipher);
+ cipher_driver_test_array_throughput(&srtp_aes_icm_256, 46, num_cipher);
for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8) {
- cipher_driver_test_array_throughput(&aes_gcm_128_openssl, AES_128_GCM_KEYSIZE_WSALT, num_cipher);
+ cipher_driver_test_array_throughput(&srtp_aes_gcm_128_openssl, SRTP_AES_128_GCM_KEYSIZE_WSALT, num_cipher);
}
for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8) {
- cipher_driver_test_array_throughput(&aes_gcm_256_openssl, AES_256_GCM_KEYSIZE_WSALT, num_cipher);
+ cipher_driver_test_array_throughput(&srtp_aes_gcm_256_openssl, SRTP_AES_256_GCM_KEYSIZE_WSALT, num_cipher);
}
#endif
}
if (do_validation) {
- cipher_driver_self_test(&null_cipher);
- cipher_driver_self_test(&aes_icm);
-#ifndef OPENSSL
- cipher_driver_self_test(&aes_cbc);
-#else
-#ifndef SRTP_NO_AES192
- cipher_driver_self_test(&aes_icm_192);
-#endif
- cipher_driver_self_test(&aes_icm_256);
- cipher_driver_self_test(&aes_gcm_128_openssl);
- cipher_driver_self_test(&aes_gcm_256_openssl);
+ cipher_driver_self_test(&srtp_null_cipher);
+ cipher_driver_self_test(&srtp_aes_icm);
+#ifdef OPENSSL
+ cipher_driver_self_test(&srtp_aes_icm_192);
+ cipher_driver_self_test(&srtp_aes_icm_256);
+ cipher_driver_self_test(&srtp_aes_gcm_128_openssl);
+ cipher_driver_self_test(&srtp_aes_gcm_256_openssl);
#endif
}
- /* do timing and/or buffer_test on null_cipher */
- status = cipher_type_alloc(&null_cipher, &c, 0, 0);
+ /* do timing and/or buffer_test on srtp_null_cipher */
+ status = srtp_cipher_type_alloc(&srtp_null_cipher, &c, 0, 0);
check_status(status);
- status = cipher_init(c, NULL);
+ status = srtp_cipher_init(c, NULL);
check_status(status);
if (do_timing_test)
@@ -244,18 +228,18 @@ main(int argc, char *argv[]) {
status = cipher_driver_test_buffering(c);
check_status(status);
}
- status = cipher_dealloc(c);
+ status = srtp_cipher_dealloc(c);
check_status(status);
/* run the throughput test on the aes_icm cipher (128-bit key) */
- status = cipher_type_alloc(&aes_icm, &c, 30, 0);
+ status = srtp_cipher_type_alloc(&srtp_aes_icm, &c, 30, 0);
if (status) {
fprintf(stderr, "error: can't allocate cipher\n");
exit(status);
}
- status = cipher_init(c, test_key);
+ status = srtp_cipher_init(c, test_key);
check_status(status);
if (do_timing_test)
@@ -266,21 +250,21 @@ main(int argc, char *argv[]) {
check_status(status);
}
- status = cipher_dealloc(c);
+ status = srtp_cipher_dealloc(c);
check_status(status);
/* repeat the tests with 256-bit keys */
#ifndef OPENSSL
- status = cipher_type_alloc(&aes_icm, &c, 46, 0);
+ status = srtp_cipher_type_alloc(&srtp_aes_icm, &c, 46, 0);
#else
- status = cipher_type_alloc(&aes_icm_256, &c, 46, 0);
+ status = srtp_cipher_type_alloc(&srtp_aes_icm_256, &c, 46, 0);
#endif
if (status) {
fprintf(stderr, "error: can't allocate cipher\n");
exit(status);
}
- status = cipher_init(c, test_key);
+ status = srtp_cipher_init(c, test_key);
check_status(status);
if (do_timing_test)
@@ -291,17 +275,17 @@ main(int argc, char *argv[]) {
check_status(status);
}
- status = cipher_dealloc(c);
+ status = srtp_cipher_dealloc(c);
check_status(status);
#ifdef OPENSSL
/* run the throughput test on the aes_gcm_128_openssl cipher */
- status = cipher_type_alloc(&aes_gcm_128_openssl, &c, AES_128_GCM_KEYSIZE_WSALT, 8);
+ status = srtp_cipher_type_alloc(&srtp_aes_gcm_128_openssl, &c, SRTP_AES_128_GCM_KEYSIZE_WSALT, 8);
if (status) {
fprintf(stderr, "error: can't allocate GCM 128 cipher\n");
exit(status);
}
- status = cipher_init(c, test_key);
+ status = srtp_cipher_init(c, test_key);
check_status(status);
if (do_timing_test) {
cipher_driver_test_throughput(c);
@@ -311,16 +295,16 @@ main(int argc, char *argv[]) {
status = cipher_driver_test_buffering(c);
check_status(status);
}
- status = cipher_dealloc(c);
+ status = srtp_cipher_dealloc(c);
check_status(status);
/* run the throughput test on the aes_gcm_256_openssl cipher */
- status = cipher_type_alloc(&aes_gcm_256_openssl, &c, AES_256_GCM_KEYSIZE_WSALT, 16);
+ status = srtp_cipher_type_alloc(&srtp_aes_gcm_256_openssl, &c, SRTP_AES_256_GCM_KEYSIZE_WSALT, 16);
if (status) {
fprintf(stderr, "error: can't allocate GCM 256 cipher\n");
exit(status);
}
- status = cipher_init(c, test_key);
+ status = srtp_cipher_init(c, test_key);
check_status(status);
if (do_timing_test) {
cipher_driver_test_throughput(c);
@@ -330,7 +314,7 @@ main(int argc, char *argv[]) {
status = cipher_driver_test_buffering(c);
check_status(status);
}
- status = cipher_dealloc(c);
+ status = srtp_cipher_dealloc(c);
check_status(status);
#endif
@@ -338,7 +322,7 @@ main(int argc, char *argv[]) {
}
void
-cipher_driver_test_throughput(cipher_t *c) {
+cipher_driver_test_throughput(srtp_cipher_t *c) {
int i;
int min_enc_len = 32;
int max_enc_len = 2048; /* should be a power of two */
@@ -348,23 +332,23 @@ cipher_driver_test_throughput(cipher_t *c) {
fflush(stdout);
for (i=min_enc_len; i <= max_enc_len; i = i * 2)
printf("msg len: %d\tgigabits per second: %f\n",
- i, cipher_bits_per_second(c, i, num_trials) / 1e9);
+ i, srtp_cipher_bits_per_second(c, i, num_trials) / 1e9);
}
-err_status_t
-cipher_driver_self_test(cipher_type_t *ct) {
- err_status_t status;
+srtp_err_status_t
+cipher_driver_self_test(srtp_cipher_type_t *ct) {
+ srtp_err_status_t status;
printf("running cipher self-test for %s...", ct->description);
- status = cipher_type_self_test(ct);
+ status = srtp_cipher_type_self_test(ct);
if (status) {
printf("failed with error code %d\n", status);
exit(status);
}
printf("passed\n");
- return err_status_ok;
+ return srtp_err_status_ok;
}
/*
@@ -374,8 +358,8 @@ cipher_driver_self_test(cipher_type_t *ct) {
*/
#define INITIAL_BUFLEN 1024
-err_status_t
-cipher_driver_test_buffering(cipher_t *c) {
+srtp_err_status_t
+cipher_driver_test_buffering(srtp_cipher_t *c) {
int i, j, num_trials = 1000;
unsigned len, buflen = INITIAL_BUFLEN;
uint8_t buffer0[INITIAL_BUFLEN], buffer1[INITIAL_BUFLEN], *current, *end;
@@ -383,7 +367,7 @@ cipher_driver_test_buffering(cipher_t *c) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34
};
- err_status_t status;
+ srtp_err_status_t status;
printf("testing output buffering for cipher %s...",
c->type->description);
@@ -396,17 +380,17 @@ cipher_driver_test_buffering(cipher_t *c) {
}
/* initialize cipher */
- status = cipher_set_iv(c, idx, direction_encrypt);
+ status = srtp_cipher_set_iv(c, (uint8_t*)idx, srtp_direction_encrypt);
if (status)
return status;
/* generate 'reference' value by encrypting all at once */
- status = cipher_encrypt(c, buffer0, &buflen);
+ status = srtp_cipher_encrypt(c, buffer0, &buflen);
if (status)
return status;
/* re-initialize cipher */
- status = cipher_set_iv(c, idx, direction_encrypt);
+ status = srtp_cipher_set_iv(c, (uint8_t*)idx, srtp_direction_encrypt);
if (status)
return status;
@@ -422,7 +406,7 @@ cipher_driver_test_buffering(cipher_t *c) {
if (current + len > end)
len = end - current;
- status = cipher_encrypt(c, current, &len);
+ status = srtp_cipher_encrypt(c, current, &len);
if (status)
return status;
@@ -442,14 +426,14 @@ cipher_driver_test_buffering(cipher_t *c) {
printf("computed: %s\n", octet_string_hex_string(buffer1, buflen));
printf("expected: %s\n", octet_string_hex_string(buffer0, buflen));
#endif
- return err_status_algo_fail;
+ return srtp_err_status_algo_fail;
}
}
}
printf("passed\n");
- return err_status_ok;
+ return srtp_err_status_ok;
}
@@ -458,40 +442,40 @@ cipher_driver_test_buffering(cipher_t *c) {
* cache thrash on cipher throughput.
*
* cipher_array_alloc_init(ctype, array, num_ciphers) creates an array
- * of cipher_t of type ctype
+ * of srtp_cipher_t of type ctype
*/
-err_status_t
-cipher_array_alloc_init(cipher_t ***ca, int num_ciphers,
- cipher_type_t *ctype, int klen) {
+srtp_err_status_t
+cipher_array_alloc_init(srtp_cipher_t ***ca, int num_ciphers,
+ srtp_cipher_type_t *ctype, int klen) {
int i, j;
- err_status_t status;
+ srtp_err_status_t status;
uint8_t *key;
- cipher_t **cipher_array;
+ srtp_cipher_t **cipher_array;
/* pad klen allocation, to handle aes_icm reading 16 bytes for the
14-byte salt */
int klen_pad = ((klen + 15) >> 4) << 4;
/* allocate array of pointers to ciphers */
- cipher_array = (cipher_t **) malloc(sizeof(cipher_t *) * num_ciphers);
+ cipher_array = (srtp_cipher_t **) malloc(sizeof(srtp_cipher_t *) * num_ciphers);
if (cipher_array == NULL)
- return err_status_alloc_fail;
+ return srtp_err_status_alloc_fail;
/* set ca to location of cipher_array */
*ca = cipher_array;
/* allocate key */
- key = crypto_alloc(klen_pad);
+ key = srtp_crypto_alloc(klen_pad);
if (key == NULL) {
free(cipher_array);
- return err_status_alloc_fail;
+ return srtp_err_status_alloc_fail;
}
/* allocate and initialize an array of ciphers */
for (i=0; i < num_ciphers; i++) {
/* allocate cipher */
- status = cipher_type_alloc(ctype, cipher_array, klen, 16);
+ status = srtp_cipher_type_alloc(ctype, cipher_array, klen, 16);
if (status)
return status;
@@ -500,7 +484,7 @@ cipher_array_alloc_init(cipher_t ***ca, int num_ciphers,
key[j] = (uint8_t) rand();
for (; j < klen_pad; j++)
key[j] = 0;
- status = cipher_init(*cipher_array, key);
+ status = srtp_cipher_init(*cipher_array, key);
if (status)
return status;
@@ -512,22 +496,22 @@ cipher_array_alloc_init(cipher_t ***ca, int num_ciphers,
cipher_array++;
}
- crypto_free(key);
+ srtp_crypto_free(key);
- return err_status_ok;
+ return srtp_err_status_ok;
}
-err_status_t
-cipher_array_delete(cipher_t *cipher_array[], int num_cipher) {
+srtp_err_status_t
+cipher_array_delete(srtp_cipher_t *cipher_array[], int num_cipher) {
int i;
for (i=0; i < num_cipher; i++) {
- cipher_dealloc(cipher_array[i]);
+ srtp_cipher_dealloc(cipher_array[i]);
}
free(cipher_array);
- return err_status_ok;
+ return srtp_err_status_ok;
}
@@ -544,7 +528,7 @@ cipher_array_delete(cipher_t *cipher_array[], int num_cipher) {
*/
uint64_t
-cipher_array_bits_per_second(cipher_t *cipher_array[], int num_cipher,
+cipher_array_bits_per_second(srtp_cipher_t *cipher_array[], int num_cipher,
unsigned octets_in_buffer, int num_trials) {
int i;
v128_t nonce;
@@ -553,7 +537,7 @@ cipher_array_bits_per_second(cipher_t *cipher_array[], int num_cipher,
int cipher_index = rand() % num_cipher;
/* Over-alloc, for NIST CBC padding */
- enc_buf = crypto_alloc(octets_in_buffer+17);
+ enc_buf = srtp_crypto_alloc(octets_in_buffer+17);
if (enc_buf == NULL)
return 0; /* indicate bad parameters by returning null */
memset(enc_buf, 0, octets_in_buffer);
@@ -562,13 +546,13 @@ cipher_array_bits_per_second(cipher_t *cipher_array[], int num_cipher,
v128_set_to_zero(&nonce);
timer = clock();
for(i=0; i < num_trials; i++, nonce.v32[3] = i) {
- /* length parameter to cipher_encrypt is in/out -- out is total, padded
+ /* length parameter to srtp_cipher_encrypt is in/out -- out is total, padded
* length -- so reset it each time. */
unsigned octets_to_encrypt = octets_in_buffer;
/* encrypt buffer with cipher */
- cipher_set_iv(cipher_array[cipher_index], &nonce, direction_encrypt);
- cipher_encrypt(cipher_array[cipher_index], enc_buf, &octets_to_encrypt);
+ srtp_cipher_set_iv(cipher_array[cipher_index], (uint8_t*)&nonce, srtp_direction_encrypt);
+ srtp_cipher_encrypt(cipher_array[cipher_index], enc_buf, &octets_to_encrypt);
/* choose a cipher at random from the array*/
cipher_index = (*((uint32_t *)enc_buf)) % num_cipher;
@@ -586,7 +570,7 @@ cipher_array_bits_per_second(cipher_t *cipher_array[], int num_cipher,
}
void
-cipher_array_test_throughput(cipher_t *ca[], int num_cipher) {
+cipher_array_test_throughput(srtp_cipher_t *ca[], int num_cipher) {
int i;
int min_enc_len = 16;
int max_enc_len = 2048; /* should be a power of two */
@@ -601,11 +585,11 @@ cipher_array_test_throughput(cipher_t *ca[], int num_cipher) {
}
-err_status_t
-cipher_driver_test_array_throughput(cipher_type_t *ct,
+srtp_err_status_t
+cipher_driver_test_array_throughput(srtp_cipher_type_t *ct,
int klen, int num_cipher) {
- cipher_t **ca = NULL;
- err_status_t status;
+ srtp_cipher_t **ca = NULL;
+ srtp_err_status_t status;
status = cipher_array_alloc_init(&ca, num_cipher, ct, klen);
if (status) {
@@ -618,5 +602,5 @@ cipher_driver_test_array_throughput(cipher_type_t *ct,
cipher_array_delete(ca, num_cipher);
- return err_status_ok;
+ return srtp_err_status_ok;
}
« no previous file with comments | « crypto/test/auth_driver.c ('k') | crypto/test/datatypes_driver.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698