Skip to content

Commit d8b23b2

Browse files
committed
fixup! WIP: generate and compute key using PSA API
1 parent 4fa42de commit d8b23b2

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/libAtomVM/otp_crypto.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,31 @@ static term make_crypto_error(const char *file, int line, const char *message, C
433433
return make_crypto_error_tag(file, line, message, BADARG_ATOM, ctx);
434434
}
435435

436+
static const char *avm_mbedtls_version_string_full(char *buf, size_t buf_size)
437+
{
438+
#if defined(MBEDTLS_VERSION_C)
439+
/*
440+
* Mbed TLS 2.x / 3.x: void mbedtls_version_get_string_full(char *string)
441+
* Mbed TLS 4.x: const char *mbedtls_version_get_string_full(void)
442+
*/
443+
#if defined(MBEDTLS_VERSION_MAJOR) && (MBEDTLS_VERSION_MAJOR >= 4)
444+
UNUSED(buf);
445+
UNUSED(buf_size);
446+
return mbedtls_version_get_string_full();
447+
#else
448+
if (buf_size < 18) {
449+
return MBEDTLS_VERSION_STRING_FULL;
450+
}
451+
mbedtls_version_get_string_full(buf);
452+
return buf;
453+
#endif
454+
#else
455+
UNUSED(buf);
456+
UNUSED(buf_size);
457+
return MBEDTLS_VERSION_STRING_FULL;
458+
#endif
459+
}
460+
436461
static term nif_crypto_crypto_one_time(Context *ctx, int argc, term argv[])
437462
{
438463
bool has_iv = argc == 5;
@@ -2954,13 +2979,9 @@ term nif_crypto_info_lib(Context *ctx, int argc, term argv[])
29542979
const char *mbedtls_str = "mbedtls";
29552980
size_t mbedtls_len = strlen("mbedtls");
29562981

2957-
#ifdef MBEDTLS_VERSION_C
2958-
// 18 bytes including null byte according to mbedtls doc
2959-
char version_string[18];
2960-
mbedtls_version_get_string_full(version_string);
2961-
#else
2962-
const char *version_string = MBEDTLS_VERSION_STRING_FULL;
2963-
#endif
2982+
char version_string_buf[18];
2983+
const char *version_string =
2984+
avm_mbedtls_version_string_full(version_string_buf, sizeof(version_string_buf));
29642985
size_t version_string_len = strlen(version_string);
29652986

29662987
if (UNLIKELY(memory_ensure_free(ctx,

0 commit comments

Comments
 (0)