summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2022-10-02 17:56:16 +0200
committerNiels Möller <nisse@lysator.liu.se>2022-10-02 17:56:16 +0200
commit76bd07fb0b2f6cbd1c649b4dd8b449090a566cca (patch)
treef35460f610b5a71001791a2ed20e879429fd5e51 /examples
parent8a446577d5a8c5f978eae3b6cf1daacf2d17a142 (diff)
downloadnettle-76bd07fb0b2f6cbd1c649b4dd8b449090a566cca.tar.gz
Add benchmarking of modulo q inversion.
Diffstat (limited to 'examples')
-rw-r--r--examples/ecc-benchmark.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/examples/ecc-benchmark.c b/examples/ecc-benchmark.c
index 3ab269c7..7e857f80 100644
--- a/examples/ecc-benchmark.c
+++ b/examples/ecc-benchmark.c
@@ -159,11 +159,17 @@ bench_modq (void *p)
}
static void
-bench_modinv (void *p)
+bench_pinv (void *p)
{
struct ecc_ctx *ctx = (struct ecc_ctx *) p;
ctx->ecc->p.invert (&ctx->ecc->p, ctx->rp, ctx->ap, ctx->tp);
}
+static void
+bench_qinv (void *p)
+{
+ struct ecc_ctx *ctx = (struct ecc_ctx *) p;
+ ctx->ecc->q.invert (&ctx->ecc->p, ctx->rp, ctx->ap, ctx->tp);
+}
#if !NETTLE_USE_MINI_GMP
static void
@@ -239,7 +245,7 @@ static void
bench_curve (const struct ecc_curve *ecc)
{
struct ecc_ctx ctx;
- double modp, reduce, modq, modinv, modinv_gcd, modinv_powm,
+ double modp, reduce, modq, pinv, qinv, modinv_gcd, modinv_powm,
dup_hh, add_hh, add_hhh,
mul_g, mul_a;
@@ -277,7 +283,8 @@ bench_curve (const struct ecc_curve *ecc)
modq = time_function (bench_modq, &ctx);
- modinv = time_function (bench_modinv, &ctx);
+ pinv = time_function (bench_pinv, &ctx);
+ qinv = time_function (bench_qinv, &ctx);
#if !NETTLE_USE_MINI_GMP
modinv_gcd = time_function (bench_modinv_gcd, &ctx);
#else
@@ -299,9 +306,9 @@ bench_curve (const struct ecc_curve *ecc)
free (ctx.bp);
free (ctx.tp);
- printf ("%4d %6.4f %6.4f %6.4f %6.2f %6.3f %6.2f %6.3f %6.3f %6.3f %6.1f %6.1f\n",
+ printf ("%4d %6.4f %6.4f %6.4f %6.2f %6.2f %6.3f %6.2f %6.3f %6.3f %6.3f %6.1f %6.1f\n",
ecc->p.bit_size, 1e6 * modp, 1e6 * reduce, 1e6 * modq,
- 1e6 * modinv, 1e6 * modinv_gcd, 1e6 * modinv_powm,
+ 1e6 * pinv, 1e6 * qinv, 1e6 * modinv_gcd, 1e6 * modinv_powm,
1e6 * dup_hh, 1e6 * add_hh, 1e6 * add_hhh,
1e6 * mul_g, 1e6 * mul_a);
}
@@ -326,8 +333,8 @@ main (int argc UNUSED, char **argv UNUSED)
unsigned i;
time_init();
- printf ("%4s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s (us)\n",
- "size", "modp", "reduce", "modq", "modinv", "mi_gcd", "mi_pow",
+ printf ("%4s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s (us)\n",
+ "size", "modp", "reduce", "modq", "pinv", "qinv", "mi_gcd", "mi_pow",
"dup_hh", "add_hh", "ad_hhh",
"mul_g", "mul_a");
for (i = 0; i < numberof (curves); i++)