Return-Path: Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (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 ; Fri, 15 Feb 2019 13:12:22 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id t18so10134350wrx.2 for ; Fri, 15 Feb 2019 04:12:22 -0800 (PST) References: <44be54bb-10ce-813d-cfc0-8a97fc097a43@linux.ibm.com> <20cb81f4-f170-83a1-76e5-54a973adf447@gmail.com> <3f2e1d05-fcde-adf2-d519-dcef67ddad82@linux.ibm.com> From: Milan Broz Message-ID: <3f1a752b-249e-d6c6-c47d-7365a0713660@gmail.com> Date: Fri, 15 Feb 2019 13:12:19 +0100 MIME-Version: 1.0 In-Reply-To: <3f2e1d05-fcde-adf2-d519-dcef67ddad82@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dm-crypt] How to get PBKDF settings of an existing key slot via libcryptsetup ? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ingo Franzki , dm-crypt@saout.de 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