diff --git a/crypto/cipher/aes_gcm_mbedtls.c b/crypto/cipher/aes_gcm_mbedtls.c index 854d72b95..285c3680d 100644 --- a/crypto/cipher/aes_gcm_mbedtls.c +++ b/crypto/cipher/aes_gcm_mbedtls.c @@ -90,6 +90,84 @@ srtp_debug_module_t srtp_mod_aes_gcm = { #define GCM_AUTH_TAG_LEN_8 8 #define FUNC_ENTRY() debug_print(srtp_mod_aes_gcm, "%s entry", __func__); + +/* + * static function declarations. + */ +static srtp_err_status_t srtp_aes_gcm_mbedtls_alloc(srtp_cipher_t **c, + size_t key_len, + size_t tlen); + +static srtp_err_status_t srtp_aes_gcm_mbedtls_dealloc(srtp_cipher_t *c); + +static srtp_err_status_t srtp_aes_gcm_mbedtls_context_init(void *cv, + const uint8_t *key); + +static srtp_err_status_t srtp_aes_gcm_mbedtls_set_iv( + void *cv, + uint8_t *iv, + srtp_cipher_direction_t direction); + +static srtp_err_status_t srtp_aes_gcm_mbedtls_set_aad(void *cv, + const uint8_t *aad, + size_t aad_len); + +static srtp_err_status_t srtp_aes_gcm_mbedtls_encrypt(void *cv, + const uint8_t *src, + size_t src_len, + uint8_t *dst, + size_t *dst_len); + +static srtp_err_status_t srtp_aes_gcm_mbedtls_decrypt(void *cv, + const uint8_t *src, + size_t src_len, + uint8_t *dst, + size_t *dst_len); + +/* + * Name of this crypto engine + */ +static const char srtp_aes_gcm_128_mbedtls_description[] = + "AES-128 GCM using mbedtls"; +static const char srtp_aes_gcm_256_mbedtls_description[] = + "AES-256 GCM using mbedtls"; + +/* + * This is the vector function table for this crypto engine. + */ +/* clang-format off */ +const srtp_cipher_type_t srtp_aes_gcm_128 = { + srtp_aes_gcm_mbedtls_alloc, + srtp_aes_gcm_mbedtls_dealloc, + srtp_aes_gcm_mbedtls_context_init, + srtp_aes_gcm_mbedtls_set_aad, + srtp_aes_gcm_mbedtls_encrypt, + srtp_aes_gcm_mbedtls_decrypt, + srtp_aes_gcm_mbedtls_set_iv, + srtp_aes_gcm_128_mbedtls_description, + &srtp_aes_gcm_128_test_case_0, + SRTP_AES_GCM_128 +}; +/* clang-format on */ + +/* + * This is the vector function table for this crypto engine. + */ +/* clang-format off */ +const srtp_cipher_type_t srtp_aes_gcm_256 = { + srtp_aes_gcm_mbedtls_alloc, + srtp_aes_gcm_mbedtls_dealloc, + srtp_aes_gcm_mbedtls_context_init, + srtp_aes_gcm_mbedtls_set_aad, + srtp_aes_gcm_mbedtls_encrypt, + srtp_aes_gcm_mbedtls_decrypt, + srtp_aes_gcm_mbedtls_set_iv, + srtp_aes_gcm_256_mbedtls_description, + &srtp_aes_gcm_256_test_case_0, + SRTP_AES_GCM_256 +}; +/* clang-format on */ + /* * This function allocates a new instance of this crypto engine. * The key_len parameter should be one of 28 or 44 for @@ -362,47 +440,3 @@ static srtp_err_status_t srtp_aes_gcm_mbedtls_decrypt(void *cv, return srtp_err_status_ok; } - -/* - * Name of this crypto engine - */ -static const char srtp_aes_gcm_128_mbedtls_description[] = - "AES-128 GCM using mbedtls"; -static const char srtp_aes_gcm_256_mbedtls_description[] = - "AES-256 GCM using mbedtls"; - -/* - * This is the vector function table for this crypto engine. - */ -/* clang-format off */ -const srtp_cipher_type_t srtp_aes_gcm_128 = { - srtp_aes_gcm_mbedtls_alloc, - srtp_aes_gcm_mbedtls_dealloc, - srtp_aes_gcm_mbedtls_context_init, - srtp_aes_gcm_mbedtls_set_aad, - srtp_aes_gcm_mbedtls_encrypt, - srtp_aes_gcm_mbedtls_decrypt, - srtp_aes_gcm_mbedtls_set_iv, - srtp_aes_gcm_128_mbedtls_description, - &srtp_aes_gcm_128_test_case_0, - SRTP_AES_GCM_128 -}; -/* clang-format on */ - -/* - * This is the vector function table for this crypto engine. - */ -/* clang-format off */ -const srtp_cipher_type_t srtp_aes_gcm_256 = { - srtp_aes_gcm_mbedtls_alloc, - srtp_aes_gcm_mbedtls_dealloc, - srtp_aes_gcm_mbedtls_context_init, - srtp_aes_gcm_mbedtls_set_aad, - srtp_aes_gcm_mbedtls_encrypt, - srtp_aes_gcm_mbedtls_decrypt, - srtp_aes_gcm_mbedtls_set_iv, - srtp_aes_gcm_256_mbedtls_description, - &srtp_aes_gcm_256_test_case_0, - SRTP_AES_GCM_256 -}; -/* clang-format on */ diff --git a/crypto/cipher/aes_icm_mbedtls.c b/crypto/cipher/aes_icm_mbedtls.c index 83879bd0b..1b5d4b83b 100644 --- a/crypto/cipher/aes_icm_mbedtls.c +++ b/crypto/cipher/aes_icm_mbedtls.c @@ -58,6 +58,90 @@ srtp_debug_module_t srtp_mod_aes_icm = { "aes icm mbedtls" /* printable module name */ }; +/* + * static function declarations. + */ +static srtp_err_status_t srtp_aes_icm_mbedtls_alloc(srtp_cipher_t **c, + size_t key_len, + size_t tlen); + +static srtp_err_status_t srtp_aes_icm_mbedtls_dealloc(srtp_cipher_t *c); + +static srtp_err_status_t srtp_aes_icm_mbedtls_context_init(void *cv, + const uint8_t *key); + +static srtp_err_status_t srtp_aes_icm_mbedtls_set_iv( + void *cv, + uint8_t *iv, + srtp_cipher_direction_t dir); + +static srtp_err_status_t srtp_aes_icm_mbedtls_encrypt(void *cv, + const uint8_t *src, + size_t src_len, + uint8_t *dst, + size_t *dst_len); + +/* + * Name of this crypto engine + */ +static const char srtp_aes_icm_128_mbedtls_description[] = + "AES-128 counter mode using mbedtls"; +static const char srtp_aes_icm_192_mbedtls_description[] = + "AES-192 counter mode using mbedtls"; +static const char srtp_aes_icm_256_mbedtls_description[] = + "AES-256 counter mode using mbedtls"; + +/* + * This is the function table for this crypto engine. + * note: the encrypt function is identical to the decrypt function + */ +const srtp_cipher_type_t srtp_aes_icm_128 = { + srtp_aes_icm_mbedtls_alloc, /* */ + srtp_aes_icm_mbedtls_dealloc, /* */ + srtp_aes_icm_mbedtls_context_init, /* */ + 0, /* set_aad */ + srtp_aes_icm_mbedtls_encrypt, /* */ + srtp_aes_icm_mbedtls_encrypt, /* */ + srtp_aes_icm_mbedtls_set_iv, /* */ + srtp_aes_icm_128_mbedtls_description, /* */ + &srtp_aes_icm_128_test_case_0, /* */ + SRTP_AES_ICM_128 /* */ +}; + +/* + * This is the function table for this crypto engine. + * note: the encrypt function is identical to the decrypt function + */ +const srtp_cipher_type_t srtp_aes_icm_192 = { + srtp_aes_icm_mbedtls_alloc, /* */ + srtp_aes_icm_mbedtls_dealloc, /* */ + srtp_aes_icm_mbedtls_context_init, /* */ + 0, /* set_aad */ + srtp_aes_icm_mbedtls_encrypt, /* */ + srtp_aes_icm_mbedtls_encrypt, /* */ + srtp_aes_icm_mbedtls_set_iv, /* */ + srtp_aes_icm_192_mbedtls_description, /* */ + &srtp_aes_icm_192_test_case_0, /* */ + SRTP_AES_ICM_192 /* */ +}; + +/* + * This is the function table for this crypto engine. + * note: the encrypt function is identical to the decrypt function + */ +const srtp_cipher_type_t srtp_aes_icm_256 = { + srtp_aes_icm_mbedtls_alloc, /* */ + srtp_aes_icm_mbedtls_dealloc, /* */ + srtp_aes_icm_mbedtls_context_init, /* */ + 0, /* set_aad */ + srtp_aes_icm_mbedtls_encrypt, /* */ + srtp_aes_icm_mbedtls_encrypt, /* */ + srtp_aes_icm_mbedtls_set_iv, /* */ + srtp_aes_icm_256_mbedtls_description, /* */ + &srtp_aes_icm_256_test_case_0, /* */ + SRTP_AES_ICM_256 /* */ +}; + /* * integer counter mode works as follows: * @@ -316,64 +400,3 @@ static srtp_err_status_t srtp_aes_icm_mbedtls_encrypt(void *cv, return srtp_err_status_ok; } - -/* - * Name of this crypto engine - */ -static const char srtp_aes_icm_128_mbedtls_description[] = - "AES-128 counter mode using mbedtls"; -static const char srtp_aes_icm_192_mbedtls_description[] = - "AES-192 counter mode using mbedtls"; -static const char srtp_aes_icm_256_mbedtls_description[] = - "AES-256 counter mode using mbedtls"; - -/* - * This is the function table for this crypto engine. - * note: the encrypt function is identical to the decrypt function - */ -const srtp_cipher_type_t srtp_aes_icm_128 = { - srtp_aes_icm_mbedtls_alloc, /* */ - srtp_aes_icm_mbedtls_dealloc, /* */ - srtp_aes_icm_mbedtls_context_init, /* */ - 0, /* set_aad */ - srtp_aes_icm_mbedtls_encrypt, /* */ - srtp_aes_icm_mbedtls_encrypt, /* */ - srtp_aes_icm_mbedtls_set_iv, /* */ - srtp_aes_icm_128_mbedtls_description, /* */ - &srtp_aes_icm_128_test_case_0, /* */ - SRTP_AES_ICM_128 /* */ -}; - -/* - * This is the function table for this crypto engine. - * note: the encrypt function is identical to the decrypt function - */ -const srtp_cipher_type_t srtp_aes_icm_192 = { - srtp_aes_icm_mbedtls_alloc, /* */ - srtp_aes_icm_mbedtls_dealloc, /* */ - srtp_aes_icm_mbedtls_context_init, /* */ - 0, /* set_aad */ - srtp_aes_icm_mbedtls_encrypt, /* */ - srtp_aes_icm_mbedtls_encrypt, /* */ - srtp_aes_icm_mbedtls_set_iv, /* */ - srtp_aes_icm_192_mbedtls_description, /* */ - &srtp_aes_icm_192_test_case_0, /* */ - SRTP_AES_ICM_192 /* */ -}; - -/* - * This is the function table for this crypto engine. - * note: the encrypt function is identical to the decrypt function - */ -const srtp_cipher_type_t srtp_aes_icm_256 = { - srtp_aes_icm_mbedtls_alloc, /* */ - srtp_aes_icm_mbedtls_dealloc, /* */ - srtp_aes_icm_mbedtls_context_init, /* */ - 0, /* set_aad */ - srtp_aes_icm_mbedtls_encrypt, /* */ - srtp_aes_icm_mbedtls_encrypt, /* */ - srtp_aes_icm_mbedtls_set_iv, /* */ - srtp_aes_icm_256_mbedtls_description, /* */ - &srtp_aes_icm_256_test_case_0, /* */ - SRTP_AES_ICM_256 /* */ -}; diff --git a/crypto/include/datatypes.h b/crypto/include/datatypes.h index a64fd0cd9..6e2a19127 100644 --- a/crypto/include/datatypes.h +++ b/crypto/include/datatypes.h @@ -54,8 +54,6 @@ #include #elif defined HAVE_WINSOCK2_H #include -#else -#error "Platform not recognized" #endif #if defined(__SSE2__) diff --git a/crypto/include/err.h b/crypto/include/err.h index c9b7649df..03bbe2905 100644 --- a/crypto/include/err.h +++ b/crypto/include/err.h @@ -47,6 +47,10 @@ #include #include + +#ifdef HAVE_CONFIG_H +#include +#endif #include "srtp.h" #if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute)) @@ -121,26 +125,44 @@ typedef struct { #ifdef ENABLE_DEBUG_LOGGING -#define debug_print0(mod, format) \ - srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name) -#define debug_print(mod, format, arg) \ - srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg) -#define debug_print2(mod, format, arg1, arg2) \ - srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \ - arg1, arg2) +#ifndef debug_print0 + #define debug_print0(mod, format) \ + srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name) +#endif + +#ifndef debug_print + #define debug_print(mod, format, arg) \ + srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \ + arg) +#endif + +#ifndef debug_print2 + #define debug_print2(mod, format, arg1, arg2) \ + srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \ + arg1, arg2) +#endif #else -#define debug_print0(mod, format) \ - if (mod.on) \ - srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name) -#define debug_print(mod, format, arg) \ - if (mod.on) \ - srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg) -#define debug_print2(mod, format, arg1, arg2) \ - if (mod.on) \ - srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \ - arg1, arg2) +#ifndef debug_print0 + #define debug_print0(mod, format) \ + if (mod.on) \ + srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name) +#endif + +#ifndef debug_print + #define debug_print(mod, format, arg) \ + if (mod.on) \ + srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \ + arg) +#endif + +#ifndef debug_print2 + #define debug_print2(mod, format, arg1, arg2) \ + if (mod.on) \ + srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \ + arg1, arg2) +#endif #endif diff --git a/srtp/srtp.c b/srtp/srtp.c index eb101543a..6aa252462 100644 --- a/srtp/srtp.c +++ b/srtp/srtp.c @@ -1507,28 +1507,28 @@ static srtp_err_status_t srtp_stream_init(srtp_stream_ctx_t *srtp, void srtp_event_reporter(srtp_event_data_t *data) { - srtp_err_report(srtp_err_level_warning, - "srtp: in stream 0x%x: ", data->ssrc); + debug_print(srtp_err_level_warning, + "srtp: in stream 0x%x: ", data->ssrc); switch (data->event) { case event_ssrc_collision: - srtp_err_report(srtp_err_level_warning, "\tSSRC collision\n"); + debug_print0(srtp_err_level_warning, "\tSSRC collision\n"); break; case event_key_soft_limit: - srtp_err_report(srtp_err_level_warning, - "\tkey usage soft limit reached\n"); + debug_print0(srtp_err_level_warning, + "\tkey usage soft limit reached\n"); break; case event_key_hard_limit: - srtp_err_report(srtp_err_level_warning, - "\tkey usage hard limit reached\n"); + debug_print0(srtp_err_level_warning, + "\tkey usage hard limit reached\n"); break; case event_packet_index_limit: - srtp_err_report(srtp_err_level_warning, - "\tpacket index limit reached\n"); + debug_print0(srtp_err_level_warning, + "\tpacket index limit reached\n"); break; default: - srtp_err_report(srtp_err_level_warning, - "\tunknown event reported to handler\n"); + debug_print0(srtp_err_level_warning, + "\tunknown event reported to handler\n"); } }