diff options
author | Aidan Dang <dang@aidan.gg> | 2022-12-04 02:26:13 +1100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2022-12-06 15:56:11 +0100 |
commit | b04ff66b426c6cffa3b27d0448e633ebf6aba147 (patch) | |
tree | f378478e40376f647ed2f554b245e1180c349116 /src | |
parent | 64e7a14146cd1f66a8b0865adf7c3495c1b5c4e9 (diff) | |
download | systemd-b04ff66b426c6cffa3b27d0448e633ebf6aba147.tar.gz |
Implement --luks-pbkdf-force-iterations for homed
Diffstat (limited to 'src')
-rw-r--r-- | src/home/homectl.c | 4 | ||||
-rw-r--r-- | src/home/homework-luks.c | 6 | ||||
-rw-r--r-- | src/shared/user-record-show.c | 2 | ||||
-rw-r--r-- | src/shared/user-record.c | 14 | ||||
-rw-r--r-- | src/shared/user-record.h | 2 |
5 files changed, 27 insertions, 1 deletions
diff --git a/src/home/homectl.c b/src/home/homectl.c index 3e846e370a..a6d25c84fc 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -2392,6 +2392,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_IO_WEIGHT, ARG_LUKS_PBKDF_TYPE, ARG_LUKS_PBKDF_HASH_ALGORITHM, + ARG_LUKS_PBKDF_FORCE_ITERATIONS, ARG_LUKS_PBKDF_TIME_COST, ARG_LUKS_PBKDF_MEMORY_COST, ARG_LUKS_PBKDF_PARALLEL_THREADS, @@ -2473,6 +2474,7 @@ static int parse_argv(int argc, char *argv[]) { { "luks-volume-key-size", required_argument, NULL, ARG_LUKS_VOLUME_KEY_SIZE }, { "luks-pbkdf-type", required_argument, NULL, ARG_LUKS_PBKDF_TYPE }, { "luks-pbkdf-hash-algorithm", required_argument, NULL, ARG_LUKS_PBKDF_HASH_ALGORITHM }, + { "luks-pbkdf-force-iterations", required_argument, NULL, ARG_LUKS_PBKDF_FORCE_ITERATIONS }, { "luks-pbkdf-time-cost", required_argument, NULL, ARG_LUKS_PBKDF_TIME_COST }, { "luks-pbkdf-memory-cost", required_argument, NULL, ARG_LUKS_PBKDF_MEMORY_COST }, { "luks-pbkdf-parallel-threads", required_argument, NULL, ARG_LUKS_PBKDF_PARALLEL_THREADS }, @@ -3093,10 +3095,12 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_LUKS_VOLUME_KEY_SIZE: + case ARG_LUKS_PBKDF_FORCE_ITERATIONS: case ARG_LUKS_PBKDF_PARALLEL_THREADS: case ARG_RATE_LIMIT_BURST: { const char *field = c == ARG_LUKS_VOLUME_KEY_SIZE ? "luksVolumeKeySize" : + c == ARG_LUKS_PBKDF_FORCE_ITERATIONS ? "luksPbkdfForceIterations" : c == ARG_LUKS_PBKDF_PARALLEL_THREADS ? "luksPbkdfParallelThreads" : c == ARG_RATE_LIMIT_BURST ? "rateLimitBurst" : NULL; unsigned n; diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 39ad56808d..4d04359740 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -1670,12 +1670,16 @@ static struct crypt_pbkdf_type* build_good_pbkdf(struct crypt_pbkdf_type *buffer assert(buffer); assert(hr); + bool benchmark = user_record_luks_pbkdf_force_iterations(hr) == UINT64_MAX; + *buffer = (struct crypt_pbkdf_type) { .hash = user_record_luks_pbkdf_hash_algorithm(hr), .type = user_record_luks_pbkdf_type(hr), - .time_ms = user_record_luks_pbkdf_time_cost_usec(hr) / USEC_PER_MSEC, + .time_ms = benchmark ? user_record_luks_pbkdf_time_cost_usec(hr) / USEC_PER_MSEC : 0, + .iterations = benchmark ? 0 : user_record_luks_pbkdf_force_iterations(hr), .max_memory_kb = user_record_luks_pbkdf_memory_cost(hr) / 1024, .parallel_threads = user_record_luks_pbkdf_parallel_threads(hr), + .flags = benchmark ? 0 : CRYPT_PBKDF_NO_BENCHMARK, }; return buffer; diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c index e89c0de120..da181c6078 100644 --- a/src/shared/user-record-show.c +++ b/src/shared/user-record-show.c @@ -314,6 +314,8 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { printf(" PBKDF Type: %s\n", hr->luks_pbkdf_type); if (hr->luks_pbkdf_hash_algorithm) printf(" PBKDF Hash: %s\n", hr->luks_pbkdf_hash_algorithm); + if (hr->luks_pbkdf_force_iterations != UINT64_MAX) + printf(" PBKDF Iters: %" PRIu64 "\n", hr->luks_pbkdf_force_iterations); if (hr->luks_pbkdf_time_cost_usec != UINT64_MAX) printf(" PBKDF Time: %s\n", FORMAT_TIMESPAN(hr->luks_pbkdf_time_cost_usec, 0)); if (hr->luks_pbkdf_memory_cost != UINT64_MAX) diff --git a/src/shared/user-record.c b/src/shared/user-record.c index 84cbdb1d30..06bc699572 100644 --- a/src/shared/user-record.c +++ b/src/shared/user-record.c @@ -55,6 +55,7 @@ UserRecord* user_record_new(void) { .luks_discard = -1, .luks_offline_discard = -1, .luks_volume_key_size = UINT64_MAX, + .luks_pbkdf_force_iterations = UINT64_MAX, .luks_pbkdf_time_cost_usec = UINT64_MAX, .luks_pbkdf_memory_cost = UINT64_MAX, .luks_pbkdf_parallel_threads = UINT64_MAX, @@ -1213,6 +1214,7 @@ static int dispatch_per_machine(const char *name, JsonVariant *variant, JsonDisp { "luksVolumeKeySize", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_volume_key_size), 0 }, { "luksPbkdfHashAlgorithm", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, luks_pbkdf_hash_algorithm), JSON_SAFE }, { "luksPbkdfType", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, luks_pbkdf_type), JSON_SAFE }, + { "luksPbkdfForceIterations", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_force_iterations), 0 }, { "luksPbkdfTimeCostUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_time_cost_usec), 0 }, { "luksPbkdfMemoryCost", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_memory_cost), 0 }, { "luksPbkdfParallelThreads", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_parallel_threads), 0 }, @@ -1566,6 +1568,7 @@ int user_record_load(UserRecord *h, JsonVariant *v, UserRecordLoadFlags load_fla { "luksVolumeKeySize", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_volume_key_size), 0 }, { "luksPbkdfHashAlgorithm", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, luks_pbkdf_hash_algorithm), JSON_SAFE }, { "luksPbkdfType", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, luks_pbkdf_type), JSON_SAFE }, + { "luksPbkdfForceIterations", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_force_iterations), 0 }, { "luksPbkdfTimeCostUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_time_cost_usec), 0 }, { "luksPbkdfMemoryCost", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_memory_cost), 0 }, { "luksPbkdfParallelThreads", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, luks_pbkdf_parallel_threads), 0 }, @@ -1842,6 +1845,17 @@ const char* user_record_luks_pbkdf_type(UserRecord *h) { return h->luks_pbkdf_type ?: "argon2id"; } +uint64_t user_record_luks_pbkdf_force_iterations(UserRecord *h) { + assert(h); + + /* propagate default "benchmark" mode as itself */ + if (h->luks_pbkdf_force_iterations == UINT64_MAX) + return UINT64_MAX; + + /* clamp everything else to actually accepted number of iterations of libcryptsetup */ + return CLAMP(h->luks_pbkdf_force_iterations, 1U, UINT32_MAX); +} + uint64_t user_record_luks_pbkdf_time_cost_usec(UserRecord *h) { assert(h); diff --git a/src/shared/user-record.h b/src/shared/user-record.h index 47f4035d45..73fb86cc94 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -309,6 +309,7 @@ typedef struct UserRecord { uint64_t luks_volume_key_size; char *luks_pbkdf_hash_algorithm; char *luks_pbkdf_type; + uint64_t luks_pbkdf_force_iterations; uint64_t luks_pbkdf_time_cost_usec; uint64_t luks_pbkdf_memory_cost; uint64_t luks_pbkdf_parallel_threads; @@ -394,6 +395,7 @@ const char *user_record_luks_cipher(UserRecord *h); const char *user_record_luks_cipher_mode(UserRecord *h); uint64_t user_record_luks_volume_key_size(UserRecord *h); const char* user_record_luks_pbkdf_type(UserRecord *h); +uint64_t user_record_luks_pbkdf_force_iterations(UserRecord *h); usec_t user_record_luks_pbkdf_time_cost_usec(UserRecord *h); uint64_t user_record_luks_pbkdf_memory_cost(UserRecord *h); uint64_t user_record_luks_pbkdf_parallel_threads(UserRecord *h); |