Skip to content

Commit 1396c2a

Browse files
authored
Merge pull request #685 from paulej/paulej_octet_string_equal
Renamed srtp_octet_string_is_eq, equal is true
2 parents 11445dc + 1586de6 commit 1396c2a

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

crypto/include/datatypes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ void v128_left_shift(v128_t *x, size_t shift_index);
163163
((((x)->v32[(bit) >> 5]) &= ~((uint32_t)1 << ((bit)&31))))
164164

165165
/*
166-
* srtp_octet_string_is_eq(a, b, len) returns true if the length len strings
167-
* a and b are NOT equal. It returns false otherwise. The running time of the
168-
* comparison depends only on len, making this safe to use for (e.g.)
166+
* srtp_octet_string_equal(a, b, len) returns true if the octet strings
167+
* a and b are equal. It returns false otherwise. The running time of the
168+
* comparison depends only on length, making this safe to use for (e.g.)
169169
* verifying authentication tags.
170170
*/
171171

172-
bool srtp_octet_string_is_eq(const uint8_t *a, const uint8_t *b, size_t len);
172+
bool srtp_octet_string_equal(const uint8_t *a, const uint8_t *b, size_t len);
173173

174174
/*
175175
* A portable way to zero out memory as recommended by

crypto/math/datatypes.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,20 @@ void bitvector_left_shift(bitvector_t *x, size_t shift)
403403

404404
#endif /* defined(__SSSE3__) */
405405

406-
bool srtp_octet_string_is_eq(const uint8_t *a, const uint8_t *b, size_t len)
406+
bool srtp_octet_string_equal(const uint8_t *a, const uint8_t *b, size_t length)
407407
{
408408
/*
409409
* We use this somewhat obscure implementation to try to ensure the running
410410
* time only depends on len, even accounting for compiler optimizations.
411411
* The accumulator ends up zero iff the strings are equal.
412412
*/
413-
const uint8_t *end = b + len;
413+
const uint8_t *end = b + length;
414414
uint32_t accumulator = 0;
415415

416416
#if defined(__SSE2__)
417417
__m128i mm_accumulator1 = _mm_setzero_si128();
418418
__m128i mm_accumulator2 = _mm_setzero_si128();
419-
for (size_t i = 0, n = len >> 5; i < n; ++i, a += 32, b += 32) {
419+
for (size_t i = 0, n = length >> 5; i < n; ++i, a += 32, b += 32) {
420420
__m128i mm_a1 = _mm_loadu_si128((const __m128i *)a);
421421
__m128i mm_b1 = _mm_loadu_si128((const __m128i *)b);
422422
__m128i mm_a2 = _mm_loadu_si128((const __m128i *)(a + 16));
@@ -454,7 +454,7 @@ bool srtp_octet_string_is_eq(const uint8_t *a, const uint8_t *b, size_t len)
454454
accumulator = _mm_cvtsi128_si32(mm_accumulator1);
455455
#else
456456
uint32_t accumulator2 = 0;
457-
for (size_t i = 0, n = len >> 3; i < n; ++i, a += 8, b += 8) {
457+
for (size_t i = 0, n = length >> 3; i < n; ++i, a += 8, b += 8) {
458458
uint32_t a_val1, b_val1;
459459
uint32_t a_val2, b_val2;
460460
memcpy(&a_val1, a, sizeof(a_val1));
@@ -481,8 +481,8 @@ bool srtp_octet_string_is_eq(const uint8_t *a, const uint8_t *b, size_t len)
481481
accumulator |= (*a++ ^ *b++);
482482
}
483483

484-
/* Return 1 if *not* equal. */
485-
return accumulator != 0;
484+
/* Return true if equal */
485+
return accumulator == 0;
486486
}
487487

488488
void srtp_cleanse(void *s, size_t len)

srtp.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ srtp_auth_type_self_test
7070
srtp_auth_type_test
7171
srtp_replace_auth_type
7272
srtp_octet_string_hex_string
73-
srtp_octet_string_is_eq
73+
srtp_octet_string_equal
7474
srtp_rdbx_get_window_size

srtp/srtp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,7 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx,
27632763
return srtp_err_status_auth_fail;
27642764
}
27652765

2766-
if (srtp_octet_string_is_eq(tmp_tag, auth_tag, tag_len)) {
2766+
if (!srtp_octet_string_equal(tmp_tag, auth_tag, tag_len)) {
27672767
return srtp_err_status_auth_fail;
27682768
}
27692769
}
@@ -4414,7 +4414,7 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx,
44144414
/* compare the tag just computed with the one in the packet */
44154415
debug_print(mod_srtp, "srtcp tag from packet: %s",
44164416
srtp_octet_string_hex_string(auth_tag, tag_len));
4417-
if (srtp_octet_string_is_eq(tmp_tag, auth_tag, tag_len)) {
4417+
if (!srtp_octet_string_equal(tmp_tag, auth_tag, tag_len)) {
44184418
return srtp_err_status_auth_fail;
44194419
}
44204420

test/srtp_driver.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ srtp_err_status_t srtp_validate(void)
18371837
debug_print(mod_driver, "ciphertext reference:\n %s",
18381838
octet_string_hex_string(srtp_ciphertext, len));
18391839

1840-
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
1840+
if (!srtp_octet_string_equal(srtp_plaintext, srtp_ciphertext, len)) {
18411841
return srtp_err_status_fail;
18421842
}
18431843

@@ -1855,7 +1855,7 @@ srtp_err_status_t srtp_validate(void)
18551855
debug_print(mod_driver, "srtcp ciphertext reference:\n %s",
18561856
octet_string_hex_string(srtcp_ciphertext, len));
18571857

1858-
if (srtp_octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
1858+
if (!srtp_octet_string_equal(rtcp_plaintext, srtcp_ciphertext, len)) {
18591859
return srtp_err_status_fail;
18601860
}
18611861

@@ -1877,7 +1877,7 @@ srtp_err_status_t srtp_validate(void)
18771877
return status;
18781878
}
18791879

1880-
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
1880+
if (!srtp_octet_string_equal(srtp_ciphertext, srtp_plaintext_ref, len)) {
18811881
return srtp_err_status_fail;
18821882
}
18831883

@@ -1890,7 +1890,7 @@ srtp_err_status_t srtp_validate(void)
18901890
return status;
18911891
}
18921892

1893-
if (srtp_octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
1893+
if (!srtp_octet_string_equal(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
18941894
return srtp_err_status_fail;
18951895
}
18961896

@@ -1996,7 +1996,7 @@ srtp_err_status_t srtp_validate_null(void)
19961996
debug_print(mod_driver, "ciphertext reference:\n %s",
19971997
octet_string_hex_string(srtp_ciphertext, len));
19981998

1999-
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
1999+
if (!srtp_octet_string_equal(srtp_plaintext, srtp_ciphertext, len)) {
20002000
return srtp_err_status_fail;
20012001
}
20022002

@@ -2014,7 +2014,7 @@ srtp_err_status_t srtp_validate_null(void)
20142014
debug_print(mod_driver, "srtcp ciphertext reference:\n %s",
20152015
octet_string_hex_string(srtcp_ciphertext, len));
20162016

2017-
if (srtp_octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
2017+
if (!srtp_octet_string_equal(rtcp_plaintext, srtcp_ciphertext, len)) {
20182018
return srtp_err_status_fail;
20192019
}
20202020

@@ -2036,7 +2036,7 @@ srtp_err_status_t srtp_validate_null(void)
20362036
return status;
20372037
}
20382038

2039-
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
2039+
if (!srtp_octet_string_equal(srtp_ciphertext, srtp_plaintext_ref, len)) {
20402040
return srtp_err_status_fail;
20412041
}
20422042

@@ -2049,7 +2049,7 @@ srtp_err_status_t srtp_validate_null(void)
20492049
return status;
20502050
}
20512051

2052-
if (srtp_octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
2052+
if (!srtp_octet_string_equal(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
20532053
return srtp_err_status_fail;
20542054
}
20552055

@@ -2157,7 +2157,7 @@ srtp_err_status_t srtp_validate_gcm(void)
21572157
debug_print(mod_driver, "srtp ciphertext reference:\n %s",
21582158
octet_string_hex_string(srtp_ciphertext, len));
21592159

2160-
if (srtp_octet_string_is_eq(rtp_plaintext, srtp_ciphertext, len)) {
2160+
if (!srtp_octet_string_equal(rtp_plaintext, srtp_ciphertext, len)) {
21612161
return srtp_err_status_fail;
21622162
}
21632163

@@ -2175,7 +2175,7 @@ srtp_err_status_t srtp_validate_gcm(void)
21752175
debug_print(mod_driver, "srtcp ciphertext reference:\n %s",
21762176
octet_string_hex_string(srtcp_ciphertext, len));
21772177

2178-
if (srtp_octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
2178+
if (!srtp_octet_string_equal(rtcp_plaintext, srtcp_ciphertext, len)) {
21792179
return srtp_err_status_fail;
21802180
}
21812181

@@ -2198,7 +2198,7 @@ srtp_err_status_t srtp_validate_gcm(void)
21982198
return status;
21992199
}
22002200

2201-
if (srtp_octet_string_is_eq(srtp_ciphertext, rtp_plaintext_ref, len)) {
2201+
if (!srtp_octet_string_equal(srtp_ciphertext, rtp_plaintext_ref, len)) {
22022202
return srtp_err_status_fail;
22032203
}
22042204

@@ -2217,7 +2217,7 @@ srtp_err_status_t srtp_validate_gcm(void)
22172217
octet_string_hex_string(rtcp_plaintext_ref,
22182218
sizeof(rtcp_plaintext_ref)));
22192219

2220-
if (srtp_octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
2220+
if (!srtp_octet_string_equal(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
22212221
return srtp_err_status_fail;
22222222
}
22232223

@@ -2321,7 +2321,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers(void)
23212321
debug_print(mod_driver, "ciphertext reference:\n %s",
23222322
srtp_octet_string_hex_string(srtp_ciphertext, len));
23232323

2324-
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
2324+
if (!srtp_octet_string_equal(srtp_plaintext, srtp_ciphertext, len)) {
23252325
return srtp_err_status_fail;
23262326
}
23272327

@@ -2345,7 +2345,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers(void)
23452345
return srtp_err_status_fail;
23462346
}
23472347

2348-
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
2348+
if (!srtp_octet_string_equal(srtp_ciphertext, srtp_plaintext_ref, len)) {
23492349
return srtp_err_status_fail;
23502350
}
23512351

@@ -2450,7 +2450,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm(void)
24502450
debug_print(mod_driver, " ? ciphertext reference:\n %s",
24512451
srtp_octet_string_hex_string(srtp_ciphertext, len));
24522452

2453-
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
2453+
if (!srtp_octet_string_equal(srtp_plaintext, srtp_ciphertext, len)) {
24542454
return srtp_err_status_fail;
24552455
}
24562456

@@ -2474,7 +2474,7 @@ srtp_err_status_t srtp_validate_encrypted_extensions_headers_gcm(void)
24742474
return srtp_err_status_fail;
24752475
}
24762476

2477-
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
2477+
if (!srtp_octet_string_equal(srtp_ciphertext, srtp_plaintext_ref, len)) {
24782478
return srtp_err_status_fail;
24792479
}
24802480

@@ -2570,7 +2570,7 @@ srtp_err_status_t srtp_validate_aes_256(void)
25702570
debug_print(mod_driver, "ciphertext reference:\n %s",
25712571
octet_string_hex_string(srtp_ciphertext, len));
25722572

2573-
if (srtp_octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
2573+
if (!srtp_octet_string_equal(srtp_plaintext, srtp_ciphertext, len)) {
25742574
return srtp_err_status_fail;
25752575
}
25762576

@@ -2592,7 +2592,7 @@ srtp_err_status_t srtp_validate_aes_256(void)
25922592
return status;
25932593
}
25942594

2595-
if (srtp_octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
2595+
if (!srtp_octet_string_equal(srtp_ciphertext, srtp_plaintext_ref, len)) {
25962596
return srtp_err_status_fail;
25972597
}
25982598

0 commit comments

Comments
 (0)