0007-Compile-with-Argon2id-support.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From 268da8d0ccce822ffa4c2d9d35fe717245daa726 Mon Sep 17 00:00:00 2001
  2. From: Ax333l <main@axelen.xyz>
  3. Date: Thu, 17 Aug 2023 00:00:00 +0000
  4. Subject: [PATCH 07/22] Compile with Argon2id support
  5. Signed-off-by: Nicholas Johnson <nick@nicholasjohnson.ch>
  6. ---
  7. Makefile.util.def | 6 +++++-
  8. grub-core/Makefile.core.def | 2 +-
  9. grub-core/disk/luks2.c | 13 +++++++++++--
  10. 3 files changed, 17 insertions(+), 4 deletions(-)
  11. diff --git a/Makefile.util.def b/Makefile.util.def
  12. index 0f74a1680..5a15e5637 100644
  13. --- a/Makefile.util.def
  14. +++ b/Makefile.util.def
  15. @@ -3,7 +3,7 @@ AutoGen definitions Makefile.tpl;
  16. library = {
  17. name = libgrubkern.a;
  18. cflags = '$(CFLAGS_GNULIB)';
  19. - cppflags = '$(CPPFLAGS_GNULIB) -I$(srcdir)/grub-core/lib/json';
  20. + cppflags = '$(CPPFLAGS_GNULIB) -I$(srcdir)/grub-core/lib/json -I$(srcdir)/grub-core/lib/argon2';
  21. common = util/misc.c;
  22. common = grub-core/kern/command.c;
  23. @@ -36,6 +36,10 @@ library = {
  24. common = grub-core/kern/misc.c;
  25. common = grub-core/kern/partition.c;
  26. common = grub-core/lib/crypto.c;
  27. + common = grub-core/lib/argon2/argon2.c;
  28. + common = grub-core/lib/argon2/core.c;
  29. + common = grub-core/lib/argon2/ref.c;
  30. + common = grub-core/lib/argon2/blake2/blake2b.c;
  31. common = grub-core/lib/json/json.c;
  32. common = grub-core/disk/luks.c;
  33. common = grub-core/disk/luks2.c;
  34. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
  35. index 452f11b20..5c1af8682 100644
  36. --- a/grub-core/Makefile.core.def
  37. +++ b/grub-core/Makefile.core.def
  38. @@ -1242,7 +1242,7 @@ module = {
  39. common = disk/luks2.c;
  40. common = lib/gnulib/base64.c;
  41. cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
  42. - cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/json';
  43. + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/json -I$(srcdir)/lib/argon2';
  44. };
  45. module = {
  46. diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
  47. index bc818ea69..5b9eaa599 100644
  48. --- a/grub-core/disk/luks2.c
  49. +++ b/grub-core/disk/luks2.c
  50. @@ -27,6 +27,7 @@
  51. #include <grub/partition.h>
  52. #include <grub/i18n.h>
  53. +#include <argon2.h>
  54. #include <base64.h>
  55. #include <json.h>
  56. @@ -462,8 +463,16 @@ luks2_decrypt_key (grub_uint8_t *out_key,
  57. {
  58. case LUKS2_KDF_TYPE_ARGON2I:
  59. case LUKS2_KDF_TYPE_ARGON2ID:
  60. - ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported");
  61. - goto err;
  62. + ret = argon2_hash (k->kdf.u.argon2.time, k->kdf.u.argon2.memory, k->kdf.u.argon2.cpus,
  63. + passphrase, passphraselen, salt, saltlen, area_key, k->area.key_size,
  64. + k->kdf.type == LUKS2_KDF_TYPE_ARGON2I ? Argon2_i : Argon2_id,
  65. + ARGON2_VERSION_NUMBER);
  66. + if (ret)
  67. + {
  68. + grub_dprintf ("luks2", "Argon2 failed: %s\n", argon2_error_message (ret));
  69. + goto err;
  70. + }
  71. + break;
  72. case LUKS2_KDF_TYPE_PBKDF2:
  73. hash = grub_crypto_lookup_md_by_name (k->kdf.u.pbkdf2.hash);
  74. if (!hash)
  75. --
  76. 2.39.2