Skip to content

Commit 5bee6ae

Browse files
Andres Amaya GarciaAndres Amaya Garcia
Andres Amaya Garcia
authored and
Andres Amaya Garcia
committed
benchmark: Check for errors in between benchmarked function calls
1 parent 58dc1f9 commit 5bee6ae

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

benchmark/main.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,11 +961,20 @@ MBED_NOINLINE static int benchmark_dhm()
961961
goto exit;
962962
}
963963

964+
/*
965+
* Benchmarking this requires two function calls that can fail. We
966+
* add a check in between them to check for any errors. In normal
967+
* operation, the overhead of this check is negligible
968+
*/
964969
BENCHMARK_PUBLIC(title, "handshake",
965-
ret = mbedtls_dhm_make_public(&dhm, (int)dhm.len,
970+
ret = mbedtls_dhm_make_public(&dhm, (int)dhm.len,
966971
buf, dhm.len, myrand,
967972
NULL);
968-
ret |= mbedtls_dhm_calc_secret(&dhm, buf, sizeof(buf),
973+
if (ret != 0) {
974+
PRINT_ERROR(ret, "mbedtls_dhm_make_public()");
975+
goto exit;
976+
}
977+
ret = mbedtls_dhm_calc_secret(&dhm, buf, sizeof(buf),
969978
&olen, myrand, NULL));
970979

971980
ret = mbedtls_snprintf(title, sizeof(title), "DH-%d", dhm_sizes[i]);
@@ -1115,11 +1124,20 @@ MBED_NOINLINE static int benchmark_ecdh()
11151124
goto exit;
11161125
}
11171126

1127+
/*
1128+
* Benchmarking this requires two function calls that can fail. We
1129+
* add a check in between them to check for any errors. In normal
1130+
* operation, the overhead of this check is negligible
1131+
*/
11181132
BENCHMARK_PUBLIC(title, "handshake",
1119-
ret = mbedtls_ecdh_make_public(&ecdh, &olen, buf,
1133+
ret = mbedtls_ecdh_make_public(&ecdh, &olen, buf,
11201134
sizeof(buf), myrand,
11211135
NULL);
1122-
ret |= mbedtls_ecdh_calc_secret(&ecdh, &olen, buf,
1136+
if (ret != 0) {
1137+
PRINT_ERROR(ret, "mbedtls_ecdh_make_public()");
1138+
goto exit;
1139+
}
1140+
ret = mbedtls_ecdh_calc_secret(&ecdh, &olen, buf,
11231141
sizeof(buf), myrand,
11241142
NULL));
11251143
mbedtls_ecdh_free(&ecdh);
@@ -1202,10 +1220,19 @@ MBED_NOINLINE static int benchmark_ecdh_curve22519()
12021220
goto exit;
12031221
}
12041222

1223+
/*
1224+
* Benchmarking this requires two function calls that can fail. We
1225+
* add a check in between them to check for any errors. In normal
1226+
* operation, the overhead of this check is negligible
1227+
*/
12051228
BENCHMARK_PUBLIC("ECDHE-Curve25519", "handshake",
1206-
ret = mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d,
1229+
ret = mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d,
12071230
&ecdh.Q, myrand, NULL);
1208-
ret |= mbedtls_ecdh_compute_shared(&ecdh.grp, &z,
1231+
if (ret != 0) {
1232+
PRINT_ERROR(ret, "mbedtls_ecdh_make_public()");
1233+
goto exit;
1234+
}
1235+
ret = mbedtls_ecdh_compute_shared(&ecdh.grp, &z,
12091236
&ecdh.Qp, &ecdh.d,
12101237
myrand, NULL));
12111238

0 commit comments

Comments
 (0)