Introduce versioning in the config files

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
diff --git a/configs/config-ccm-psk-tls1_2.h b/configs/config-ccm-psk-tls1_2.h
index 51bb962..cd74d86 100644
--- a/configs/config-ccm-psk-tls1_2.h
+++ b/configs/config-ccm-psk-tls1_2.h
@@ -30,6 +30,8 @@
  * See README.txt for usage instructions.
  */
 
+#define MBEDTLS_CONFIG_VERSION 1
+
 /* System support */
 //#define MBEDTLS_HAVE_TIME /* Optionally used in Hello messages */
 /* Other MBEDTLS_HAVE_XXX flags irrelevant for this configuration */
diff --git a/configs/config-no-entropy.h b/configs/config-no-entropy.h
index edba4a0..acfad38 100644
--- a/configs/config-no-entropy.h
+++ b/configs/config-no-entropy.h
@@ -29,6 +29,8 @@
  * See README.txt for usage instructions.
  */
 
+#define MBEDTLS_CONFIG_VERSION 1
+
 /* System support */
 #define MBEDTLS_HAVE_ASM
 #define MBEDTLS_HAVE_TIME
diff --git a/configs/config-suite-b.h b/configs/config-suite-b.h
index c70773d..264826d 100644
--- a/configs/config-suite-b.h
+++ b/configs/config-suite-b.h
@@ -33,6 +33,8 @@
  * See README.txt for usage instructions.
  */
 
+#define MBEDTLS_CONFIG_VERSION 1
+
 /* System support */
 #define MBEDTLS_HAVE_ASM
 #define MBEDTLS_HAVE_TIME
diff --git a/configs/config-symmetric-only.h b/configs/config-symmetric-only.h
index 6aff42f..6b22cba 100644
--- a/configs/config-symmetric-only.h
+++ b/configs/config-symmetric-only.h
@@ -20,6 +20,8 @@
  *  limitations under the License.
  */
 
+#define MBEDTLS_CONFIG_VERSION 1
+
 /* System support */
 //#define MBEDTLS_HAVE_ASM
 #define MBEDTLS_HAVE_TIME
diff --git a/configs/config-thread.h b/configs/config-thread.h
index be889a1..d8ee1c8 100644
--- a/configs/config-thread.h
+++ b/configs/config-thread.h
@@ -32,6 +32,8 @@
  * See README.txt for usage instructions.
  */
 
+#define MBEDTLS_CONFIG_VERSION 1
+
 /* System support */
 #define MBEDTLS_HAVE_ASM
 
diff --git a/include/mbedtls/build_info.h b/include/mbedtls/build_info.h
index ab4ceff..2498a73 100644
--- a/include/mbedtls/build_info.h
+++ b/include/mbedtls/build_info.h
@@ -36,13 +36,26 @@
 #include MBEDTLS_CONFIG_FILE
 #endif
 
+#if !defined(MBEDTLS_CONFIG_VERSION) || \
+    MBEDTLS_CONFIG_VERSION != 1
+#error "Invalid config version, MBEDTLS_CONFIG_VERSION != 1"
+#endif
+
 /* Target and application specific configurations
  *
  * Allow user to override any previous default.
  *
  */
+#if defined(MBEDTLS_USER_CONFIG_VERSION)
+#error "MBEDTLS_USER_CONFIG_VERSION defined outside MBEDTLS_USER_CONFIG_FILE"
+#endif
+
 #if defined(MBEDTLS_USER_CONFIG_FILE)
 #include MBEDTLS_USER_CONFIG_FILE
+#if !defined(MBEDTLS_USER_CONFIG_VERSION) || \
+    MBEDTLS_USER_CONFIG_VERSION != MBEDTLS_CONFIG_VERSION
+#error "Version mismatch between config file and MBEDTLS_USER_CONFIG_FILE"
+#endif
 #endif
 
 #if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h
index 5212fb3..af2c438 100644
--- a/include/mbedtls/mbedtls_config.h
+++ b/include/mbedtls/mbedtls_config.h
@@ -24,6 +24,8 @@
  *  limitations under the License.
  */
 
+#define MBEDTLS_CONFIG_VERSION 1
+
 /**
  * \name SECTION: System support
  *
diff --git a/tests/scripts/check-names.sh b/tests/scripts/check-names.sh
index 2a06adc..7649970 100755
--- a/tests/scripts/check-names.sh
+++ b/tests/scripts/check-names.sh
@@ -102,7 +102,7 @@
     | sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \
     | grep MBEDTLS | sort -u > _MBEDTLS_XXX
 TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \
-            | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true )
+            | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$|^MBEDTLS_USER_CONFIG_VERSION$' || true )
 rm _MBEDTLS_XXX _caps
 if [ "x$TYPOS" = "x" ]; then
     echo "PASS"