0006-Error-on-missing-Argon2id-parameters.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 916de62553b3bcc4a565e1ea8f562031fb2a7b0f 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 06/14] Error on missing Argon2id parameters
  5. Signed-off-by: Nicholas Johnson <nick@nicholasjohnson.ch>
  6. ---
  7. grub-core/disk/luks2.c | 13 ++++++++-----
  8. 1 file changed, 8 insertions(+), 5 deletions(-)
  9. diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
  10. index d5106402f..bc818ea69 100644
  11. --- a/grub-core/disk/luks2.c
  12. +++ b/grub-core/disk/luks2.c
  13. @@ -38,6 +38,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
  14. enum grub_luks2_kdf_type
  15. {
  16. LUKS2_KDF_TYPE_ARGON2I,
  17. + LUKS2_KDF_TYPE_ARGON2ID,
  18. LUKS2_KDF_TYPE_PBKDF2
  19. };
  20. typedef enum grub_luks2_kdf_type grub_luks2_kdf_type_t;
  21. @@ -90,7 +91,7 @@ struct grub_luks2_keyslot
  22. grub_int64_t time;
  23. grub_int64_t memory;
  24. grub_int64_t cpus;
  25. - } argon2i;
  26. + } argon2;
  27. struct
  28. {
  29. const char *hash;
  30. @@ -160,10 +161,11 @@ luks2_parse_keyslot (grub_luks2_keyslot_t *out, const grub_json_t *keyslot)
  31. return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing or invalid KDF");
  32. else if (!grub_strcmp (type, "argon2i") || !grub_strcmp (type, "argon2id"))
  33. {
  34. - out->kdf.type = LUKS2_KDF_TYPE_ARGON2I;
  35. - if (grub_json_getint64 (&out->kdf.u.argon2i.time, &kdf, "time") ||
  36. - grub_json_getint64 (&out->kdf.u.argon2i.memory, &kdf, "memory") ||
  37. - grub_json_getint64 (&out->kdf.u.argon2i.cpus, &kdf, "cpus"))
  38. + out->kdf.type = !grub_strcmp (type, "argon2i")
  39. + ? LUKS2_KDF_TYPE_ARGON2I : LUKS2_KDF_TYPE_ARGON2ID;
  40. + if (grub_json_getint64 (&out->kdf.u.argon2.time, &kdf, "time") ||
  41. + grub_json_getint64 (&out->kdf.u.argon2.memory, &kdf, "memory") ||
  42. + grub_json_getint64 (&out->kdf.u.argon2.cpus, &kdf, "cpus"))
  43. return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing Argon2i parameters");
  44. }
  45. else if (!grub_strcmp (type, "pbkdf2"))
  46. @@ -459,6 +461,7 @@ luks2_decrypt_key (grub_uint8_t *out_key,
  47. switch (k->kdf.type)
  48. {
  49. case LUKS2_KDF_TYPE_ARGON2I:
  50. + case LUKS2_KDF_TYPE_ARGON2ID:
  51. ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported");
  52. goto err;
  53. case LUKS2_KDF_TYPE_PBKDF2:
  54. --
  55. 2.39.2