@@ -19,7 +19,7 @@ usage() {
1919 --skip-mark Don't send the leading mark byte (0xFF)
2020 --zero-copy Enable zero-copy RX buffers (requires recv_pkt/release_pkt)
2121 --log-minimal Minimize logger RAM/stack usage
22- --crypto LIB Use methods from LIB ( openssl/ mbedtls/* tinyaes)
22+ --crypto LIB Crypto backend: auto| openssl| mbedtls| tinyaes (default: auto )
2323 --crypto-include-dir DIR Include directory for crypto LIB if not in system path
2424 --crypto-ld-flags Args to pass to linker for the crypto LIB
2525 --no-colours Don't colourize log ouputs
@@ -149,15 +149,43 @@ if [[ -d .git ]]; then
149149 GIT_DIFF=$( git diff --quiet --exit-code || echo +)
150150fi
151151
152- if [[ " ${CRYPTO} " == " openssl" ]]; then
152+ # # Crypto backend selection: auto probes openssl → mbedtls → tinyaes by
153+ # # looking for the backend's public header through the compiler's default
154+ # # include path. Explicit names skip the probe and are used as-is.
155+ probe_header () {
156+ echo " #include <$1 >" | ${CC} -xc -E - > /dev/null 2>&1
157+ }
158+
159+ CRYPTO=${CRYPTO:- auto}
160+ if [[ " ${CRYPTO} " == " auto" ]]; then
161+ if probe_header openssl/evp.h; then
162+ CRYPTO=openssl
163+ elif probe_header mbedtls/aes.h; then
164+ CRYPTO=mbedtls
165+ else
166+ CRYPTO=tinyaes
167+ fi
168+ fi
169+
170+ case " ${CRYPTO} " in
171+ openssl)
172+ echo " Crypto backend: OpenSSL"
153173 LIBOSDP_SOURCES+=" src/crypto/openssl.c"
154- elif [[ " ${CRYPTO} " == " mbedtls" ]]; then
174+ ;;
175+ mbedtls)
176+ echo " Crypto backend: MbedTLS"
155177 LIBOSDP_SOURCES+=" src/crypto/mbedtls.c"
156178 LDFLAGS+=" -lmbedcrypto -lmbedtls"
157- else
158- echo " Using in-tree AES methods. Consider using openssl/mbedtls (see --crypto)"
179+ ;;
180+ tinyaes)
181+ echo " Crypto backend: TinyAES (bundled)"
159182 LIBOSDP_SOURCES+=" src/crypto/tinyaes_src.c src/crypto/tinyaes.c"
160- fi
183+ ;;
184+ * )
185+ echo " --crypto must be one of: auto, openssl, mbedtls, tinyaes (got '${CRYPTO} ')"
186+ exit 1
187+ ;;
188+ esac
161189
162190if [[ ! -z " ${CRYPTO_INCLUDE_DIR} " ]]; then
163191 CCFLAGS+=" -I${CRYPTO_INCLUDE_DIR} "
0 commit comments