[v2,06/13] qcrypto-block: pass keyslot index rather that pointer to the keyslot
diff mbox series

Message ID 20190826135103.22410-7-mlevitsk@redhat.com
State New
Headers show
Series
  • RFC crypto/luks: preparation for encryption key managment
Related show

Commit Message

Maxim Levitsky Aug. 26, 2019, 1:50 p.m. UTC
Another minor refactoring

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 crypto/block-luks.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Daniel P. Berrangé Sept. 6, 2019, 12:32 p.m. UTC | #1
On Mon, Aug 26, 2019 at 04:50:56PM +0300, Maxim Levitsky wrote:
> Another minor refactoring
> 
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
>  crypto/block-luks.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/crypto/block-luks.c b/crypto/block-luks.c
> index 331377293d..0d81f2ac61 100644
> --- a/crypto/block-luks.c
> +++ b/crypto/block-luks.c
> @@ -410,7 +410,7 @@ qcrypto_block_luks_essiv_cipher(QCryptoCipherAlgorithm cipher,
>   */
>  static int
>  qcrypto_block_luks_load_key(QCryptoBlock *block,
> -                            QCryptoBlockLUKSKeySlot *slot,
> +                            unsigned int slot_idx,

FWIW, I tend to prefer 'size_t' for things which are array
indexes especially....

>                              const char *password,
>                              QCryptoCipherAlgorithm cipheralg,
>                              QCryptoCipherMode ciphermode,
> @@ -424,6 +424,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block,
>                              Error **errp)
>  {
>      QCryptoBlockLUKS *luks = block->opaque;
> +    const QCryptoBlockLUKSKeySlot *slot = &luks->header.key_slots[slot_idx];
>      g_autofree uint8_t *splitkey = NULL;
>      size_t splitkeylen;
>      g_autofree uint8_t *possiblekey = NULL;
> @@ -580,13 +581,12 @@ qcrypto_block_luks_find_key(QCryptoBlock *block,
>                              void *opaque,
>                              Error **errp)
>  {
> -    QCryptoBlockLUKS *luks = block->opaque;
>      size_t i;
>      int rv;
>  
>      for (i = 0; i < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS; i++) {
>          rv = qcrypto_block_luks_load_key(block,
> -                                         &luks->header.key_slots[i],
> +                                         i,

..given that 'i' is size_t here.

>                                           password,
>                                           cipheralg,
>                                           ciphermode,

With that type changed

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel

Patch
diff mbox series

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index 331377293d..0d81f2ac61 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -410,7 +410,7 @@  qcrypto_block_luks_essiv_cipher(QCryptoCipherAlgorithm cipher,
  */
 static int
 qcrypto_block_luks_load_key(QCryptoBlock *block,
-                            QCryptoBlockLUKSKeySlot *slot,
+                            unsigned int slot_idx,
                             const char *password,
                             QCryptoCipherAlgorithm cipheralg,
                             QCryptoCipherMode ciphermode,
@@ -424,6 +424,7 @@  qcrypto_block_luks_load_key(QCryptoBlock *block,
                             Error **errp)
 {
     QCryptoBlockLUKS *luks = block->opaque;
+    const QCryptoBlockLUKSKeySlot *slot = &luks->header.key_slots[slot_idx];
     g_autofree uint8_t *splitkey = NULL;
     size_t splitkeylen;
     g_autofree uint8_t *possiblekey = NULL;
@@ -580,13 +581,12 @@  qcrypto_block_luks_find_key(QCryptoBlock *block,
                             void *opaque,
                             Error **errp)
 {
-    QCryptoBlockLUKS *luks = block->opaque;
     size_t i;
     int rv;
 
     for (i = 0; i < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS; i++) {
         rv = qcrypto_block_luks_load_key(block,
-                                         &luks->header.key_slots[i],
+                                         i,
                                          password,
                                          cipheralg,
                                          ciphermode,