mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] scripts: rkimage: Use non-deprecated functions for sha256/512
@ 2023-05-02 12:27 Sascha Hauer
  2023-05-02 14:59 ` Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2023-05-02 12:27 UTC (permalink / raw)
  To: Barebox List

SHA256_Init() and SHA512_Init() are deprecated since OpensSSL 3.0. Use
EVP functions instead to calculate hashes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/rkimage.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/scripts/rkimage.c b/scripts/rkimage.c
index 6e68d508ac..551114ed82 100644
--- a/scripts/rkimage.c
+++ b/scripts/rkimage.c
@@ -9,7 +9,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <time.h>
-#include <openssl/sha.h>
+#include <openssl/evp.h>
 #include <errno.h>
 #include <stdbool.h>
 
@@ -22,20 +22,24 @@
 
 static void sha256(const void *buf, int len, void *out)
 {
-	SHA256_CTX sha256;
+	EVP_MD_CTX *md_ctx;
 
-	SHA256_Init(&sha256);
-	SHA256_Update(&sha256, buf, len);
-	SHA256_Final(out, &sha256);
+	md_ctx = EVP_MD_CTX_new();
+	EVP_DigestInit(md_ctx, EVP_sha256());
+	EVP_DigestUpdate(md_ctx, buf, len);
+	EVP_DigestFinal(md_ctx, out, NULL);
+	EVP_MD_CTX_free(md_ctx);
 }
 
 static void sha512(const void *buf, int len, void *out)
 {
-	SHA512_CTX sha512;
+	EVP_MD_CTX *md_ctx;
 
-	SHA512_Init(&sha512);
-	SHA512_Update(&sha512, buf, len);
-	SHA512_Final(out, &sha512);
+	md_ctx = EVP_MD_CTX_new();
+	EVP_DigestInit(md_ctx, EVP_sha512());
+	EVP_DigestUpdate(md_ctx, buf, len);
+	EVP_DigestFinal(md_ctx, out, NULL);
+	EVP_MD_CTX_free(md_ctx);
 }
 
 typedef enum {
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: rkimage: Use non-deprecated functions for sha256/512
  2023-05-02 12:27 [PATCH] scripts: rkimage: Use non-deprecated functions for sha256/512 Sascha Hauer
@ 2023-05-02 14:59 ` Ahmad Fatoum
  2023-05-02 15:10   ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2023-05-02 14:59 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On 02.05.23 14:27, Sascha Hauer wrote:
> SHA256_Init() and SHA512_Init() are deprecated since OpensSSL 3.0. Use
> EVP functions instead to calculate hashes.

Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

I'd have preferred we just drop the OpenSSL dependency here though (:.

> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  scripts/rkimage.c | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/rkimage.c b/scripts/rkimage.c
> index 6e68d508ac..551114ed82 100644
> --- a/scripts/rkimage.c
> +++ b/scripts/rkimage.c
> @@ -9,7 +9,7 @@
>  #include <stdint.h>
>  #include <string.h>
>  #include <time.h>
> -#include <openssl/sha.h>
> +#include <openssl/evp.h>
>  #include <errno.h>
>  #include <stdbool.h>
>  
> @@ -22,20 +22,24 @@
>  
>  static void sha256(const void *buf, int len, void *out)
>  {
> -	SHA256_CTX sha256;
> +	EVP_MD_CTX *md_ctx;
>  
> -	SHA256_Init(&sha256);
> -	SHA256_Update(&sha256, buf, len);
> -	SHA256_Final(out, &sha256);
> +	md_ctx = EVP_MD_CTX_new();
> +	EVP_DigestInit(md_ctx, EVP_sha256());
> +	EVP_DigestUpdate(md_ctx, buf, len);
> +	EVP_DigestFinal(md_ctx, out, NULL);
> +	EVP_MD_CTX_free(md_ctx);
>  }
>  
>  static void sha512(const void *buf, int len, void *out)
>  {
> -	SHA512_CTX sha512;
> +	EVP_MD_CTX *md_ctx;
>  
> -	SHA512_Init(&sha512);
> -	SHA512_Update(&sha512, buf, len);
> -	SHA512_Final(out, &sha512);
> +	md_ctx = EVP_MD_CTX_new();
> +	EVP_DigestInit(md_ctx, EVP_sha512());
> +	EVP_DigestUpdate(md_ctx, buf, len);
> +	EVP_DigestFinal(md_ctx, out, NULL);
> +	EVP_MD_CTX_free(md_ctx);
>  }
>  
>  typedef enum {

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: rkimage: Use non-deprecated functions for sha256/512
  2023-05-02 14:59 ` Ahmad Fatoum
@ 2023-05-02 15:10   ` Sascha Hauer
  0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2023-05-02 15:10 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: Barebox List

On Tue, May 02, 2023 at 04:59:50PM +0200, Ahmad Fatoum wrote:
> On 02.05.23 14:27, Sascha Hauer wrote:
> > SHA256_Init() and SHA512_Init() are deprecated since OpensSSL 3.0. Use
> > EVP functions instead to calculate hashes.
> 
> Acked-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> 
> I'd have preferred we just drop the OpenSSL dependency here though (:.

I know. We depend on openssl for several other host tools anyway, like
imx-image, rsatoc and mxsimage, so I took the easy way out.

Sascha

> 
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  scripts/rkimage.c | 22 +++++++++++++---------
> >  1 file changed, 13 insertions(+), 9 deletions(-)
> > 
> > diff --git a/scripts/rkimage.c b/scripts/rkimage.c
> > index 6e68d508ac..551114ed82 100644
> > --- a/scripts/rkimage.c
> > +++ b/scripts/rkimage.c
> > @@ -9,7 +9,7 @@
> >  #include <stdint.h>
> >  #include <string.h>
> >  #include <time.h>
> > -#include <openssl/sha.h>
> > +#include <openssl/evp.h>
> >  #include <errno.h>
> >  #include <stdbool.h>
> >  
> > @@ -22,20 +22,24 @@
> >  
> >  static void sha256(const void *buf, int len, void *out)
> >  {
> > -	SHA256_CTX sha256;
> > +	EVP_MD_CTX *md_ctx;
> >  
> > -	SHA256_Init(&sha256);
> > -	SHA256_Update(&sha256, buf, len);
> > -	SHA256_Final(out, &sha256);
> > +	md_ctx = EVP_MD_CTX_new();
> > +	EVP_DigestInit(md_ctx, EVP_sha256());
> > +	EVP_DigestUpdate(md_ctx, buf, len);
> > +	EVP_DigestFinal(md_ctx, out, NULL);
> > +	EVP_MD_CTX_free(md_ctx);
> >  }
> >  
> >  static void sha512(const void *buf, int len, void *out)
> >  {
> > -	SHA512_CTX sha512;
> > +	EVP_MD_CTX *md_ctx;
> >  
> > -	SHA512_Init(&sha512);
> > -	SHA512_Update(&sha512, buf, len);
> > -	SHA512_Final(out, &sha512);
> > +	md_ctx = EVP_MD_CTX_new();
> > +	EVP_DigestInit(md_ctx, EVP_sha512());
> > +	EVP_DigestUpdate(md_ctx, buf, len);
> > +	EVP_DigestFinal(md_ctx, out, NULL);
> > +	EVP_MD_CTX_free(md_ctx);
> >  }
> >  
> >  typedef enum {
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-02 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 12:27 [PATCH] scripts: rkimage: Use non-deprecated functions for sha256/512 Sascha Hauer
2023-05-02 14:59 ` Ahmad Fatoum
2023-05-02 15:10   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox