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

Fix IAR enum conversion warnings when using mbedtls_md_type_t and mbedtls_cipher_type_t #7543

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion include/mbedtls/cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ typedef struct mbedtls_cipher_context_t {
* \return A statically-allocated array of cipher identifiers
* of type cipher_type_t. The last entry is zero.
*/
const int *mbedtls_cipher_list(void);
const mbedtls_cipher_type_t *mbedtls_cipher_list(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an incompatible change which we can't accept in a minor release. It breaks application code like

const int *array = mbedtls_cipher_list();


/**
* \brief This function retrieves the cipher-information
Expand Down
2 changes: 1 addition & 1 deletion include/mbedtls/md.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, siz
* message-digest enumeration #mbedtls_md_type_t.
* The last entry is 0.
*/
const int *mbedtls_md_list(void);
const mbedtls_md_type_t *mbedtls_md_list(void);

/**
* \brief This function returns the message-digest information
Expand Down
4 changes: 2 additions & 2 deletions library/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@

static int supported_init = 0;

const int *mbedtls_cipher_list(void)
const mbedtls_cipher_type_t *mbedtls_cipher_list(void)
{
const mbedtls_cipher_definition_t *def;
int *type;
mbedtls_cipher_type_t *type;

if (!supported_init) {
def = mbedtls_cipher_definitions;
Expand Down
2 changes: 1 addition & 1 deletion library/cipher_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,6 @@ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =

#define NUM_CIPHERS (sizeof(mbedtls_cipher_definitions) / \
sizeof(mbedtls_cipher_definitions[0]))
int mbedtls_cipher_supported[NUM_CIPHERS];
mbedtls_cipher_type_t mbedtls_cipher_supported[NUM_CIPHERS];

#endif /* MBEDTLS_CIPHER_C */
2 changes: 1 addition & 1 deletion library/cipher_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ typedef struct {

extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];

extern int mbedtls_cipher_supported[];
extern mbedtls_cipher_type_t mbedtls_cipher_supported[];

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions library/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info)
/*
* Reminder: update profiles in x509_crt.c when adding a new hash!
*/
static const int supported_digests[] = {
static const mbedtls_md_type_t supported_digests[] = {

#if defined(MBEDTLS_MD_CAN_SHA512)
MBEDTLS_MD_SHA512,
Expand Down Expand Up @@ -708,7 +708,7 @@ static const int supported_digests[] = {
MBEDTLS_MD_NONE
};

const int *mbedtls_md_list(void)
const mbedtls_md_type_t *mbedtls_md_list(void)
{
return supported_digests;
}
Expand Down
19 changes: 10 additions & 9 deletions programs/aes/crypt_and_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,25 @@ int main(int argc, char *argv[])
* Parse the command-line arguments.
*/
if (argc != 7) {
const int *list;
const mbedtls_cipher_type_t *cipher_list;
const mbedtls_md_type_t *md_list;

mbedtls_printf(USAGE);

mbedtls_printf("Available ciphers:\n");
list = mbedtls_cipher_list();
while (*list) {
cipher_info = mbedtls_cipher_info_from_type(*list);
cipher_list = mbedtls_cipher_list();
while (*cipher_list) {
cipher_info = mbedtls_cipher_info_from_type(*cipher_list);
mbedtls_printf(" %s\n", mbedtls_cipher_info_get_name(cipher_info));
list++;
cipher_list++;
}

mbedtls_printf("\nAvailable message digests:\n");
list = mbedtls_md_list();
while (*list) {
md_info = mbedtls_md_info_from_type(*list);
md_list = mbedtls_md_list();
while (*md_list) {
md_info = mbedtls_md_info_from_type(*md_list);
mbedtls_printf(" %s\n", mbedtls_md_get_name(md_info));
list++;
md_list++;
}

goto exit;
Expand Down
2 changes: 1 addition & 1 deletion programs/hash/generic_sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int main(int argc, char *argv[])
mbedtls_md_init(&md_ctx);

if (argc < 2) {
const int *list;
const mbedtls_md_type_t *list;

mbedtls_printf("print mode: generic_sum <mbedtls_md> <file> <file> ...\n");
mbedtls_printf("check mode: generic_sum <mbedtls_md> -c <checksum file>\n");
Expand Down
4 changes: 2 additions & 2 deletions tests/suites/test_suite_cipher.function
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ int buffer_is_all_zero(const uint8_t *buf, size_t size)
/* BEGIN_CASE */
void mbedtls_cipher_list()
{
const int *cipher_type;
const mbedtls_cipher_type_t *cipher_type;

for (cipher_type = mbedtls_cipher_list(); *cipher_type != 0; cipher_type++) {
for (cipher_type = mbedtls_cipher_list(); *cipher_type != MBEDTLS_CIPHER_NONE; cipher_type++) {
const mbedtls_cipher_info_t *info =
mbedtls_cipher_info_from_type(*cipher_type);
mbedtls_test_set_step(*cipher_type);
Expand Down
10 changes: 5 additions & 5 deletions tests/suites/test_suite_md.function
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/* BEGIN_CASE depends_on:MBEDTLS_MD_C */
void mbedtls_md_list()
{
const int *md_type_ptr;
const mbedtls_md_type_t *md_type_ptr;
const mbedtls_md_info_t *info;
mbedtls_md_context_t ctx;
unsigned char out[MBEDTLS_MD_MAX_SIZE] = { 0 };
Expand All @@ -21,7 +21,7 @@ void mbedtls_md_list()
/*
* Test that mbedtls_md_list() only returns valid MDs.
*/
for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++) {
for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != MBEDTLS_MD_NONE; md_type_ptr++) {
info = mbedtls_md_info_from_type(*md_type_ptr);
TEST_ASSERT(info != NULL);
TEST_EQUAL(0, mbedtls_md_setup(&ctx, info, 0));
Expand Down Expand Up @@ -115,7 +115,7 @@ void md_info(int md_type, char *md_name, int md_size)
{
const mbedtls_md_info_t *md_info;
#if defined(MBEDTLS_MD_C)
const int *md_type_ptr;
const mbedtls_md_type_t *md_type_ptr;
#else
(void) md_name;
#endif
Expand All @@ -134,8 +134,8 @@ void md_info(int md_type, char *md_name, int md_size)
TEST_EQUAL(0, strcmp(mbedtls_md_get_name(md_info), md_name));

int found = 0;
for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != 0; md_type_ptr++) {
if (*md_type_ptr == md_type) {
for (md_type_ptr = mbedtls_md_list(); *md_type_ptr != MBEDTLS_MD_NONE; md_type_ptr++) {
if (*md_type_ptr == (mbedtls_md_type_t) md_type) {
found = 1;
}
}
Expand Down