Skip to content

Commit 4c74586

Browse files
authored
Merge pull request #680 from paulej/paulej_loop_index
Change loops to use local size_t variables
2 parents fcc2517 + e6539d2 commit 4c74586

File tree

6 files changed

+46
-53
lines changed

6 files changed

+46
-53
lines changed

crypto/cipher/aes_icm.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
300300
{
301301
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
302302
unsigned int bytes_to_encr = (unsigned int)*enc_len;
303-
unsigned int i;
304303
uint32_t *b;
305304

306305
/* check that there's enough segment left*/
@@ -313,7 +312,7 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
313312
debug_print(srtp_mod_aes_icm, "block index: %d", htons(c->counter.v16[7]));
314313
if (bytes_to_encr <= (unsigned int)c->bytes_in_buffer) {
315314
/* deal with odd case of small bytes_to_encr */
316-
for (i = (sizeof(v128_t) - c->bytes_in_buffer);
315+
for (size_t i = (sizeof(v128_t) - c->bytes_in_buffer);
317316
i < (sizeof(v128_t) - c->bytes_in_buffer + bytes_to_encr); i++) {
318317
*buf++ ^= c->keystream_buffer.v8[i];
319318
}
@@ -325,8 +324,8 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
325324

326325
} else {
327326
/* encrypt bytes until the remaining data is 16-byte aligned */
328-
for (i = (sizeof(v128_t) - c->bytes_in_buffer); i < sizeof(v128_t);
329-
i++) {
327+
for (size_t i = (sizeof(v128_t) - c->bytes_in_buffer);
328+
i < sizeof(v128_t); i++) {
330329
*buf++ ^= c->keystream_buffer.v8[i];
331330
}
332331

@@ -335,7 +334,7 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
335334
}
336335

337336
/* now loop over entire 16-byte blocks of keystream */
338-
for (i = 0; i < (bytes_to_encr / sizeof(v128_t)); i++) {
337+
for (size_t i = 0; i < (bytes_to_encr / sizeof(v128_t)); i++) {
339338
/* fill buffer with new keystream */
340339
srtp_aes_icm_advance(c);
341340

@@ -385,12 +384,12 @@ static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
385384
/* fill buffer with new keystream */
386385
srtp_aes_icm_advance(c);
387386

388-
for (i = 0; i < (bytes_to_encr & 0xf); i++) {
387+
for (size_t i = 0; i < (bytes_to_encr & 0xf); i++) {
389388
*buf++ ^= c->keystream_buffer.v8[i];
390389
}
391390

392391
/* reset the keystream buffer size to right value */
393-
c->bytes_in_buffer = sizeof(v128_t) - i;
392+
c->bytes_in_buffer = sizeof(v128_t) - (bytes_to_encr & 0xf);
394393
} else {
395394
/* no tail, so just reset the keystream buffer size to zero */
396395
c->bytes_in_buffer = 0;

crypto/hash/hmac.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ static srtp_err_status_t srtp_hmac_init(void *statev,
117117
size_t key_len)
118118
{
119119
srtp_hmac_ctx_t *state = (srtp_hmac_ctx_t *)statev;
120-
size_t i;
121120
uint8_t ipad[64];
122121

123122
/*
@@ -132,12 +131,12 @@ static srtp_err_status_t srtp_hmac_init(void *statev,
132131
* set values of ipad and opad by exoring the key into the
133132
* appropriate constant values
134133
*/
135-
for (i = 0; i < key_len; i++) {
134+
for (size_t i = 0; i < key_len; i++) {
136135
ipad[i] = key[i] ^ 0x36;
137136
state->opad[i] = key[i] ^ 0x5c;
138137
}
139138
/* set the rest of ipad, opad to constant values */
140-
for (; i < 64; i++) {
139+
for (size_t i = key_len; i < 64; i++) {
141140
ipad[i] = 0x36;
142141
((uint8_t *)state->opad)[i] = 0x5c;
143142
}

fuzzer/fuzzer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static srtp_master_key_t *extract_master_key(const uint8_t **data,
346346
static srtp_master_key_t **extract_master_keys(const uint8_t **data,
347347
size_t *size,
348348
const size_t key_size,
349-
unsigned long *num_master_keys)
349+
size_t *num_master_keys)
350350
{
351351
const uint8_t *data_orig = *data;
352352
size_t size_orig = *size;

include/srtp.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -328,29 +328,29 @@ typedef struct srtp_master_key_t {
328328
*/
329329

330330
typedef struct srtp_policy_t {
331-
srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the */
332-
/**< flags SSRC_ANY_INBOUND or */
333-
/**< SSRC_ANY_OUTBOUND if key sharing */
334-
/**< is used for this policy element. */
335-
srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */
336-
srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */
337-
unsigned char *key; /**< Pointer to the SRTP master key for */
338-
/**< this stream. */
339-
srtp_master_key_t **keys; /** Array of Master Key structures */
340-
unsigned long num_master_keys; /** Number of master keys */
341-
unsigned long window_size; /**< The window size to use for replay */
342-
/**< protection. */
343-
bool allow_repeat_tx; /**< Whether retransmissions of */
344-
/**< packets with the same sequence */
345-
/**< number are allowed. */
346-
/**< (Note that such repeated */
347-
/**< transmissions must have the same */
348-
/**< RTP payload, or a severe security */
349-
/**< weakness is introduced!) */
350-
int *enc_xtn_hdr; /**< List of header ids to encrypt. */
351-
int enc_xtn_hdr_count; /**< Number of entries in list of header */
352-
/**< ids. */
353-
struct srtp_policy_t *next; /**< Pointer to next stream policy. */
331+
srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the */
332+
/**< flags SSRC_ANY_INBOUND or */
333+
/**< SSRC_ANY_OUTBOUND if key sharing */
334+
/**< is used for this policy element. */
335+
srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */
336+
srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */
337+
unsigned char *key; /**< Pointer to the SRTP master key for */
338+
/**< this stream. */
339+
srtp_master_key_t **keys; /** Array of Master Key structures */
340+
size_t num_master_keys; /** Number of master keys */
341+
unsigned long window_size; /**< The window size to use for replay */
342+
/**< protection. */
343+
bool allow_repeat_tx; /**< Whether retransmissions of */
344+
/**< packets with the same sequence */
345+
/**< number are allowed. */
346+
/**< (Note that such repeated */
347+
/**< transmissions must have the same */
348+
/**< RTP payload, or a severe security */
349+
/**< weakness is introduced!) */
350+
int *enc_xtn_hdr; /**< List of header ids to encrypt. */
351+
int enc_xtn_hdr_count; /**< Number of entries in list of header */
352+
/**< ids. */
353+
struct srtp_policy_t *next; /**< Pointer to next stream policy. */
354354
} srtp_policy_t;
355355

356356
/**

include/srtp_priv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ srtp_stream_t srtp_get_stream(srtp_t srtp, uint32_t ssrc);
8484
*/
8585
srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp,
8686
srtp_master_key_t *master_key,
87-
const unsigned int current_mki_index);
87+
const size_t current_mki_index);
8888

8989
/*
9090
* srtp_stream_init_all_master_keys(s, k, m) (re)initializes the srtp_stream_t s
@@ -95,7 +95,7 @@ srtp_err_status_t srtp_stream_init_all_master_keys(
9595
srtp_stream_ctx_t *srtp,
9696
unsigned char *key,
9797
srtp_master_key_t **keys,
98-
const unsigned int max_master_keys);
98+
const size_t max_master_keys);
9999

100100
/*
101101
* libsrtp internal datatypes
@@ -134,7 +134,7 @@ typedef struct srtp_session_keys_t {
134134
typedef struct srtp_stream_ctx_t_ {
135135
uint32_t ssrc;
136136
srtp_session_keys_t *session_keys;
137-
unsigned int num_master_keys;
137+
size_t num_master_keys;
138138
srtp_rdbx_t rtp_rdbx;
139139
srtp_sec_serv_t rtp_services;
140140
srtp_rdb_t rtcp_rdb;

srtp/srtp.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ static srtp_err_status_t srtp_stream_dealloc(
177177
const srtp_stream_ctx_t *stream_template)
178178
{
179179
srtp_err_status_t status;
180-
unsigned int i = 0;
181180
srtp_session_keys_t *session_keys = NULL;
182181
srtp_session_keys_t *template_session_keys = NULL;
183182

@@ -187,7 +186,7 @@ static srtp_err_status_t srtp_stream_dealloc(
187186
* anything else
188187
*/
189188
if (stream->session_keys) {
190-
for (i = 0; i < stream->num_master_keys; i++) {
189+
for (size_t i = 0; i < stream->num_master_keys; i++) {
191190
session_keys = &stream->session_keys[i];
192191

193192
if (stream_template &&
@@ -377,7 +376,7 @@ static srtp_err_status_t srtp_stream_alloc(srtp_stream_ctx_t **str_ptr,
377376
{
378377
srtp_stream_ctx_t *str;
379378
srtp_err_status_t stat;
380-
unsigned int i = 0;
379+
size_t i = 0;
381380
srtp_session_keys_t *session_keys = NULL;
382381

383382
stat = srtp_valid_policy(p);
@@ -544,7 +543,6 @@ static srtp_err_status_t srtp_stream_clone(
544543
{
545544
srtp_err_status_t status;
546545
srtp_stream_ctx_t *str;
547-
unsigned int i = 0;
548546
srtp_session_keys_t *session_keys = NULL;
549547
const srtp_session_keys_t *template_session_keys = NULL;
550548

@@ -566,7 +564,7 @@ static srtp_err_status_t srtp_stream_clone(
566564
return srtp_err_status_alloc_fail;
567565
}
568566

569-
for (i = 0; i < stream_template->num_master_keys; i++) {
567+
for (size_t i = 0; i < stream_template->num_master_keys; i++) {
570568
session_keys = &str->session_keys[i];
571569
template_session_keys = &stream_template->session_keys[i];
572570

@@ -914,13 +912,11 @@ size_t srtp_inject_mki(uint8_t *mki_tag_location,
914912
return mki_size;
915913
}
916914

917-
srtp_err_status_t srtp_stream_init_all_master_keys(
918-
srtp_stream_ctx_t *srtp,
919-
unsigned char *key,
920-
srtp_master_key_t **keys,
921-
const unsigned int max_master_keys)
915+
srtp_err_status_t srtp_stream_init_all_master_keys(srtp_stream_ctx_t *srtp,
916+
unsigned char *key,
917+
srtp_master_key_t **keys,
918+
const size_t max_master_keys)
922919
{
923-
unsigned int i = 0;
924920
srtp_err_status_t status = srtp_err_status_ok;
925921
srtp_master_key_t single_master_key;
926922

@@ -933,8 +929,8 @@ srtp_err_status_t srtp_stream_init_all_master_keys(
933929
} else {
934930
srtp->num_master_keys = max_master_keys;
935931

936-
for (i = 0; i < srtp->num_master_keys && i < SRTP_MAX_NUM_MASTER_KEYS;
937-
i++) {
932+
for (size_t i = 0;
933+
i < srtp->num_master_keys && i < SRTP_MAX_NUM_MASTER_KEYS; i++) {
938934
status = srtp_stream_init_keys(srtp, keys[i], i);
939935

940936
if (status) {
@@ -948,7 +944,7 @@ srtp_err_status_t srtp_stream_init_all_master_keys(
948944

949945
srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp,
950946
srtp_master_key_t *master_key,
951-
const unsigned int current_mki_index)
947+
const size_t current_mki_index)
952948
{
953949
srtp_err_status_t stat;
954950
srtp_kdf_t kdf;
@@ -1637,7 +1633,6 @@ srtp_session_keys_t *srtp_get_session_keys(srtp_stream_ctx_t *stream,
16371633
size_t base_mki_start_location = pkt_octet_len;
16381634
size_t mki_start_location = 0;
16391635
size_t tag_len = 0;
1640-
unsigned int i = 0;
16411636

16421637
// Determine the authentication tag size
16431638
if (stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_128 ||
@@ -1654,7 +1649,7 @@ srtp_session_keys_t *srtp_get_session_keys(srtp_stream_ctx_t *stream,
16541649

16551650
base_mki_start_location -= tag_len;
16561651

1657-
for (i = 0; i < stream->num_master_keys; i++) {
1652+
for (size_t i = 0; i < stream->num_master_keys; i++) {
16581653
if (stream->session_keys[i].mki_size != 0 &&
16591654
stream->session_keys[i].mki_size <= base_mki_start_location) {
16601655
*mki_size = stream->session_keys[i].mki_size;

0 commit comments

Comments
 (0)