qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0


From: Radim Krčmář
Subject: Re: [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0
Date: Fri, 10 Jul 2015 15:31:31 +0200

2015-07-10 13:56+0100, Peter Maydell:
> On 10 July 2015 at 13:33, Radim Krčmář <address@hidden> wrote:
>> @@ -83,8 +87,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm 
>> alg,
>> -        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;
>> @@ -98,8 +102,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm 
>> alg,
>> -        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;
> 
> Why do we need the casts here at all?  If the functions
> we're passing around don't have the right signature
> anyway we're in big trouble and casting them is
> just going to hide the problem until runtime...

Yes.

We pass 'ctx' as a 'void *' in the code, but these functions accept
specialized structures, which makes them incompatible:

  void nettle_cipher_func(const void *ctx, size_t length, [...])

  void aes_decrypt(const struct aes_ctx *ctx, size_t length, [...])
  void des_decrypt(const struct des_ctx *ctx, size_t length, [...])

We could take make struct QCryptoCipherNettle into an aes/des union
(it's already tagged by QCryptoCipher->mode) to make coding a bit safer,
but C types can't guarantee everything.  Also, cbc_encrypt() takes
nettle_cipher_func, so we need to directly cast at some point.



reply via email to

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