浏览代码

Merge pull request #1281 from DL6ER/fix/mbedtls_tls13

mbedTLS: Fix TLS 1.3 support
bel2125 9 月之前
父节点
当前提交
8c75f07667
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      src/mod_mbedtls.inl

+ 12 - 0
src/mod_mbedtls.inl

@@ -88,6 +88,18 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt)
 	mbedtls_ctr_drbg_init(&ctx->ctr);
 	mbedtls_ctr_drbg_init(&ctx->ctr);
 	mbedtls_x509_crt_init(&ctx->cert);
 	mbedtls_x509_crt_init(&ctx->cert);
 
 
+#ifdef MBEDTLS_PSA_CRYPTO_C
+	/* Initialize PSA crypto (mandatory with TLS 1.3)
+	 * This must be done before calling any other PSA Crypto
+	 * functions or they will fail with PSA_ERROR_BAD_STATE
+	 */
+	const psa_status_t status = psa_crypto_init();
+	if (status != PSA_SUCCESS) {
+		DEBUG_TRACE("Failed to initialize PSA crypto, returned %d\n", (int) status);
+		return -1;
+	}
+#endif
+
 	rc = mbedtls_ctr_drbg_seed(&ctx->ctr,
 	rc = mbedtls_ctr_drbg_seed(&ctx->ctr,
 	                           mbedtls_entropy_func,
 	                           mbedtls_entropy_func,
 	                           &ctx->entropy,
 	                           &ctx->entropy,