Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use uint8_t for byte and byte pointer #681

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crypto/cipher/aes_gcm_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_context_init(void *cv,
break;
}

errCode = mbedtls_gcm_setkey(c->ctx, MBEDTLS_CIPHER_ID_AES,
(const unsigned char *)key, key_len_in_bits);
errCode =
mbedtls_gcm_setkey(c->ctx, MBEDTLS_CIPHER_ID_AES, key, key_len_in_bits);
if (errCode != 0) {
debug_print(srtp_mod_aes_gcm, "mbedtls error code: %d", errCode);
return srtp_err_status_init_fail;
Expand Down Expand Up @@ -281,7 +281,7 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_set_aad(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_mbedtls_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
FUNC_ENTRY();
Expand Down Expand Up @@ -337,7 +337,7 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_get_tag(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_mbedtls_decrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
FUNC_ENTRY();
Expand Down
10 changes: 5 additions & 5 deletions crypto/cipher/aes_gcm_nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,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,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
Expand Down Expand Up @@ -328,7 +328,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_do_crypto(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_nss_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
Expand All @@ -338,8 +338,8 @@ static srtp_err_status_t srtp_aes_gcm_nss_encrypt(void *cv,
// even though there's no data, we need to give NSS a buffer
// where it can write the tag. We can't just use c->tag because
// memcpy has undefined behavior on overlapping ranges.
unsigned char tagbuf[16];
unsigned char *non_null_buf = buf;
uint8_t tagbuf[16];
uint8_t *non_null_buf = buf;
if (!non_null_buf && (*enc_len == 0)) {
non_null_buf = tagbuf;
} else if (!non_null_buf) {
Expand Down Expand Up @@ -387,7 +387,7 @@ static srtp_err_status_t srtp_aes_gcm_nss_get_tag(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_nss_decrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_err_status_t status = srtp_aes_gcm_nss_do_crypto(cv, 0, buf, enc_len);
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 @@ -293,7 +293,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_openssl_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
Expand Down Expand Up @@ -354,7 +354,7 @@ static srtp_err_status_t srtp_aes_gcm_openssl_get_tag(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_openssl_decrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
Expand Down
2 changes: 1 addition & 1 deletion crypto/cipher/aes_icm.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static void srtp_aes_icm_advance(srtp_aes_icm_ctx_t *c)
*/

static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
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 @@ -290,7 +290,7 @@ static srtp_err_status_t srtp_aes_icm_mbedtls_set_iv(
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_icm_mbedtls_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
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 @@ -323,7 +323,7 @@ static srtp_err_status_t srtp_aes_icm_nss_set_iv(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_icm_nss_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
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 @@ -298,7 +298,7 @@ static srtp_err_status_t srtp_aes_icm_openssl_set_iv(
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_icm_openssl_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *enc_len)
{
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
Expand Down
22 changes: 9 additions & 13 deletions crypto/cipher/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,16 @@ size_t srtp_cipher_get_key_length(const srtp_cipher_t *c)
* A trivial platform independent random source.
* For use in test only.
*/
void srtp_cipher_rand_for_tests(void *dest, size_t len)
void srtp_cipher_rand_for_tests(uint8_t *dest, size_t len)
{
/* Generic C-library (rand()) version */
/* This is a random source of last resort */
uint8_t *dst = (uint8_t *)dest;
while (len) {
int val = rand();
/* rand() returns 0-32767 (ugh) */
/* Is this a good enough way to get random bytes?
It is if it passes FIPS-140... */
*dst++ = val & 0xff;
*dest++ = val & 0xff;
len--;
}
}
Expand All @@ -191,7 +190,7 @@ void srtp_cipher_rand_for_tests(void *dest, size_t len)
uint32_t srtp_cipher_rand_u32_for_tests(void)
{
uint32_t r;
srtp_cipher_rand_for_tests(&r, sizeof(r));
srtp_cipher_rand_for_tests((uint8_t *)&r, sizeof(r));
return r;
}

Expand Down Expand Up @@ -266,8 +265,7 @@ srtp_err_status_t srtp_cipher_type_test(
buffer, test_case->plaintext_length_octets));

/* set the initialization vector */
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
srtp_direction_encrypt);
status = srtp_cipher_set_iv(c, test_case->idx, srtp_direction_encrypt);
if (status) {
srtp_cipher_dealloc(c);
return status;
Expand Down Expand Up @@ -370,8 +368,7 @@ srtp_err_status_t srtp_cipher_type_test(
buffer, test_case->plaintext_length_octets));

/* set the initialization vector */
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
srtp_direction_decrypt);
status = srtp_cipher_set_iv(c, test_case->idx, srtp_direction_decrypt);
if (status) {
srtp_cipher_dealloc(c);
return status;
Expand Down Expand Up @@ -492,8 +489,7 @@ srtp_err_status_t srtp_cipher_type_test(
}

/* set initialization vector */
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
srtp_direction_encrypt);
status = srtp_cipher_set_iv(c, test_case->idx, srtp_direction_encrypt);
if (status) {
srtp_cipher_dealloc(c);
return status;
Expand Down Expand Up @@ -630,13 +626,13 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
int i;
v128_t nonce;
clock_t timer;
unsigned char *enc_buf;
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 };
size_t aad_len = 4;

enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer + tag_len);
enc_buf = (uint8_t *)srtp_crypto_alloc(octets_in_buffer + tag_len);
if (enc_buf == NULL) {
return 0; /* indicate bad parameters by returning null */
}
Expand Down Expand Up @@ -667,7 +663,7 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,

// Get tag if supported by the cipher
if (c->type->get_tag) {
if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + len), &tag_len) !=
if (srtp_cipher_get_tag(c, enc_buf + len, &tag_len) !=
srtp_err_status_ok) {
srtp_crypto_free(enc_buf);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion crypto/cipher/null_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static srtp_err_status_t srtp_null_cipher_set_iv(void *cv,
}

static srtp_err_status_t srtp_null_cipher_encrypt(void *cv,
unsigned char *buf,
uint8_t *buf,
size_t *bytes_to_encr)
{
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
Expand Down
2 changes: 1 addition & 1 deletion crypto/include/cipher_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern "C" {
* A trivial platform independent random source.
* For use in test only.
*/
void srtp_cipher_rand_for_tests(void *dest, size_t len);
void srtp_cipher_rand_for_tests(uint8_t *dest, size_t len);

/*
* A trivial platform independent 32 bit random number.
Expand Down
4 changes: 2 additions & 2 deletions crypto/test/aes_calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int main(int argc, char *argv[])
AES_MAX_KEY_LEN * 2, (unsigned)strlen(argv[1]));
exit(1);
}
len = hex_string_to_octet_string((char *)key, argv[1], AES_MAX_KEY_LEN * 2);
len = hex_string_to_octet_string(key, argv[1], AES_MAX_KEY_LEN * 2);
/* check that hex string is the right length */
if (len != 32 && len != 48 && len != 64) {
fprintf(stderr,
Expand All @@ -131,7 +131,7 @@ int main(int argc, char *argv[])
16 * 2, (unsigned)strlen(argv[2]));
exit(1);
}
len = hex_string_to_octet_string((char *)(&data), argv[2], 16 * 2);
len = hex_string_to_octet_string((uint8_t *)&data, argv[2], 16 * 2);
/* check that hex string is the right length */
if (len < 16 * 2) {
fprintf(stderr,
Expand Down
6 changes: 3 additions & 3 deletions crypto/test/cipher_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c)
}

/* initialize cipher */
status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
status = srtp_cipher_set_iv(c, idx, srtp_direction_encrypt);
if (status)
return status;

Expand All @@ -377,7 +377,7 @@ srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c)
return status;

/* re-initialize cipher */
status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
status = srtp_cipher_set_iv(c, idx, srtp_direction_encrypt);
if (status)
return status;

Expand Down Expand Up @@ -525,7 +525,7 @@ uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[],
int i;
v128_t nonce;
clock_t timer;
unsigned char *enc_buf;
uint8_t *enc_buf;
int cipher_index = srtp_cipher_rand_u32_for_tests() % num_cipher;

/* Over-alloc, for NIST CBC padding */
Expand Down
2 changes: 1 addition & 1 deletion crypto/test/datatypes_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void test_hex_string_funcs(void)
{
char hex1[] = "abadcafe";
char hex2[] = "0123456789abcdefqqqqq";
char raw[10];
uint8_t raw[10];
size_t len;

len = hex_string_to_octet_string(raw, hex1, strlen(hex1));
Expand Down
8 changes: 4 additions & 4 deletions crypto/test/sha1_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ srtp_err_status_t hash_test_case_add(hash_test_case_t **list_ptr,
if (test_case == NULL)
return srtp_err_status_alloc_fail;

tmp_len = hex_string_to_octet_string((char *)test_case->data, hex_data,
data_len * 2);
tmp_len =
hex_string_to_octet_string(test_case->data, hex_data, data_len * 2);
if (tmp_len != data_len * 2) {
free(test_case);
return srtp_err_status_parse_err;
}

tmp_len = hex_string_to_octet_string((char *)test_case->hash, hex_hash,
hash_len * 2);
tmp_len =
hex_string_to_octet_string(test_case->hash, hex_hash, hash_len * 2);
if (tmp_len != hash_len * 2) {
free(test_case);
return srtp_err_status_parse_err;
Expand Down
Loading
Loading