aboutsummaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>2024-02-22 12:14:28 +0100
committerGilles Peskine <Gilles.Peskine@arm.com>2024-02-22 12:29:06 +0100
commitdd9cbf99c237ba26b645ce379740206c82acd4df (patch)
tree4b0d42b512ae0a6dbd0c2591be3eae74f90380af /programs
parent74589ba31c7244c1586ac1146938fd7fd5e02815 (diff)
downloadmbedtls-dd9cbf99c237ba26b645ce379740206c82acd4df.zip
mbedtls-dd9cbf99c237ba26b645ce379740206c82acd4df.tar.gz
mbedtls-dd9cbf99c237ba26b645ce379740206c82acd4df.tar.bz2
Benchmark only one side of ECDH, both static and ephemeral
Static ECDH is of interest to us as developers because it's a generic scalar multiplication (as opposed to using the standard base point) and it's useful to have that handy. For reference the other operations of interest to developers are: - multiplication of the conventional base point: ECDSA signing is almost exactly that (just a few field ops on top, notably 1 inversion); - linear combination: ECDSA verification is almost exactly that too. Including ephemeral as well, because it's hopefully what's of interest to most users. Compared to the previous version, include only one side of the operations. I don't think including both sides is of interest to anyone. Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
Diffstat (limited to 'programs')
-rw-r--r--programs/test/benchmark.c57
1 files changed, 42 insertions, 15 deletions
diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
index 0861d0f..93c1729 100644
--- a/programs/test/benchmark.c
+++ b/programs/test/benchmark.c
@@ -1191,7 +1191,7 @@ int main(int argc, char *argv[])
mbedtls_ecdh_context ecdh_srv, ecdh_cli;
unsigned char buf_srv[BUFSIZE], buf_cli[BUFSIZE];
const mbedtls_ecp_curve_info *curve_info;
- size_t olen;
+ size_t params_len, publen, seclen;
for (curve_info = curve_list;
curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
@@ -1201,33 +1201,60 @@ int main(int argc, char *argv[])
}
mbedtls_ecdh_init(&ecdh_srv);
- mbedtls_ecdh_init(&ecdh_cli);
+
+ CHECK_AND_CONTINUE(mbedtls_ecdh_setup(&ecdh_srv, curve_info->grp_id));
+ CHECK_AND_CONTINUE(mbedtls_ecdh_make_params(&ecdh_srv, &params_len, buf_srv,
+ sizeof(buf_srv), myrand, NULL));
mbedtls_snprintf(title, sizeof(title), "ECDHE-%s", curve_info->name);
TIME_PUBLIC(title,
- "full handshake",
+ "ephemeral handshake",
const unsigned char *p_srv = buf_srv;
-
- CHECK_AND_CONTINUE(mbedtls_ecdh_setup(&ecdh_srv, curve_info->grp_id));
- CHECK_AND_CONTINUE(mbedtls_ecdh_make_params(&ecdh_srv, &olen, buf_srv,
- sizeof(buf_srv), myrand, NULL));
+ mbedtls_ecdh_init(&ecdh_cli);
CHECK_AND_CONTINUE(mbedtls_ecdh_read_params(&ecdh_cli, &p_srv,
- p_srv + olen));
- CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh_cli, &olen, buf_cli,
+ p_srv + params_len));
+ CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh_cli, &publen, buf_cli,
sizeof(buf_cli), myrand, NULL));
- CHECK_AND_CONTINUE(mbedtls_ecdh_read_public(&ecdh_srv, buf_cli, olen));
- CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh_srv, &olen, buf_srv,
- sizeof(buf_srv), myrand, NULL));
-
- CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh_cli, &olen, buf_cli,
+ CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh_cli, &seclen, buf_cli,
sizeof(buf_cli), myrand, NULL));
mbedtls_ecdh_free(&ecdh_cli);
+ );
- mbedtls_ecdh_free(&ecdh_srv);
+ mbedtls_ecdh_free(&ecdh_srv);
+ }
+
+ for (curve_info = curve_list;
+ curve_info->grp_id != MBEDTLS_ECP_DP_NONE;
+ curve_info++) {
+ if (!mbedtls_ecdh_can_do(curve_info->grp_id)) {
+ continue;
+ }
+
+ mbedtls_ecdh_init(&ecdh_srv);
+ mbedtls_ecdh_init(&ecdh_cli);
+
+ CHECK_AND_CONTINUE(mbedtls_ecdh_setup(&ecdh_srv, curve_info->grp_id));
+ CHECK_AND_CONTINUE(mbedtls_ecdh_make_params(&ecdh_srv, &params_len, buf_srv,
+ sizeof(buf_srv), myrand, NULL));
+
+ const unsigned char *p_srv = buf_srv;
+ CHECK_AND_CONTINUE(mbedtls_ecdh_read_params(&ecdh_cli, &p_srv,
+ p_srv + params_len));
+ CHECK_AND_CONTINUE(mbedtls_ecdh_make_public(&ecdh_cli, &publen, buf_cli,
+ sizeof(buf_cli), myrand, NULL));
+
+
+ mbedtls_snprintf(title, sizeof(title), "ECDH-%s", curve_info->name);
+ TIME_PUBLIC(title,
+ "static handshake",
+ CHECK_AND_CONTINUE(mbedtls_ecdh_calc_secret(&ecdh_cli, &seclen, buf_cli,
+ sizeof(buf_cli), myrand, NULL));
);
+ mbedtls_ecdh_free(&ecdh_cli);
+ mbedtls_ecdh_free(&ecdh_srv);
}
}
#endif