Received: from eggs.gnu.org ([2001:4830:134:3::10]:42666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCqIH-0003cw-C0 for qemu-devel@nongnu.org; Tue, 14 Jun 2016 11:30:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCqIE-0004V9-Ue for qemu-devel@nongnu.org; Tue, 14 Jun 2016 11:30:20 -0400 References: <1465901813-510-1-git-send-email-berrange@redhat.com> <1465901813-510-2-git-send-email-berrange@redhat.com> From: Max Reitz Message-ID: <11697daf-01e5-7a0a-23a8-72c5dff8b794@redhat.com> Date: Tue, 14 Jun 2016 17:30:03 +0200 MIME-Version: 1.0 In-Reply-To: <1465901813-510-2-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pWKJ1jFi0GneTgkhUKBFeiC3x4OGFluxX" Subject: Re: [Qemu-devel] [PATCH v2 1/2] crypto: add support for querying parameters for block encryption List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Eric Blake , qemu-block@nongnu.org, Kevin Wolf This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --pWKJ1jFi0GneTgkhUKBFeiC3x4OGFluxX From: Max Reitz To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Eric Blake , qemu-block@nongnu.org, Kevin Wolf Message-ID: <11697daf-01e5-7a0a-23a8-72c5dff8b794@redhat.com> Subject: Re: [PATCH v2 1/2] crypto: add support for querying parameters for block encryption References: <1465901813-510-1-git-send-email-berrange@redhat.com> <1465901813-510-2-git-send-email-berrange@redhat.com> In-Reply-To: <1465901813-510-2-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 14.06.2016 12:56, Daniel P. Berrange wrote: > When creating new block encryption volumes, we accept a list of > parameters to control the formatting process. It is useful to > be able to query what those parameters were for existing block > devices. Add a qcrypto_block_get_info() method which returns a > QCryptoBlockInfo instance to report this data. >=20 > Signed-off-by: Daniel P. Berrange > --- > crypto/block-luks.c | 70 ++++++++++++++++++++++++++++++++++++++++++= ++++ > crypto/block.c | 17 +++++++++++ > crypto/blockpriv.h | 4 +++ > include/crypto/block.h | 16 +++++++++++ > qapi/crypto.json | 76 ++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 5 files changed, 183 insertions(+) >=20 > diff --git a/crypto/block-luks.c b/crypto/block-luks.c > index 63649f1..6a6ef07 100644 > --- a/crypto/block-luks.c > +++ b/crypto/block-luks.c [...] > @@ -1284,6 +1305,54 @@ qcrypto_block_luks_create(QCryptoBlock *block, > } > =20 > =20 > +static int qcrypto_block_luks_get_info(QCryptoBlock *block, > + QCryptoBlockInfo *info, > + Error **errp) > +{ > + QCryptoBlockLUKS *luks =3D block->opaque; > + QCryptoBlockInfoLUKSSlot *slot; > + QCryptoBlockInfoLUKSSlotList *slots =3D NULL, *prev =3D NULL; You could make prev a double pointer, initializing it to &info->u.luks.slots... [1] > + size_t i; > + > + info->u.luks.cipher_alg =3D luks->cipher_alg; > + info->u.luks.cipher_mode =3D luks->cipher_mode; > + info->u.luks.ivgen_alg =3D luks->ivgen_alg; > + if (info->u.luks.ivgen_alg =3D=3D QCRYPTO_IVGEN_ALG_ESSIV) { > + info->u.luks.has_ivgen_hash_alg =3D true; > + info->u.luks.ivgen_hash_alg =3D luks->ivgen_hash_alg; > + } > + info->u.luks.hash_alg =3D luks->hash_alg; > + info->u.luks.payload_offset =3D block->payload_offset; > + info->u.luks.master_key_iters =3D luks->header.master_key_iteratio= ns; > + info->u.luks.uuid =3D g_strdup((const char *)luks->header.uuid); Wouldn't g_strndup() with sizeof(luks->header.uuid) be a better choice? > + > + for (i =3D 0; i < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS; i++) { > + slots =3D g_new0(QCryptoBlockInfoLUKSSlotList, 1); > + if (i =3D=3D 0) { > + info->u.luks.slots =3D slots; > + } else { > + prev->next =3D slots; > + } [1] ...then unconditionally use *prev =3D slots here... > + > + slots->value =3D slot =3D g_new0(QCryptoBlockInfoLUKSSlot, 1);= > + slot->active =3D luks->header.key_slots[i].active =3D=3D > + QCRYPTO_BLOCK_LUKS_KEY_SLOT_ENABLED; > + slot->key_offset =3D luks->header.key_slots[i].key_offset > + * QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; > + if (slot->active) { > + slot->has_iters =3D true; > + slot->iters =3D luks->header.key_slots[i].iterations; > + slot->has_stripes =3D true; > + slot->stripes =3D luks->header.key_slots[i].stripes; > + } > + > + prev =3D slots; [1] ...and prev =3D &slots->next here. > + } > + > + return 0; > +} > + > + > static void qcrypto_block_luks_cleanup(QCryptoBlock *block) > { > g_free(block->opaque); [...] > diff --git a/include/crypto/block.h b/include/crypto/block.h > index a21e11f..6256f64 100644 > --- a/include/crypto/block.h > +++ b/include/crypto/block.h > @@ -138,6 +138,22 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCre= ateOptions *options, > void *opaque, > Error **errp); > =20 > + > +/** > + * qcrypto_block_get_info: > + * block: the block encryption object I think this is missing an @. Max > + * @errp: pointer to a NULL-initialized error object > + * > + * Get information about the configuration options for the > + * block encryption object. This includes details such as > + * the cipher algorithms, modes, and initialization vector > + * generators. > + * > + * Returns: a block encryption info object, or NULL on error > + */ > +QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block, > + Error **errp); > + > /** > * @qcrypto_block_decrypt: > * @block: the block encryption object --pWKJ1jFi0GneTgkhUKBFeiC3x4OGFluxX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXYCL7AAoJEDuxQgLoOKyt6EYH/3pmoi3nWMkzYHu/lxOeXDEj C45D+dtJubS0fv9p6kTfKzP5EpDPfyNq/H4Z9EDYhpKaIrbNSc19ge7pSM+RVAZ3 Dox/QKn0TIAxtjD1Apcm4e6QX3k0BtW9h/m0PFL3eqritUQu/ntCzU9Pe9csBp8d nFC5Ha6hSA8UcsA9lNVGrGu8qigNJqfIPwJ9ofHyy0uJrueD+soH2J4XeXp2/nhf SqXI822mH/d9bjJdSrZAeSLmLLgTwvlFMAfHgTcYeTa63vNuY2/5zO0TOnoBdgGl 9aSjmZ+KQrfqXDnISV5pl6KzBqoDusw/VqslSXHlKiRHFcEy7K4aiLjRA7fQrFo= =UWDD -----END PGP SIGNATURE----- --pWKJ1jFi0GneTgkhUKBFeiC3x4OGFluxX--