From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0
Date: Fri, 10 Jul 2015 15:31:31 +0200 [thread overview]
Message-ID: <20150710133131.GB3818@potion.brq.redhat.com> (raw)
In-Reply-To: <CAFEAcA-2E=0qUkASMPRuf-WLOY9fUa-W+7zoReTehHskb8fMJw@mail.gmail.com>
2015-07-10 13:56+0100, Peter Maydell:
> On 10 July 2015 at 13:33, Radim Krčmář <rkrcmar@redhat.com> 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.
next prev parent reply other threads:[~2015-07-10 13:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-10 12:33 [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0 Radim Krčmář
2015-07-10 12:56 ` Peter Maydell
2015-07-10 13:31 ` Radim Krčmář [this message]
2015-07-10 13:38 ` Peter Maydell
2015-07-10 13:56 ` Peter Maydell
2015-07-10 17:21 ` Radim Krčmář
2015-07-10 13:59 ` Radim Krčmář
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150710133131.GB3818@potion.brq.redhat.com \
--to=rkrcmar@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).