One addition with LUKS2 was support of the key derival function Argon2 in addition to the previously supported PBKDF2 algortihm. In order to ease getting in initial support for LUKS2, we only reused infrastructure to support LUKS2 with PBKDF2, but left out Argon2.
This commit now introduces support for Argon2 to enable decryption of LUKS2 partitions using this key derival function. As the code for Argon2 has been added in a previous commit in this series, adding support is now trivial. Signed-off-by: Patrick Steinhardt <p...@pks.im> --- Makefile.util.def | 4 +++- grub-core/Makefile.core.def | 2 +- grub-core/disk/luks2.c | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile.util.def b/Makefile.util.def index 94336392b..e0c98aa1c 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -3,7 +3,7 @@ AutoGen definitions Makefile.tpl; library = { name = libgrubkern.a; cflags = '$(CFLAGS_GNULIB)'; - cppflags = '$(CPPFLAGS_GNULIB) -I$(srcdir)/grub-core/lib/json'; + cppflags = '$(CPPFLAGS_GNULIB) -I$(srcdir)/grub-core/lib/json -I$(srcdir)/grub-core/lib/argon2'; common = util/misc.c; common = grub-core/kern/command.c; @@ -36,6 +36,8 @@ library = { common = grub-core/kern/misc.c; common = grub-core/kern/partition.c; common = grub-core/lib/crypto.c; + common = grub-core/lib/argon2/argon2.c; + common = grub-core/lib/argon2/blake2/blake2b.c; common = grub-core/lib/json/json.c; common = grub-core/disk/luks.c; common = grub-core/disk/luks2.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index b9e7a4171..914325369 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1202,7 +1202,7 @@ module = { common = disk/luks2.c; common = lib/gnulib/base64.c; cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; - cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/json'; + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/json -I$(srcdir)/lib/argon2'; }; module = { diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index 767631198..9c5b416c4 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -27,6 +27,7 @@ #include <grub/partition.h> #include <grub/i18n.h> +#include <argon2.h> #include <base64.h> #include <json.h> @@ -435,8 +436,17 @@ luks2_decrypt_key (grub_uint8_t *out_key, { case LUKS2_KDF_TYPE_ARGON2I: case LUKS2_KDF_TYPE_ARGON2ID: - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported"); - goto err; + ret = grub_crypto_argon2 (passphrase, passphraselen, salt, saltlen, + k->kdf.u.argon2.time, k->kdf.u.argon2.memory, k->kdf.u.argon2.cpus, + k->kdf.type == LUKS2_KDF_TYPE_ARGON2I ? GRUB_ARGON2_I : GRUB_ARGON2_ID, + GRUB_ARGON2_VERSION_NUMBER, + area_key, k->area.key_size); + if (ret) + { + grub_dprintf ("luks2", "Argon2 failed: %s\n", grub_errmsg); + goto err; + } + break; case LUKS2_KDF_TYPE_PBKDF2: hash = grub_crypto_lookup_md_by_name (k->kdf.u.pbkdf2.hash); if (!hash) -- 2.25.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel