Skip to content

Commit 11445dc

Browse files
authored
Merge pull request cisco#684 from paulej/paulej_int_changes
Type usage consistency, braces, etc.
2 parents 24da558 + b10e1df commit 11445dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1045
-807
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ srtp_create(&session, &policy);
502502
// main loop: get rtp packets, send srtp packets
503503
while (1) {
504504
char rtp_buffer[2048];
505-
unsigned len;
505+
size_t len;
506506

507507
len = get_rtp_packet(rtp_buffer);
508508
srtp_protect(session, rtp_buffer, &len);

crypto/cipher/aes.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,18 +1404,15 @@ static const uint32_t U4[256] = {
14041404
static void aes_128_expand_encryption_key(const uint8_t *key,
14051405
srtp_aes_expanded_key_t *expanded_key)
14061406
{
1407-
int i;
1408-
uint8_t rc;
1409-
14101407
/* initialize round constant */
1411-
rc = 1;
1408+
uint8_t rc = 1;
14121409

14131410
expanded_key->num_rounds = 10;
14141411

14151412
v128_copy_octet_string(&expanded_key->round[0], key);
14161413

14171414
/* loop over round keys */
1418-
for (i = 1; i < 11; i++) {
1415+
for (size_t i = 1; i < 11; i++) {
14191416
/* munge first word of round key */
14201417
expanded_key->round[i].v8[0] =
14211418
aes_sbox[expanded_key->round[i - 1].v8[13]] ^ rc;
@@ -1445,22 +1442,19 @@ static void aes_128_expand_encryption_key(const uint8_t *key,
14451442
}
14461443
}
14471444

1448-
static void aes_256_expand_encryption_key(const unsigned char *key,
1445+
static void aes_256_expand_encryption_key(const uint8_t *key,
14491446
srtp_aes_expanded_key_t *expanded_key)
14501447
{
1451-
int i;
1452-
uint8_t rc;
1453-
14541448
/* initialize round constant */
1455-
rc = 1;
1449+
uint8_t rc = 1;
14561450

14571451
expanded_key->num_rounds = 14;
14581452

14591453
v128_copy_octet_string(&expanded_key->round[0], key);
14601454
v128_copy_octet_string(&expanded_key->round[1], key + 16);
14611455

14621456
/* loop over rest of round keys */
1463-
for (i = 2; i < 15; i++) {
1457+
for (size_t i = 2; i < 15; i++) {
14641458
/* munge first word of round key */
14651459
if ((i & 1) == 0) {
14661460
expanded_key->round[i].v8[0] =
@@ -1525,17 +1519,16 @@ srtp_err_status_t srtp_aes_expand_decryption_key(
15251519
size_t key_len,
15261520
srtp_aes_expanded_key_t *expanded_key)
15271521
{
1528-
int i;
15291522
srtp_err_status_t status;
1530-
int num_rounds = expanded_key->num_rounds;
1523+
size_t num_rounds = expanded_key->num_rounds;
15311524

15321525
status = srtp_aes_expand_encryption_key(key, key_len, expanded_key);
15331526
if (status) {
15341527
return status;
15351528
}
15361529

15371530
/* invert the order of the round keys */
1538-
for (i = 0; i < num_rounds / 2; i++) {
1531+
for (size_t i = 0; i < num_rounds / 2; i++) {
15391532
v128_t tmp;
15401533
v128_copy(&tmp, &expanded_key->round[num_rounds - i]);
15411534
v128_copy(&expanded_key->round[num_rounds - i],
@@ -1551,7 +1544,7 @@ srtp_err_status_t srtp_aes_expand_decryption_key(
15511544
* followed by the T4 table (which cancels out the use of the sbox
15521545
* in the U-tables)
15531546
*/
1554-
for (i = 1; i < num_rounds; i++) {
1547+
for (size_t i = 1; i < num_rounds; i++) {
15551548
#ifdef CPU_RISC
15561549
uint32_t tmp;
15571550

crypto/cipher/aes_gcm_mbedtls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#include "cipher_test_cases.h"
5656

5757
srtp_debug_module_t srtp_mod_aes_gcm = {
58-
0, /* debugging is off by default */
58+
false, /* debugging is off by default */
5959
"aes gcm mbedtls" /* printable module name */
6060
};
6161

crypto/cipher/aes_gcm_nss.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#include <nspr.h>
5959

6060
srtp_debug_module_t srtp_mod_aes_gcm = {
61-
0, /* debugging is off by default */
61+
false, /* debugging is off by default */
6262
"aes gcm nss" /* printable module name */
6363
};
6464

@@ -280,7 +280,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_set_aad(void *cv,
280280
}
281281

282282
static srtp_err_status_t srtp_aes_gcm_nss_do_crypto(void *cv,
283-
int encrypt,
283+
bool encrypt,
284284
uint8_t *buf,
285285
size_t *enc_len)
286286
{
@@ -347,7 +347,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_encrypt(void *cv,
347347
}
348348

349349
srtp_err_status_t status =
350-
srtp_aes_gcm_nss_do_crypto(cv, 1, non_null_buf, enc_len);
350+
srtp_aes_gcm_nss_do_crypto(cv, true, non_null_buf, enc_len);
351351
if (status != srtp_err_status_ok) {
352352
return status;
353353
}
@@ -390,7 +390,8 @@ static srtp_err_status_t srtp_aes_gcm_nss_decrypt(void *cv,
390390
uint8_t *buf,
391391
size_t *enc_len)
392392
{
393-
srtp_err_status_t status = srtp_aes_gcm_nss_do_crypto(cv, 0, buf, enc_len);
393+
srtp_err_status_t status =
394+
srtp_aes_gcm_nss_do_crypto(cv, false, buf, enc_len);
394395
if (status != srtp_err_status_ok) {
395396
int err = PR_GetError();
396397
if (err == SEC_ERROR_BAD_DATA) {

crypto/cipher/aes_gcm_ossl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include "cipher_test_cases.h"
5858

5959
srtp_debug_module_t srtp_mod_aes_gcm = {
60-
0, /* debugging is off by default */
60+
false, /* debugging is off by default */
6161
"aes gcm" /* printable module name */
6262
};
6363

@@ -268,7 +268,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv,
268268
* OpenSSL copy its content to the context), so we can make
269269
* aad read-only in this function and all its wrappers.
270270
*/
271-
unsigned char dummy_tag[GCM_AUTH_TAG_LEN];
271+
uint8_t dummy_tag[GCM_AUTH_TAG_LEN];
272272
memset(dummy_tag, 0x0, GCM_AUTH_TAG_LEN);
273273
if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len,
274274
&dummy_tag)) {

crypto/cipher/aes_icm.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#include "cipher_test_cases.h"
5656

5757
srtp_debug_module_t srtp_mod_aes_icm = {
58-
0, /* debugging is off by default */
58+
false, /* debugging is off by default */
5959
"aes icm" /* printable module name */
6060
};
6161

@@ -299,18 +299,18 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
299299
size_t *enc_len)
300300
{
301301
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
302-
unsigned int bytes_to_encr = (unsigned int)*enc_len;
302+
size_t bytes_to_encr = *enc_len;
303303
uint32_t *b;
304304

305305
/* check that there's enough segment left*/
306-
unsigned int bytes_of_new_keystream = bytes_to_encr - c->bytes_in_buffer;
307-
unsigned int blocks_of_new_keystream = (bytes_of_new_keystream + 15) >> 4;
306+
size_t bytes_of_new_keystream = bytes_to_encr - c->bytes_in_buffer;
307+
size_t blocks_of_new_keystream = (bytes_of_new_keystream + 15) >> 4;
308308
if ((blocks_of_new_keystream + htons(c->counter.v16[7])) > 0xffff) {
309309
return srtp_err_status_terminus;
310310
}
311311

312312
debug_print(srtp_mod_aes_icm, "block index: %d", htons(c->counter.v16[7]));
313-
if (bytes_to_encr <= (unsigned int)c->bytes_in_buffer) {
313+
if (bytes_to_encr <= c->bytes_in_buffer) {
314314
/* deal with odd case of small bytes_to_encr */
315315
for (size_t i = (sizeof(v128_t) - c->bytes_in_buffer);
316316
i < (sizeof(v128_t) - c->bytes_in_buffer + bytes_to_encr); i++) {

crypto/cipher/aes_icm_mbedtls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#include "cipher_test_cases.h"
5555

5656
srtp_debug_module_t srtp_mod_aes_icm = {
57-
0, /* debugging is off by default */
57+
false, /* debugging is off by default */
5858
"aes icm mbedtls" /* printable module name */
5959
};
6060

crypto/cipher/aes_icm_nss.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#include "cipher_test_cases.h"
5656

5757
srtp_debug_module_t srtp_mod_aes_icm = {
58-
0, /* debugging is off by default */
58+
false, /* debugging is off by default */
5959
"aes icm nss" /* printable module name */
6060
};
6161

crypto/cipher/aes_icm_ossl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#include "cipher_test_cases.h"
6262

6363
srtp_debug_module_t srtp_mod_aes_icm = {
64-
0, /* debugging is off by default */
64+
false, /* debugging is off by default */
6565
"aes icm ossl" /* printable module name */
6666
};
6767

crypto/cipher/cipher.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#include "alloc.h" /* for crypto_alloc(), crypto_free() */
5656

5757
srtp_debug_module_t srtp_mod_cipher = {
58-
0, /* debugging is off by default */
58+
false, /* debugging is off by default */
5959
"cipher" /* printable module name */
6060
};
6161

@@ -88,7 +88,7 @@ srtp_err_status_t srtp_cipher_init(srtp_cipher_t *c, const uint8_t *key)
8888

8989
srtp_err_status_t srtp_cipher_set_iv(srtp_cipher_t *c,
9090
uint8_t *iv,
91-
int direction)
91+
srtp_cipher_direction_t direction)
9292
{
9393
if (!c || !c->type || !c->state) {
9494
return (srtp_err_status_bad_param);
@@ -213,8 +213,7 @@ srtp_err_status_t srtp_cipher_type_test(
213213
uint8_t buffer2[SELF_TEST_BUF_OCTETS];
214214
size_t tag_len;
215215
size_t len;
216-
int i, j, case_num = 0;
217-
unsigned k = 0;
216+
size_t case_num = 0;
218217

219218
debug_print(srtp_mod_cipher, "running self-test for cipher %s",
220219
ct->description);
@@ -256,7 +255,7 @@ srtp_err_status_t srtp_cipher_type_test(
256255
srtp_cipher_dealloc(c);
257256
return srtp_err_status_bad_param;
258257
}
259-
for (k = 0; k < test_case->plaintext_length_octets; k++) {
258+
for (size_t k = 0; k < test_case->plaintext_length_octets; k++) {
260259
buffer[k] = test_case->plaintext[k];
261260
}
262261

@@ -321,11 +320,11 @@ srtp_err_status_t srtp_cipher_type_test(
321320
return srtp_err_status_algo_fail;
322321
}
323322
status = srtp_err_status_ok;
324-
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
323+
for (size_t k = 0; k < test_case->ciphertext_length_octets; k++) {
325324
if (buffer[k] != test_case->ciphertext[k]) {
326325
status = srtp_err_status_algo_fail;
327-
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
328-
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
326+
debug_print(srtp_mod_cipher, "test case %zu failed", case_num);
327+
debug_print(srtp_mod_cipher, "(failure at byte %zu)", k);
329328
break;
330329
}
331330
}
@@ -359,7 +358,7 @@ srtp_err_status_t srtp_cipher_type_test(
359358
srtp_cipher_dealloc(c);
360359
return srtp_err_status_bad_param;
361360
}
362-
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
361+
for (size_t k = 0; k < test_case->ciphertext_length_octets; k++) {
363362
buffer[k] = test_case->ciphertext[k];
364363
}
365364

@@ -408,11 +407,11 @@ srtp_err_status_t srtp_cipher_type_test(
408407
return srtp_err_status_algo_fail;
409408
}
410409
status = srtp_err_status_ok;
411-
for (k = 0; k < test_case->plaintext_length_octets; k++) {
410+
for (size_t k = 0; k < test_case->plaintext_length_octets; k++) {
412411
if (buffer[k] != test_case->plaintext[k]) {
413412
status = srtp_err_status_algo_fail;
414-
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
415-
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
413+
debug_print(srtp_mod_cipher, "test case %zu failed", case_num);
414+
debug_print(srtp_mod_cipher, "(failure at byte %zu)", k);
416415
}
417416
}
418417
if (status) {
@@ -452,7 +451,7 @@ srtp_err_status_t srtp_cipher_type_test(
452451
return status;
453452
}
454453

455-
for (j = 0; j < NUM_RAND_TESTS; j++) {
454+
for (size_t j = 0; j < NUM_RAND_TESTS; j++) {
456455
size_t length;
457456
size_t plaintext_len;
458457
uint8_t key[MAX_KEY_LEN];
@@ -467,7 +466,7 @@ srtp_err_status_t srtp_cipher_type_test(
467466
srtp_octet_string_hex_string(buffer, length));
468467

469468
/* copy plaintext into second buffer */
470-
for (i = 0; (unsigned int)i < length; i++) {
469+
for (size_t i = 0; i < length; i++) {
471470
buffer2[i] = buffer[i];
472471
}
473472

@@ -578,12 +577,12 @@ srtp_err_status_t srtp_cipher_type_test(
578577
return srtp_err_status_algo_fail;
579578
}
580579
status = srtp_err_status_ok;
581-
for (k = 0; k < plaintext_len; k++) {
580+
for (size_t k = 0; k < plaintext_len; k++) {
582581
if (buffer[k] != buffer2[k]) {
583582
status = srtp_err_status_algo_fail;
584-
debug_print(srtp_mod_cipher, "random test case %d failed",
583+
debug_print(srtp_mod_cipher, "random test case %zu failed",
585584
case_num);
586-
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
585+
debug_print(srtp_mod_cipher, "(failure at byte %zu)", k);
587586
}
588587
}
589588
if (status) {
@@ -621,15 +620,14 @@ srtp_err_status_t srtp_cipher_type_self_test(const srtp_cipher_type_t *ct)
621620
*/
622621
uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
623622
size_t octets_in_buffer,
624-
int num_trials)
623+
size_t num_trials)
625624
{
626-
int i;
627625
v128_t nonce;
628626
clock_t timer;
629627
uint8_t *enc_buf;
630628
size_t len = octets_in_buffer;
631629
size_t tag_len = SRTP_MAX_TAG_LEN;
632-
unsigned char aad[4] = { 0, 0, 0, 0 };
630+
uint8_t aad[4] = { 0, 0, 0, 0 };
633631
size_t aad_len = 4;
634632

635633
enc_buf = (uint8_t *)srtp_crypto_alloc(octets_in_buffer + tag_len);
@@ -639,7 +637,7 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
639637
/* time repeated trials */
640638
v128_set_to_zero(&nonce);
641639
timer = clock();
642-
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
640+
for (size_t i = 0; i < num_trials; i++, nonce.v32[3] = (uint32_t)i) {
643641
// Set IV
644642
if (srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt) !=
645643
srtp_err_status_ok) {

0 commit comments

Comments
 (0)