public inbox for cryptsetup@lists.linux.dev
 help / color / mirror / Atom feed
* Equivalent of --integrity-recalculate
@ 2025-05-10 15:51 Marc SCHAEFER
  2025-05-10 16:18 ` Milan Broz
  0 siblings, 1 reply; 4+ messages in thread
From: Marc SCHAEFER @ 2025-05-10 15:51 UTC (permalink / raw)
  To: cryptsetup

Hello,

If you create a cryptsetup/luks device with integrity with:

   cryptsetup luksFormat -q --type luks2 --integrity hmac-sha256 $dev

and then open it:

   cryptsetup open $dev backup-copy

you then get, according to lsblk, two additional devices:

   - backup-copy (the transparently decrypted/encrypting volume)

   - backup-copy_dif (the integrity device)

(which is similar, AFAIK, as when you use dm-integrity with LVM)

If you create an integrity device separately, you get a

   integritysetup --integrity-recalculate open $dev integrity

command which allows to recalculate the integrity blocks.

I don't think cryptsetup has this option (*); is there a way to
do it anyway?  Or maybe remove the backup-copy_dif and
re-add it?

Thank you for any pointer.

(*) it looks there is a feature request pending
       https://gitlab.com/cryptsetup/cryptsetup/-/issues/854

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Equivalent of --integrity-recalculate
  2025-05-10 15:51 Equivalent of --integrity-recalculate Marc SCHAEFER
@ 2025-05-10 16:18 ` Milan Broz
  2025-05-11  8:25   ` Disabling integrity metadata verification (was: Equivalent of --integrity-recalculate) Marc SCHAEFER
  0 siblings, 1 reply; 4+ messages in thread
From: Milan Broz @ 2025-05-10 16:18 UTC (permalink / raw)
  To: Marc SCHAEFER, cryptsetup

On 5/10/25 5:51 PM, Marc SCHAEFER wrote:
> Hello,
> 
> If you create a cryptsetup/luks device with integrity with:
> 
>     cryptsetup luksFormat -q --type luks2 --integrity hmac-sha256 $dev
> 
> and then open it:
> 
>     cryptsetup open $dev backup-copy
> 
> you then get, according to lsblk, two additional devices:
> 
>     - backup-copy (the transparently decrypted/encrypting volume)
> 
>     - backup-copy_dif (the integrity device)
> 
> (which is similar, AFAIK, as when you use dm-integrity with LVM)
> 
> If you create an integrity device separately, you get a
> 
>     integritysetup --integrity-recalculate open $dev integrity
> 
> command which allows to recalculate the integrity blocks.
> 
> I don't think cryptsetup has this option (*); is there a way to
> do it anyway?  Or maybe remove the backup-copy_dif and
> re-add it?

No, because such option is not implemented (and never will be) in dm-crypt.

Note, for integritysetup you use dm-integrity, for cryptsetup
dm-integrity only provides metadata space, AEAD encrypton
is performed in dm-crypt above.

Sometimes it is not even possible, AEAD just cannot take
data with wrong authentication tag and fix it.
This is only possible when the integrity is calculated separately.

Milan


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Disabling integrity metadata verification (was: Equivalent of --integrity-recalculate)
  2025-05-10 16:18 ` Milan Broz
@ 2025-05-11  8:25   ` Marc SCHAEFER
  2025-05-11 18:46     ` Disabling integrity metadata verification Milan Broz
  0 siblings, 1 reply; 4+ messages in thread
From: Marc SCHAEFER @ 2025-05-11  8:25 UTC (permalink / raw)
  To: cryptsetup

Hello,

Thank you for this insight:

On Sat, May 10, 2025 at 06:18:18PM +0200, Milan Broz wrote:
> Note, for integritysetup you use dm-integrity, for cryptsetup
> dm-integrity only provides metadata space, AEAD encrypton
> is performed in dm-crypt above.

So, if I understand well, integrity with cryptsetup is implemented with a HMAC
that needs cleartext data (just before encryption) and produce hashed-signed
integrity data that protects against tampering and is not fixable by an
attacker (resistant to voluntary corruption).

Where if I create a dm-integrity layer with a luks crypted volume on top, I get
integrity, but an attacker can modify the crypted data and the hash easily
(only resistant to accidental corruption).

Now, another question: assuming the metadata space is corrupted, but I know
that the crypted space is not, is it possible to ignore the metadata altogether
(to not produce read errors)?

Thank you.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Disabling integrity metadata verification
  2025-05-11  8:25   ` Disabling integrity metadata verification (was: Equivalent of --integrity-recalculate) Marc SCHAEFER
@ 2025-05-11 18:46     ` Milan Broz
  0 siblings, 0 replies; 4+ messages in thread
From: Milan Broz @ 2025-05-11 18:46 UTC (permalink / raw)
  To: Marc SCHAEFER, cryptsetup

Hi,

On 5/11/25 10:25 AM, Marc SCHAEFER wrote:
...
> So, if I understand well, integrity with cryptsetup is implemented with a HMAC
> that needs cleartext data (just before encryption) and produce hashed-signed
> integrity data that protects against tampering and is not fixable by an
> attacker (resistant to voluntary corruption).

Cryptsetup (dm-crypt) always use AEAD (authenticated encryption).

Simplified, this can be constructed two ways

  - it is "true" AEAD algorithm (like AEGIS) with one key. You cannot separate
authenticated tag calculation here.

- it is constructed as combination of length-preserving cipher (AES-XTS) and
authentication tag (HMAC). It uses two independent keys in this case.
While we use kernel AEAD interface, it can be split and the authentication
tag verification ignored.

So you can ignore authentication tag in the second option, but you cannot "fix"
it without knowledge of the key.

> Where if I create a dm-integrity layer with a luks crypted volume on top, I get
> integrity, but an attacker can modify the crypted data and the hash easily
> (only resistant to accidental corruption).

I am not sure I understand what you mean. there is always dm-integrity, but
in the case of AEAD it provides only storage, dm-crypt performs both encryption
and authentication.

Stacking dm-crypt with length-preserving encryption over standalone dm-integrity
with HMAC over ciphertext (produced by dm-crypt above) does not make much sense,
but authentication tag still cannot be modified by attacker as HMAC is keyed algorithm.

Use of non-keyed algorithms for integrity protection (xxhash, CRC or plain hash) does
not much sense in combination with encryption, but it can be useful for triggering
recovery in RAID in the case of random data corruption.

> Now, another question: assuming the metadata space is corrupted, but I know
> that the crypted space is not, is it possible to ignore the metadata altogether
> (to not produce read errors)?

It depends, see above - it can be done only in the second option.
Cryptsetup does not support it, but in some related issue I already explained the trick.

Milan


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-11 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-10 15:51 Equivalent of --integrity-recalculate Marc SCHAEFER
2025-05-10 16:18 ` Milan Broz
2025-05-11  8:25   ` Disabling integrity metadata verification (was: Equivalent of --integrity-recalculate) Marc SCHAEFER
2025-05-11 18:46     ` Disabling integrity metadata verification Milan Broz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox