Skip to content

Commit

Permalink
Type usage consistency, braces, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
paulej committed Jan 14, 2024
1 parent 1742c3d commit e9a2c8b
Show file tree
Hide file tree
Showing 53 changed files with 1,015 additions and 781 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ srtp_create(&session, &policy);
// main loop: get rtp packets, send srtp packets
while (1) {
char rtp_buffer[2048];
unsigned len;
size_t len;

len = get_rtp_packet(rtp_buffer);
srtp_protect(session, rtp_buffer, &len);
Expand Down
23 changes: 8 additions & 15 deletions crypto/cipher/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,18 +1404,15 @@ static const uint32_t U4[256] = {
static void aes_128_expand_encryption_key(const uint8_t *key,
srtp_aes_expanded_key_t *expanded_key)
{
int i;
uint8_t rc;

/* initialize round constant */
rc = 1;
uint8_t rc = 1;

expanded_key->num_rounds = 10;

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

/* loop over round keys */
for (i = 1; i < 11; i++) {
for (size_t i = 1; i < 11; i++) {
/* munge first word of round key */
expanded_key->round[i].v8[0] =
aes_sbox[expanded_key->round[i - 1].v8[13]] ^ rc;
Expand Down Expand Up @@ -1445,22 +1442,19 @@ static void aes_128_expand_encryption_key(const uint8_t *key,
}
}

static void aes_256_expand_encryption_key(const unsigned char *key,
static void aes_256_expand_encryption_key(const uint8_t *key,
srtp_aes_expanded_key_t *expanded_key)
{
int i;
uint8_t rc;

/* initialize round constant */
rc = 1;
uint8_t rc = 1;

expanded_key->num_rounds = 14;

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

/* loop over rest of round keys */
for (i = 2; i < 15; i++) {
for (size_t i = 2; i < 15; i++) {
/* munge first word of round key */
if ((i & 1) == 0) {
expanded_key->round[i].v8[0] =
Expand Down Expand Up @@ -1525,17 +1519,16 @@ srtp_err_status_t srtp_aes_expand_decryption_key(
size_t key_len,
srtp_aes_expanded_key_t *expanded_key)
{
int i;
srtp_err_status_t status;
int num_rounds = expanded_key->num_rounds;
size_t num_rounds = expanded_key->num_rounds;

status = srtp_aes_expand_encryption_key(key, key_len, expanded_key);
if (status) {
return status;
}

/* invert the order of the round keys */
for (i = 0; i < num_rounds / 2; i++) {
for (size_t i = 0; i < num_rounds / 2; i++) {
v128_t tmp;
v128_copy(&tmp, &expanded_key->round[num_rounds - i]);
v128_copy(&expanded_key->round[num_rounds - i],
Expand All @@ -1551,7 +1544,7 @@ srtp_err_status_t srtp_aes_expand_decryption_key(
* followed by the T4 table (which cancels out the use of the sbox
* in the U-tables)
*/
for (i = 1; i < num_rounds; i++) {
for (size_t i = 1; i < num_rounds; i++) {
#ifdef CPU_RISC
uint32_t tmp;

Expand Down
2 changes: 1 addition & 1 deletion crypto/cipher/aes_gcm_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "cipher_test_cases.h"

srtp_debug_module_t srtp_mod_aes_gcm = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"aes gcm mbedtls" /* printable module name */
};

Expand Down
9 changes: 5 additions & 4 deletions crypto/cipher/aes_gcm_nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include <nspr.h>

srtp_debug_module_t srtp_mod_aes_gcm = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"aes gcm nss" /* printable module name */
};

Expand Down Expand Up @@ -280,7 +280,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_set_aad(void *cv,
}

static srtp_err_status_t srtp_aes_gcm_nss_do_crypto(void *cv,
int encrypt,
bool encrypt,
uint8_t *buf,
size_t *enc_len)
{
Expand Down Expand Up @@ -347,7 +347,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_encrypt(void *cv,
}

srtp_err_status_t status =
srtp_aes_gcm_nss_do_crypto(cv, 1, non_null_buf, enc_len);
srtp_aes_gcm_nss_do_crypto(cv, true, non_null_buf, enc_len);
if (status != srtp_err_status_ok) {
return status;
}
Expand Down Expand Up @@ -390,7 +390,8 @@ static srtp_err_status_t srtp_aes_gcm_nss_decrypt(void *cv,
uint8_t *buf,
size_t *enc_len)
{
srtp_err_status_t status = srtp_aes_gcm_nss_do_crypto(cv, 0, buf, enc_len);
srtp_err_status_t status =
srtp_aes_gcm_nss_do_crypto(cv, false, buf, enc_len);
if (status != srtp_err_status_ok) {
int err = PR_GetError();
if (err == SEC_ERROR_BAD_DATA) {
Expand Down
4 changes: 2 additions & 2 deletions crypto/cipher/aes_gcm_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#include "cipher_test_cases.h"

srtp_debug_module_t srtp_mod_aes_gcm = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"aes gcm" /* printable module name */
};

Expand Down Expand Up @@ -268,7 +268,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv,
* OpenSSL copy its content to the context), so we can make
* aad read-only in this function and all its wrappers.
*/
unsigned char dummy_tag[GCM_AUTH_TAG_LEN];
uint8_t dummy_tag[GCM_AUTH_TAG_LEN];
memset(dummy_tag, 0x0, GCM_AUTH_TAG_LEN);
if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len,
&dummy_tag)) {
Expand Down
10 changes: 5 additions & 5 deletions crypto/cipher/aes_icm.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "cipher_test_cases.h"

srtp_debug_module_t srtp_mod_aes_icm = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"aes icm" /* printable module name */
};

Expand Down Expand Up @@ -299,18 +299,18 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
size_t *enc_len)
{
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
unsigned int bytes_to_encr = (unsigned int)*enc_len;
size_t bytes_to_encr = *enc_len;
uint32_t *b;

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

debug_print(srtp_mod_aes_icm, "block index: %d", htons(c->counter.v16[7]));
if (bytes_to_encr <= (unsigned int)c->bytes_in_buffer) {
if (bytes_to_encr <= c->bytes_in_buffer) {
/* deal with odd case of small bytes_to_encr */
for (size_t i = (sizeof(v128_t) - c->bytes_in_buffer);
i < (sizeof(v128_t) - c->bytes_in_buffer + bytes_to_encr); i++) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/cipher/aes_icm_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include "cipher_test_cases.h"

srtp_debug_module_t srtp_mod_aes_icm = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"aes icm mbedtls" /* printable module name */
};

Expand Down
2 changes: 1 addition & 1 deletion crypto/cipher/aes_icm_nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "cipher_test_cases.h"

srtp_debug_module_t srtp_mod_aes_icm = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"aes icm nss" /* printable module name */
};

Expand Down
2 changes: 1 addition & 1 deletion crypto/cipher/aes_icm_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include "cipher_test_cases.h"

srtp_debug_module_t srtp_mod_aes_icm = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"aes icm ossl" /* printable module name */
};

Expand Down
40 changes: 19 additions & 21 deletions crypto/cipher/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "alloc.h" /* for crypto_alloc(), crypto_free() */

srtp_debug_module_t srtp_mod_cipher = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"cipher" /* printable module name */
};

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

srtp_err_status_t srtp_cipher_set_iv(srtp_cipher_t *c,
uint8_t *iv,
int direction)
srtp_cipher_direction_t direction)
{
if (!c || !c->type || !c->state) {
return (srtp_err_status_bad_param);
Expand Down Expand Up @@ -213,8 +213,7 @@ srtp_err_status_t srtp_cipher_type_test(
uint8_t buffer2[SELF_TEST_BUF_OCTETS];
size_t tag_len;
size_t len;
int i, j, case_num = 0;
unsigned k = 0;
size_t case_num = 0;

debug_print(srtp_mod_cipher, "running self-test for cipher %s",
ct->description);
Expand Down Expand Up @@ -256,7 +255,7 @@ srtp_err_status_t srtp_cipher_type_test(
srtp_cipher_dealloc(c);
return srtp_err_status_bad_param;
}
for (k = 0; k < test_case->plaintext_length_octets; k++) {
for (size_t k = 0; k < test_case->plaintext_length_octets; k++) {
buffer[k] = test_case->plaintext[k];
}

Expand Down Expand Up @@ -321,11 +320,11 @@ srtp_err_status_t srtp_cipher_type_test(
return srtp_err_status_algo_fail;
}
status = srtp_err_status_ok;
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
for (size_t k = 0; k < test_case->ciphertext_length_octets; k++) {
if (buffer[k] != test_case->ciphertext[k]) {
status = srtp_err_status_algo_fail;
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
debug_print(srtp_mod_cipher, "test case %zu failed", case_num);
debug_print(srtp_mod_cipher, "(failure at byte %zu)", k);
break;
}
}
Expand Down Expand Up @@ -359,7 +358,7 @@ srtp_err_status_t srtp_cipher_type_test(
srtp_cipher_dealloc(c);
return srtp_err_status_bad_param;
}
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
for (size_t k = 0; k < test_case->ciphertext_length_octets; k++) {
buffer[k] = test_case->ciphertext[k];
}

Expand Down Expand Up @@ -408,11 +407,11 @@ srtp_err_status_t srtp_cipher_type_test(
return srtp_err_status_algo_fail;
}
status = srtp_err_status_ok;
for (k = 0; k < test_case->plaintext_length_octets; k++) {
for (size_t k = 0; k < test_case->plaintext_length_octets; k++) {
if (buffer[k] != test_case->plaintext[k]) {
status = srtp_err_status_algo_fail;
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
debug_print(srtp_mod_cipher, "test case %zu failed", case_num);
debug_print(srtp_mod_cipher, "(failure at byte %zu)", k);
}
}
if (status) {
Expand Down Expand Up @@ -452,7 +451,7 @@ srtp_err_status_t srtp_cipher_type_test(
return status;
}

for (j = 0; j < NUM_RAND_TESTS; j++) {
for (size_t j = 0; j < NUM_RAND_TESTS; j++) {
size_t length;
size_t plaintext_len;
uint8_t key[MAX_KEY_LEN];
Expand All @@ -467,7 +466,7 @@ srtp_err_status_t srtp_cipher_type_test(
srtp_octet_string_hex_string(buffer, length));

/* copy plaintext into second buffer */
for (i = 0; (unsigned int)i < length; i++) {
for (size_t i = 0; i < length; i++) {
buffer2[i] = buffer[i];
}

Expand Down Expand Up @@ -578,12 +577,12 @@ srtp_err_status_t srtp_cipher_type_test(
return srtp_err_status_algo_fail;
}
status = srtp_err_status_ok;
for (k = 0; k < plaintext_len; k++) {
for (size_t k = 0; k < plaintext_len; k++) {
if (buffer[k] != buffer2[k]) {
status = srtp_err_status_algo_fail;
debug_print(srtp_mod_cipher, "random test case %d failed",
debug_print(srtp_mod_cipher, "random test case %zu failed",
case_num);
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
debug_print(srtp_mod_cipher, "(failure at byte %zu)", k);
}
}
if (status) {
Expand Down Expand Up @@ -621,15 +620,14 @@ srtp_err_status_t srtp_cipher_type_self_test(const srtp_cipher_type_t *ct)
*/
uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
size_t octets_in_buffer,
int num_trials)
size_t num_trials)
{
int i;
v128_t nonce;
clock_t timer;
uint8_t *enc_buf;
size_t len = octets_in_buffer;
size_t tag_len = SRTP_MAX_TAG_LEN;
unsigned char aad[4] = { 0, 0, 0, 0 };
uint8_t aad[4] = { 0, 0, 0, 0 };
size_t aad_len = 4;

enc_buf = (uint8_t *)srtp_crypto_alloc(octets_in_buffer + tag_len);
Expand All @@ -639,7 +637,7 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
/* time repeated trials */
v128_set_to_zero(&nonce);
timer = clock();
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
for (size_t i = 0; i < num_trials; i++, nonce.v32[3] = (uint32_t)i) {
// Set IV
if (srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt) !=
srtp_err_status_ok) {
Expand Down
6 changes: 3 additions & 3 deletions crypto/hash/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/* the debug module for authentiation */

srtp_debug_module_t srtp_mod_auth = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"auth func" /* printable name for module */
};

Expand Down Expand Up @@ -90,7 +90,7 @@ srtp_err_status_t srtp_auth_type_test(const srtp_auth_type_t *at,
srtp_err_status_t status;
uint8_t tag[SELF_TEST_TAG_BUF_OCTETS];
size_t i = 0;
unsigned int case_num = 0;
size_t case_num = 0;

debug_print(srtp_mod_auth, "running self-test for auth function %s",
at->description);
Expand Down Expand Up @@ -157,7 +157,7 @@ srtp_err_status_t srtp_auth_type_test(const srtp_auth_type_t *at,
for (i = 0; i < test_case->tag_length_octets; i++) {
if (tag[i] != test_case->tag[i]) {
status = srtp_err_status_algo_fail;
debug_print(srtp_mod_auth, "test case %d failed", case_num);
debug_print(srtp_mod_auth, "test case %zu failed", case_num);
debug_print(srtp_mod_auth, " (mismatch at octet %zu)", i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/hash/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/* the debug module for authentiation */

srtp_debug_module_t srtp_mod_hmac = {
0, /* debugging is off by default */
false, /* debugging is off by default */
"hmac sha-1" /* printable name for module */
};

Expand Down
Loading

0 comments on commit e9a2c8b

Please sign in to comment.