Return-Path: Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 ; Sun, 5 Aug 2018 23:53:49 +0200 (CEST) Received: by mail-pf1-x432.google.com with SMTP id j8-v6so5848631pff.6 for ; Sun, 05 Aug 2018 14:53:48 -0700 (PDT) Received: from localhost (user-94-254-227-89.play-internet.pl. [94.254.227.89]) by smtp.gmail.com with ESMTPSA id q81-v6sm18332557pfd.15.2018.08.05.14.53.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Aug 2018 14:53:44 -0700 (PDT) From: Mikhail Morfikov Message-ID: <3a015c32-03d0-fe2f-41c3-7c445e7efa8a@gmail.com> Date: Sun, 5 Aug 2018 23:53:37 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: [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 My friend zeroed out the first 3 GiB of a drive, including the partition table, LUKSv1 header, and EXT4 superblock + some data of the first partition. He realized what he did, and before rebooting the system, he recovered the master key via the following command: ----------------------------- # dmsetup table --showkeys /dev/mapper/encrypted | awk '{ print $5 }' | xxd -r -p > /tmp/master_key ----------------------------- He saved the key and later on (offline) he wanted to recreate the LUKS header using the following command: ----------------------------- # 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?