blob: af0eb86d233819dc9256d39c973b2dc1f089010f [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include "mbedtls/version.h"
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakker3ac1b2d2010-06-18 22:47:29 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02006 * depends_on:MBEDTLS_VERSION_C
Paul Bakker33b43f12013-08-20 11:48:36 +02007 * END_DEPENDENCIES
8 */
Paul Bakker5690efc2011-05-26 13:16:06 +00009
Paul Bakker33b43f12013-08-20 11:48:36 +020010/* BEGIN_CASE */
Gilles Peskine449bd832023-01-11 14:50:10 +010011void check_compiletime_version(char *version_str)
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000012{
13 char build_str[100];
14 char build_str_full[100];
15 unsigned int build_int;
16
Gilles Peskine449bd832023-01-11 14:50:10 +010017 memset(build_str, 0, 100);
18 memset(build_str_full, 0, 100);
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000019
Gilles Peskine449bd832023-01-11 14:50:10 +010020 mbedtls_snprintf(build_str, 100, "%d.%d.%d", MBEDTLS_VERSION_MAJOR,
21 MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH);
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000022
Gilles Peskinee820c0a2023-08-03 17:45:20 +020023 mbedtls_snprintf(build_str_full, 100, "Mbed TLS %d.%d.%d", MBEDTLS_VERSION_MAJOR,
Gilles Peskine449bd832023-01-11 14:50:10 +010024 MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH);
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026 build_int = MBEDTLS_VERSION_MAJOR << 24 |
Gilles Peskine449bd832023-01-11 14:50:10 +010027 MBEDTLS_VERSION_MINOR << 16 |
28 MBEDTLS_VERSION_PATCH << 8;
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000029
Gilles Peskine449bd832023-01-11 14:50:10 +010030 TEST_ASSERT(build_int == MBEDTLS_VERSION_NUMBER);
31 TEST_ASSERT(strcmp(build_str, MBEDTLS_VERSION_STRING) == 0);
32 TEST_ASSERT(strcmp(build_str_full, MBEDTLS_VERSION_STRING_FULL) == 0);
33 TEST_ASSERT(strcmp(version_str, MBEDTLS_VERSION_STRING) == 0);
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000034}
Paul Bakker33b43f12013-08-20 11:48:36 +020035/* END_CASE */
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000036
Paul Bakker33b43f12013-08-20 11:48:36 +020037/* BEGIN_CASE */
Gilles Peskine449bd832023-01-11 14:50:10 +010038void check_runtime_version(char *version_str)
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000039{
40 char build_str[100];
Bence Szépkútib2ba9fa2025-08-18 11:35:47 +020041 const char *get_str;
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000042 char build_str_full[100];
Bence Szépkútib2ba9fa2025-08-18 11:35:47 +020043 const char *get_str_full;
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000044 unsigned int get_int;
45
Gilles Peskine449bd832023-01-11 14:50:10 +010046 memset(build_str, 0, 100);
Gilles Peskine449bd832023-01-11 14:50:10 +010047 memset(build_str_full, 0, 100);
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000048
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049 get_int = mbedtls_version_get_number();
Bence Szépkútib2ba9fa2025-08-18 11:35:47 +020050 get_str = mbedtls_version_get_string();
51 get_str_full = mbedtls_version_get_string_full();
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000052
Gilles Peskine449bd832023-01-11 14:50:10 +010053 mbedtls_snprintf(build_str, 100, "%u.%u.%u",
54 (get_int >> 24) & 0xFF,
55 (get_int >> 16) & 0xFF,
56 (get_int >> 8) & 0xFF);
Gilles Peskinee820c0a2023-08-03 17:45:20 +020057 mbedtls_snprintf(build_str_full, 100, "Mbed TLS %s", version_str);
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000058
Gilles Peskine449bd832023-01-11 14:50:10 +010059 TEST_ASSERT(strcmp(build_str, version_str) == 0);
60 TEST_ASSERT(strcmp(build_str_full, get_str_full) == 0);
61 TEST_ASSERT(strcmp(version_str, get_str) == 0);
Paul Bakker3ac1b2d2010-06-18 22:47:29 +000062}
Paul Bakker33b43f12013-08-20 11:48:36 +020063/* END_CASE */
Paul Bakker0f90d7d2014-04-30 11:49:44 +020064
Deomid Ryabkovde420a42016-11-27 14:50:06 +000065/* BEGIN_CASE depends_on:MBEDTLS_VERSION_FEATURES */
Gilles Peskine449bd832023-01-11 14:50:10 +010066void check_feature(char *feature, int result)
Paul Bakker0f90d7d2014-04-30 11:49:44 +020067{
Gilles Peskine449bd832023-01-11 14:50:10 +010068 int check = mbedtls_version_check_feature(feature);
69 TEST_ASSERT(check == result);
Paul Bakker0f90d7d2014-04-30 11:49:44 +020070}
71/* END_CASE */