From 277a3a6609bf800e0b1329c012d66524d4d14c91 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 16 Feb 2021 18:55:05 +0100 Subject: [PATCH] Work around MSVC bug with duplicate static declarations Signed-off-by: Gilles Peskine --- library/psa_crypto_random_impl.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/psa_crypto_random_impl.h b/library/psa_crypto_random_impl.h index 3b8e3ec9b..3c4c09a28 100644 --- a/library/psa_crypto_random_impl.h +++ b/library/psa_crypto_random_impl.h @@ -125,8 +125,18 @@ typedef struct } mbedtls_psa_random_context_t; /* Defined in include/mbedtls/psa_util.h so that it's visible to - * application code. */ + * application code. The declaration here is redundant, but included + * as a safety net to make it more likely that a future change that + * accidentally causes the implementation to diverge from the interface + * will be noticed. */ +/* Do not include the declaration under MSVC because it doesn't accept it + * ("error C2370: 'mbedtls_psa_get_random' : redefinition; different storage class"). + * Observed with Visual Studio 2013. A known bug apparently: + * https://stackoverflow.com/questions/8146541/duplicate-external-static-declarations-not-allowed-in-visual-studio + */ +#if !defined(_MSC_VER) static mbedtls_f_rng_t *const mbedtls_psa_get_random; +#endif /** The maximum number of bytes that mbedtls_psa_get_random() is expected to * return.