Re: How to get PBKDF settings of an existing key slot via libcryptsetup ?

Milan Broz <[email protected]>
Newsgroups gmane.linux.kernel.device-mapper.dm-crypt
Message-ID <[email protected]>
Hello Ingo,

On 14/02/2019 10:28, Ingo Franzki wrote:
> I have now added support for calling crypt_keyslot_get_pbkdf(). 
> Works great, with one little exception:
> 
> When getting a PBKDF from a key slot, the field time_ms is zero. 

Yes, it is zero here, because it is the time intended for a benchmark.
(IOW it says: benchmark the PBKDF and set parameters such a way, that unlocking should take approximately this time.)

This requested time is not stored in keyslot (only the final calculated values are stored here).

> When setting this PBKDF using crypt_set_pbkdf_type() I get an error that time can not be zero:
> Message "Requested PBKDF target time cannot be zero." from function verify_pbkdf_params().
> 
> Looking at function LUKS2_keyslot_pbkdf() it seems that there is a little copy & paste error:
> 
> 	if (json_object_object_get_ex(jobj_kdf, "iterations", &jobj))
> 		pbkdf->iterations = json_object_get_int(jobj);
> 	if (json_object_object_get_ex(jobj_kdf, "time", &jobj))
> 		pbkdf->iterations = json_object_get_int(jobj); <--- should set field time_ms, not iterations

The code is correct ;-)

It is tricky, for PBKDF2 it is named "iterations" , for Argon it is "time" (means time cost),
but it is in the end stored in the same pbkdf->iterations value.

Only one of the value is in JSON, so it will not overwrite..

I admit this is not the best solution but we had already stable data structure in API.

> Not a big deal, I can set time_ms manually before calling crypt_set_pbkdf_type() when it is zero.

If you want to run benchmark, then you need to set time_ms to requested value (default is 2000 ms).

The other option is to force reuse the same parameters and skip benchmark, then you can keep
time_ms value to 0 but you have to set pbkdf->flags bit CRYPT_PBKDF_NO_BENCHMARK.

Milan
_______________________________________________
dm-crypt mailing list
[email protected]
https://www.saout.de/mailman/listinfo/dm-crypt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.