Support Argon2 KDF
cover Support Argon2 KDF
This patch series imports the Argon2 code and tests from libgcrypt and adds Argon2 support to LUKS2.
Patch 1 and 2 introduces grub_crypto_argon2().
Patch 3 and 4 integrates the Argon2 tests from libgcrypt into functional_test.
Patch 5 leverages grub_crypto_argon2() to add Argon2 support to LUKS2. Patch 6 changes the default KDF of the LUKS2 test to Argon2id. Patch 7 documents argon2 and argon2_test modules.
Gary Lin (7):
argon2: Extract Argon2 code from libgcrypt
argon2: Introduce grub_crypto_argon2()
Import Argon2 tests from libgcrypt
Integrate Argon2 tests into functional_test disk/luks2: Add Argon2 support tests/util/grub-fs-tester: Use Argon2id for LUKS2 test
docs: Document argon2 and argon2_test
Makefile.util.def | 37 +- docs/grub.texi | 11 + grub-core/Makefile.core.def | 13 + grub-core/disk/luks2.c | 38 +- grub-core/lib/argon2.c | 659 ++++++++++++++++++++++++++ grub-core/tests/argon2_test.c | 139 ++++++ grub-core/tests/lib/functional_test.c | 1 + include/grub/crypto.h | 18 + tests/util/grub-fs-tester.in | 10 +- 9 files changed, 912 insertions(+), 14 deletions(-) create mode 100644 grub-core/lib/argon2.c create mode 100644 grub-core/tests/argon2_test.c
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/7 argon2: Extract Argon2 code from libgcrypt
Extract the Argon2 code snippet from libgcrypt/cipher/kdf.c.
--- grub-core/lib/argon2.c | 575 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 575 insertions(+) create mode 100644 grub-core/lib/argon2.c
grub-core/lib/argon2.c new file +575 -0
@@ -0,0 +1,575 @@ +typedef struct argon2_context *argon2_ctx_t ; + +/* Per thread data for Argon2. */ +struct argon2_thread_data { +argon2_ctx_t a; +unsigned int pass; +unsigned int slice; +unsigned int lane; +}; + +/* Argon2 context */ +struct argon2_context { +int algo; +int hash_type; + +unsigned int outlen; + +const unsigned char *password; +size_t passwordlen; + +const unsigned char *salt; +size_t saltlen; + +const unsigned char *key; +size_t keylen; + +const unsigned char *ad; +size_t adlen; + +unsigned int m_cost; + +unsigned int passes; +unsigned int memory_blocks; +unsigned int segment_length; +unsigned int lane_length; +unsigned int lanes; + +u64 *block; +struct argon2_thread_data *thread_data; + +unsigned char out[1 ];/* In future, we may use flexible array member. */ +}; + +#define ARGON2_VERSION 0x13 + +#define ARGON2_WORDS_IN_BLOCK (1024/8) + +static void +xor_block (u64 *dst,const u64 *src) +{ +int i; + +for (i =0 ; i <ARGON2_WORDS_IN_BLOCK ; i++) + dst[i] ^= src[i]; +} + +static void +beswap64_block (u64 *dst) +{ +#ifdef WORDS_BIGENDIAN +int i; + +/* Swap a block in big-endian 64-bit word into one in +little-endian. */ +for (i =0 ; i <ARGON2_WORDS_IN_BLOCK ; i++) + dst[i] =_gcry_bswap64 (dst[i]); +#else +/* Nothing to do. */ + (void )dst; +#endif +} + + +static gpg_err_code_t +argon2_fill_first_blocks (argon2_ctx_t a) +{ +unsigned char h0_01_i[72 ]; +unsigned char buf[10 ][4 ]; +gcry_buffer_t iov[8 ]; +unsigned int iov_count =0 ; +int i; + +/* Generate H0. */ +buf_put_le32 (buf[0 ], a->lanes); +buf_put_le32 (buf[1 ], a->outlen); +buf_put_le32 (buf[2 ], a->m_cost); +buf_put_le32 (buf[3 ], a->passes); +buf_put_le32 (buf[4 ],ARGON2_VERSION ); +buf_put_le32 (buf[5 ], a->hash_type); +buf_put_le32 (buf[6 ], a->passwordlen); + iov[iov_count].data = buf[0 ]; + iov[iov_count].len =4 *7 ; + iov[iov_count].off =0 ; + iov_count++; +if (a->passwordlen) + { + iov[iov_count].data = (void *)a->password; + iov[iov_count].len = a->passwordlen; + iov[iov_count].off =0 ; + iov_count++; + } + +buf_put_le32 (buf[7 ], a->saltlen); + iov[iov_count].data = buf[7 ]; + iov[iov_count].len =4 ; + iov[iov_count].off =0 ; + iov_count++; + iov[iov_count].data = (void *)a->salt; + iov[iov_count].len = a->saltlen; + iov[iov_count].off =0 ; + iov_count++; + +buf_put_le32 (buf[8 ], a->keylen); + iov[iov_count].data = buf[8 ]; + iov[iov_count].len =4 ; + iov[iov_count].off =0 ; + iov_count++; +if (a->key) + { + iov[iov_count].data = (void *)a->key; + iov[iov_count].len = a->keylen; + iov[iov_count].off =0 ; + iov_count++; + } + +buf_put_le32 (buf[9 ], a->adlen); + iov[iov_count].data = buf[9 ]; + iov[iov_count].len =4 ; + iov[iov_count].off =0 ; + iov_count++; +if (a->ad) + { + iov[iov_count].data = (void *)a->ad; + iov[iov_count].len = a->adlen; + iov[iov_count].off =0 ; + iov_count++; + } + + _gcry_digest_spec_blake2b_512.hash_buffers (h0_01_i,64 , iov, iov_count); + +for (i =0 ; i < a->lanes; i++) + { +memset (h0_01_i+64 ,0 ,4 ); +buf_put_le32 (h0_01_i+64 +4 , i); +blake2b_vl_hash (h0_01_i,72 ,1024 , + &a->block[i*a->lane_length*ARGON2_WORDS_IN_BLOCK ]); +beswap64_block (&a->block[i*a->lane_length*ARGON2_WORDS_IN_BLOCK ]); + +buf_put_le32 (h0_01_i+64 ,1 ); +blake2b_vl_hash (h0_01_i,72 ,1024 , + &a->block[(i*a->lane_length+1 )*ARGON2_WORDS_IN_BLOCK ]); +beswap64_block (&a->block[(i*a->lane_length+1 )*ARGON2_WORDS_IN_BLOCK ]); + } +return 0 ; +} + +static gpg_err_code_t +argon2_init (argon2_ctx_t a,unsigned int parallelism, +unsigned int m_cost,unsigned int t_cost) +{ +gpg_err_code_t ec =0 ; +unsigned int memory_blocks; +unsigned int segment_length; +void *block; +struct argon2_thread_data *thread_data; + + memory_blocks = m_cost; +if (memory_blocks <8 * parallelism) + memory_blocks =8 * parallelism; + + segment_length = memory_blocks / (parallelism *4 ); + memory_blocks = segment_length * parallelism *4 ; + + a->passes = t_cost; + a->memory_blocks = memory_blocks; + a->segment_length = segment_length; + a->lane_length = segment_length *4 ; + a->lanes = parallelism; + + a->block =NULL ; + a->thread_data =NULL ; + + block =xtrymalloc (1024 * memory_blocks); +if (!block) + { + ec =gpg_err_code_from_errno (errno); +return ec; + } +memset (block,0 ,1024 * memory_blocks); + + thread_data =xtrymalloc (a->lanes *sizeof (struct argon2_thread_data )); +if (!thread_data) + { + ec =gpg_err_code_from_errno (errno); +xfree (block); +return ec; + } + +memset (thread_data,0 , a->lanes *sizeof (struct argon2_thread_data )); + + a->block = block; + a->thread_data = thread_data; +return 0 ; +} + + +static u64 fBlaMka (u64 x,u64 y) +{ +const u64 m =U64_C (0xFFFFFFFF ); +return x + y +2 * (x & m) * (y & m); +} + +static u64 rotr64 (u64 w,unsigned int c) +{ +return (w >> c) | (w << (64 - c)); +} + +#define G (a, b, c, d) \ + do { \ + a = fBlaMka(a, b); \ + d = rotr64(d ^ a, 32); \ + c = fBlaMka(c, d); \ + b = rotr64(b ^ c, 24); \ + a = fBlaMka(a, b); \ + d = rotr64(d ^ a, 16); \ + c = fBlaMka(c, d); \ + b = rotr64(b ^ c, 63); \ + } while ((void)0, 0) + +#define BLAKE2_ROUND_NOMSG (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, \ + v12, v13, v14, v15) \ + do { \ + G(v0, v4, v8, v12); \ + G(v1, v5, v9, v13); \ + G(v2, v6, v10, v14); \ + G(v3, v7, v11, v15); \ + G(v0, v5, v10, v15); \ + G(v1, v6, v11, v12); \ + G(v2, v7, v8, v13); \ + G(v3, v4, v9, v14); \ + } while ((void)0, 0) + +static void +fill_block (const u64 *prev_block,const u64 *ref_block,u64 *curr_block, +int with_xor) +{ +u64 block_r[ARGON2_WORDS_IN_BLOCK ]; +u64 block_tmp[ARGON2_WORDS_IN_BLOCK ]; +int i; + +memcpy (block_r, ref_block,1024 ); +if (prev_block) +xor_block (block_r, prev_block); +memcpy (block_tmp, block_r,1024 ); + +if (with_xor) +xor_block (block_tmp, curr_block); + +for (i =0 ; i <8 ; ++i) +BLAKE2_ROUND_NOMSG + (block_r[16 * i], block_r[16 * i +1 ], block_r[16 * i +2 ], + block_r[16 * i +3 ], block_r[16 * i +4 ], block_r[16 * i +5 ], + block_r[16 * i +6 ], block_r[16 * i +7 ], block_r[16 * i +8 ], + block_r[16 * i +9 ], block_r[16 * i +10 ], block_r[16 * i +11 ], + block_r[16 * i +12 ], block_r[16 * i +13 ], block_r[16 * i +14 ], + block_r[16 * i +15 ]); + +for (i =0 ; i <8 ; i++) +BLAKE2_ROUND_NOMSG + (block_r[2 * i], block_r[2 * i +1 ], block_r[2 * i +16 ], + block_r[2 * i +17 ], block_r[2 * i +32 ], block_r[2 * i +33 ], + block_r[2 * i +48 ], block_r[2 * i +49 ], block_r[2 * i +64 ], + block_r[2 * i +65 ], block_r[2 * i +80 ], block_r[2 * i +81 ], + block_r[2 * i +96 ], block_r[2 * i +97 ], block_r[2 * i +112 ], + block_r[2 * i +113 ]); + +memcpy (curr_block, block_tmp,1024 ); +xor_block (curr_block, block_r); +} + +static void +pseudo_random_generate (u64 *random_block,u64 *input_block) +{ + input_block[6 ]++; +fill_block (NULL , input_block, random_block,0 ); +fill_block (NULL , random_block, random_block,0 ); +} + +static u32 +index_alpha (argon2_ctx_t a,const struct argon2_thread_data *t, +int segment_index,u32 random,int same_lane) +{ +u32 reference_area_size; +u64 relative_position; +u32 start_position; + +if (t->pass ==0 ) + { +if (t->slice ==0 ) + reference_area_size = segment_index -1 ; +else + { +if (same_lane) + reference_area_size = t->slice * a->segment_length + + segment_index -1 ; +else + reference_area_size = t->slice * a->segment_length + + ((segment_index ==0 ) ?-1 :0 ); + } + } +else + { +if (same_lane) + reference_area_size = a->lane_length + - a->segment_length + segment_index -1 ; +else + reference_area_size = a->lane_length + - a->segment_length + ((segment_index ==0 ) ?-1 :0 ); + } + + relative_position = (random * (u64 )random) >>32 ; + relative_position = reference_area_size -1 - + ((reference_area_size * relative_position) >>32 ); + +if (t->pass ==0 ) + start_position =0 ; +else + start_position = (t->slice ==4 -1 ) + ?0 + : (t->slice +1 ) * a->segment_length; + +return (start_position + relative_position) % a->lane_length; +} + +static void +argon2_compute_segment (void *priv) +{ +const struct argon2_thread_data *t = (const struct argon2_thread_data *)priv; +argon2_ctx_t a = t->a; +int i; +int prev_offset, curr_offset; +u32 ref_index, ref_lane; +u64 input_block[1024 /sizeof (u64)]; +u64 address_block[1024 /sizeof (u64)]; +u64 *random_block =NULL ; + +if (a->hash_type ==GCRY_KDF_ARGON2I + || (a->hash_type ==GCRY_KDF_ARGON2ID && t->pass ==0 && t->slice <2 )) + { +memset (input_block,0 ,1024 ); + input_block[0 ] = t->pass; + input_block[1 ] = t->lane; + input_block[2 ] = t->slice; + input_block[3 ] = a->memory_blocks; + input_block[4 ] = a->passes; + input_block[5 ] = a->hash_type; + random_block = address_block; + } + +if (t->pass ==0 && t->slice ==0 ) + { +if (random_block) +pseudo_random_generate (random_block, input_block); + i =2 ; + } +else + i =0 ; + + curr_offset = t->lane * a->lane_length + t->slice * a->segment_length + i; +if ((curr_offset % a->lane_length)) + prev_offset = curr_offset -1 ; +else + prev_offset = curr_offset + a->lane_length -1 ; + +for (; i < a->segment_length; i++, curr_offset++, prev_offset++) + { +u64 *ref_block, *curr_block; +u64 rand64; + +if ((curr_offset % a->lane_length) ==1 ) + prev_offset = curr_offset -1 ; + +if (random_block) + { +if ((i % (1024 /sizeof (u64))) ==0 ) +pseudo_random_generate (random_block, input_block); + + rand64 = random_block[(i% (1024 /sizeof (u64)))]; + } +else + rand64 = a->block[prev_offset*ARGON2_WORDS_IN_BLOCK ]; + +if (t->pass ==0 && t->slice ==0 ) + ref_lane = t->lane; +else + ref_lane = (rand64 >>32 ) % a->lanes; + + ref_index =index_alpha (a, t, i, (rand64 &0xffffffff ), + ref_lane == t->lane); + ref_block = + &a->block[(a->lane_length * ref_lane + ref_index)*ARGON2_WORDS_IN_BLOCK ]; + + curr_block = &a->block[curr_offset *ARGON2_WORDS_IN_BLOCK ]; +fill_block (&a->block[prev_offset *ARGON2_WORDS_IN_BLOCK ], ref_block, + curr_block, t->pass !=0 ); + } +} + + +static gpg_err_code_t +argon2_compute (argon2_ctx_t a,const struct gcry_kdf_thread_ops *ops) +{ +gpg_err_code_t ec; +unsigned int r; +unsigned int s; +unsigned int l; +int ret; + + ec =argon2_fill_first_blocks (a); +if (ec) +return ec; + +for (r =0 ; r < a->passes; r++) +for (s =0 ; s <4 ; s++) + { +for (l =0 ; l < a->lanes; l++) + { +struct argon2_thread_data *thread_data; + +/* launch a thread. */ + thread_data = &a->thread_data[l]; + thread_data->a = a; + thread_data->pass = r; + thread_data->slice = s; + thread_data->lane = l; + +if (ops) + { + ret = ops->dispatch_job (ops->jobs_context, + argon2_compute_segment, thread_data); +if (ret <0 ) +return GPG_ERR_CANCELED ; + } +else +argon2_compute_segment (thread_data); + } + +if (ops) + { + ret = ops->wait_all_jobs (ops->jobs_context); +if (ret <0 ) +return GPG_ERR_CANCELED ; + } + } + +return 0 ; +} + + +static gpg_err_code_t +argon2_final (argon2_ctx_t a,size_t resultlen,void *result) +{ +int i; + +if (resultlen != a->outlen) +return GPG_ERR_INV_VALUE ; + +memset (a->block,0 ,1024 ); +for (i =0 ; i < a->lanes; i++) + { +u64 *last_block; + + last_block = &a->block[(a->lane_length * i + (a->lane_length -1 )) + *ARGON2_WORDS_IN_BLOCK ]; +xor_block (a->block, last_block); + } + +beswap64_block (a->block); +blake2b_vl_hash (a->block,1024 , a->outlen, result); +return 0 ; +} + +static void +argon2_close (argon2_ctx_t a) +{ +size_t n; + + n = offsetof (struct argon2_context , out) + a->outlen; + +if (a->block) + { +wipememory (a->block,1024 * a->memory_blocks); +xfree (a->block); + } + +if (a->thread_data) +xfree (a->thread_data); + +wipememory (a, n); +xfree (a); +} + +static gpg_err_code_t +argon2_open (gcry_kdf_hd_t *hd,int subalgo, +const unsigned long *param,unsigned int paramlen, +const void *password,size_t passwordlen, +const void *salt,size_t saltlen, +const void *key,size_t keylen, +const void *ad,size_t adlen) +{ +int hash_type; +unsigned int taglen; +unsigned int t_cost; +unsigned int m_cost; +unsigned int parallelism =1 ; +argon2_ctx_t a; +gpg_err_code_t ec; +size_t n; + +if (subalgo !=GCRY_KDF_ARGON2D + && subalgo !=GCRY_KDF_ARGON2I + && subalgo !=GCRY_KDF_ARGON2ID ) +return GPG_ERR_INV_VALUE ; +else + hash_type = subalgo; + +/* param : [ tag_length, t_cost, m_cost, parallelism ] */ +if (paramlen <3 || paramlen >4 ) +return GPG_ERR_INV_VALUE ; +else + { + taglen = (unsigned int )param[0 ]; + t_cost = (unsigned int )param[1 ]; + m_cost = (unsigned int )param[2 ]; +if (paramlen >=4 ) + parallelism = (unsigned int )param[3 ]; + } + +if (parallelism ==0 ) +return GPG_ERR_INV_VALUE ; + + n = offsetof (struct argon2_context , out) + taglen; + a =xtrymalloc (n); +if (!a) +return gpg_err_code_from_errno (errno); + + a->algo =GCRY_KDF_ARGON2 ; + a->hash_type = hash_type; + + a->outlen = taglen; + + a->password = password; + a->passwordlen = passwordlen; + a->salt = salt; + a->saltlen = saltlen; + a->key = key; + a->keylen = keylen; + a->ad = ad; + a->adlen = adlen; + + a->m_cost = m_cost; + + a->block =NULL ; + a->thread_data =NULL ; + + ec =argon2_init (a, parallelism, m_cost, t_cost); +if (ec) + { +xfree (a); +return ec; + } + + *hd = (void *)a; +return 0 ; +}
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/7 argon2: Introduce grub_crypto_argon2()
In reply to Gary Lin via Grub-develThis commit introduces grub_crypto_argon2() by refactoring the Argon2 implementation from libgcrypt.
In GRUB's libgcrypt build, the hash_buffer() function is disabled. To work around this, a new 'argon2_blake2b_512_hash_buffers()' function was implemented to replace '_gcry_digest_spec_blake2b_512.hash_buffers()'.
--- Makefile.util.def | 37 +++++-- grub-core/Makefile.core.def | 8 ++ grub-core/lib/argon2.c | 190 ++++++++++++++++++++++++++---------- include/grub/crypto.h | 18 ++++ 4 files changed, 191 insertions(+), 62 deletions(-)
Makefile.util.def +28 -9
@@ -181,6 +181,14 @@ library = { common = grub-core/lib/zstd/zstd_decompress.c; }; +library = { + name = libgrubargon2.a; + common = grub-core/lib/argon2.c; + + cflags = '$(CFLAGS_GCRY)'; + cppflags = '$(CPPFLAGS_GCRY)'; +}; + program = { name = grub-mkimage; mansection = 1;
@@ -225,8 +233,9 @@ program = { cflags = '-I$(srcdir)/grub-core/lib/tss2 -I$(srcdir)/grub-core/commands/tpm2_key_protector'; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBTASN1)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
@@ -323,8 +332,9 @@ program = { common = grub-core/osdep/init.c; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; };
@@ -378,8 +388,9 @@ program = { common = grub-core/osdep/init.c; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; };
@@ -401,6 +412,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
@@ -421,6 +433,7 @@ program = { ldadd = libgrubmods.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
@@ -466,8 +479,9 @@ program = { common = grub-core/kern/emu/argp_common.c; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; };
@@ -605,8 +619,9 @@ program = { ldadd = '$(LIBLZMA)'; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
@@ -691,8 +706,9 @@ program = { ldadd = '$(LIBLZMA)'; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; };
@@ -1400,8 +1416,9 @@ program = { common = grub-core/kern/emu/argp_common.c; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; };
@@ -1434,8 +1451,9 @@ program = { common = grub-core/osdep/init.c; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; };
@@ -1463,8 +1481,9 @@ program = { common = grub-core/osdep/init.c; ldadd = libgrubmods.a; - ldadd = libgrubgcry.a; ldadd = libgrubkern.a; + ldadd = libgrubargon2.a; + ldadd = libgrubgcry.a; ldadd = grub-core/lib/gnulib/libgnu.a; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; };
grub-core/Makefile.core.def +8 -0
@@ -1694,6 +1694,14 @@ module = { common = lib/pbkdf2.c; }; +module = { + name = argon2; + common = lib/argon2.c; + + cflags = '$(CFLAGS_GCRY)'; + cppflags = '$(CPPFLAGS_GCRY)'; +}; + module = { name = relocator; common = lib/relocator.c;
grub-core/lib/argon2.c +137 -53
364 lines not on this page · raw message
include/grub/crypto.h +18 -0
@@ -34,6 +34,7 @@ typedef enumGPG_ERR_BAD_MPI ,GPG_ERR_BAD_SECKEY ,GPG_ERR_BAD_SIGNATURE , +GPG_ERR_CANCELED ,GPG_ERR_CIPHER_ALGO ,GPG_ERR_CONFLICT , GPG_ERR_DECRYPT_FAILED,
@@ -512,6 +513,7 @@ extern gcry_md_spec_t _gcry_digest_spec_sha1;extern gcry_md_spec_t _gcry_digest_spec_sha256;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;extern gcry_cipher_spec_t _gcry_cipher_spec_aes;#define GRUB_MD_MD5 ((const gcry_md_spec_t *) &_gcry_digest_spec_md5)#define GRUB_MD_SHA1 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha1)
@@ -533,6 +535,22 @@ grub_crypto_pbkdf2 (const struct gcry_md_spec *md,unsigned int c, grub_uint8_t *DK, grub_size_t dkLen); +enum grub_gcry_kdf_subalgo_argon2 + { +GRUB_GCRY_KDF_ARGON2D =0 , +GRUB_GCRY_KDF_ARGON2I =1 , +GRUB_GCRY_KDF_ARGON2ID =2 + }; + +gcry_err_code_t +grub_crypto_argon2 (int subalgo, +const unsigned long *param,unsigned int paramlen, +const void *password,grub_size_t passwordlen, +const void *salt,grub_size_t saltlen, +const void *key,grub_size_t keylen, +const void *ad,grub_size_t adlen, +grub_size_t resultlen,void *result); +int grub_crypto_memcmp (const void *a,const void *b,grub_size_t n);
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 3/7 Import Argon2 tests from libgcrypt
In reply to Gary Lin via Grub-develCopy the Argon2 test function, check_argon2(), from t-kdf.c in libgcrypt to grub-core/tests/argon2_test.c.
--- grub-core/tests/argon2_test.c | 141 ++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 grub-core/tests/argon2_test.c
grub-core/tests/argon2_test.c new file +141 -0
@@ -0,0 +1,141 @@ +static void +check_argon2 (void ) +{ +gcry_error_t err; +static struct { +int subalgo; +unsigned long param[4 ]; +size_t passlen; +const char *pass; +size_t saltlen; +const char *salt; +size_t keylen; +const char *key; +size_t adlen; +const char *ad; +size_t dklen; +const char *dk; + } tv[] = { + { +GCRY_KDF_ARGON2D , + {32 ,3 ,32 ,4 }, +32 , +"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" +"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" , +16 , +"\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02" , +8 , +"\x03\x03\x03\x03\x03\x03\x03\x03" , +12 , +"\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04" , +32 , +"\x51\x2b\x39\x1b\x6f\x11\x62\x97\x53\x71\xd3\x09\x19\x73\x42\x94" +"\xf8\x68\xe3\xbe\x39\x84\xf3\xc1\xa1\x3a\x4d\xb9\xfa\xbe\x4a\xcb" + }, + { +GCRY_KDF_ARGON2I , + {32 ,3 ,32 ,4 }, +32 , +"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" +"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" , +16 , +"\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02" , +8 , +"\x03\x03\x03\x03\x03\x03\x03\x03" , +12 , +"\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04" , +32 , +"\xc8\x14\xd9\xd1\xdc\x7f\x37\xaa\x13\xf0\xd7\x7f\x24\x94\xbd\xa1" +"\xc8\xde\x6b\x01\x6d\xd3\x88\xd2\x99\x52\xa4\xc4\x67\x2b\x6c\xe8" + }, + { +GCRY_KDF_ARGON2ID , + {32 ,3 ,32 ,4 }, +32 , +"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" +"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" , +16 , +"\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02" , +8 , +"\x03\x03\x03\x03\x03\x03\x03\x03" , +12 , +"\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04" , +32 , +"\x0d\x64\x0d\xf5\x8d\x78\x76\x6c\x08\xc0\x37\xa3\x4a\x8b\x53\xc9" +"\xd0\x1e\xf0\x45\x2d\x75\xb6\x5e\xb5\x25\x20\xe9\x6b\x01\xe6\x59" + }, + { +/* empty password */ +GCRY_KDF_ARGON2I , + {32 ,3 ,128 ,1 }, +0 ,NULL , +16 , +"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" , +0 ,NULL , +0 ,NULL , +32 , +"\xbb\x1f\xf2\xb9\x9f\xd4\x4a\xd9\xdf\x7f\xb9\x54\x55\x9e\xb8\xeb" +"\xb5\x9d\xab\xce\x2e\x62\x9f\x9b\x89\x09\xfe\xde\x57\xcc\x63\x86" + }, + { +/* empty password */ +GCRY_KDF_ARGON2ID , + {32 ,3 ,128 ,1 }, +0 ,NULL , +16 , +"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" , +0 ,NULL , +0 ,NULL , +32 , +"\x09\x2f\x38\x35\xac\xb2\x43\x92\x93\xeb\xcd\xe8\x04\x16\x6a\x31" +"\xce\x14\xd4\x55\xdb\xd8\xf7\xe6\xb4\xf5\x9d\x64\x8e\xd0\x3a\xdb" + }, + }; +unsigned char out[32 ]; +int i; +int count; + +for (count =0 ; count <DIM (tv); count++) + { +if (verbose) +fprintf (stderr,"checking ARGON2 test vector %d\n" , count); + + err =my_kdf_derive (0 ,GCRY_KDF_ARGON2 , + tv[count].subalgo, tv[count].param,4 , + tv[count].pass, tv[count].passlen, + tv[count].salt, tv[count].saltlen, + tv[count].key, tv[count].keylen, + tv[count].ad, tv[count].adlen, + tv[count].dklen, out); +if (err) +fail ("argon2 test %d failed: %s\n" , count*2 +0 ,gpg_strerror (err)); +else if (memcmp (out, tv[count].dk, tv[count].dklen)) + { +fail ("argon2 test %d failed: mismatch\n" , count*2 +0 ); +fputs ("got:" , stderr); +for (i=0 ; i < tv[count].dklen; i++) +fprintf (stderr," %02x" , out[i]); +putc ('\n' , stderr); + } + +#ifdef HAVE_PTHREAD + err =my_kdf_derive (1 ,GCRY_KDF_ARGON2 , + tv[count].subalgo, tv[count].param,4 , + tv[count].pass, tv[count].passlen, + tv[count].salt, tv[count].saltlen, + tv[count].key, tv[count].keylen, + tv[count].ad, tv[count].adlen, + tv[count].dklen, out); +if (err) +fail ("argon2 test %d failed: %s\n" , count*2 +1 ,gpg_strerror (err)); +else if (memcmp (out, tv[count].dk, tv[count].dklen)) + { +fail ("argon2 test %d failed: mismatch\n" , count*2 +1 ); +fputs ("got:" , stderr); +for (i=0 ; i < tv[count].dklen; i++) +fprintf (stderr," %02x" , out[i]); +putc ('\n' , stderr); + } +#endif + } +}
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 4/7 Integrate Argon2 tests into functional_test
In reply to Gary Lin via Grub-develRefactor the Argon2 tests to enable the module build and integrate the tests into function_test.
--- grub-core/Makefile.core.def | 5 ++ grub-core/tests/argon2_test.c | 104 +++++++++++++------------- grub-core/tests/lib/functional_test.c | 1 + 3 files changed, 57 insertions(+), 53 deletions(-)
grub-core/Makefile.core.def +5 -0
@@ -2225,6 +2225,11 @@ module = { common = tests/pbkdf2_test.c; }; +module = { + name = argon2_test; + common = tests/argon2_test.c; +}; + module = { name = legacy_password_test; common = tests/legacy_password_test.c;
grub-core/tests/argon2_test.c +51 -53
152 lines not on this page · raw message
grub-core/tests/lib/functional_test.c +1 -0
@@ -80,6 +80,7 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),grub_dl_load ("mul_test" );grub_dl_load ("shift_test" );grub_dl_load ("asn1_test" ); +grub_dl_load ("argon2_test" );FOR_LIST_ELEMENTS (test, grub_test_list) ok = !grub_test_run (test) && ok;
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 5/7 disk/luks2: Add Argon2 support
In reply to Gary Lin via Grub-develLeverage the new grub_crypto_argon2() function to add support for the Argon2i and Argon2id KDFs in LUKS2
--- grub-core/disk/luks2.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
grub-core/disk/luks2.c +35 -3
@@ -39,6 +39,7 @@ GRUB_MOD_LICENSE ("GPLv3+");enum grub_luks2_kdf_type {LUKS2_KDF_TYPE_ARGON2I , +LUKS2_KDF_TYPE_ARGON2ID ,LUKS2_KDF_TYPE_PBKDF2 };typedef enum grub_luks2_kdf_type grub_luks2_kdf_type_t ;
@@ -159,7 +160,7 @@ luks2_parse_keyslot (grub_luks2_keyslot_t *out, const grub_json_t *keyslot) grub_json_getstring (&type, &kdf, "type") || grub_json_getstring (&out->kdf.salt, &kdf, "salt"))return grub_error (GRUB_ERR_BAD_ARGUMENT ,"Missing or invalid KDF" ); - else if (!grub_strcmp (type, "argon2i") || !grub_strcmp (type, "argon2id")) + else if (!grub_strcmp (type, "argon2i")) { out->kdf.type =LUKS2_KDF_TYPE_ARGON2I ; if (grub_json_getint64 (&out->kdf.u.argon2i.time, &kdf, "time") ||
@@ -167,6 +168,14 @@ luks2_parse_keyslot (grub_luks2_keyslot_t *out, const grub_json_t *keyslot) grub_json_getint64 (&out->kdf.u.argon2i.cpus, &kdf, "cpus"))return grub_error (GRUB_ERR_BAD_ARGUMENT ,"Missing Argon2i parameters" ); } +else if (!grub_strcmp (type,"argon2id" )) + { + out->kdf.type =LUKS2_KDF_TYPE_ARGON2ID ; +if (grub_json_getint64 (&out->kdf.u.argon2i.time, &kdf,"time" ) || +grub_json_getint64 (&out->kdf.u.argon2i.memory, &kdf,"memory" ) || +grub_json_getint64 (&out->kdf.u.argon2i.cpus, &kdf,"cpus" )) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"Missing Argon2id parameters" ); + }else if (!grub_strcmp (type,"pbkdf2" )) { out->kdf.type =LUKS2_KDF_TYPE_PBKDF2 ;
@@ -444,6 +453,8 @@ luks2_decrypt_key (grub_uint8_t *out_key,grub_uint8_t salt[GRUB_CRYPTODISK_MAX_KEYLEN ];grub_uint8_t *split_key =NULL ;idx_t saltlen =sizeof (salt); +int subalgo; +unsigned long param[4 ];char cipher[32 ], *p;const gcry_md_spec_t *hash;gcry_err_code_t gcry_ret;
@@ -460,8 +471,29 @@ luks2_decrypt_key (grub_uint8_t *out_key,switch (k->kdf.type) {case LUKS2_KDF_TYPE_ARGON2I : - ret =grub_error (GRUB_ERR_BAD_ARGUMENT ,"Argon2 not supported" ); - goto err; +case LUKS2_KDF_TYPE_ARGON2ID : +if (k->kdf.type ==LUKS2_KDF_TYPE_ARGON2I ) + subalgo =GRUB_GCRY_KDF_ARGON2I ; +else + subalgo =GRUB_GCRY_KDF_ARGON2ID ; + + param[0 ] = k->area.key_size; + param[1 ] = k->kdf.u.argon2i.time; + param[2 ] = k->kdf.u.argon2i.memory; + param[3 ] = k->kdf.u.argon2i.cpus; + + gcry_ret =grub_crypto_argon2 (subalgo, param,4 , + passphrase, passphraselen, + salt, saltlen, +NULL ,0 ,NULL ,0 , + k->area.key_size, area_key); +if (gcry_ret) + { + ret =grub_crypto_gcry_error (gcry_ret); + goto err; + } + +break ;case LUKS2_KDF_TYPE_PBKDF2 : hash =grub_crypto_lookup_md_by_name (k->kdf.u.pbkdf2.hash);if (!hash)
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 6/7 tests/util/grub-fs-tester: Use Argon2id for LUKS2 test
In reply to Gary Lin via Grub-develGiven that the LUKS1 test already covers PBKDF2, the default KDF for the LUKS2 test has been switched to Argon2id to ensure both algorithms are validated.
--- tests/util/grub-fs-tester.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tests/util/grub-fs-tester.in +8 -2
@@ -860,8 +860,14 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do MOUNTDEVICE="/dev/mapper/grub_test-testvol" MOUNTFS=ext2 "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; - x"luks"*) - echo -n "$PASS" | cryptsetup luksFormat --type "$fs" --sector-size $SECSIZE --pbkdf pbkdf2 --force-password --disable-locks $LODEVICE + xluks1) + echo -n "$PASS" | cryptsetup luksFormat --type luks1 --sector-size $SECSIZE --pbkdf pbkdf2 --force-password --disable-locks $LODEVICE + echo -n "$PASS" | cryptsetup open --disable-locks $LODEVICE "$DMNAME" + MOUNTDEVICE="/dev/mapper/${DMNAME}" + MOUNTFS=ext2 + "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;; + xluks2) + echo -n "$PASS" | cryptsetup luksFormat --type luks2 --sector-size $SECSIZE --pbkdf argon2id --force-password --disable-locks $LODEVICE echo -n "$PASS" | cryptsetup open --disable-locks $LODEVICE "$DMNAME" MOUNTDEVICE="/dev/mapper/${DMNAME}" MOUNTFS=ext2
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 7/7 docs: Document argon2 and argon2_test
In reply to Gary Lin via Grub-develDocument the argon2 and argon2_test modules.
--- docs/grub.texi | 11 +++++++++++ 1 file changed, 11 insertions(+)
docs/grub.texi +11 -0
@@ -3889,6 +3889,8 @@ Modules can be loaded via the @command{insmod} (@pxref{insmod}) command. * aout_module:: * appleldr_module:: * archelp_module:: +* argon2_module:: +* argon2_test_module:: * at_keyboard_module:: * ata_module:: * backtrace_module::
@@ -4244,6 +4246,15 @@ computer (Intel based Macs). This module provides Archive Helper functions for archive based file systems such as TAR and CPIO archives. +@node argon2_module +@section argon2 +This module provides support for the Argon2 key derivation function. + +@node argon2_test_module +@section argon2_test +This module is intended for performing a functional test of the Argon2 +operation in GRUB. + @node at_keyboard_module @section at_keyboard This module provides support for the AT keyboard input for the GRUB terminal.
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Hi Gary,
Gary Lin via Grub-devel wrote,
Quoted 2 lines
This patch series imports the Argon2 code and tests from libgcrypt and adds Argon2 support to LUKS2.
I am trying to use your patch series, but compilation is failing. I am using Debian 12 with gcc 12.
Attached is the logfile of the make invocation with the failures.
Any ideas why it is working for you? Older gcc? Or are you using --disable-werror in the configure step?
best regards
Waldemar
make all-recursive
make[1]: Entering directory '/root/grub/build'
Making all in grub-core/lib/gnulib
make[2]: Entering directory '/root/grub/build/grub-core/lib/gnulib'
make all-recursive
make[3]: Entering directory '/root/grub/build/grub-core/lib/gnulib'
make[4]: Entering directory '/root/grub/build/grub-core/lib/gnulib'
make[4]: Nothing to be done for 'all-am'.
make[4]: Leaving directory '/root/grub/build/grub-core/lib/gnulib'
make[3]: Leaving directory '/root/grub/build/grub-core/lib/gnulib'
make[2]: Leaving directory '/root/grub/build/grub-core/lib/gnulib'
Making all in .
make[2]: Entering directory '/root/grub/build'
gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub-core/lib/libgcrypt-grub/cipher/arcfour.c\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I../grub-core/lib/libgcrypt_wrap -I../grub-core/lib/posix_wrap -D_GCRYPT_IN_LIBGCRYPT=1 -D_GCRYPT_CONFIG_H_INCLUDED=1 -I../include/grub/gcrypt -D_FILE_OFFSET_BITS=64 -std=gnu99 -fno-common -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror -Wno-sign-compare -Wno-missing-field-initializers -Wno-redundant-decls -Wno-undef -fno-builtin -MT grub-core/lib/libgcrypt-grub/cipher/libgrubgcry_a-arcfour.o -MD -MP -MF grub-core/lib/libgcrypt-grub/cipher/.deps-util/libgrubgcry_a-arcfour.Tpo -c -o grub-core/lib/libgcrypt-grub/cipher/libgrubgcry_a-arcfour.o test -f 'grub-core/lib/libgcrypt-grub/cipher/arcfour.c' || echo '../'grub-core/lib/libgcrypt-grub/cipher/arcfour.c In file included from ../grub-core/lib/libgcrypt-grub/cipher/types.h:2,
from ../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:30:../grub-core/lib/libgcrypt_wrap/cipher_wrap.h:82: error: "strtoul" redefined [-Werror]
82 | #define strtoul grub_strtoul
|
In file included from ../grub-core/lib/libgcrypt_wrap/cipher_wrap.h:76:
../include/grub/gcrypt/g10lib.h:207: note: this is the location of the previous definition
207 | #define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
|
../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: error: initialization of ‘int’ from ‘const char *’ makes integer from pointer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~~~~~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: note: (near initialization for ‘_gcry_cipher_spec_arcfour.algo’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: error: initializer element is not computable at load time../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: note: (near initialization for ‘_gcry_cipher_spec_arcfour.algo’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:16: error: initialization of ‘unsigned char:1’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:16: note: (near initialization for ‘_gcry_cipher_spec_arcfour.flags.disabled’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:22: error: initialization of ‘unsigned char:1’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:22: note: (near initialization for ‘_gcry_cipher_spec_arcfour.flags.fips’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:28: note: (near initialization for ‘_gcry_cipher_spec_arcfour.name’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:31: error: initialization of ‘const char **’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:31: note: (near initialization for ‘_gcry_cipher_spec_arcfour.aliases’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:36: error: initialization of ‘const gcry_cipher_oid_spec_t *’ {aka ‘const struct gcry_cipher_oid_spec *’} from ‘long unsigned int’ makes pointer from integer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:36: note: (near initialization for ‘_gcry_cipher_spec_arcfour.oids’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:5: error: initialization of ‘long unsigned int’ from ‘gcry_err_code_t (*)(void *, const byte *, unsigned int)’ {aka ‘gpg_err_code_t (*)(void *, const unsigned char *, unsigned int)’} makes integer from pointer without a cast [-Werror=int-conversion]
128 | arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream,
| ^~~~~~~~~~~~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:5: note: (near initialization for ‘_gcry_cipher_spec_arcfour.blocksize’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:21: error: initialization of ‘long unsigned int’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
128 | arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream,
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:21: note: (near initialization for ‘_gcry_cipher_spec_arcfour.keylen’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:27: error: initialization of ‘long unsigned int’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
128 | arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream,
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:27: note: (near initialization for ‘_gcry_cipher_spec_arcfour.contextsize’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:33: error: initialization of ‘gcry_err_code_t (*)(void *, const unsigned char *, unsigned int, struct cipher_bulk_ops *)’ {aka ‘gpg_err_code_t (*)(void *, const unsigned char *, unsigned int, struct cipher_bulk_ops *)’} from incompatible pointer type ‘void (*)(void *, byte *, const byte *, unsigned int)’ {aka ‘void (*)(void *, unsigned char *, const unsigned char *, unsigned int)’} [-Werror=incompatible-pointer-types]
128 | arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream,
| ^~~~~~~~~~~~~~
../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:33: note: (near initialization for ‘_gcry_cipher_spec_arcfour.setkey’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:49: error: initialization of ‘unsigned int (*)(void *, unsigned char *, const unsigned char *)’ from incompatible pointer type ‘void (*)(void *, byte *, const byte *, unsigned int)’ {aka ‘void (*)(void *, unsigned char *, const unsigned char *, unsigned int)’} [-Werror=incompatible-pointer-types]
128 | arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream,
| ^~~~~~~~~~~~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:49: note: (near initialization for ‘_gcry_cipher_spec_arcfour.encrypt’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:126:3: error: missing braces around initializer [-Werror=missing-braces]
126 | {
| ^cc1: all warnings being treated as errors
make[2]: *** [Makefile:6403: grub-core/lib/libgcrypt-grub/cipher/libgrubgcry_a-arcfour.o] Error 1 make[2]: Leaving directory '/root/grub/build'
make[1]: *** [Makefile:12468: all-recursive] Error 1
make[1]: Leaving directory '/root/grub/build'
make: *** [Makefile:4058: all] Error 2
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 1 line · Waldemar Brodkorb
Hi Gary,
Hi Waldemar,
Quoted 5 lines
Gary Lin via Grub-devel wrote,
Quoted 2 lines
This patch series imports the Argon2 code and tests from libgcrypt and adds Argon2 support to LUKS2.
Quoted 8 lines
I am trying to use your patch series, but compilation is failing. I am using Debian 12 with gcc 12.
Attached is the logfile of the make invocation with the failures.
Any ideas why it is working for you? Older gcc? Or are you using --disable-werror in the configure step?
I didn't touch arcfour.c. Are you using git master? Could you try to remove grub-core/lib/libgcrypt-grub/ and run 'autogen.sh' to update libgcrypt-grub?
Cheers,
Gary Lin
Quoted 73 lines
best regards
Waldemarmake all-recursive
make[1]: Entering directory '/root/grub/build'
Making all in grub-core/lib/gnulib
make[2]: Entering directory '/root/grub/build/grub-core/lib/gnulib'
make all-recursive
make[3]: Entering directory '/root/grub/build/grub-core/lib/gnulib'
make[4]: Entering directory '/root/grub/build/grub-core/lib/gnulib'
make[4]: Nothing to be done for 'all-am'.
make[4]: Leaving directory '/root/grub/build/grub-core/lib/gnulib'
make[3]: Leaving directory '/root/grub/build/grub-core/lib/gnulib'
make[2]: Leaving directory '/root/grub/build/grub-core/lib/gnulib'
Making all in .
make[2]: Entering directory '/root/grub/build'
gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub-core/lib/libgcrypt-grub/cipher/arcfour.c\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I../grub-core/lib/libgcrypt_wrap -I../grub-core/lib/posix_wrap -D_GCRYPT_IN_LIBGCRYPT=1 -D_GCRYPT_CONFIG_H_INCLUDED=1 -I../include/grub/gcrypt -D_FILE_OFFSET_BITS=64 -std=gnu99 -fno-common -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror -Wno-sign-compare -Wno-missing-field-initializers -Wno-redundant-decls -Wno-undef -fno-builtin -MTgrub-core/lib/libgcrypt-grub/cipher/libgrubgcry_a-arcfour.o-MD -MP -MF grub-core/lib/libgcrypt-grub/cipher/.deps-util/libgrubgcry_a-arcfour.Tpo -c -ogrub-core/lib/libgcrypt-grub/cipher/libgrubgcry_a-arcfour.otest -f 'grub-core/lib/libgcrypt-grub/cipher/arcfour.c' || echo '../'grub-core/lib/libgcrypt-grub/cipher/arcfour.cIn file included from../grub-core/lib/libgcrypt-grub/cipher/types.h:2,
from../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:30:../grub-core/lib/libgcrypt_wrap/cipher_wrap.h:82: error: "strtoul" redefined [-Werror]
82 | #define strtoulgrub_strtoul| In file included from ../grub-core/lib/libgcrypt_wrap/cipher_wrap.h:76: ../include/grub/gcrypt/g10lib.h:207: note: this is the location of the previous definition 207 | #define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c))) | ../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: error: initialization of ‘int’ from ‘const char *’ makes integer from pointer without a cast [-Werror=int-conversion] 127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context), | ^~~~~~~~~
../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: note: (near initialization for ‘_gcry_cipher_spec_arcfour.algo’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: error: initializer element is not computable at load time../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:5: note: (near initialization for ‘_gcry_cipher_spec_arcfour.algo’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:16: error: initialization of ‘unsigned char:1’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:16: note: (near initialization for ‘_gcry_cipher_spec_arcfour.flags.disabled’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:22: error: initialization of ‘unsigned char:1’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:22: note: (near initialization for ‘_gcry_cipher_spec_arcfour.flags.fips’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:28: error: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:28: note: (near initialization for ‘_gcry_cipher_spec_arcfour.name’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:31: error: initialization of ‘const char **’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:31: note: (near initialization for ‘_gcry_cipher_spec_arcfour.aliases’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:36: error: initialization of ‘constgcry_cipher_oid_spec_t*’ {aka ‘const structgcry_cipher_oid_spec*’} from ‘long unsigned int’ makes pointer from integer without a cast [-Werror=int-conversion]
127 | "ARCFOUR", NULL, NULL, 1, 128, sizeof (ARCFOUR_context),
| ^~~~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:127:36: note: (near initialization for ‘_gcry_cipher_spec_arcfour.oids’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:5: error: initialization of ‘long unsigned int’ from ‘gcry_err_code_t (*)(void *, const byte *, unsigned int)’ {aka ‘gpg_err_code_t (*)(void *, const unsigned char *, unsigned int)’} makes integer from pointer without a cast [-Werror=int-conversion]128 | arcfour_setkey, NULL, NULL, encrypt_stream, encrypt_stream, | ^~~~~~~~~~~~~~
../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:5: note: (near initialization for ‘_gcry_cipher_spec_arcfour.blocksize’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:21: error: initialization of ‘long unsigned int’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
128 |arcfour_setkey, NULL, NULL,encrypt_stream,encrypt_stream,
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:21: note: (near initialization for ‘_gcry_cipher_spec_arcfour.keylen’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:27: error: initialization of ‘long unsigned int’ from ‘void *’ makes integer from pointer without a cast [-Werror=int-conversion]
128 |arcfour_setkey, NULL, NULL,encrypt_stream,encrypt_stream,
| ^~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:27: note: (near initialization for ‘_gcry_cipher_spec_arcfour.contextsize’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:33: error: initialization of ‘gcry_err_code_t (*)(void *, const unsigned char *, unsigned int, structcipher_bulk_ops*)’ {aka ‘gpg_err_code_t (*)(void *, const unsigned char *, unsigned int, structcipher_bulk_ops*)’} from incompatible pointer type ‘void (*)(void *, byte *, const byte *, unsigned int)’ {aka ‘void (*)(void *, unsigned char *, const unsigned char *, unsigned int)’} [-Werror=incompatible-pointer-types]
128 |arcfour_setkey, NULL, NULL,encrypt_stream,encrypt_stream,| ^~~~~~~~~~~~~~
../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:33: note: (near initialization for ‘_gcry_cipher_spec_arcfour.setkey’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:49: error: initialization of ‘unsigned int (*)(void *, unsigned char *, const unsigned char *)’ from incompatible pointer type ‘void (*)(void *, byte *, const byte *, unsigned int)’ {aka ‘void (*)(void *, unsigned char *, const unsigned char *, unsigned int)’} [-Werror=incompatible-pointer-types]
128 |arcfour_setkey, NULL, NULL,encrypt_stream,encrypt_stream,
| ^~~~~~~~~~~~~~../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:128:49: note: (near initialization for ‘_gcry_cipher_spec_arcfour.encrypt’)../grub-core/lib/libgcrypt-grub/cipher/arcfour.c:126:3: error: missing braces around initializer [-Werror=missing-braces]
Quoted 8 lines
126 | { | ^cc1: all warnings being treated as errors
make[2]: *** [Makefile:6403:grub-core/lib/libgcrypt-grub/cipher/libgrubgcry_a-arcfour.o] Error 1 make[2]: Leaving directory '/root/grub/build'
make[1]: *** [Makefile:12468: all-recursive] Error 1
make[1]: Leaving directory '/root/grub/build'
make: *** [Makefile:4058: all] Error 2
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Hi Gary,
Gary Lin wrote,
Quoted 12 lines · Waldemar Brodkorb
Quoted 1 line
Hi Gary,
Hi Waldemar,
Quoted 8 lines
Gary Lin via Grub-devel wrote,
Quoted 2 lines
This patch series imports the Argon2 code and tests from libgcrypt and adds Argon2 support to LUKS2.
I am trying to use your patch series, but compilation is failing. I am using Debian 12 with gcc 12.
Quoted 8 lines
Quoted 5 lines
Attached is the logfile of the make invocation with the failures.
Any ideas why it is working for you? Older gcc? Or are you using --disable-werror in the configure step?
I didn't touch
arcfour.c. Are you using git master? Could you try to remove grub-core/lib/libgcrypt-grub/ and run 'autogen.sh' to update libgcrypt-grub?
Thanks! That made it work. Sorry for the noise, I forgot to autogen.sh after pulling the latest stuff.
At least I see no regression after installing grub with your patch set. Next I try to convert to argon2.
best regards
Waldemar
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Waldemar Brodkorb
Tested-byHi Gary,
Waldemar Brodkorb wrote,
Quoted 20 lines
Hi Gary,
Gary Lin wrote,Quoted 17 lines · Waldemar Brodkorb
Quoted 1 line
Hi Gary,
Hi Waldemar,
Quoted 13 lines
Gary Lin via Grub-devel wrote,
Quoted 2 lines
This patch series imports the Argon2 code and tests from libgcrypt and adds Argon2 support to LUKS2.
I am trying to use your patch series, but compilation is failing. I am using Debian 12 with gcc 12.
Attached is the logfile of the make invocation with the failures.
Any ideas why it is working for you? Older gcc? Or are you using --disable-werror in the configure step?
Quoted 8 lines
Quoted 3 lines
I didn't touch
arcfour.c. Are you using git master? Could you try to remove grub-core/lib/libgcrypt-grub/ and run 'autogen.sh' to update libgcrypt-grub?Thanks! That made it work. Sorry for the noise, I forgot to
autogen.shafter pulling the latest stuff.
At least I see no regression after installing grub with your patch set. Next I try to convert to argon2.
That worked, too. You can add my
if you want.
best regards
Waldemar
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 27 lines · Waldemar Brodkorb
Hi Gary,
Waldemar Brodkorb wrote,Quoted 24 lines
Hi Gary,
Gary Lin wrote,Quoted 20 lines · Waldemar Brodkorb
Quoted 1 line
Hi Gary,
Hi Waldemar,
Quoted 5 lines
Gary Lin via Grub-devel wrote,
Quoted 2 lines
This patch series imports the Argon2 code and tests from libgcrypt and adds Argon2 support to LUKS2.
Quoted 8 lines
I am trying to use your patch series, but compilation is failing. I am using Debian 12 with gcc 12.
Attached is the logfile of the make invocation with the failures.
Any ideas why it is working for you? Older gcc? Or are you using --disable-werror in the configure step?
I didn't touch
arcfour.c. Are you using git master? Could you try to remove grub-core/lib/libgcrypt-grub/ and run 'autogen.sh' to update libgcrypt-grub?
Quoted 8 lines
Quoted 4 lines
Thanks! That made it work. Sorry for the noise, I forgot to
autogen.shafter pulling the latest stuff.
At least I see no regression after installing grub with your patch set. Next I try to convert to argon2.That worked, too. You can add my
Tested-by Waldemar Brodkorb <[email protected]>if you want.
Thanks for testing the patches!
I'll add your Tested-By gratefully.
Cheers,
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel