Up now the core knows which is the internal structure used by the crypto
library to verify sw-description. The structure strongly depends on the
selected crypto library and this forbids to build SWUpdate with support
for multiple verification methods, and just one crypto library can be
linked at once. Structures are already allocated by the initialization
function for the crypto service, and it does not need to be known
outside the service, so use opaque pointer in the core.
core/crypto.c | 18 ++++++-------
crypto/swupdate_HASH_mbedtls.c | 13 +++++----
crypto/swupdate_HASH_openssl.c | 16 ++++++-----
crypto/swupdate_cms_verify_openssl.c | 6 +++--
crypto/swupdate_decrypt_mbedtls.c | 14 ++++++----
crypto/swupdate_decrypt_openssl.c | 15 +++++++----
crypto/swupdate_decrypt_pkcs11.c | 13 +++++----
crypto/swupdate_gpg.h | 17 ++++++++++++
crypto/swupdate_gpg_verify.c | 5 ++--
crypto/swupdate_mbedtls.h | 2 +-
crypto/swupdate_openssl.h | 2 +-
crypto/swupdate_pkcs7_verify_wolfssl.c | 5 ++--
crypto/swupdate_rsa_verify_mbedtls.c | 5 ++--
crypto/swupdate_rsa_verify_openssl.c | 11 ++++----
crypto/swupdate_wolfssl.h | 4 +--
include/channel_curl.h | 2 +-
include/swupdate_crypto.h | 37 +++++++++++++-------------
test/test_hash.c | 2 +-
18 files changed, 113 insertions(+), 74 deletions(-)
create mode 100644 crypto/swupdate_gpg.h
diff --git a/core/crypto.c b/core/crypto.c
index cce6884e..b41c477c 100644
--- a/core/crypto.c
+++ b/core/crypto.c
@@ -139,7 +139,7 @@ void print_registered_cryptolib(void)
}
}
-struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv)
+void *swupdate_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv)
{
swupdate_decrypt_lib *lib;
if (!get_cryptolib())
@@ -149,7 +149,7 @@ struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, char keylen, u
return lib->DECRYPT_init(key, keylen, iv);
}
-int swupdate_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *buf,
+int swupdate_DECRYPT_update(void *dgst, unsigned char *buf,
int *outlen, const unsigned char *cryptbuf, int inlen)
{
swupdate_decrypt_lib *lib;
@@ -160,7 +160,7 @@ int swupdate_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *buf,
return lib->DECRYPT_update(dgst, buf, outlen, cryptbuf, inlen);
}
-int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf, int *outlen)
+int swupdate_DECRYPT_final(void *dgst, unsigned char *buf, int *outlen)
{
swupdate_decrypt_lib *lib;
if (!get_cryptolib())
@@ -169,7 +169,7 @@ int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf, int
return lib->DECRYPT_final(dgst, buf, outlen);
}
-void swupdate_DECRYPT_cleanup(struct swupdate_digest *dgst)
+void swupdate_DECRYPT_cleanup(void *dgst)
{
swupdate_decrypt_lib *lib;
if (!get_cryptolib())
@@ -178,7 +178,7 @@ void swupdate_DECRYPT_cleanup(struct swupdate_digest *dgst)
return lib->DECRYPT_cleanup(dgst);
}
-struct swupdate_digest *swupdate_HASH_init(const char *SHAlength)
+void *swupdate_HASH_init(const char *SHAlength)
{
swupdate_HASH_lib *lib;
@@ -189,7 +189,7 @@ struct swupdate_digest *swupdate_HASH_init(const char *SHAlength)
return lib->HASH_init(SHAlength);
}
-int swupdate_HASH_update(struct swupdate_digest *dgst, const unsigned char *buf, size_t len)
+int swupdate_HASH_update(void *dgst, const unsigned char *buf, size_t len)
{
swupdate_HASH_lib *lib;
@@ -200,7 +200,7 @@ int swupdate_HASH_update(struct swupdate_digest *dgst, const unsigned char *buf,
return lib->HASH_update(dgst, buf, len);
}
-int swupdate_HASH_final(struct swupdate_digest *dgst, unsigned char *md_value, unsigned int *md_len)
+int swupdate_HASH_final(void *dgst, unsigned char *md_value, unsigned int *md_len)
{
swupdate_HASH_lib *lib;
@@ -222,7 +222,7 @@ int swupdate_HASH_compare(const unsigned char *hash1, const unsigned char *hash2
return lib->HASH_compare(hash1, hash2);
}
-void swupdate_HASH_cleanup(struct swupdate_digest *dgst)
+void swupdate_HASH_cleanup(void *dgst)
{
swupdate_HASH_lib *lib;
@@ -244,7 +244,7 @@ int swupdate_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
return lib->dgst_init(sw, keyfile);
}
-int swupdate_verify_file(struct swupdate_digest *dgst, const char *sigfile,
+int swupdate_verify_file(void *dgst, const char *sigfile,
const char *file, const char *signer_name)
{
swupdate_dgst_lib *lib;
diff --git a/crypto/swupdate_HASH_mbedtls.c b/crypto/swupdate_HASH_mbedtls.c
index df04ff8b..95060ffc 100644
--- a/crypto/swupdate_HASH_mbedtls.c
+++ b/crypto/swupdate_HASH_mbedtls.c
@@ -24,9 +24,9 @@ static char *algo_upper(const char *algo)
return result;
}
-static struct swupdate_digest *mbedtls_HASH_init(const char *algo)
+static void *mbedtls_HASH_init(const char *algo)
{
- struct swupdate_digest *dgst;
+ struct mbedtls_digest *dgst;
int error;
const mbedtls_md_info_t *info = mbedtls_md_info_from_string(algo_upper(algo));
@@ -61,9 +61,10 @@ fail:
return 0;
}
-static int mbedtls_HASH_update(struct swupdate_digest *dgst, const unsigned char *buf,
+static int mbedtls_HASH_update(void *ctx, const unsigned char *buf,
size_t len)
{
+ struct mbedtls_digest *dgst = (struct mbedtls_digest *)ctx;
if (!dgst) {
return -EFAULT;
}
@@ -77,9 +78,10 @@ static int mbedtls_HASH_update(struct swupdate_digest *dgst, const unsigned char
return 0;
}
-static int mbedtls_HASH_final(struct swupdate_digest *dgst, unsigned char *md_value,
+static int mbedtls_HASH_final(void *ctx, unsigned char *md_value,
unsigned int *md_len)
{
+ struct mbedtls_digest *dgst = (struct mbedtls_digest *)ctx;
if (!dgst) {
return -EFAULT;
}
@@ -99,8 +101,9 @@ static int mbedtls_HASH_final(struct swupdate_digest *dgst, unsigned char *md_va
}
-static void mbedtls_HASH_cleanup(struct swupdate_digest *dgst)
+static void mbedtls_HASH_cleanup(void *ctx)
{
+ struct mbedtls_digest *dgst = (struct mbedtls_digest *)ctx;
if (!dgst) {
return;
}
diff --git a/crypto/swupdate_HASH_openssl.c b/crypto/swupdate_HASH_openssl.c
index 082c9744..0c143797 100644
--- a/crypto/swupdate_HASH_openssl.c
+++ b/crypto/swupdate_HASH_openssl.c
@@ -22,7 +22,7 @@
static swupdate_HASH_lib hash;
-static int dgst_init(struct swupdate_digest *dgst, const EVP_MD *md)
+static int dgst_init(struct openssl_digest *dgst, const EVP_MD *md)
{
int rc;
@@ -36,9 +36,9 @@ static int dgst_init(struct swupdate_digest *dgst, const EVP_MD *md)
return 0;
}
-static struct swupdate_digest *openssl_HASH_init(const char *SHAlength)
+static void *openssl_HASH_init(const char *SHAlength)
{
- struct swupdate_digest *dgst;
+ struct openssl_digest *dgst;
const EVP_MD *md;
int ret;
@@ -68,9 +68,9 @@ static struct swupdate_digest *openssl_HASH_init(const char *SHAlength)
return dgst;
}
-static int openssl_HASH_update(struct swupdate_digest *dgst, const unsigned char *buf,
- size_t len)
+static int openssl_HASH_update(void *ctx, const unsigned char *buf, size_t len)
{
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
if (!dgst)
return -EFAULT;
@@ -80,9 +80,10 @@ static int openssl_HASH_update(struct swupdate_digest *dgst, const unsigned char
return 0;
}
-static int openssl_HASH_final(struct swupdate_digest *dgst, unsigned char *md_value,
+static int openssl_HASH_final(void *ctx, unsigned char *md_value,
unsigned int *md_len)
{
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
if (!dgst)
return -EFAULT;
@@ -90,8 +91,9 @@ static int openssl_HASH_final(struct swupdate_digest *dgst, unsigned char *md_va
}
-static void openssl_HASH_cleanup(struct swupdate_digest *dgst)
+static void openssl_HASH_cleanup(void *ctx)
{
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
if (dgst) {
EVP_MD_CTX_destroy(dgst->ctx);
free(dgst);
diff --git a/crypto/swupdate_cms_verify_openssl.c b/crypto/swupdate_cms_verify_openssl.c
index a26a3854..6e980c39 100644
--- a/crypto/swupdate_cms_verify_openssl.c
+++ b/crypto/swupdate_cms_verify_openssl.c
@@ -264,7 +264,7 @@ static int check_verified_signer(CMS_ContentInfo* cms, X509_STORE* store)
static int openssl_cms_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
{
- struct swupdate_digest *dgst;
+ struct openssl_digest *dgst;
int ret;
/*
@@ -332,13 +332,15 @@ dgst_init_error:
return ret;
}
-static int openssl_cms_verify_file(struct swupdate_digest *dgst, const char *sigfile,
+static int openssl_cms_verify_file(void *ctx, const char *sigfile,
const char *file, const char *signer_name)
{
int status = -EFAULT;
CMS_ContentInfo *cms = NULL;
BIO *content_bio = NULL;
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
+
/* Open CMS blob that needs to be checked */
BIO *sigfile_bio = BIO_new_file(sigfile, "rb");
if (!sigfile_bio) {
diff --git a/crypto/swupdate_decrypt_mbedtls.c b/crypto/swupdate_decrypt_mbedtls.c
index 84894ce0..794f89d6 100644
--- a/crypto/swupdate_decrypt_mbedtls.c
+++ b/crypto/swupdate_decrypt_mbedtls.c
@@ -10,9 +10,9 @@
static swupdate_decrypt_lib mbedtls;
-static struct swupdate_digest *mbedtls_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv)
+static void *mbedtls_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv)
{
- struct swupdate_digest *dgst;
+ struct mbedtls_digest *dgst;
mbedtls_cipher_type_t cipher_type;
const mbedtls_cipher_info_t *cipher_info;
int key_bitlen;
@@ -92,9 +92,10 @@ fail:
return NULL;
}
-static int mbedtls_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *buf,
+static int mbedtls_DECRYPT_update(void *ctx, unsigned char *buf,
int *outlen, const unsigned char *cryptbuf, int inlen)
{
+ struct mbedtls_digest *dgst = (struct mbedtls_digest *)ctx;
int error;
size_t olen = *outlen;
@@ -108,11 +109,12 @@ static int mbedtls_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *b
return 0;
}
-static int mbedtls_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf,
+static int mbedtls_DECRYPT_final(void *ctx, unsigned char *buf,
int *outlen)
{
int error;
size_t olen = *outlen;
+ struct mbedtls_digest *dgst = (struct mbedtls_digest *)ctx;
if (!dgst) {
return -EINVAL;
@@ -131,8 +133,10 @@ static int mbedtls_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *bu
}
-static void mbedtls_DECRYPT_cleanup(struct swupdate_digest *dgst)
+static void mbedtls_DECRYPT_cleanup(void *ctx)
{
+ struct mbedtls_digest *dgst = (struct mbedtls_digest *)ctx;
+
if (!dgst) {
return;
}
diff --git a/crypto/swupdate_decrypt_openssl.c b/crypto/swupdate_decrypt_openssl.c
index 13e3c119..70026eb2 100644
--- a/crypto/swupdate_decrypt_openssl.c
+++ b/crypto/swupdate_decrypt_openssl.c
@@ -20,9 +20,9 @@
static void openssl_probe(void);
static swupdate_decrypt_lib openssl;
-static struct swupdate_digest *openssl_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv)
+static void *openssl_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv)
{
- struct swupdate_digest *dgst;
+ struct openssl_digest *dgst;
const EVP_CIPHER *cipher;
int ret;
@@ -82,9 +82,12 @@ static struct swupdate_digest *openssl_DECRYPT_init(unsigned char *key, char key
return dgst;
}
-static int openssl_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *buf,
+static int openssl_DECRYPT_update(void *ctx, unsigned char *buf,
int *outlen, const unsigned char *cryptbuf, int inlen)
{
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
+ if (!dgst)
+ return -EINVAL;
if (EVP_DecryptUpdate(SSL_GET_CTXDEC(dgst), buf, outlen, cryptbuf, inlen) != 1) {
const char *reason = ERR_reason_error_string(ERR_peek_error());
ERROR("Update: Decryption error 0x%lx, reason: %s", ERR_get_error(),
@@ -95,9 +98,10 @@ static int openssl_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *b
return 0;
}
-static int openssl_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf,
+static int openssl_DECRYPT_final(void *ctx, unsigned char *buf,
int *outlen)
{
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
if (!dgst)
return -EINVAL;
@@ -114,8 +118,9 @@ static int openssl_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *bu
}
-static void openssl_DECRYPT_cleanup(struct swupdate_digest *dgst)
+static void openssl_DECRYPT_cleanup(void *ctx)
{
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
if (dgst) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
EVP_CIPHER_CTX_cleanup(SSL_GET_CTXDEC(dgst));
diff --git a/crypto/swupdate_decrypt_pkcs11.c b/crypto/swupdate_decrypt_pkcs11.c
index ff4afc51..7991286d 100644
--- a/crypto/swupdate_decrypt_pkcs11.c
+++ b/crypto/swupdate_decrypt_pkcs11.c
@@ -25,10 +25,10 @@ static void wolfssl_debug(int __attribute__ ((__unused__)) level, const char *co
}
#endif
-static struct swupdate_digest *wolfssl_DECRYPT_init(unsigned char *uri,
+static void *wolfssl_DECRYPT_init(unsigned char *uri,
char __attribute__ ((__unused__)) keylen, unsigned char *iv)
{
- struct swupdate_digest *dgst;
+ struct wolfssl_digest *dgst;
const char *library;
const char *pin;
const char *msg;
@@ -119,9 +119,10 @@ err_free:
return NULL;
}
-static int wolfssl_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *buf,
+static int wolfssl_DECRYPT_update(void *ctx, unsigned char *buf,
int *outlen, const unsigned char *cryptbuf, int inlen)
{
+ struct wolfssl_digest *dgst = (struct wolfssl_digest *)ctx;
// precondition: len(buf) >= inlen + AES_BLK_SIZE
unsigned char *pad_buf = &buf[AES_BLK_SIZE];
const char *msg;
@@ -156,8 +157,9 @@ static int wolfssl_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *b
}
// Gets rid of PKCS#7 padding
-static int wolfssl_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf, int *outlen)
+static int wolfssl_DECRYPT_final(void *ctx, unsigned char *buf, int *outlen)
{
+ struct wolfssl_digest *dgst = (struct wolfssl_digest *)ctx;
unsigned char last_oct = dgst->last_decr[AES_BLK_SIZE - 1];
if (last_oct > AES_BLK_SIZE || last_oct == 0) {
#ifndef CONFIG_ENCRYPTED_IMAGES_HARDEN_LOGGING
@@ -181,8 +183,9 @@ static int wolfssl_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *bu
return 0;
}
-static void wolfssl_DECRYPT_cleanup(struct swupdate_digest *dgst)
+static void wolfssl_DECRYPT_cleanup(void *ctx)
{
+ struct wolfssl_digest *dgst = (struct wolfssl_digest *)ctx;
if (dgst) {
if (&dgst->pktoken)
wc_Pkcs11Token_Final(&dgst->pktoken);
diff --git a/crypto/swupdate_gpg.h b/crypto/swupdate_gpg.h
new file mode 100644
index 00000000..c2ea55a7
--- /dev/null
+++ b/crypto/swupdate_gpg.h
@@ -0,0 +1,17 @@
+/*
+ * (C) Copyright 2016-2024
+ * Stefano Babic,
stefan...@swupdate.org.
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include "util.h"
+
+struct gpg_digest {
+ char *gpg_home_directory;
+ bool verbose;
+ char *gpgme_protocol;
+};
diff --git a/crypto/swupdate_gpg_verify.c b/crypto/swupdate_gpg_verify.c
index d2b7840c..b726336f 100644
--- a/crypto/swupdate_gpg_verify.c
+++ b/crypto/swupdate_gpg_verify.c
@@ -31,7 +31,7 @@ status_cb(void *opaque, const char *keyword, const char *value)
static int gpg_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
{
- struct swupdate_digest *dgst;
+ struct gpg_digest *dgst;
int ret;
/*
@@ -62,9 +62,10 @@ dgst_init_error:
return ret;
}
-static int gpg_verify_file(struct swupdate_digest *dgst, const char *sigfile,
+static int gpg_verify_file(void *gpgdgst, const char *sigfile,
const char *file, const char *signer_name)
{
+ struct gpg_digest *dgst = (struct gpg_digest *)gpgdgst;
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_data_t image_sig, image;
diff --git a/crypto/swupdate_mbedtls.h b/crypto/swupdate_mbedtls.h
index facd0951..175b70cc 100644
--- a/crypto/swupdate_mbedtls.h
+++ b/crypto/swupdate_mbedtls.h
@@ -17,7 +17,7 @@
#define EVP_MAX_BLOCK_LENGTH (16)
-struct swupdate_digest {
+struct mbedtls_digest {
mbedtls_md_context_t mbedtls_md_context;
mbedtls_pk_context mbedtls_pk_context;
mbedtls_cipher_context_t mbedtls_cipher_context;
diff --git a/crypto/swupdate_openssl.h b/crypto/swupdate_openssl.h
index 00d1d917..4dc79503 100644
--- a/crypto/swupdate_openssl.h
+++ b/crypto/swupdate_openssl.h
@@ -31,7 +31,7 @@
#define SSL_PURPOSE_CODE_SIGN X509_PURPOSE_CODE_SIGN
#define SSL_PURPOSE_DEFAULT SSL_PURPOSE_EMAIL_PROT
-struct swupdate_digest {
+struct openssl_digest {
EVP_PKEY *pkey; /* this is used for RSA key */
EVP_PKEY_CTX *ckey; /* this is used for RSA key */
X509_STORE *certs; /* this is used if CMS is set */
diff --git a/crypto/swupdate_pkcs7_verify_wolfssl.c b/crypto/swupdate_pkcs7_verify_wolfssl.c
index 76407c8e..39a29c89 100644
--- a/crypto/swupdate_pkcs7_verify_wolfssl.c
+++ b/crypto/swupdate_pkcs7_verify_wolfssl.c
@@ -107,7 +107,7 @@ static int check_signer_name(const char *name)
static int wolfssl_pkcs7_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
{
- struct swupdate_digest *dgst;
+ struct wolfssl_digest *dgst;
int ret;
/*
@@ -154,9 +154,10 @@ dgst_init_error:
return ret;
}
-static int wolfssl_pkcs7_verify_file(struct swupdate_digest *dgst, const char *sigfile,
+static int wolfssl_pkcs7_verify_file(void *ctx, const char *sigfile,
const char *file, const char *signer_name)
{
+ struct wolfssl_digest *dgst = (struct wolfssl_digest *)ctx;
int status = -EFAULT;
WOLFSSL_PKCS7* pkcs7 = (WOLFSSL_PKCS7 *)PKCS7_new();
BIO *bio_mem = NULL;
diff --git a/crypto/swupdate_rsa_verify_mbedtls.c b/crypto/swupdate_rsa_verify_mbedtls.c
index a1ca8cfa..207c27ae 100644
--- a/crypto/swupdate_rsa_verify_mbedtls.c
+++ b/crypto/swupdate_rsa_verify_mbedtls.c
@@ -46,9 +46,10 @@ exit:
return result;
}
-static int mbedtls_rsa_verify_file(struct swupdate_digest *dgst, const char *sigfile,
+static int mbedtls_rsa_verify_file(void *ctx, const char *sigfile,
const char *file, const char *signer_name)
{
+ struct mbedtls_digest *dgst = (struct mbedtls_digest *)ctx;
int error;
uint8_t hash_computed[32];
const mbedtls_md_info_t *md_info;
@@ -95,7 +96,7 @@ static int mbedtls_rsa_verify_file(struct swupdate_digest *dgst, const char *sig
static int mbedtls_rsa_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
{
- struct swupdate_digest *dgst;
+ struct mbedtls_digest *dgst;
dgst = calloc(1, sizeof(*dgst));
if (!dgst) {
diff --git a/crypto/swupdate_rsa_verify_openssl.c b/crypto/swupdate_rsa_verify_openssl.c
index 2a0c2302..1382293c 100644
--- a/crypto/swupdate_rsa_verify_openssl.c
+++ b/crypto/swupdate_rsa_verify_openssl.c
@@ -51,7 +51,7 @@ end:
return(pkey);
}
-static int dgst_verify_init(struct swupdate_digest *dgst)
+static int dgst_verify_init(struct openssl_digest *dgst)
{
int rc;
@@ -77,7 +77,7 @@ static int dgst_verify_init(struct swupdate_digest *dgst)
return 0;
}
-static int verify_update(struct swupdate_digest *dgst, char *msg, unsigned int mlen)
+static int verify_update(struct openssl_digest *dgst, char *msg, unsigned int mlen)
{
int rc;
@@ -90,7 +90,7 @@ static int verify_update(struct swupdate_digest *dgst, char *msg, unsigned int m
return 0;
}
-static int verify_final(struct swupdate_digest *dgst, unsigned char *sig, unsigned int slen)
+static int verify_final(struct openssl_digest *dgst, unsigned char *sig, unsigned int slen)
{
unsigned int rc;
@@ -105,9 +105,10 @@ static int verify_final(struct swupdate_digest *dgst, unsigned char *sig, unsign
return rc;
}
-static int openssl_rsa_verify_file(struct swupdate_digest *dgst, const char *sigfile,
+static int openssl_rsa_verify_file(void *ctx, const char *sigfile,
const char *file, const char *signer_name)
{
+ struct openssl_digest *dgst = (struct openssl_digest *)ctx;
FILE *fp = NULL;
BIO *sigbio;
int siglen = 0;
@@ -201,7 +202,7 @@ out:
static int openssl_rsa_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
{
- struct swupdate_digest *dgst;
+ struct openssl_digest *dgst;
int ret;
/*
diff --git a/crypto/swupdate_wolfssl.h b/crypto/swupdate_wolfssl.h
index feff2775..00f18714 100644
--- a/crypto/swupdate_wolfssl.h
+++ b/crypto/swupdate_wolfssl.h
@@ -39,9 +39,9 @@
#define X509_PURPOSE_CODE_SIGN EXTKEYUSE_CODESIGN
#define SSL_PURPOSE_EMAIL_PROT EXTKEYUSE_EMAILPROT
-//#define SSL_PURPOSE_DEFAULT SSL_PURPOSE_EMAIL_PROT
+#define openssl_digest wolfssl_digest
-struct swupdate_digest {
+struct wolfssl_digest {
EVP_PKEY *pkey; /* this is used for RSA key */
EVP_PKEY_CTX *ckey; /* this is used for RSA key */
X509_STORE *certs; /* this is used if CMS is set */
diff --git a/include/channel_curl.h b/include/channel_curl.h
index ae49b2bc..ccd4158f 100644
--- a/include/channel_curl.h
+++ b/include/channel_curl.h
@@ -86,7 +86,7 @@ typedef struct {
int read_fifo;
size_t (*headers)(char *streamdata, size_t size, size_t nmemb,
void *data);
- struct swupdate_digest *dgst;
+ void *dgst;
char sha1hash[SWUPDATE_SHA_DIGEST_LENGTH * 2 + 1];
sourcetype source;
struct dict *headers_to_send;
diff --git a/include/swupdate_crypto.h b/include/swupdate_crypto.h
index 067c0a2c..243b6068 100644
--- a/include/swupdate_crypto.h
+++ b/include/swupdate_crypto.h
@@ -37,25 +37,25 @@ typedef enum {
} ssl_cert_purpose_t;
typedef struct {
- struct swupdate_digest *(*DECRYPT_init)(unsigned char *key, char keylen, unsigned char *iv);
- int (*DECRYPT_update)(struct swupdate_digest *dgst, unsigned char *buf,
+ void *(*DECRYPT_init)(unsigned char *key, char keylen, unsigned char *iv);
+ int (*DECRYPT_update)(void *ctx, unsigned char *buf,
int *outlen, const unsigned char *cryptbuf, int inlen);
- int (*DECRYPT_final)(struct swupdate_digest *dgst, unsigned char *buf, int *outlen);
- void (*DECRYPT_cleanup)(struct swupdate_digest *dgst);
+ int (*DECRYPT_final)(void *ctx, unsigned char *buf, int *outlen);
+ void (*DECRYPT_cleanup)(void *ctx);
} swupdate_decrypt_lib;
typedef struct {
- struct swupdate_digest *(*HASH_init)(const char *SHAlength);
- int (*HASH_update)(struct swupdate_digest *dgst, const unsigned char *buf, size_t len);
- int (*HASH_final)(struct swupdate_digest *dgst, unsigned char *md_value, unsigned int *md_len);
+ void *(*HASH_init)(const char *SHAlength);
+ int (*HASH_update)(void *ctx, const unsigned char *buf, size_t len);
+ int (*HASH_final)(void *ctx, unsigned char *md_value, unsigned int *md_len);
int (*HASH_compare)(const unsigned char *hash1, const unsigned char *hash2);
- void (*HASH_cleanup)(struct swupdate_digest *dgst);
+ void (*HASH_cleanup)(void *ctx);
} swupdate_HASH_lib;
typedef struct {
int (*dgst_init)(struct swupdate_cfg *sw, const char *keyfile);
- int (*verify_file)(struct swupdate_digest *dgst, const char *sigfile, const char *file, const char *signer_name);
+ int (*verify_file)(void *ctx, const char *sigfile, const char *file, const char *signer_name);
} swupdate_dgst_lib;
/*
@@ -106,20 +106,19 @@ void print_registered_cryptolib(void);
struct swupdate_cfg;
int swupdate_dgst_init(struct swupdate_cfg *sw, const char *keyfile);
-struct swupdate_digest *swupdate_HASH_init(const char *SHALength);
-int swupdate_HASH_update(struct swupdate_digest *dgst, const unsigned char *buf,
+void *swupdate_HASH_init(const char *SHALength);
+int swupdate_HASH_update(void *ctx, const unsigned char *buf,
size_t len);
-int swupdate_HASH_final(struct swupdate_digest *dgst, unsigned char *md_value,
+int swupdate_HASH_final(void *ctx, unsigned char *md_value,
unsigned int *md_len);
-void swupdate_HASH_cleanup(struct swupdate_digest *dgst);
-int swupdate_verify_file(struct swupdate_digest *dgst, const char *sigfile,
+void swupdate_HASH_cleanup(void *ctx);
+int swupdate_verify_file(void *ctx, const char *sigfile,
const char *file, const char *signer_name);
int swupdate_HASH_compare(const unsigned char *hash1, const unsigned char *hash2);
-
-struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv);
-int swupdate_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *buf,
+void *swupdate_DECRYPT_init(unsigned char *key, char keylen, unsigned char *iv);
+int swupdate_DECRYPT_update(void *ctx, unsigned char *buf,
int *outlen, const unsigned char *cryptbuf, int inlen);
-int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf,
+int swupdate_DECRYPT_final(void *ctx, unsigned char *buf,
int *outlen);
-void swupdate_DECRYPT_cleanup(struct swupdate_digest *dgst);
+void swupdate_DECRYPT_cleanup(void *ctx);
diff --git a/test/test_hash.c b/test/test_hash.c
index 4d62b03a..895dcf4c 100644
--- a/test/test_hash.c
+++ b/test/test_hash.c
@@ -72,7 +72,7 @@ static void do_concrete_hash(const char* algo, const char* input, const char* ex
uint8_t result[32] = {0};
unsigned len = 0;
uint8_t expected_bin[32] = {0};
- struct swupdate_digest *dgst;
+ void *dgst;
dgst = swupdate_HASH_init(algo);
assert_non_null(dgst);
--
2.43.0