diff mbox series

[u-boot,v2019.04-aspeed-openbmc,06/11] image-fit: use hashing infra

Message ID 20210413080755.73572-7-joel@jms.id.au
State New
Headers show
Series Use HACE to | expand

Commit Message

Joel Stanley April 13, 2021, 8:07 a.m. UTC
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 common/image-fit.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Klaus Heinrich Kiwi April 13, 2021, 12:38 p.m. UTC | #1
On 4/13/2021 5:07 AM, Joel Stanley wrote:
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
>   common/image-fit.c | 16 +++++++++++++++-
>   1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/common/image-fit.c b/common/image-fit.c
> index e64949dfa73d..b9c3d79b83e1 100644
> --- a/common/image-fit.c
> +++ b/common/image-fit.c
> @@ -1135,9 +1135,22 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
>    *     0, on success
>    *    -1, when algo is unsupported
>    */
> -int calculate_hash(const void *data, int data_len, const char *algo,
> +int calculate_hash(const void *data, int data_len, const char *algo_name,
>   			uint8_t *value, int *value_len)
Is the API changing here, or you just needed the 'algo' variable name for something else?
Are all callers OK with that?

>   {
> +	struct hash_algo *algo;
> +
> +	if (hash_lookup_algo(algo_name, &algo)) {
> +		debug("Unsupported hash alogrithm\n");
> +		return -1;
> +	}
> +
> +	algo->hash_func_ws(data, data_len, value, algo->chunk_size);
> +	*value_len = algo->digest_size;
> +
> +	return 0;
> +
> +#if 0

Can you expand the rationale behind keeping this dead code around?

>   	if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) {
>   		*((uint32_t *)value) = crc32_wd(0, data, data_len,
>   							CHUNKSZ_CRC32);
> @@ -1167,6 +1180,7 @@ int calculate_hash(const void *data, int data_len, const char *algo,
>   		return -1;
>   	}
>   	return 0;
> +#endif
>   }
> 
>   static int fit_image_check_hash(const void *fit, int noffset, const void *data,
>
Joel Stanley April 13, 2021, 11:49 p.m. UTC | #2
On Tue, 13 Apr 2021 at 12:38, Klaus Heinrich Kiwi
<klaus@linux.vnet.ibm.com> wrote:
>
>
>
> On 4/13/2021 5:07 AM, Joel Stanley wrote:
> > Signed-off-by: Joel Stanley <joel@jms.id.au>
> > ---
> >   common/image-fit.c | 16 +++++++++++++++-
> >   1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/common/image-fit.c b/common/image-fit.c
> > index e64949dfa73d..b9c3d79b83e1 100644
> > --- a/common/image-fit.c
> > +++ b/common/image-fit.c
> > @@ -1135,9 +1135,22 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
> >    *     0, on success
> >    *    -1, when algo is unsupported
> >    */
> > -int calculate_hash(const void *data, int data_len, const char *algo,
> > +int calculate_hash(const void *data, int data_len, const char *algo_name,
> >                       uint8_t *value, int *value_len)
> Is the API changing here, or you just needed the 'algo' variable name for something else?
> Are all callers OK with that?
>
> >   {
> > +     struct hash_algo *algo;
> > +
> > +     if (hash_lookup_algo(algo_name, &algo)) {
> > +             debug("Unsupported hash alogrithm\n");
> > +             return -1;
> > +     }
> > +
> > +     algo->hash_func_ws(data, data_len, value, algo->chunk_size);
> > +     *value_len = algo->digest_size;
> > +
> > +     return 0;
> > +
> > +#if 0
>
> Can you expand the rationale behind keeping this dead code around?

Good catch, I sent the wrong version of the patch. I'll send v2 with
the version that went upstream.
diff mbox series

Patch

diff --git a/common/image-fit.c b/common/image-fit.c
index e64949dfa73d..b9c3d79b83e1 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1135,9 +1135,22 @@  int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
  *     0, on success
  *    -1, when algo is unsupported
  */
-int calculate_hash(const void *data, int data_len, const char *algo,
+int calculate_hash(const void *data, int data_len, const char *algo_name,
 			uint8_t *value, int *value_len)
 {
+	struct hash_algo *algo;
+
+	if (hash_lookup_algo(algo_name, &algo)) {
+		debug("Unsupported hash alogrithm\n");
+		return -1;
+	}
+
+	algo->hash_func_ws(data, data_len, value, algo->chunk_size);
+	*value_len = algo->digest_size;
+
+	return 0;
+
+#if 0
 	if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) {
 		*((uint32_t *)value) = crc32_wd(0, data, data_len,
 							CHUNKSZ_CRC32);
@@ -1167,6 +1180,7 @@  int calculate_hash(const void *data, int data_len, const char *algo,
 		return -1;
 	}
 	return 0;
+#endif
 }
 
 static int fit_image_check_hash(const void *fit, int noffset, const void *data,