diff mbox series

[1/2] Move swupdate_dgst_init to the right place

Message ID 20200520210029.1138-1-bastiangermann@fishpost.de
State Accepted
Headers show
Series [1/2] Move swupdate_dgst_init to the right place | expand

Commit Message

Bastian Germann May 20, 2020, 9 p.m. UTC
Compiling with mbedTLS and the options HASH_VERIFY=y and SIGNED_IMAGES=n
results in linking error "undefined reference to `swupdate_dgst_init'".

Move swupdate_dgst_init to the verify_signature_mbedtls module that is
available with this configuration, analogous to the OpenSSL based
implementation.

Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
---
 corelib/swupdate_rsa_verify_mbedtls.c | 26 --------------------------
 corelib/verify_signature_mbedtls.c    | 26 ++++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 26 deletions(-)

Comments

Stefano Babic May 21, 2020, 7:27 a.m. UTC | #1
On 20.05.20 23:00, Bastian Germann wrote:
> Compiling with mbedTLS and the options HASH_VERIFY=y and SIGNED_IMAGES=n
> results in linking error "undefined reference to `swupdate_dgst_init'".

Confirmed, thanks for fixing.

What about to add a config to check this use case ? Build is then
automatically checked by each commit.

> 
> Move swupdate_dgst_init to the verify_signature_mbedtls module that is
> available with this configuration, analogous to the OpenSSL based
> implementation.
> 
> Signed-off-by: Bastian Germann <bastiangermann@fishpost.de>
> ---
>  corelib/swupdate_rsa_verify_mbedtls.c | 26 --------------------------
>  corelib/verify_signature_mbedtls.c    | 26 ++++++++++++++++++++++++++
>  2 files changed, 26 insertions(+), 26 deletions(-)
> 
> diff --git a/corelib/swupdate_rsa_verify_mbedtls.c b/corelib/swupdate_rsa_verify_mbedtls.c
> index beeb03d..beeed0e 100644
> --- a/corelib/swupdate_rsa_verify_mbedtls.c
> +++ b/corelib/swupdate_rsa_verify_mbedtls.c
> @@ -16,32 +16,6 @@
>  #include "sslapi.h"
>  #include "util.h"
>  
> -int swupdate_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
> -{
> -	struct swupdate_digest *dgst;
> -	int error;
> -
> -	dgst = calloc(1, sizeof(*dgst));
> -	if (!dgst) {
> -		return -ENOMEM;
> -	}
> -
> -	mbedtls_pk_init(&dgst->mbedtls_pk_context);
> -
> -	error = mbedtls_pk_parse_public_keyfile(&dgst->mbedtls_pk_context, keyfile);
> -	if (error) {
> -		ERROR("mbedtls_pk_parse_public_keyfile: %d", error);
> -		goto fail;
> -	}
> -
> -	sw->dgst = dgst;
> -	return 0;
> -
> -fail:
> -	free(dgst);
> -	return -EIO;
> -}
> -
>  static int read_file_into_buffer(uint8_t *buffer, int size, const char *filename)
>  {
>  	int fd;
> diff --git a/corelib/verify_signature_mbedtls.c b/corelib/verify_signature_mbedtls.c
> index 2921462..4c964c4 100644
> --- a/corelib/verify_signature_mbedtls.c
> +++ b/corelib/verify_signature_mbedtls.c
> @@ -105,3 +105,29 @@ int swupdate_HASH_compare(const unsigned char *hash1, const unsigned char *hash2
>  {
>  	return memcmp(hash1, hash2, SHA256_HASH_LENGTH) ? -1 : 0;
>  }
> +
> +int swupdate_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
> +{
> +	struct swupdate_digest *dgst;
> +	int error;
> +
> +	dgst = calloc(1, sizeof(*dgst));
> +	if (!dgst) {
> +		return -ENOMEM;
> +	}
> +
> +	mbedtls_pk_init(&dgst->mbedtls_pk_context);
> +
> +	error = mbedtls_pk_parse_public_keyfile(&dgst->mbedtls_pk_context, keyfile);
> +	if (error) {
> +		ERROR("mbedtls_pk_parse_public_keyfile: %d", error);
> +		goto fail;
> +	}
> +
> +	sw->dgst = dgst;
> +	return 0;
> +
> +fail:
> +	free(dgst);
> +	return -EIO;
> +}
> 

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/swupdate_rsa_verify_mbedtls.c b/corelib/swupdate_rsa_verify_mbedtls.c
index beeb03d..beeed0e 100644
--- a/corelib/swupdate_rsa_verify_mbedtls.c
+++ b/corelib/swupdate_rsa_verify_mbedtls.c
@@ -16,32 +16,6 @@ 
 #include "sslapi.h"
 #include "util.h"
 
-int swupdate_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
-{
-	struct swupdate_digest *dgst;
-	int error;
-
-	dgst = calloc(1, sizeof(*dgst));
-	if (!dgst) {
-		return -ENOMEM;
-	}
-
-	mbedtls_pk_init(&dgst->mbedtls_pk_context);
-
-	error = mbedtls_pk_parse_public_keyfile(&dgst->mbedtls_pk_context, keyfile);
-	if (error) {
-		ERROR("mbedtls_pk_parse_public_keyfile: %d", error);
-		goto fail;
-	}
-
-	sw->dgst = dgst;
-	return 0;
-
-fail:
-	free(dgst);
-	return -EIO;
-}
-
 static int read_file_into_buffer(uint8_t *buffer, int size, const char *filename)
 {
 	int fd;
diff --git a/corelib/verify_signature_mbedtls.c b/corelib/verify_signature_mbedtls.c
index 2921462..4c964c4 100644
--- a/corelib/verify_signature_mbedtls.c
+++ b/corelib/verify_signature_mbedtls.c
@@ -105,3 +105,29 @@  int swupdate_HASH_compare(const unsigned char *hash1, const unsigned char *hash2
 {
 	return memcmp(hash1, hash2, SHA256_HASH_LENGTH) ? -1 : 0;
 }
+
+int swupdate_dgst_init(struct swupdate_cfg *sw, const char *keyfile)
+{
+	struct swupdate_digest *dgst;
+	int error;
+
+	dgst = calloc(1, sizeof(*dgst));
+	if (!dgst) {
+		return -ENOMEM;
+	}
+
+	mbedtls_pk_init(&dgst->mbedtls_pk_context);
+
+	error = mbedtls_pk_parse_public_keyfile(&dgst->mbedtls_pk_context, keyfile);
+	if (error) {
+		ERROR("mbedtls_pk_parse_public_keyfile: %d", error);
+		goto fail;
+	}
+
+	sw->dgst = dgst;
+	return 0;
+
+fail:
+	free(dgst);
+	return -EIO;
+}