[for-4.1,2/2] crypto: fix function signatures for nettle 2.7 vs 3
diff mbox series

Message ID 20190712101849.8993-3-berrange@redhat.com
State New
Headers show
Series
  • Compatibility fixes for nettle 2.7 vs 3.0 vs 3.5
Related show

Commit Message

Daniel P. Berrangé July 12, 2019, 10:18 a.m. UTC
Nettle version 2.7.x used 'unsigned int' instead of 'size_t' for length
parameters in functions. Use a local typedef so that we can build with
the correct signature depending on nettle version, as we already do in
the cipher code.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 crypto/hash-nettle.c | 12 +++++++++---
 crypto/hmac-nettle.c | 17 +++++++++++++----
 2 files changed, 22 insertions(+), 7 deletions(-)

Comments

Alex Bennée July 12, 2019, 12:10 p.m. UTC | #1
Daniel P. Berrangé <berrange@redhat.com> writes:

> Nettle version 2.7.x used 'unsigned int' instead of 'size_t' for length
> parameters in functions. Use a local typedef so that we can build with
> the correct signature depending on nettle version, as we already do in
> the cipher code.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  crypto/hash-nettle.c | 12 +++++++++---
>  crypto/hmac-nettle.c | 17 +++++++++++++----
>  2 files changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c
> index 96f186f442..6ffb9c3db7 100644
> --- a/crypto/hash-nettle.c
> +++ b/crypto/hash-nettle.c
> @@ -26,12 +26,18 @@
>  #include <nettle/sha.h>
>  #include <nettle/ripemd160.h>
>
> +#if CONFIG_NETTLE_VERSION_MAJOR < 3
> +typedef unsigned int     hash_length_t;
> +#else
> +typedef size_t       hash_length_t;
> +#endif
> +
>  typedef void (*qcrypto_nettle_init)(void *ctx);
>  typedef void (*qcrypto_nettle_write)(void *ctx,
> -                                     unsigned int len,
> +                                     hash_length_t len,
>                                       const uint8_t *buf);
>  typedef void (*qcrypto_nettle_result)(void *ctx,
> -                                      unsigned int len,
> +                                      hash_length_t len,
>                                        uint8_t *buf);
>
>  union qcrypto_hash_ctx {
> @@ -112,7 +118,7 @@ qcrypto_nettle_hash_bytesv(QCryptoHashAlgorithm alg,
>                             size_t *resultlen,
>                             Error **errp)
>  {
> -    int i;
> +    size_t i;
>      union qcrypto_hash_ctx ctx;
>
>      if (!qcrypto_hash_supports(alg)) {
> diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c
> index ec2d61bdde..1152b741fd 100644
> --- a/crypto/hmac-nettle.c
> +++ b/crypto/hmac-nettle.c
> @@ -18,14 +18,23 @@
>  #include "hmacpriv.h"
>  #include <nettle/hmac.h>
>
> +#if CONFIG_NETTLE_VERSION_MAJOR < 3
> +typedef unsigned int hmac_length_t;
> +#else
> +typedef size_t hmac_length_t;
> +#endif
> +
>  typedef void (*qcrypto_nettle_hmac_setkey)(void *ctx,
> -              size_t key_length, const uint8_t *key);
> +                                           hmac_length_t key_length,
> +                                           const uint8_t *key);
>
>  typedef void (*qcrypto_nettle_hmac_update)(void *ctx,
> -              size_t length, const uint8_t *data);
> +                                           hmac_length_t length,
> +                                           const uint8_t *data);
>
>  typedef void (*qcrypto_nettle_hmac_digest)(void *ctx,
> -              size_t length, uint8_t *digest);
> +                                           hmac_length_t length,
> +                                           uint8_t *digest);
>
>  typedef struct QCryptoHmacNettle QCryptoHmacNettle;
>  struct QCryptoHmacNettle {
> @@ -135,7 +144,7 @@ qcrypto_nettle_hmac_bytesv(QCryptoHmac *hmac,
>                             Error **errp)
>  {
>      QCryptoHmacNettle *ctx;
> -    int i;
> +    size_t i;
>
>      ctx = (QCryptoHmacNettle *)hmac->opaque;


--
Alex Bennée
Philippe Mathieu-Daudé July 12, 2019, 5:15 p.m. UTC | #2
On 7/12/19 12:18 PM, Daniel P. Berrangé wrote:
> Nettle version 2.7.x used 'unsigned int' instead of 'size_t' for length
> parameters in functions. Use a local typedef so that we can build with
> the correct signature depending on nettle version, as we already do in
> the cipher code.
> 

Reported-by: Amol Surati <suratiamol@gmail.com>

> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  crypto/hash-nettle.c | 12 +++++++++---
>  crypto/hmac-nettle.c | 17 +++++++++++++----
>  2 files changed, 22 insertions(+), 7 deletions(-)
> 
> diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c
> index 96f186f442..6ffb9c3db7 100644
> --- a/crypto/hash-nettle.c
> +++ b/crypto/hash-nettle.c
> @@ -26,12 +26,18 @@
>  #include <nettle/sha.h>
>  #include <nettle/ripemd160.h>
>  
> +#if CONFIG_NETTLE_VERSION_MAJOR < 3
> +typedef unsigned int     hash_length_t;
> +#else
> +typedef size_t       hash_length_t;
> +#endif
> +
>  typedef void (*qcrypto_nettle_init)(void *ctx);
>  typedef void (*qcrypto_nettle_write)(void *ctx,
> -                                     unsigned int len,
> +                                     hash_length_t len,
>                                       const uint8_t *buf);
>  typedef void (*qcrypto_nettle_result)(void *ctx,
> -                                      unsigned int len,
> +                                      hash_length_t len,
>                                        uint8_t *buf);
>  
>  union qcrypto_hash_ctx {
> @@ -112,7 +118,7 @@ qcrypto_nettle_hash_bytesv(QCryptoHashAlgorithm alg,
>                             size_t *resultlen,
>                             Error **errp)
>  {
> -    int i;
> +    size_t i;
>      union qcrypto_hash_ctx ctx;
>  
>      if (!qcrypto_hash_supports(alg)) {
> diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c
> index ec2d61bdde..1152b741fd 100644
> --- a/crypto/hmac-nettle.c
> +++ b/crypto/hmac-nettle.c
> @@ -18,14 +18,23 @@
>  #include "hmacpriv.h"
>  #include <nettle/hmac.h>
>  
> +#if CONFIG_NETTLE_VERSION_MAJOR < 3
> +typedef unsigned int hmac_length_t;
> +#else
> +typedef size_t hmac_length_t;
> +#endif
> +
>  typedef void (*qcrypto_nettle_hmac_setkey)(void *ctx,
> -              size_t key_length, const uint8_t *key);
> +                                           hmac_length_t key_length,
> +                                           const uint8_t *key);
>  
>  typedef void (*qcrypto_nettle_hmac_update)(void *ctx,
> -              size_t length, const uint8_t *data);
> +                                           hmac_length_t length,
> +                                           const uint8_t *data);
>  
>  typedef void (*qcrypto_nettle_hmac_digest)(void *ctx,
> -              size_t length, uint8_t *digest);
> +                                           hmac_length_t length,
> +                                           uint8_t *digest);
>  
>  typedef struct QCryptoHmacNettle QCryptoHmacNettle;
>  struct QCryptoHmacNettle {
> @@ -135,7 +144,7 @@ qcrypto_nettle_hmac_bytesv(QCryptoHmac *hmac,
>                             Error **errp)
>  {
>      QCryptoHmacNettle *ctx;
> -    int i;
> +    size_t i;
>  
>      ctx = (QCryptoHmacNettle *)hmac->opaque;
>  
>

Patch
diff mbox series

diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c
index 96f186f442..6ffb9c3db7 100644
--- a/crypto/hash-nettle.c
+++ b/crypto/hash-nettle.c
@@ -26,12 +26,18 @@ 
 #include <nettle/sha.h>
 #include <nettle/ripemd160.h>
 
+#if CONFIG_NETTLE_VERSION_MAJOR < 3
+typedef unsigned int     hash_length_t;
+#else
+typedef size_t       hash_length_t;
+#endif
+
 typedef void (*qcrypto_nettle_init)(void *ctx);
 typedef void (*qcrypto_nettle_write)(void *ctx,
-                                     unsigned int len,
+                                     hash_length_t len,
                                      const uint8_t *buf);
 typedef void (*qcrypto_nettle_result)(void *ctx,
-                                      unsigned int len,
+                                      hash_length_t len,
                                       uint8_t *buf);
 
 union qcrypto_hash_ctx {
@@ -112,7 +118,7 @@  qcrypto_nettle_hash_bytesv(QCryptoHashAlgorithm alg,
                            size_t *resultlen,
                            Error **errp)
 {
-    int i;
+    size_t i;
     union qcrypto_hash_ctx ctx;
 
     if (!qcrypto_hash_supports(alg)) {
diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c
index ec2d61bdde..1152b741fd 100644
--- a/crypto/hmac-nettle.c
+++ b/crypto/hmac-nettle.c
@@ -18,14 +18,23 @@ 
 #include "hmacpriv.h"
 #include <nettle/hmac.h>
 
+#if CONFIG_NETTLE_VERSION_MAJOR < 3
+typedef unsigned int hmac_length_t;
+#else
+typedef size_t hmac_length_t;
+#endif
+
 typedef void (*qcrypto_nettle_hmac_setkey)(void *ctx,
-              size_t key_length, const uint8_t *key);
+                                           hmac_length_t key_length,
+                                           const uint8_t *key);
 
 typedef void (*qcrypto_nettle_hmac_update)(void *ctx,
-              size_t length, const uint8_t *data);
+                                           hmac_length_t length,
+                                           const uint8_t *data);
 
 typedef void (*qcrypto_nettle_hmac_digest)(void *ctx,
-              size_t length, uint8_t *digest);
+                                           hmac_length_t length,
+                                           uint8_t *digest);
 
 typedef struct QCryptoHmacNettle QCryptoHmacNettle;
 struct QCryptoHmacNettle {
@@ -135,7 +144,7 @@  qcrypto_nettle_hmac_bytesv(QCryptoHmac *hmac,
                            Error **errp)
 {
     QCryptoHmacNettle *ctx;
-    int i;
+    size_t i;
 
     ctx = (QCryptoHmacNettle *)hmac->opaque;