From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDYOx-0008Os-Tb for qemu-devel@nongnu.org; Fri, 10 Jul 2015 09:31:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZDYOt-0001HW-Ss for qemu-devel@nongnu.org; Fri, 10 Jul 2015 09:31:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDYOt-0001H4-Nq for qemu-devel@nongnu.org; Fri, 10 Jul 2015 09:31:35 -0400 Date: Fri, 10 Jul 2015 15:31:31 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Message-ID: <20150710133131.GB3818@potion.brq.redhat.com> References: <1436531615-30183-1-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Developers 2015-07-10 13:56+0100, Peter Maydell: > On 10 July 2015 at 13:33, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: >> @@ -83,8 +87,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgor= ithm alg, >> - ctx->alg_encrypt =3D (nettle_crypt_func *)des_encrypt; >> - ctx->alg_decrypt =3D (nettle_crypt_func *)des_decrypt; >> + ctx->alg_encrypt =3D (nettle_cipher_func *)des_encrypt; >> + ctx->alg_decrypt =3D (nettle_cipher_func *)des_decrypt; >> @@ -98,8 +102,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgo= rithm alg, >> - ctx->alg_encrypt =3D (nettle_crypt_func *)aes_encrypt; >> - ctx->alg_decrypt =3D (nettle_crypt_func *)aes_decrypt; >> + ctx->alg_encrypt =3D (nettle_cipher_func *)aes_encrypt; >> + ctx->alg_decrypt =3D (nettle_cipher_func *)aes_decrypt; >=20 > 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.