@@ -961,11 +961,20 @@ MBED_NOINLINE static int benchmark_dhm()
961
961
goto exit;
962
962
}
963
963
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
+ */
964
969
BENCHMARK_PUBLIC (title, " handshake" ,
965
- ret = mbedtls_dhm_make_public (&dhm, (int )dhm.len ,
970
+ ret = mbedtls_dhm_make_public (&dhm, (int )dhm.len ,
966
971
buf, dhm.len , myrand,
967
972
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),
969
978
&olen, myrand, NULL ));
970
979
971
980
ret = mbedtls_snprintf (title, sizeof (title), " DH-%d" , dhm_sizes[i]);
@@ -1115,11 +1124,20 @@ MBED_NOINLINE static int benchmark_ecdh()
1115
1124
goto exit;
1116
1125
}
1117
1126
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
+ */
1118
1132
BENCHMARK_PUBLIC (title, " handshake" ,
1119
- ret = mbedtls_ecdh_make_public (&ecdh, &olen, buf,
1133
+ ret = mbedtls_ecdh_make_public (&ecdh, &olen, buf,
1120
1134
sizeof (buf), myrand,
1121
1135
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,
1123
1141
sizeof (buf), myrand,
1124
1142
NULL ));
1125
1143
mbedtls_ecdh_free (&ecdh);
@@ -1202,10 +1220,19 @@ MBED_NOINLINE static int benchmark_ecdh_curve22519()
1202
1220
goto exit;
1203
1221
}
1204
1222
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
+ */
1205
1228
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 ,
1207
1230
&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,
1209
1236
&ecdh.Qp , &ecdh.d ,
1210
1237
myrand, NULL ));
1211
1238
0 commit comments