]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virCryptoEncryptDataAESgnutls: Properly initialize data structures
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Dec 2022 11:37:30 +0000 (12:37 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Dec 2022 13:40:26 +0000 (14:40 +0100)
The initialization vector is not optional thus we also don't need to
check whether the caller passed it in. Additionally we can use c99
initializers for the gnutls_datum_t structs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/vircrypto.c

index 1bddb333dcbd533aa254fb0fcc5a8ad0cb19a4e1..b28d3fc23dc4385eacc4fbdf4b789291bcfb8630 100644 (file)
@@ -125,8 +125,8 @@ virCryptoEncryptDataAESgnutls(gnutls_cipher_algorithm_t gnutls_enc_alg,
     int rc;
     size_t i;
     gnutls_cipher_hd_t handle = NULL;
-    gnutls_datum_t enc_key;
-    gnutls_datum_t iv_buf;
+    gnutls_datum_t enc_key = { .data = enckey, .size = enckeylen };
+    gnutls_datum_t iv_buf = { .data = iv, .size = ivlen };
     uint8_t *ciphertext;
     size_t ciphertextlen;
 
@@ -146,13 +146,6 @@ virCryptoEncryptDataAESgnutls(gnutls_cipher_algorithm_t gnutls_enc_alg,
     for (i = datalen; i < ciphertextlen; i++)
         ciphertext[i] = ciphertextlen - datalen;
 
-    /* Initialize the gnutls cipher */
-    enc_key.size = enckeylen;
-    enc_key.data = enckey;
-    if (iv) {
-        iv_buf.size = ivlen;
-        iv_buf.data = iv;
-    }
     if ((rc = gnutls_cipher_init(&handle, gnutls_enc_alg,
                                  &enc_key, &iv_buf)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,