Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.server123.net (Postfix) with ESMTPS for ; Mon, 6 Aug 2018 12:05:31 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id f12-v6so11747799wrv.12 for ; Mon, 06 Aug 2018 03:05:31 -0700 (PDT) Received: from localhost (user-94-254-230-186.play-internet.pl. [94.254.230.186]) by smtp.gmail.com with ESMTPSA id k12-v6sm10535226wru.38.2018.08.06.03.05.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 03:05:30 -0700 (PDT) References: <3a015c32-03d0-fe2f-41c3-7c445e7efa8a@gmail.com> <20180805223359.2nz3rtx5paunxjye@h-174-65.A328.priv.bahnhof.se> From: Mikhail Morfikov Message-ID: Date: Mon, 6 Aug 2018 12:05:27 +0200 MIME-Version: 1.0 In-Reply-To: <20180805223359.2nz3rtx5paunxjye@h-174-65.A328.priv.bahnhof.se> Content-Type: text/plain; charset="utf-8" Content-Language: pl-PL Content-Transfer-Encoding: 8bit Subject: Re: [dm-crypt] Recreation of LUKS header when the master key is known List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: dm-crypt@saout.de On 2018-08-06 00:33, Michael Kjörling wrote: > On 5 Aug 2018 23:53 +0200, from mmorfikov@gmail.com (Mikhail Morfikov): >> # cryptsetup luksFormat -v -y -c aes-xts-plain64 >> --master-key-file=/tmp/master_key /dev/sdd1 >> >> But he was unable to decrypt the data (I know the ext4 superblock is damaged, >> but the volume can be tested whether it is decrypted or not, and in this case it >> wasn't). >> >> He said that the original container was created (probably) using this command: >> >> # cryptsetup -v -y -c aes-xts-plain64 -s 512 -h sha512 -i 5000 --use-random >> luksFormat /dev/sdd1 >> >> He ultimately found the header backup and everything went well, but I have a >> question -- what parameters are needed in order to recreate the header when the >> master key is known? > > Well, the cipher spec for one would obviously need to match exactly > for the newly created header to be useful for decrypting the existing > data. So depending on the defaults, the missing `-s 512` absolutely > could make a difference. > > My cryptsetup says the default for LUKS1 is aes-xts-plain64 with 256 > bits of key. So if your friend's system is similar to mine, chances > are good that the missing key length specifier had something to do > with it. The man page doesn't seem to say anything about what happens > if the provided master key file has a length different from the key > length that ends up being used by the selected cipher. > > Keep in mind that with XTS you're effectively running the cipher > itself in half the key length mode (so if you specify AES-XTS and 256 > bits of key, then the actual key used by AES is a 128 bit one). Thus, > the difference between specifying 512 bits and 256 bits means running > AES with a 256 bit key or a 128 bit key, respectively. Specifically > for AES, this also means running a different number of rounds; IIRC, > with a 256 bit key, AES uses 14 rounds, whereas with a 128 bit key, it > uses 10 rounds. So it's effectively a _very_ different cipher if you > use a different key length. > > Personally, I have written down the exact commands used to create the > LUKS containers, just in case. > > At least in this case your friend _had_ a header backup. > Thanks for the answer.