[PATCH 2/3] mpi/mpiutil: define constant number structures statically
Jussi Kivilinna
jussi.kivilinna at iki.fi
Tue May 14 18:46:00 CEST 2019
* mpi/mpiutil.c (constant_limbs): New.
(constants): Change from array of pointers to array of mpi strucutres,
and initialize constant structures.
(_gcry_mpi_init): Remove constant initialization.
(_gcry_mpi_count): Adjust to structure change.
--
GnuPG-bug-id: 4499
Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
0 files changed
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index 9dde37fb4..fabb55a57 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -43,8 +43,21 @@
#endif
-/* Constants allocated right away at startup. */
-static gcry_mpi_t constants[MPI_NUMBER_OF_CONSTANTS];
+/* Fixed constants allocated staticly. */
+static mpi_limb_t constant_limbs[MPI_NUMBER_OF_CONSTANTS] =
+{
+ 0, 1, 2, 3, 4, 8
+};
+
+static struct gcry_mpi constants[MPI_NUMBER_OF_CONSTANTS] =
+{
+ /* [MPI_C_ZERO] = */ { 1, 0, 0, (16 | 32), &constant_limbs[0] },
+ /* [MPI_C_ONE] = */ { 1, 1, 0, (16 | 32), &constant_limbs[1] },
+ /* [MPI_C_TWO] = */ { 1, 1, 0, (16 | 32), &constant_limbs[2] },
+ /* [MPI_C_THREE] = */ { 1, 1, 0, (16 | 32), &constant_limbs[3] },
+ /* [MPI_C_FOUR] = */ { 1, 1, 0, (16 | 32), &constant_limbs[4] },
+ /* [MPI_C_EIGHT] = */ { 1, 1, 0, (16 | 32), &constant_limbs[5] },
+};
@@ -60,25 +73,6 @@ _gcry_mpi_get_hw_config (void)
gcry_err_code_t
_gcry_mpi_init (void)
{
- int idx;
- unsigned long value;
-
- for (idx=0; idx < MPI_NUMBER_OF_CONSTANTS; idx++)
- {
- switch (idx)
- {
- case MPI_C_ZERO: value = 0; break;
- case MPI_C_ONE: value = 1; break;
- case MPI_C_TWO: value = 2; break;
- case MPI_C_THREE: value = 3; break;
- case MPI_C_FOUR: value = 4; break;
- case MPI_C_EIGHT: value = 8; break;
- default: log_bug ("invalid mpi_const selector %d\n", idx);
- }
- constants[idx] = mpi_alloc_set_ui (value);
- constants[idx]->flags = (16|32);
- }
-
return 0;
}
@@ -756,7 +750,5 @@ _gcry_mpi_const (enum gcry_mpi_constants no)
{
if ((int)no < 0 || no > MPI_NUMBER_OF_CONSTANTS)
log_bug("invalid mpi_const selector %d\n", no);
- if (!constants[no])
- log_bug("MPI subsystem not initialized\n");
- return constants[no];
+ return &constants[no];
}
More information about the Gcrypt-devel
mailing list