qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] crypto/cipher-nettle.c: Pass correct function type


From: Richard W.M. Jones
Subject: [Qemu-devel] [PATCH] crypto/cipher-nettle.c: Pass correct function type to cbc_encrypt and cbc_decrypt.
Date: Thu, 16 Jul 2015 10:55:22 +0100

The prototypes of the {nettle_}cbc_encrypt and cbc_decrypt functions
are:

void
cbc_encrypt(const void *ctx, nettle_cipher_func *f,
            size_t block_size, uint8_t *iv,
            size_t length, uint8_t *dst,
            const uint8_t *src);

void
cbc_decrypt(const void *ctx, nettle_cipher_func *f,
            size_t block_size, uint8_t *iv,
            size_t length, uint8_t *dst,
            const uint8_t *src);

Since we passed nettle_crypt_func (instead of nettle_cipher_func) as
the second argument, this gave the errors below.

In file included from crypto/cipher.c:71:0:
./crypto/cipher-nettle.c: In function ‘qcrypto_cipher_encrypt’:
./crypto/cipher-nettle.c:154:39: error: passing argument 2 of 
‘nettle_cbc_encrypt’ from incompatible pointer type 
[-Werror=incompatible-pointer-types]
         cbc_encrypt(ctx->ctx_encrypt, ctx->alg_encrypt,
                                       ^
In file included from ./crypto/cipher-nettle.c:24:0,
                 from crypto/cipher.c:71:
/usr/include/nettle/cbc.h:48:1: note: expected ‘void (*)(const void *, size_t,  
uint8_t *, const uint8_t *) {aka void (*)(const void *, long unsigned int,  
unsigned char *, const unsigned char *)}’ but argument is of type ‘void 
(*)(void *, size_t,  uint8_t *, const uint8_t *) {aka void (*)(void *, long 
unsigned int,  unsigned char *, const unsigned char *)}’
 cbc_encrypt(const void *ctx, nettle_cipher_func *f,
 ^
In file included from crypto/cipher.c:71:0:
./crypto/cipher-nettle.c: In function ‘qcrypto_cipher_decrypt’:
./crypto/cipher-nettle.c:183:21: error: passing argument 2 of 
‘nettle_cbc_decrypt’ from incompatible pointer type 
[-Werror=incompatible-pointer-types]
                     ctx->alg_decrypt, ctx->niv, ctx->iv,
                     ^
In file included from ./crypto/cipher-nettle.c:24:0,
                 from crypto/cipher.c:71:
/usr/include/nettle/cbc.h:54:1: note: expected ‘void (*)(const void *, size_t,  
uint8_t *, const uint8_t *) {aka void (*)(const void *, long unsigned int,  
unsigned char *, const unsigned char *)}’ but argument is of type ‘void 
(*)(void *, size_t,  uint8_t *, const uint8_t *) {aka void (*)(void *, long 
unsigned int,  unsigned char *, const unsigned char *)}’
 cbc_decrypt(const void *ctx, nettle_cipher_func *f,

Signed-off-by: Richard W.M. Jones <address@hidden>
---
 crypto/cipher-nettle.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c
index e5a14bc..f06ea92 100644
--- a/crypto/cipher-nettle.c
+++ b/crypto/cipher-nettle.c
@@ -27,8 +27,8 @@ typedef struct QCryptoCipherNettle QCryptoCipherNettle;
 struct QCryptoCipherNettle {
     void *ctx_encrypt;
     void *ctx_decrypt;
-    nettle_crypt_func *alg_encrypt;
-    nettle_crypt_func *alg_decrypt;
+    nettle_cipher_func *alg_encrypt;
+    nettle_cipher_func *alg_decrypt;
     uint8_t *iv;
     size_t niv;
 };
@@ -83,8 +83,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
         des_set_key(ctx->ctx_encrypt, rfbkey);
         g_free(rfbkey);
 
-        ctx->alg_encrypt = (nettle_crypt_func *)des_encrypt;
-        ctx->alg_decrypt = (nettle_crypt_func *)des_decrypt;
+        ctx->alg_encrypt = (nettle_cipher_func *)des_encrypt;
+        ctx->alg_decrypt = (nettle_cipher_func *)des_decrypt;
 
         ctx->niv = DES_BLOCK_SIZE;
         break;
@@ -98,8 +98,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
         aes_set_encrypt_key(ctx->ctx_encrypt, nkey, key);
         aes_set_decrypt_key(ctx->ctx_decrypt, nkey, key);
 
-        ctx->alg_encrypt = (nettle_crypt_func *)aes_encrypt;
-        ctx->alg_decrypt = (nettle_crypt_func *)aes_decrypt;
+        ctx->alg_encrypt = (nettle_cipher_func *)aes_encrypt;
+        ctx->alg_decrypt = (nettle_cipher_func *)aes_decrypt;
 
         ctx->niv = AES_BLOCK_SIZE;
         break;
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]