All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: grub-devel@gnu.org
Cc: Patrick Steinhardt <ps@pks.im>,
	Daniel Kiper <dkiper@net-space.pl>,
	Leif Lindholm <leif@nuviainc.com>,
	agraf@csgraf.de, pjones@redhat.com, mjg59@google.com,
	phcoder@gmail.com, Milan Broz <gmazyland@gmail.com>,
	Daniel Kiper <daniel.kiper@oracle.com>
Subject: [PATCH v3 5/5] luks2: Support key derival via Argon2
Date: Tue, 10 Mar 2020 19:58:32 +0100	[thread overview]
Message-ID: <012e3d44221f6ba55930a1d5e1be9347d0c6e265.1583866610.git.ps@pks.im> (raw)
In-Reply-To: <cover.1583866610.git.ps@pks.im>

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 <ps@pks.im>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 Makefile.util.def           |  6 +++++-
 grub-core/Makefile.core.def |  2 +-
 grub-core/disk/luks2.c      | 13 +++++++++++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/Makefile.util.def b/Makefile.util.def
index 1e0799a68..f07cf9deb 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,10 @@ 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/core.c;
+  common = grub-core/lib/argon2/ref.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 30147a899..9e4c89791 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1204,7 +1204,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..3c79f14aa 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,16 @@ 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 = argon2_hash (k->kdf.u.argon2.time, k->kdf.u.argon2.memory, k->kdf.u.argon2.cpus,
+			   passphrase, passphraselen, salt, saltlen, area_key, k->area.key_size,
+			   k->kdf.type == LUKS2_KDF_TYPE_ARGON2I ? Argon2_i : Argon2_id,
+			   ARGON2_VERSION_NUMBER);
+        if (ret)
+	  {
+	    grub_dprintf ("luks2", "Argon2 failed: %s\n", argon2_error_message (ret));
+	    goto err;
+	  }
+        break;
       case LUKS2_KDF_TYPE_PBKDF2:
 	hash = grub_crypto_lookup_md_by_name (k->kdf.u.pbkdf2.hash);
 	if (!hash)
-- 
2.25.1



  parent reply	other threads:[~2020-03-10 18:58 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-10 18:58 [PATCH v3 0/5] Support Argon2 KDF in LUKS2 Patrick Steinhardt
2020-03-10 18:58 ` [PATCH v3 1/5] efi: Always try to allocate heap size of 1.6GB Patrick Steinhardt
2020-03-13 12:42   ` Daniel Kiper
2020-03-13 12:55   ` Leif Lindholm
2020-03-13 13:59     ` Daniel Kiper
2020-03-15 14:01       ` Patrick Steinhardt
2020-03-15 10:14     ` Patrick Steinhardt
2020-03-15 10:41     ` Patrick Steinhardt
2020-03-10 18:58 ` [PATCH v3 2/5] types.h: add UINT-related macros needed for Argon2 Patrick Steinhardt
2020-03-13 12:49   ` Daniel Kiper
2020-03-10 18:58 ` [PATCH v3 3/5] argon2: Import Argon2 from cryptsetup Patrick Steinhardt
2020-03-10 20:44   ` Eli Schwartz
2020-03-10 21:42     ` Patrick Steinhardt
2020-03-13 13:13   ` Daniel Kiper
2020-03-16 17:21     ` Daniel Kiper
2020-03-16 17:52       ` Patrick Steinhardt
2020-03-16 20:03         ` Daniel Kiper
2020-03-17  5:51           ` Patrick Steinhardt
2020-03-17 10:45             ` Leif Lindholm
2020-03-16 19:57       ` Konrad Rzeszutek Wilk
2020-03-18 11:52         ` Patrick Steinhardt
2021-01-19  0:07   ` Petr Vorel
2021-01-19 11:10     ` Dmitry
2021-01-19 13:06       ` Petr Vorel
2021-01-19 15:42         ` Matt Turner
2021-01-19 19:03         ` Patrick Steinhardt
2021-01-19 19:31           ` Petr Vorel
2021-01-21 14:49             ` IS: GRUB release cycle: WAS: " Daniel Kiper
2021-01-21 21:30               ` Petr Vorel
2021-01-26 13:00                 ` Daniel Kiper
2021-01-26 19:57                   ` Petr Vorel
2021-08-08 13:58   ` [PATCH v4 0/5] Support Argon2 KDF in LUKS2 Patrick Steinhardt
2021-08-08 13:58     ` [PATCH v4 1/5] kern: dl: Allow modules under CC0 license Patrick Steinhardt
2021-08-08 15:03       ` Petr Vorel
2021-08-08 13:58     ` [PATCH v4 2/5] types.h: Add UINT-related macros needed for Argon2 Patrick Steinhardt
2021-08-08 13:58     ` [PATCH v4 3/5] argon2: Import reference implementation of Argon2 Patrick Steinhardt
2021-08-08 13:58     ` [PATCH v4 4/5] luks2: Discern Argon2i and Argon2id Patrick Steinhardt
2021-08-08 13:59     ` [PATCH v4 5/5] luks2: Support key derival via Argon2 Patrick Steinhardt
2020-03-10 18:58 ` [PATCH v3 4/5] luks2: Discern Argon2i and Argon2id Patrick Steinhardt
2020-03-10 18:58 ` Patrick Steinhardt [this message]
2020-03-25 17:12 ` [PATCH v3 0/5] Support Argon2 KDF in LUKS2 Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=012e3d44221f6ba55930a1d5e1be9347d0c6e265.1583866610.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=agraf@csgraf.de \
    --cc=daniel.kiper@oracle.com \
    --cc=dkiper@net-space.pl \
    --cc=gmazyland@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=leif@nuviainc.com \
    --cc=mjg59@google.com \
    --cc=phcoder@gmail.com \
    --cc=pjones@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.