This patch series imports the Argon2 code and tests from libgcrypt and
adds Argon2 support to LUKS2.
- Patch 1~6 import kdf.c from libgcrypt and extract the Argon2 related
functions. The _gcry_kdf_* functions are also imported to make it
easier to support other KDF functions when necessary.
- Patch 7 introduces grub_crypto_argon2().
- Patch 8 leverages grub_crypto_argon2() to add Argon2 support to LUKS2.
- Patch 9 and 10 integrates the Argon2 tests from libgcrypt into
functional_test.
- Patch 11 changes the default KDF of the LUKS2 test to Argon2id.
- Patch 12 documents argon2 and argon2_test modules.
- Patch 13 reduces Argon2 computation time by introducing a faster
grub_memcpy() implementation for aligned buffers. Per my test, this
patch lowers the decryption time from 22s to 12s.
v5:
- Updating the commit messages of patch 2, 3, and 13
- Tweaking the patch order slightly
- Replacing 'unsigned long' with 'grub_addr_t' in grub_memcpy() and
__memcpy_aligned()
- Adding the length check before calling __memcpy_aligned()
v4:
- Handling the error from argon2_blake2b_512_hash_buffers()
- Implementing a faster grub_memcpy() to reduce Argon2 computation time
v3:
- Updating comments in import_gcry.py
- Splitting the kdf build patch into 3 smaller patches
- Fixing the build error on 32-bit platforms
- Adjusting the order of 'ldadd' in Makefile.util.def
- Fixing the error messages in luks2_parse_keyslot()
v2:
- Import Argon2 code differently to improve maintainability
* Updating import_gcry.py to import Argon2 and _gcry_kdf_* functions
from kdf.c instead of extracting the code manually
* Implementing grub_crypto_argon2() with the _gcry_kdf_* functions to
avoid the GCRY flags when building argon2.c
* Building argon2.c inside libgrubkernel.a since the GCRY flags are not
needed anymore
Gary Lin (13):
util/import_gcry: Import kdf.c for Argon2
crypto: Update crypto.h for libgcrypt KDF functions
libgcrypt/kdf: Implement hash_buffers() for BLAKE2b-512
libgcrypt/kdf: Get rid of gpg_err_code_from_errno()
libgcrypt/kdf: Remove unsupported KDFs
libgcrypt/kdf: Fix 64-bit modulus on 32-bit platforms
argon2: Introduce grub_crypto_argon2()
disk/luks2: Add Argon2 support
Import Argon2 tests from libgcrypt
Integrate Argon2 tests into functional_test
tests/util/grub-fs-tester: Use Argon2id for LUKS2 test
docs: Document argon2 and argon2_test
kern/misc: Implement faster grub_memcpy() for aligned buffers
Makefile.util.def | 55 +++---
conf/Makefile.extra-dist | 4 +
docs/grub.texi | 11 ++
grub-core/Makefile.core.def | 10 ++
grub-core/disk/luks2.c | 40 ++++-
grub-core/kern/compiler-rt.c | 8 +-
grub-core/kern/misc.c | 31 ++++
grub-core/lib/argon2.c | 52 ++++++
.../09-blake2b-hash-buffers.patch | 63 +++++++
.../10-kdf-use-GPG-errs.patch | 48 +++++
.../11-kdf-remove-unsupported-kdfs.patch | 166 ++++++++++++++++++
.../12-kdf-use-grub_divmod64.patch | 79 +++++++++
grub-core/tests/argon2_test.c | 139 +++++++++++++++
grub-core/tests/lib/functional_test.c | 1 +
include/grub/crypto.h | 49 ++++++
include/grub/misc.h | 8 +-
tests/util/grub-fs-tester.in | 10 +-
util/import_gcry.py | 31 +++-
18 files changed, 758 insertions(+), 47 deletions(-)
create mode 100644 grub-core/lib/argon2.c
create mode 100644
grub-core/lib/libgcrypt-patches/09-blake2b-hash-buffers.patch
create mode 100644 grub-core/lib/libgcrypt-patches/10-kdf-use-GPG-errs.patch
create mode 100644
grub-core/lib/libgcrypt-patches/11-kdf-remove-unsupported-kdfs.patch
create mode 100644
grub-core/lib/libgcrypt-patches/12-kdf-use-grub_divmod64.patch
create mode 100644 grub-core/tests/argon2_test.c
Range-diff against v4:
1: 4c2b3fec8 ! 1: 00cfb3cb0 util/import_gcry: Import kdf.c for Argon2
@@ Commit message
the Argon2 implementation, all unrelated functions have been removed.
Signed-off-by: Gary Lin <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## util/import_gcry.py ##
@@ util/import_gcry.py: with codecs.open (os.path.join (cipher_dir_out,
"crypto.lst"), "w", "utf-8") as
2: 210b6292b ! 2: 7be62dd80 crypto: Update crypto.h for libgcrypt KDF
functions
@@ Metadata
## Commit message ##
crypto: Update crypto.h for libgcrypt KDF functions
- Add the following items to crypto.h
- - more GPG error types
- - _gcry_digest_spec_blake2b_512 for Argon2
- - KDF algorithm IDs for Argon2
- - prototypes of '_gcry_kdf_*' functions
+ This commit introduces the necessary changes to crypto.h in prepartion
+ for implementing Argon2 support via the generic KDF functions
+ ('_gcry_kdf_*').
+
+ - Adding new GPG error types required by kdf.c
+ - Declaring _gcry_digest_spec_blake2b_512 to enable BLAKE2b-512 digest
+ calculations
+ - Defining the gcrypt KDF algorithm IDs for Argon2
+ - Adding the prototypes of '_gcry_kdf_*' functions
Signed-off-by: Gary Lin <[email protected]>
- Reviewed-by: Vladimir Serbinenko<[email protected]>
+ Reviewed-by: Vladimir Serbinenko <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## include/grub/crypto.h ##
@@ include/grub/crypto.h: typedef enum
@@ include/grub/crypto.h: typedef enum
GPG_ERR_WEAK_KEY,
GPG_ERR_WRONG_KEY_USAGE,
GPG_ERR_WRONG_PUBKEY_ALGO,
-@@ include/grub/crypto.h: extern gcry_md_spec_t _gcry_digest_spec_sha1;
- extern gcry_md_spec_t _gcry_digest_spec_sha256;
+@@ include/grub/crypto.h: extern gcry_md_spec_t _gcry_digest_spec_sha256;
+ extern gcry_md_spec_t _gcry_digest_spec_sha384;
extern gcry_md_spec_t _gcry_digest_spec_sha512;
extern gcry_md_spec_t _gcry_digest_spec_crc32;
+extern gcry_md_spec_t _gcry_digest_spec_blake2b_512;
3: 3b72e07b8 ! 3: 9b94c223e libgcrypt/kdf: Implement
blake2b_512.hash_buffers()
@@ Metadata
Author: Gary Lin <[email protected]>
## Commit message ##
- libgcrypt/kdf: Implement blake2b_512.hash_buffers()
+ libgcrypt/kdf: Implement hash_buffers() for BLAKE2b-512
- Add argon2_blake2b_512_hash_buffers() as the replacement of
- _gcry_digest_spec_blake2b_512.hash_buffers().
+ The hash_buffers() functions are disabled in GRUB by default but the
+ Argon2 implementation requires hash_buffers() for BLAKE2b-512.
+
+ This commit implements argon2_blake2b_512_hash_buffers() as the
+ replacement of _gcry_digest_spec_blake2b_512.hash_buffers().
Signed-off-by: Gary Lin <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## conf/Makefile.extra-dist ##
@@ conf/Makefile.extra-dist: EXTRA_DIST +=
grub-core/lib/libgcrypt-patches/05_disable_rsa_shake.patch
4: d90a709b1 ! 4: 6e1b27baa libgcrypt/kdf: Get rid of
gpg_err_code_from_errno()
@@ Commit message
with GPG_ERR_* to avoid the build errors.
Signed-off-by: Gary Lin <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## conf/Makefile.extra-dist ##
@@ conf/Makefile.extra-dist: EXTRA_DIST +=
grub-core/lib/libgcrypt-patches/06_blake.patch
5: 5980e8a1a ! 5: 6450b2d19 libgcrypt/kdf: Remove unsupported KDFs
@@ Commit message
Clean up _gcry_kdf_*() to remove unsupported KDFs.
Signed-off-by: Gary Lin <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## conf/Makefile.extra-dist ##
@@ conf/Makefile.extra-dist: EXTRA_DIST +=
grub-core/lib/libgcrypt-patches/07_disable_64div.patch
6: 6f3a415ca ! 6: e8caa69b4 libgcrypt/kdf: Fix 64-bit modulus on 32-bit
platforms
@@ Commit message
32-bit platforms.
Signed-off-by: Gary Lin <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## conf/Makefile.extra-dist ##
@@ conf/Makefile.extra-dist: EXTRA_DIST +=
grub-core/lib/libgcrypt-patches/08_sexp_leak.patch
7: 8298d3139 ! 7: 3ff651364 argon2: Introduce grub_crypto_argon2()
@@ Commit message
linker can discover those functions.
Signed-off-by: Gary Lin <[email protected]>
- Reviewed-by: Vladimir Serbinenko<[email protected]>
+ Reviewed-by: Vladimir Serbinenko <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## Makefile.util.def ##
@@ Makefile.util.def: library = {
10: 3bc593992 ! 8: 2818c8bf6 disk/luks2: Add Argon2 support
@@ Commit message
Signed-off-by: Gary Lin <[email protected]>
Tested-By: Waldemar Brodkorb <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## grub-core/disk/luks2.c ##
@@ grub-core/disk/luks2.c: GRUB_MOD_LICENSE ("GPLv3+");
8: e3ff82e7c ! 9: 41c93e165 Import Argon2 tests from libgcrypt
@@ Commit message
Signed-off-by: Gary Lin <[email protected]>
Tested-By: Waldemar Brodkorb <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## grub-core/tests/argon2_test.c (new) ##
@@
9: 168a8d24b ! 10: 9c14beff1 Integrate Argon2 tests into functional_test
@@ Commit message
Signed-off-by: Gary Lin <[email protected]>
Tested-By: Waldemar Brodkorb <[email protected]>
- Reviewed-by: Vladimir Serbinenko<[email protected]>
+ Reviewed-by: Vladimir Serbinenko <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## grub-core/Makefile.core.def ##
@@ grub-core/Makefile.core.def: module = {
11: 1fb5cac29 ! 11: 81a48124e tests/util/grub-fs-tester: Use Argon2id for
LUKS2 test
@@ Commit message
Signed-off-by: Gary Lin <[email protected]>
Tested-By: Waldemar Brodkorb <[email protected]>
- Reviewed-by: Vladimir Serbinenko<[email protected]>
+ Reviewed-by: Vladimir Serbinenko <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## tests/util/grub-fs-tester.in ##
@@ tests/util/grub-fs-tester.in: for LOGSECSIZE in $(range
"$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
12: 840cf2fb0 ! 12: 42397663d docs: Document argon2 and argon2_test
@@ Commit message
Signed-off-by: Gary Lin <[email protected]>
Tested-By: Waldemar Brodkorb <[email protected]>
- Reviewed-by: Vladimir Serbinenko<[email protected]>
+ Reviewed-by: Vladimir Serbinenko <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## docs/grub.texi ##
@@ docs/grub.texi: Modules can be loaded via the @command{insmod}
(@pxref{insmod}) command.
13: 1fbd2a278 ! 13: 0212dc2ef kern/misc: Implement faster grub_memcpy() for
aligned buffers
@@ Commit message
kern/misc: Implement faster grub_memcpy() for aligned buffers
When both "dest" and "src" are aligned, copying the data in chunks
- (unsigned long) is more efficient than a byte-by-byte copy.
+ (grub_addr_t) is more efficient than a byte-by-byte copy.
Also tweak '__aeabi_memcpy()', '__aeabi_memcpy4()', and
'__aeabi_memcpy8()', since 'grub_memcpy()' is not inline anymore.
+ Optimization for unaligned buffers was omitted to maintain code
+ simplicity and readability. The current chunk-copy optimization
+ for aligned buffers already provides a noticeable performance
+ improvement(*) for Argon2 keyslot decryption.
+
+ (*) On my system, for a LUKS2 keyslot configured with a 1 GB Argon2
+ memory requirement, this patch reduces the decryption time from 22
+ seconds to 12 seconds.
+
Signed-off-by: Gary Lin <[email protected]>
## grub-core/kern/compiler-rt.c ##
@@ grub-core/kern/misc.c: grub_memmove (void *dest, const void *src,
grub_size_t n)
+static void *
+__memcpy_aligned (void *dest, const void *src, grub_size_t n)
+{
-+ unsigned long *dw = (unsigned long *) dest;
-+ const unsigned long *sw = (const unsigned long *) src;
++ grub_addr_t *dw = (grub_addr_t *) dest;
++ const grub_addr_t *sw = (const grub_addr_t *) src;
+ grub_uint8_t *d;
+ const grub_uint8_t *s;
+
-+ for (; n >= sizeof (unsigned long); n -= sizeof (unsigned long))
++ for (; n >= sizeof (grub_addr_t); n -= sizeof (grub_addr_t))
+ *dw++ = *sw++;
+
+ d = (grub_uint8_t *) dw;
@@ grub-core/kern/misc.c: grub_memmove (void *dest, const void *src,
grub_size_t n)
+grub_memcpy (void *dest, const void *src, grub_size_t n)
+{
+ /* Check if 'dest' and 'src' are aligned */
-+ if (((grub_addr_t) dest & (sizeof (unsigned long) - 1)) == 0 &&
-+ ((grub_addr_t) src & (sizeof (unsigned long) - 1)) == 0)
++ if (((grub_addr_t) dest & (sizeof (grub_addr_t) - 1)) == 0 &&
++ ((grub_addr_t) src & (sizeof (grub_addr_t) - 1)) == 0 &&
++ n >= sizeof (grub_addr_t))
+ return __memcpy_aligned (dest, src, n);
+
+ return grub_memmove (dest, src, n);
@@ grub-core/kern/misc.c: grub_memmove (void *dest, const void *src,
grub_size_t n)
## include/grub/misc.h ##
@@
- #define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE,
__LINE__, condition, __VA_ARGS__)
+ #define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE,
__FUNCTION__, __LINE__, condition, __VA_ARGS__)
void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t
n);
+void *EXPORT_FUNC(grub_memcpy) (void *dest, const void *src, grub_size_t
n);
--
2.51.0
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel