[PATCH 5/8] mpi:ec: Resize when GCRYECC_FLAG_LEAST_LEAK.
NIIBE Yutaka via Gcrypt-devel <[email protected]> Thu, 27 Mar 2025 14:19:08 +0900
| Newsgroups | gmane.comp.encryption.gpg.libgcrypt.devel |
|---|---|
| Message-ID | <794b8e7378e84c344a0629af61b1154f8830aca4.1743052412.git.gniibe@fsij.org> |
* mpi/ec.c (ec_p_init): Also resize when GCRYECC_FLAG_LEAST_LEAK. Signed-off-by: NIIBE Yutaka <[email protected]> --- mpi/ec.c | 33 ++++++++++++++++++--------------- src/cipher.h | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) _______________________________________________ Gcrypt-devel mailing list [email protected] https://lists.gnupg.org/mailman/listinfo/gcrypt-devel
0005-mpi-ec-Resize-when-GCRYECC_FLAG_LEAST_LEAK.patch
(text/x-patch, 1.9 KB)
diff --git a/mpi/ec.c b/mpi/ec.c
index 4e24d817..d13c0fd8 100644
--- a/mpi/ec.c
+++ b/mpi/ec.c
@@ -29,6 +29,7 @@
#include "context.h"
#include "ec-context.h"
#include "ec-internal.h"
+#include "cipher.h" /* for GCRYECC_FLAG_LEAST_LEAK */
extern void reverse_buffer (unsigned char *buffer, unsigned int length);
@@ -887,24 +888,26 @@ ec_p_init (mpi_ec_t ctx, enum gcry_mpi_ec_models model,
ctx->mul2 = field_table[i].mul2 ? field_table[i].mul2 : ctx->mul2;
ctx->pow2 = field_table[i].pow2 ? field_table[i].pow2 : ctx->pow2;
ctx->mod = field_table[i].mod ? field_table[i].mod : ctx->mod;
+ break;
+ }
+ }
- if (ctx->a)
- {
- mpi_resize (ctx->a, ctx->p->nlimbs);
- ctx->a->nlimbs = ctx->p->nlimbs;
- }
-
- if (ctx->b)
- {
- mpi_resize (ctx->b, ctx->p->nlimbs);
- ctx->b->nlimbs = ctx->p->nlimbs;
- }
-
- for (i=0; i< DIM(ctx->t.scratch) && ctx->t.scratch[i]; i++)
- ctx->t.scratch[i]->nlimbs = ctx->p->nlimbs;
+ if (field_table[i].p || (flags & GCRYECC_FLAG_LEAST_LEAK))
+ {
+ if (ctx->a)
+ {
+ mpi_resize (ctx->a, ctx->p->nlimbs);
+ ctx->a->nlimbs = ctx->p->nlimbs;
+ }
- break;
+ if (ctx->b)
+ {
+ mpi_resize (ctx->b, ctx->p->nlimbs);
+ ctx->b->nlimbs = ctx->p->nlimbs;
}
+
+ for (i=0; i< DIM(ctx->t.scratch) && ctx->t.scratch[i]; i++)
+ ctx->t.scratch[i]->nlimbs = ctx->p->nlimbs;
}
/* Prepare for fast reduction. */
diff --git a/src/cipher.h b/src/cipher.h
index 78a7c7ce..652bdd6f 100644
--- a/src/cipher.h
+++ b/src/cipher.h
@@ -48,7 +48,7 @@
* The internal flag to select least leak implementation for ECC.
* It needs to be a distinct value not covered by PUBKEY_* above.
*/
-#define GCRYECC_FLAG_LEAST_LEAK (1 << 30)
+#define GCRYECC_FLAG_LEAST_LEAK (1 << 30)
enum pk_operation