All of lore.kernel.org
 help / color / mirror / Atom feed
* sha256 in "AF hash" despite using sha512 during luksFormat
@ 2022-09-09 22:50 doffloster
  2022-09-10  5:25 ` Milan Broz
  2022-09-10 10:34 ` Milan Broz
  0 siblings, 2 replies; 10+ messages in thread
From: doffloster @ 2022-09-09 22:50 UTC (permalink / raw)
  To: cryptsetup

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

Dear cryptsetup/LUKS Team,

I was using sha512 in the luksFormat command.
Later I used luksAddKey while thinking that it should be using the
sha512 hash that I defined in luksFormat.
But, when I did luksDump, then I noticed that the field "AF hash" for
the second key (which was added via luksAddKey ; its keyslot is #1)
contains the value "sha256".
I expected it to contain sha512.
Notice that keyslot#0 has "sha512" in its corresponding "AF hash" field.

Attached script which reproduces that issue, filename
"reproduce_commands_without_hash.sh".
Attached output of the script, filename
"reproduce_commands_without_hash.log.txt".

Did I miss something?

Best regards,
David.

[-- Attachment #2: reproduce_commands_without_hash.log.txt --]
[-- Type: text/plain, Size: 11146 bytes --]

LUKS Format:
# cryptsetup 2.4.3 processing "cryptsetup --type=luks2 --verbose --debug --hash sha512 --key-size 512 --header /tmp/header.img --key-file - --iter-time=50 luksFormat /dev/sdb1"
# Running command luksFormat.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating context for crypt device /tmp/header.img.
# Trying to open and read device /tmp/header.img with direct-io.
# Trying to open device /tmp/header.img without direct-io.
# Initialising device-mapper backend library.
WARNING: Device /tmp/header.img already contains a 'crypto_LUKS' superblock signature.
# STDIN descriptor passphrase entry requested.
# Crypto backend (OpenSSL 3.0.2 15 Mar 2022 [default][legacy]) initialized in cryptsetup library version 2.4.3.
# Detected kernel Linux 5.15.0-43-generic x86_64.
# PBKDF argon2id, time_ms 50 (iterations 0), max_memory_kb 1048576, parallel_threads 4.
Existing 'crypto_LUKS' superblock signature on device /tmp/header.img will be wiped.
Existing 'crypto_LUKS' superblock signature on device /tmp/header.img will be wiped.
# Formatting device /tmp/header.img as type LUKS2.
# Auto-detected optimal encryption sector size for device /tmp/header.img is 4096 bytes.
# dm version   [ opencount flush ]   [16384] (*1)
# dm versions   [ opencount flush ]   [16384] (*1)
# Detected dm-ioctl version 4.45.0.
# Device-mapper backend running with UDEV support enabled.
# Trying to open and read device /dev/sdb1 with direct-io.
# Checking if cipher aes-xts-plain64 is usable.
# Using userspace crypto wrapper to access keyslot area.
# Formatting LUKS2 with JSON metadata area 12288 bytes and keyslots area 16744448 bytes.
# Creating new digest 0 (pbkdf2).
# Setting PBKDF2 type key digest 0.
# Running pbkdf2(sha512) benchmark.
# PBKDF benchmark: memory cost = 0, iterations = 1638400, threads = 0 (took 20 ms)
# PBKDF benchmark: memory cost = 0, iterations = 1741820, threads = 0 (took 301 ms)
# PBKDF benchmark: memory cost = 0, iterations = 1744718, threads = 0 (took 601 ms)
# Benchmark returns pbkdf2(sha512) 1744718 iterations, 0 memory, 0 threads (for 512-bits key).
# Segment 0 assigned to digest 0.
# Wiping LUKS areas (0x000000 - 0x001000) with zeroes.
# Wiping keyslots area (0x008000 - 0x1000000) with random data.
# Reusing open rw fd on device /tmp/header.img
# Device size 16777216, offset 16777216.
# Acquiring write lock for device /tmp/header.img.
# Verifying lock handle for /tmp/header.img.
# Device /tmp/header.img WRITE lock taken.
# Trying to write LUKS2 header (16384 bytes) at offset 0.
# Reusing open rw fd on device /tmp/header.img
# Checksum:7080b40cfa78985838b93520b7c434e4abe4f4352f431614b57ac4a13eb87363 (in-memory)
# Trying to write LUKS2 header (16384 bytes) at offset 16384.
# Reusing open rw fd on device /tmp/header.img
# Checksum:3008ee2430be15229759d89ce03daf169a1a0cd40472bfbe0c6395fba356e427 (in-memory)
# Device /tmp/header.img WRITE lock released.
# Adding new keyslot -1 using volume key.
# Adding new keyslot -1 with volume key assigned to a crypt segment.
# Selected keyslot 0.
# Keyslot 0 assigned to digest 0.
# Trying to allocate LUKS2 keyslot 0.
# Found area 32768 -> 290816
# Running argon2id() benchmark.
# PBKDF benchmark: memory cost = 65536, iterations = 4, threads = 4 (took 60 ms)
# PBKDF benchmark: memory cost = 273066, iterations = 4, threads = 4 (took 228 ms)
# PBKDF benchmark: memory cost = 299414, iterations = 4, threads = 4 (took 252 ms)
# Benchmark returns argon2id() 4 iterations, 65536 memory, 4 threads (for 512-bits key).
# Calculating attributes for LUKS2 keyslot 0.
# Acquiring write lock for device /tmp/header.img.
# Verifying lock handle for /tmp/header.img.
# Device /tmp/header.img WRITE lock taken.
# Checking context sequence id matches value stored on disk.
# Reusing open ro fd on device /tmp/header.img
# Running keyslot key derivation.
# Updating keyslot area [0x8000].
# Reusing open rw fd on device /tmp/header.img
# Device size 16777216, offset 16777216.
# Device /tmp/header.img WRITE lock already held.
# Trying to write LUKS2 header (16384 bytes) at offset 0.
# Reusing open rw fd on device /tmp/header.img
# Checksum:7c8b2c722311412a14c3721ec7a01c4b11894701f4aa94500caf854cad8c6cc6 (in-memory)
# Trying to write LUKS2 header (16384 bytes) at offset 16384.
# Reusing open rw fd on device /tmp/header.img
# Checksum:f3826f590069d99638ea2cc1d58c976f29f39b1582fdac1a82c26b3ff3059696 (in-memory)
# Device /tmp/header.img WRITE lock released.
Key slot 0 created.
# Releasing crypt device /tmp/header.img context.
# Releasing device-mapper backend.
# Closing read only fd for /tmp/header.img.
# Closing read write fd for /tmp/header.img.
# Unlocking memory.
Command successful.

Add a key file:
# cryptsetup 2.4.3 processing "cryptsetup --verbose --debug --key-file - --iter-time=50 luksAddKey /tmp/header.img /tmp/key"
# Running command luksAddKey.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating context for crypt device /tmp/header.img.
# Trying to open and read device /tmp/header.img with direct-io.
# Trying to open device /tmp/header.img without direct-io.
# Initialising device-mapper backend library.
# Trying to load any crypt type from device /tmp/header.img.
# Crypto backend (OpenSSL 3.0.2 15 Mar 2022 [default][legacy]) initialized in cryptsetup library version 2.4.3.
# Detected kernel Linux 5.15.0-43-generic x86_64.
# Loading LUKS2 header (repair disabled).
# Acquiring read lock for device /tmp/header.img.
# Verifying lock handle for /tmp/header.img.
# Device /tmp/header.img READ lock taken.
# Trying to read primary LUKS2 header at offset 0x0.
# Opening locked device /tmp/header.img
# Verifying locked device handle (regular file)
# LUKS2 header version 2 of size 16384 bytes, checksum sha256.
# Checksum:7c8b2c722311412a14c3721ec7a01c4b11894701f4aa94500caf854cad8c6cc6 (on-disk)
# Checksum:7c8b2c722311412a14c3721ec7a01c4b11894701f4aa94500caf854cad8c6cc6 (in-memory)
# Trying to read secondary LUKS2 header at offset 0x4000.
# Reusing open ro fd on device /tmp/header.img
# LUKS2 header version 2 of size 16384 bytes, checksum sha256.
# Checksum:f3826f590069d99638ea2cc1d58c976f29f39b1582fdac1a82c26b3ff3059696 (on-disk)
# Checksum:f3826f590069d99638ea2cc1d58c976f29f39b1582fdac1a82c26b3ff3059696 (in-memory)
# Device size 16777216, offset 16777216.
# Device /tmp/header.img READ lock released.
# PBKDF argon2id, time_ms 2000 (iterations 0), max_memory_kb 1048576, parallel_threads 4.
# PBKDF argon2id, time_ms 50 (iterations 0), max_memory_kb 1048576, parallel_threads 4.
# STDIN descriptor passphrase entry requested.
# Checking volume passphrase [keyslot -1] using passphrase.
# Keyslot 0 priority 1 != 2 (required), skipped.
# Trying to open LUKS2 keyslot 0.
# Running keyslot key derivation.
# Reading keyslot area [0x8000].
# Acquiring read lock for device /tmp/header.img.
# Verifying lock handle for /tmp/header.img.
# Device /tmp/header.img READ lock taken.
# Reusing open ro fd on device /tmp/header.img
# Device /tmp/header.img READ lock released.
# Verifying key from keyslot 0, digest 0.
# dm version   [ opencount flush ]   [16384] (*1)
# dm versions   [ opencount flush ]   [16384] (*1)
# Detected dm-ioctl version 4.45.0.
# Device-mapper backend running with UDEV support enabled.
Key slot 0 unlocked.
# File descriptor passphrase entry requested.
# Adding new keyslot, existing passphrase provided,new passphrase provided.
# Selected keyslot 1.
# Keyslot 0 priority 1 != 2 (required), skipped.
# Trying to open LUKS2 keyslot 0.
# Running keyslot key derivation.
# Reading keyslot area [0x8000].
# Acquiring read lock for device /tmp/header.img.
# Verifying lock handle for /tmp/header.img.
# Device /tmp/header.img READ lock taken.
# Reusing open ro fd on device /tmp/header.img
# Device /tmp/header.img READ lock released.
# Verifying key from keyslot 0, digest 0.
# Keyslot 1 assigned to digest 0.
# Trying to allocate LUKS2 keyslot 1.
# Found area 290816 -> 548864
# Running argon2id() benchmark.
# PBKDF benchmark: memory cost = 65536, iterations = 4, threads = 4 (took 52 ms)
# PBKDF benchmark: memory cost = 315076, iterations = 4, threads = 4 (took 261 ms)
# Benchmark returns argon2id() 4 iterations, 65536 memory, 4 threads (for 512-bits key).
# Calculating attributes for LUKS2 keyslot 1.
# Acquiring write lock for device /tmp/header.img.
# Verifying lock handle for /tmp/header.img.
# Device /tmp/header.img WRITE lock taken.
# Checking context sequence id matches value stored on disk.
# Reusing open ro fd on device /tmp/header.img
# Running keyslot key derivation.
# Updating keyslot area [0x47000].
# Opening locked device /tmp/header.img
# Verifying locked device handle (regular file)
# Device size 16777216, offset 16777216.
# Device /tmp/header.img WRITE lock already held.
# Trying to write LUKS2 header (16384 bytes) at offset 0.
# Reusing open rw fd on device /tmp/header.img
# Checksum:3600aeb87da586f74cf113089e0e37faefe420338e89f24c65a18ba8ea329d37 (in-memory)
# Trying to write LUKS2 header (16384 bytes) at offset 16384.
# Reusing open rw fd on device /tmp/header.img
# Checksum:91a974803aa8ab158440983c51b9fdebb88b21240b168d1c4bb246a2443e00e1 (in-memory)
# Device /tmp/header.img WRITE lock released.
Key slot 1 created.
# Releasing crypt device /tmp/header.img context.
# Releasing device-mapper backend.
# Closing read only fd for /tmp/header.img.
# Closing read write fd for /tmp/header.img.
# Unlocking memory.
Command successful.

LUKS header information
Version:       	2
Epoch:         	4
Metadata area: 	16384 [bytes]
Keyslots area: 	16744448 [bytes]
UUID:          	49f5c9d2-00d3-4d5b-8a9a-0197077be6c9
Label:         	(no label)
Subsystem:     	(no subsystem)
Flags:       	(no flags)

Data segments:
  0: crypt
	offset: 0 [bytes]
	length: (whole device)
	cipher: aes-xts-plain64
	sector: 4096 [bytes]

Keyslots:
  0: luks2
	Key:        512 bits
	Priority:   normal
	Cipher:     aes-xts-plain64
	Cipher key: 512 bits
	PBKDF:      argon2id
	Time cost:  4
	Memory:     65536
	Threads:    4
	Salt:       a0 2f 35 ff 70 ab 22 d8 5f c8 93 29 63 8b 54 e9 
	            8a 18 f2 fe c6 dd 27 bf ba 61 07 2d 4a c0 9b f5 
	AF stripes: 4000
	AF hash:    sha512
	Area offset:32768 [bytes]
	Area length:258048 [bytes]
	Digest ID:  0
  1: luks2
	Key:        512 bits
	Priority:   normal
	Cipher:     aes-xts-plain64
	Cipher key: 512 bits
	PBKDF:      argon2id
	Time cost:  4
	Memory:     65536
	Threads:    4
	Salt:       a2 a0 a7 94 cb cc 61 84 cc 79 75 52 39 5a c1 4c 
	            1d 39 ee 2e f2 89 0c 53 81 e0 54 5e c9 1f 5a 5a 
	AF stripes: 4000
	AF hash:    sha256
	Area offset:290816 [bytes]
	Area length:258048 [bytes]
	Digest ID:  0
Tokens:
Digests:
  0: pbkdf2
	Hash:       sha512
	Iterations: 218089
	Salt:       1b 9a 78 f6 a5 fe 3d f7 70 8c be c8 a2 3a 4d 12 
	            1a aa 61 ff ad 56 d7 93 0b 93 15 10 b8 7a 6a af 
	Digest:     b8 15 55 0f 66 b2 4d bc 67 e3 a0 75 4a 4c b6 6f 
	            62 c3 22 c2 3c 11 9d a4 e7 4b 3f 63 bc d8 80 8e 
	            4f 16 58 61 cf 0e 8c a3 51 27 1c b1 ea 5a 02 fe 
	            1f 33 35 70 49 57 22 4e e5 63 9c 88 69 b4 1d 38 

[-- Attachment #3: reproduce_commands_without_hash.sh --]
[-- Type: application/x-shellscript, Size: 1972 bytes --]

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

end of thread, other threads:[~2022-09-17 18:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-09 22:50 sha256 in "AF hash" despite using sha512 during luksFormat doffloster
2022-09-10  5:25 ` Milan Broz
2022-09-10  7:26   ` doffloster
2022-09-10  9:21     ` Michael Kjörling
2022-09-10 10:28     ` Milan Broz
2022-09-10 12:53       ` doffloster
2022-09-15 14:17         ` Milan Broz
2022-09-17 18:15           ` doffloster
2022-09-10 10:34 ` Milan Broz
2022-09-10 12:56   ` doffloster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.