Mbed-TLS / mbedtls

An open source, portable, easy to use, readable and flexible TLS library, and reference implementation of the PSA Cryptography API. Releases are on a varying cadence, typically around 3 - 6 months between releases.
https://www.trustedfirmware.org/projects/mbed-tls/
Other
5.52k stars 2.6k forks source link

psa_crypto_cipher.h should be included with double quotes, not angle brackets #6103

Closed mman closed 2 years ago

mman commented 2 years ago

Summary

Compiling mbedtls-3.2.1 with default config and stricter compiler checks, the compilation fails with:

./mbedtls/library/psa_crypto_cipher.c:25:10: error: 'psa_crypto_cipher.h' file not found with <angled> include; use "quotes" instead
#include <psa_crypto_cipher.h>
         ^~~~~~~~~~~~~~~~~~~~~
         "psa_crypto_cipher.h"
1 error generated.

I think the compiler is right since psa_crypto_cipher.h is located along with sources in library folder.

This patch fixed it:

diff --git a/library/psa_crypto_cipher.c b/library/psa_crypto_cipher.c
index fafe68b07..70dc74d74 100644
--- a/library/psa_crypto_cipher.c
+++ b/library/psa_crypto_cipher.c
@@ -22,7 +22,7 @@

 #if defined(MBEDTLS_PSA_CRYPTO_C)

-#include <psa_crypto_cipher.h>
+#include "psa_crypto_cipher.h"
 #include "psa_crypto_core.h"
 #include "psa_crypto_random_impl.h"

System information

Mbed TLS version (number or commit id): 3.2.1 Operating system and version: macOS 12.4

tom-cosgrove-arm commented 2 years ago

Which compiler and options were you using to get this warning?

mman commented 2 years ago

I am using clang shipping with Xcode and in fact compiling mbedtls as a static library as part of swift package wrapping it. The flags are pretty standard only specifying -I to include mbedtls public headers. Nothing extra special there:

I have been using this approach since mbedtls-2.10 without any troubles as I can see that Cmakefile is pretty basic with no special requirements on the flags. Correct?

Apple clang version 14.0.0 (clang-1400.0.28.1)
Target: x86_64-apple-darwin21.5.0

And the build command used (simplified) is pasted here:

clang -fobjc-arc -target x86_64-apple-macosx10.13 -g -O0 -DSWIFT_PACKAGE=1 -DDEBUG=1 -fblocks  -fmodules -fmodule-name=mbedtls -I mbedtls-swift/Sources/mbedtls/include -fPIC -MD -MT dependencies -MF mbedtls-swift/.build/x86_64-apple-macosx/debug/mbedtls.build/library/platform.c.d -c mbedtls-swift/Sources/mbedtls/library/platform.c -o mbedtls-swift/.build/x86_64-apple-macosx/debug/mbedtls.build/library/platform.c.o
mbedtls-swift/Sources/mbedtls/library/psa_crypto_cipher.c:25:10: error: 'psa_crypto_cipher.h' file not found with <angled> include; use "quotes" instead
#include <psa_crypto_cipher.h>
         ^~~~~~~~~~~~~~~~~~~~~
         "psa_crypto_cipher.h"
1 error generated.
tom-cosgrove-arm commented 2 years ago

Okay, thanks, looks like there's not a compiler -W flag we can enable to see this in our builds.

Are you able to create a PR with your patch? It will need to include a ChangeLog entry (a file in ChangeLog.d) and a backport to mbedtls-2.28 (and a DCO Signed-off-by: line in the commit(s)).

mman commented 2 years ago

@tom-cosgrove-arm Not sure if I followed the procedure correctly, but here is the PR against development branch: https://github.com/Mbed-TLS/mbedtls/pull/6114

tom-cosgrove-arm commented 2 years ago

Closing as this has been fixed by now-merged PRs #6114 for development and #6168 for 2.28-LTS backport.

Thanks for the report and for creating the PRs - much appreciated