Re: [PATCH v8 10/18] cryptodisk: Add macro GRUB_TYPE_BITS() to replace some literals

2020-12-12 Thread Patrick Steinhardt
On Tue, Dec 08, 2020 at 04:45:41PM -0600, Glenn Washburn wrote:
> The new macro GRUB_TYPE_BITS(type) returns the number of bits allocated for
> type.
> 
> Signed-off-by: Glenn Washburn 

Reviewed-by: Patrick Steinhardt 

> ---
>  grub-core/disk/cryptodisk.c | 7 ---
>  include/grub/types.h| 2 ++
>  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
> index 473c93976..0e955a020 100644
> --- a/grub-core/disk/cryptodisk.c
> +++ b/grub-core/disk/cryptodisk.c
> @@ -281,20 +281,21 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev,
> }
> break;
>   case GRUB_CRYPTODISK_MODE_IV_PLAIN64:
> -   iv[1] = grub_cpu_to_le32 (sector >> 32);
> +   iv[1] = grub_cpu_to_le32 (sector >> GRUB_TYPE_BITS (iv[0]));
> /* FALLTHROUGH */
>   case GRUB_CRYPTODISK_MODE_IV_PLAIN:
> iv[0] = grub_cpu_to_le32 (sector & 0x);
> break;
>   case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64:
> -   iv[1] = grub_cpu_to_le32 (sector >> (32 - dev->log_sector_size));
> +   iv[1] = grub_cpu_to_le32 (sector >> (GRUB_TYPE_BITS (iv[1])
> +- dev->log_sector_size));
> iv[0] = grub_cpu_to_le32 ((sector << dev->log_sector_size)
>   & 0x);
> break;
>   case GRUB_CRYPTODISK_MODE_IV_BENBI:
> {
>   grub_uint64_t num = (sector << dev->benbi_log) + 1;
> - iv[sz - 2] = grub_cpu_to_be32 (num >> 32);
> + iv[sz - 2] = grub_cpu_to_be32 (num >> GRUB_TYPE_BITS (iv[0]));
>   iv[sz - 1] = grub_cpu_to_be32 (num & 0x);
> }
> break;
> diff --git a/include/grub/types.h b/include/grub/types.h
> index f22055f98..9989e3a16 100644
> --- a/include/grub/types.h
> +++ b/include/grub/types.h
> @@ -80,6 +80,8 @@
>  # define GRUB_CHAR_BIT   __CHAR_BIT__
>  #endif
>  
> +#define GRUB_TYPE_BITS(type) (sizeof(type) * GRUB_CHAR_BIT)
> +
>  /* Define various wide integers.  */
>  typedef signed char  grub_int8_t;
>  typedef shortgrub_int16_t;
> -- 
> 2.27.0
> 


signature.asc
Description: PGP signature
___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v8 10/18] cryptodisk: Add macro GRUB_TYPE_BITS() to replace some literals

2020-12-09 Thread Daniel Kiper
On Tue, Dec 08, 2020 at 04:45:41PM -0600, Glenn Washburn wrote:
> The new macro GRUB_TYPE_BITS(type) returns the number of bits allocated for
> type.
>
> Signed-off-by: Glenn Washburn 

Reviewed-by: Daniel Kiper 

Daniel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v8 10/18] cryptodisk: Add macro GRUB_TYPE_BITS() to replace some literals

2020-12-08 Thread Glenn Washburn
The new macro GRUB_TYPE_BITS(type) returns the number of bits allocated for
type.

Signed-off-by: Glenn Washburn 
---
 grub-core/disk/cryptodisk.c | 7 ---
 include/grub/types.h| 2 ++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
index 473c93976..0e955a020 100644
--- a/grub-core/disk/cryptodisk.c
+++ b/grub-core/disk/cryptodisk.c
@@ -281,20 +281,21 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev,
  }
  break;
case GRUB_CRYPTODISK_MODE_IV_PLAIN64:
- iv[1] = grub_cpu_to_le32 (sector >> 32);
+ iv[1] = grub_cpu_to_le32 (sector >> GRUB_TYPE_BITS (iv[0]));
  /* FALLTHROUGH */
case GRUB_CRYPTODISK_MODE_IV_PLAIN:
  iv[0] = grub_cpu_to_le32 (sector & 0x);
  break;
case GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64:
- iv[1] = grub_cpu_to_le32 (sector >> (32 - dev->log_sector_size));
+ iv[1] = grub_cpu_to_le32 (sector >> (GRUB_TYPE_BITS (iv[1])
+  - dev->log_sector_size));
  iv[0] = grub_cpu_to_le32 ((sector << dev->log_sector_size)
& 0x);
  break;
case GRUB_CRYPTODISK_MODE_IV_BENBI:
  {
grub_uint64_t num = (sector << dev->benbi_log) + 1;
-   iv[sz - 2] = grub_cpu_to_be32 (num >> 32);
+   iv[sz - 2] = grub_cpu_to_be32 (num >> GRUB_TYPE_BITS (iv[0]));
iv[sz - 1] = grub_cpu_to_be32 (num & 0x);
  }
  break;
diff --git a/include/grub/types.h b/include/grub/types.h
index f22055f98..9989e3a16 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -80,6 +80,8 @@
 # define GRUB_CHAR_BIT __CHAR_BIT__
 #endif
 
+#define GRUB_TYPE_BITS(type) (sizeof(type) * GRUB_CHAR_BIT)
+
 /* Define various wide integers.  */
 typedef signed chargrub_int8_t;
 typedef short  grub_int16_t;
-- 
2.27.0


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel