Fix build errors of not removing functions if crypto not used
diff --git a/src/Recipient.c b/src/Recipient.c
index 618fef3..b970106 100644
--- a/src/Recipient.c
+++ b/src/Recipient.c
@@ -123,6 +123,7 @@
return;
}
+#if defined(USE_HKDF_SHA2) || defined(USE_HKDF_AES)
/**
* Perform an AES-CCM Decryption operation
*
@@ -153,6 +154,7 @@
if (fECDH) {
+#ifdef USE_ECDH
cn_cbor * pkeyMessage;
if (pKeyPrivate != NULL) {
@@ -185,6 +187,9 @@
if (!ECDH_ComputeSecret(pCose, (cn_cbor **)&pKeyPrivate, pkeyMessage, &pbSecret, &cbSecret, CBOR_CONTEXT_PARAM_COMMA perr)) goto errorReturn;
}
+#else
+ goto errorReturn;
+#endif
}
else {
CHECK_CONDITION(pKeyPrivate != NULL, COSE_ERR_INVALID_PARAMETER);
@@ -201,12 +206,20 @@
}
if (fHMAC) {
+#ifdef USE_HKDF_SHA2
if (!HKDF_Extract(pCose, pbSecret, cbSecret, cbitHash, rgbDigest, &cbDigest, CBOR_CONTEXT_PARAM_COMMA perr)) goto errorReturn;
if (!HKDF_Expand(pCose, cbitHash, rgbDigest, cbDigest, pbContext, cbContext, pbKey, cbitKey / 8, perr)) goto errorReturn;
+#else
+ goto errorReturn;
+#endif
}
else {
+#ifdef USE_HKDF_AES
if (!HKDF_AES_Expand(pCose, cbitHash, pbSecret, cbSecret, pbContext, cbContext, pbKey, cbitKey / 8, perr)) goto errorReturn;
+#else
+ goto errorReturn;
+#endif
}
fRet = true;
@@ -219,6 +232,7 @@
if (pbContext != NULL) COSE_FREE(pbContext, context);
return fRet;
}
+#endif // defined(USE_HKDF_SHA2) || defined(USE_HKDF_AES)
bool _COSE_Recipient_decrypt(COSE_RecipientInfo * pRecip, COSE_RecipientInfo * pRecipUse, int algIn, int cbitKeyOut, byte * pbKeyOut, cose_errback * perr)
{
diff --git a/src/configure.h b/src/configure.h
index 811e7b5..1be4d3f 100644
--- a/src/configure.h
+++ b/src/configure.h
@@ -77,6 +77,10 @@
#define USE_ECDH_ES_HKDF_512
#define USE_ECDH_SS_HKDF_256
#define USE_ECDH_SS_HKDF_512
+#if defined(USE_ECDH_ES_HKDF_256) || defined(USE_ECDH_ES_HKDF_512) || defined(USE_ECDH_SS_HKDF_256) || defined(USE_ECDH_SS_HKDF_512)
+#define USE_ECDH 1
+#define USE_HKDF_SHA2 1
+#endif
#endif // !defined(USE_MBED_TLS)
#if !defined(USE_MBED_TLS)
@@ -86,6 +90,10 @@
#define USE_ECDH_SS_A128KW
#define USE_ECDH_SS_A192KW
#define USE_ECDH_SS_A256KW
+#if defined(USE_ECDH_ES_A128KW) || defined(USE_ECDH_ES_A192KW) || defined(USE_ECDH_ES_A256KW) || defined(USE_ECDH_SS_A128KW) || defined(USE_ECDH_SS_A192KW) || defined(USE_ECDH_SS_A256KW)
+#define USE_ECDH 1
+#define USE_HKDF_AES 1
+#endif
#endif // !defined(USE_MBED_TLS)
//
@@ -107,6 +115,12 @@
#define USE_Direct_HKDF_HMAC_SHA_512
#define USE_Direct_HKDF_AES_128
#define USE_Direct_HKDF_AES_256
+#if defined(USE_Direct_HKDF_HMAC_SHA_256) || defined(USE_Direct_HKDF_HMAC_SHA_512)
+#define USE_HKDF_SHA2 1
+#endif
+#if defined(USE_Direct_HKDF_AES_128) || defined(USE_Direct_KDF_AES_256)
+#define USE_HKDF_AES 1
+#endif
#endif // !defined(USE_MBED_TLS)