Because LibreSSL returns 2.x for the version numbers, the macros think
that OpenSSL 1.1 should be used. This patch checks to see if there is
an LIBRESSL_VERSION_NUMBER defined.
Also, add a check to see if CONFIG_SIGALG_CMS is enabled in sslapi.h
before including openssl/cms.h. LibreSSL does not support cms and
probably never will. As such, LibreSSL doesn't include it and will
fail during a build that would otherwise pass.
Signed-off-by: Adam Duskett <
adus...@gmail.com>
---
corelib/swupdate_decrypt.c | 4 ++--
include/sslapi.h | 8 +++++---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/corelib/swupdate_decrypt.c b/corelib/swupdate_decrypt.c
index ea68fdd..8e092c8 100644
--- a/corelib/swupdate_decrypt.c
+++ b/corelib/swupdate_decrypt.c
@@ -43,7 +43,7 @@ struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, unsigned char
return NULL;
}
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
EVP_CIPHER_CTX_init(&dgst->ctxdec);
#else
dgst->ctxdec = EVP_CIPHER_CTX_new();
@@ -103,7 +103,7 @@ int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf,
void swupdate_DECRYPT_cleanup(struct swupdate_digest *dgst)
{
if (dgst) {
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
EVP_CIPHER_CTX_cleanup(SSL_GET_CTXDEC(dgst));
#else
EVP_CIPHER_CTX_free(SSL_GET_CTXDEC(dgst));
diff --git a/include/sslapi.h b/include/sslapi.h
index acc0813..40c52b3 100644
--- a/include/sslapi.h
+++ b/include/sslapi.h
@@ -35,21 +35,23 @@
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/aes.h>
+#ifdef CONFIG_SIGALG_CMS
#include <openssl/cms.h>
+#endif
#include <openssl/opensslv.h>
struct swupdate_digest {
EVP_PKEY *pkey; /* this is used for RSA key */
X509_STORE *certs; /* this is used if CMS is set */
EVP_MD_CTX *ctx;
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
EVP_CIPHER_CTX ctxdec;
#else
EVP_CIPHER_CTX *ctxdec;
#endif
};
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
#define SSL_GET_CTXDEC(dgst) &dgst->ctxdec
#else
#define SSL_GET_CTXDEC(dgst) dgst->ctxdec
@@ -60,7 +62,7 @@ struct swupdate_digest {
* library
* It must be called just once
*/
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
#define swupdate_crypto_init() { \
do { \
CRYPTO_malloc_init(); \
--
2.13.0