[libvirt] [PATCH REPOST 4/4] util: Adjust virCryptoEncryptData code to use macros

Ján Tomko jtomko at redhat.com
Tue Jun 7 08:00:28 UTC 2016


On Mon, Jun 06, 2016 at 02:13:49PM -0400, John Ferlan wrote:
> Will make it easier to add new key lengths
> 
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  src/util/vircrypto.c | 50 +++++++++++++++++++++++++++-----------------------
>  1 file changed, 27 insertions(+), 23 deletions(-)
> 
> diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c
> index 27a3d1d..f50ac6a 100644
> --- a/src/util/vircrypto.c
> +++ b/src/util/vircrypto.c
> @@ -229,36 +229,40 @@ virCryptoEncryptData(virCryptoCipher algorithm,
>                       uint8_t **ciphertext,
>                       size_t *ciphertextlen)
>  {
> +    /*
> +     * Encrypt the data buffer using an encryption key and
> +     * initialization vector via the gnutls_cipher_encrypt API
> +     * for the specific cipher algorithm.
> +     */
> +# define DO_CRYPT(ekl, ivl, alg, nam)                                       \
> +    do {                                                                    \
> +        if (enckeylen != ekl) {                                             \
> +            virReportError(VIR_ERR_INVALID_ARG,                             \
> +                           _("'%s' encryption invalid keylen=%d"),          \
> +                           nam, ekl);                                       \
> +            return -1;                                                      \
> +        }                                                                   \
> +        if (ivlen != ivl) {                                                 \
> +            virReportError(VIR_ERR_INVALID_ARG,                             \
> +                           _("'%s' initialization vector invalid len=%d"),  \
> +                           nam, ivl);                                       \
> +            return -1;                                                      \
> +        }                                                                   \

If these values depend on the VIR_CRYPTO_CIPHER, we should not need to
pass them around.

Jan




More information about the libvir-list mailing list