@@ -154,8 +154,7 @@ do { \
154
154
mbedtls_printf (HEADER_FORMAT, TITLE); \
155
155
fflush (stdout); \
156
156
\
157
- for (i = 1 , alarmed = 0 , t.attach (alarm, 1.0 ); !alarmed; i++) \
158
- { \
157
+ for (i = 1 , alarmed = 0 , t.attach (alarm, 1.0 ); !alarmed; i++) { \
159
158
ret = CODE; \
160
159
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) { \
161
160
mbedtls_printf (" Feature unsupported\n " ); \
@@ -171,34 +170,29 @@ do { \
171
170
} \
172
171
} while (0 )
173
172
174
- #define BENCHMARK_PUBLIC (TITLE, TYPE, CODE ) \
175
- do { \
176
- unsigned long ms; \
177
- Timer t; \
178
- \
179
- mbedtls_printf (HEADER_FORMAT, TITLE); \
180
- fflush (stdout); \
181
- \
182
- t.start (); \
183
- CODE; \
184
- t.stop (); \
185
- ms = t.read_ms (); \
186
- \
187
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)\
188
- { \
189
- mbedtls_printf (" Feature unsupported\n " ); \
190
- break ; \
191
- } \
192
- else if (ret != 0 ) \
193
- { \
194
- PRINT_ERROR (ret, " Public function" ); \
195
- goto exit; \
196
- } \
197
- else \
198
- { \
199
- mbedtls_printf (" %6lu ms/" TYPE, ms); \
200
- mbedtls_printf (" \n " ); \
201
- } \
173
+ #define BENCHMARK_PUBLIC (TITLE, TYPE, CODE ) \
174
+ do { \
175
+ unsigned long ms; \
176
+ Timer t; \
177
+ \
178
+ mbedtls_printf (HEADER_FORMAT, TITLE); \
179
+ fflush (stdout); \
180
+ \
181
+ t.start (); \
182
+ CODE; \
183
+ t.stop (); \
184
+ ms = t.read_ms (); \
185
+ \
186
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {\
187
+ mbedtls_printf (" Feature unsupported\n " ); \
188
+ break ; \
189
+ } else if (ret != 0 ) { \
190
+ PRINT_ERROR (ret, " Public function" ); \
191
+ goto exit; \
192
+ } else { \
193
+ mbedtls_printf (" %6lu ms/" TYPE, ms); \
194
+ mbedtls_printf (" \n " ); \
195
+ } \
202
196
} while (0 )
203
197
204
198
/* Clear some memory that was used to prepare the context */
@@ -703,14 +697,12 @@ MBED_NOINLINE static int benchmark_camellia()
703
697
memset (tmp, 0 , sizeof (tmp));
704
698
705
699
ret = mbedtls_camellia_setkey_enc (&camellia, tmp, keysize);
706
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
707
- {
700
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
708
701
/* Do not consider this as a failure */
709
702
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
710
703
ret = 0 ;
711
704
continue ;
712
- }
713
- else if (ret != 0 ) {
705
+ } else if (ret != 0 ) {
714
706
PRINT_ERROR (ret, " mbedtls_camellia_setkey_enc()" );
715
707
goto exit;
716
708
}
@@ -758,15 +750,12 @@ MBED_NOINLINE static int benchmark_blowfish()
758
750
memset (tmp, 0 , sizeof (tmp));
759
751
760
752
ret = mbedtls_blowfish_setkey (blowfish, tmp, keysize);
761
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
762
- {
753
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
763
754
/* Do not consider this as a failure */
764
755
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
765
756
ret = 0 ;
766
757
continue ;
767
- }
768
- else if (ret != 0 )
769
- {
758
+ } else if (ret != 0 ) {
770
759
PRINT_ERROR (ret, " mbedtls_blowfish_setkey()" );
771
760
goto exit;
772
761
}
@@ -934,14 +923,12 @@ MBED_NOINLINE static int benchmark_rsa()
934
923
935
924
ret = mbedtls_pk_parse_key (&pk, (const unsigned char *)rsa_keys[i],
936
925
strlen (rsa_keys[i]) + 1 , NULL , 0 );
937
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
938
- {
926
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
939
927
/* Do not consider this as a failure */
940
928
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
941
929
ret = 0 ;
942
930
continue ;
943
- }
944
- else if (ret != 0 ) {
931
+ } else if (ret != 0 ) {
945
932
PRINT_ERROR (ret, " mbedtls_pk_parse_key()" );
946
933
goto exit;
947
934
}
@@ -1013,14 +1000,12 @@ MBED_NOINLINE static int benchmark_dhm()
1013
1000
dhm.len = mbedtls_mpi_size (&dhm.P );
1014
1001
ret = mbedtls_dhm_make_public (&dhm, (int ) dhm.len , buf, dhm.len ,
1015
1002
myrand, NULL );
1016
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1017
- {
1003
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1018
1004
/* Do not consider this as a failure */
1019
1005
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1020
1006
ret = 0 ;
1021
1007
continue ;
1022
- }
1023
- else if (ret != 0 ) {
1008
+ } else if (ret != 0 ) {
1024
1009
PRINT_ERROR (ret, " mbedtls_dhm_make_public()" );
1025
1010
goto exit;
1026
1011
}
@@ -1098,14 +1083,12 @@ MBED_NOINLINE static int benchmark_ecdsa()
1098
1083
}
1099
1084
1100
1085
ret = mbedtls_ecdsa_genkey (&ecdsa, curve_info->grp_id , myrand, NULL );
1101
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1102
- {
1086
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1103
1087
/* Do not consider this as a failure */
1104
1088
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1105
1089
ret = 0 ;
1106
1090
continue ;
1107
- }
1108
- else if (ret != 0 ) {
1091
+ } else if (ret != 0 ) {
1109
1092
PRINT_ERROR (ret, " mbedtls_ecdsa_genkey()" );
1110
1093
goto exit;
1111
1094
}
@@ -1129,14 +1112,12 @@ MBED_NOINLINE static int benchmark_ecdsa()
1129
1112
mbedtls_ecdsa_init (&ecdsa);
1130
1113
1131
1114
ret = mbedtls_ecdsa_genkey (&ecdsa, curve_info->grp_id , myrand, NULL );
1132
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1133
- {
1115
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1134
1116
/* Do not consider this as a failure */
1135
1117
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1136
1118
ret = 0 ;
1137
1119
continue ;
1138
- }
1139
- else if (ret != 0 ) {
1120
+ } else if (ret != 0 ) {
1140
1121
PRINT_ERROR (ret, " mbedtls_ecdsa_genkey()" );
1141
1122
goto exit;
1142
1123
}
@@ -1145,14 +1126,12 @@ MBED_NOINLINE static int benchmark_ecdsa()
1145
1126
ret = mbedtls_ecdsa_write_signature (&ecdsa, MBEDTLS_MD_SHA256, buf,
1146
1127
hash_len, tmp, &sig_len, myrand,
1147
1128
NULL );
1148
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1149
- {
1129
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1150
1130
/* Do not consider this as a failure */
1151
1131
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1152
1132
ret = 0 ;
1153
1133
continue ;
1154
- }
1155
- else if (ret != 0 ) {
1134
+ } else if (ret != 0 ) {
1156
1135
PRINT_ERROR (ret, " mbedtls_ecdsa_write_signature()" );
1157
1136
goto exit;
1158
1137
}
@@ -1194,14 +1173,12 @@ MBED_NOINLINE static int benchmark_ecdh()
1194
1173
mbedtls_ecdh_init (&ecdh);
1195
1174
1196
1175
ret = mbedtls_ecp_group_load (&ecdh.grp , curve_info->grp_id );
1197
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1198
- {
1176
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1199
1177
/* Do not consider this as a failure */
1200
1178
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1201
1179
ret = 0 ;
1202
1180
continue ;
1203
- }
1204
- else if (ret != 0 ) {
1181
+ } else if (ret != 0 ) {
1205
1182
PRINT_ERROR (ret, " mbedtls_ecp_group_load()" );
1206
1183
goto exit;
1207
1184
}
@@ -1216,27 +1193,23 @@ MBED_NOINLINE static int benchmark_ecdh()
1216
1193
1217
1194
ret = mbedtls_ecdh_make_public (&ecdh, &olen, buf, sizeof (buf),
1218
1195
myrand, NULL );
1219
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1220
- {
1196
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1221
1197
/* Do not consider this as a failure */
1222
1198
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1223
1199
ret = 0 ;
1224
1200
continue ;
1225
- }
1226
- else if (ret != 0 ) {
1201
+ } else if (ret != 0 ) {
1227
1202
PRINT_ERROR (ret, " mbedtls_ecdh_make_public()" );
1228
1203
goto exit;
1229
1204
}
1230
1205
1231
1206
ret = mbedtls_ecp_copy (&ecdh.Qp , &ecdh.Q );
1232
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1233
- {
1207
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1234
1208
/* Do not consider this as a failure */
1235
1209
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1236
1210
ret = 0 ;
1237
1211
continue ;
1238
- }
1239
- else if (ret != 0 ) {
1212
+ } else if (ret != 0 ) {
1240
1213
PRINT_ERROR (ret, " mbedtls_ecp_copy()" );
1241
1214
goto exit;
1242
1215
}
@@ -1268,14 +1241,12 @@ MBED_NOINLINE static int benchmark_ecdh()
1268
1241
mbedtls_ecdh_init (&ecdh);
1269
1242
1270
1243
ret = mbedtls_ecp_group_load (&ecdh.grp , curve_info->grp_id );
1271
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1272
- {
1244
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1273
1245
/* Do not consider this as a failure */
1274
1246
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1275
1247
ret = 0 ;
1276
1248
continue ;
1277
- }
1278
- else if (ret != 0 ) {
1249
+ } else if (ret != 0 ) {
1279
1250
PRINT_ERROR (ret, " mbedtls_ecp_group_load()" );
1280
1251
goto exit;
1281
1252
}
@@ -1290,41 +1261,35 @@ MBED_NOINLINE static int benchmark_ecdh()
1290
1261
1291
1262
ret = mbedtls_ecdh_make_public (&ecdh, &olen, buf, sizeof (buf), myrand,
1292
1263
NULL );
1293
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1294
- {
1264
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1295
1265
/* Do not consider this as a failure */
1296
1266
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1297
1267
ret = 0 ;
1298
1268
continue ;
1299
- }
1300
- else if (ret != 0 ) {
1269
+ } else if (ret != 0 ) {
1301
1270
PRINT_ERROR (ret, " mbedtls_ecdh_make_public()" );
1302
1271
goto exit;
1303
1272
}
1304
1273
1305
1274
ret = mbedtls_ecp_copy (&ecdh.Qp , &ecdh.Q );
1306
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1307
- {
1275
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1308
1276
/* Do not consider this as a failure */
1309
1277
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1310
1278
ret = 0 ;
1311
1279
continue ;
1312
- }
1313
- else if (ret != 0 ) {
1280
+ } else if (ret != 0 ) {
1314
1281
PRINT_ERROR (ret, " mbedtls_ecp_copy()" );
1315
1282
goto exit;
1316
1283
}
1317
1284
1318
1285
ret = mbedtls_ecdh_make_public (&ecdh, &olen, buf, sizeof (buf), myrand,
1319
1286
NULL );
1320
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1321
- {
1287
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1322
1288
/* Do not consider this as a failure */
1323
1289
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1324
1290
ret = 0 ;
1325
1291
continue ;
1326
- }
1327
- else if (ret != 0 ) {
1292
+ } else if (ret != 0 ) {
1328
1293
PRINT_ERROR (ret, " mbedtls_ecdh_make_public()" );
1329
1294
goto exit;
1330
1295
}
@@ -1356,36 +1321,31 @@ MBED_NOINLINE static int benchmark_ecdh_curve22519()
1356
1321
mbedtls_mpi_init (&z);
1357
1322
1358
1323
ret = mbedtls_snprintf (title, sizeof (title), " ECDHE-Curve25519" );
1359
- if (ret < 0 || static_cast <size_t >(ret) >= sizeof (title))
1360
- {
1324
+ if (ret < 0 || static_cast <size_t >(ret) >= sizeof (title)) {
1361
1325
mbedtls_printf (" Failed to compose title string using "
1362
1326
" mbedtls_snprintf(): %d\n " , ret);
1363
1327
goto exit;
1364
1328
}
1365
1329
1366
1330
ret = mbedtls_ecp_group_load (&ecdh.grp , MBEDTLS_ECP_DP_CURVE25519);
1367
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1368
- {
1331
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1369
1332
/* Do not consider this as a failure */
1370
1333
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1371
1334
ret = 0 ;
1372
1335
goto exit;
1373
- }
1374
- else if (ret != 0 ) {
1336
+ } else if (ret != 0 ) {
1375
1337
PRINT_ERROR (ret, " mbedtls_ecp_group_load()" );
1376
1338
goto exit;
1377
1339
}
1378
1340
1379
1341
ret = mbedtls_ecdh_gen_public (&ecdh.grp , &ecdh.d , &ecdh.Qp , myrand,
1380
1342
NULL );
1381
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1382
- {
1343
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1383
1344
/* Do not consider this as a failure */
1384
1345
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1385
1346
ret = 0 ;
1386
1347
goto exit;
1387
- }
1388
- else if (ret != 0 ) {
1348
+ } else if (ret != 0 ) {
1389
1349
PRINT_ERROR (ret, " mbedtls_ecdh_gen_public()" );
1390
1350
goto exit;
1391
1351
}
@@ -1419,41 +1379,34 @@ MBED_NOINLINE static int benchmark_ecdh_curve22519()
1419
1379
goto exit;
1420
1380
}
1421
1381
ret = mbedtls_ecp_group_load (&ecdh.grp , MBEDTLS_ECP_DP_CURVE25519);
1422
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1423
- {
1382
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1424
1383
/* Do not consider this as a failure */
1425
1384
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1426
1385
ret = 0 ;
1427
1386
goto exit;
1428
- }
1429
- else if (ret != 0 ) {
1387
+ } else if (ret != 0 ) {
1430
1388
PRINT_ERROR (ret, " mbedtls_ecp_group_load()" );
1431
1389
goto exit;
1432
1390
}
1433
1391
1434
1392
ret = mbedtls_ecdh_gen_public (&ecdh.grp , &ecdh.d , &ecdh.Qp , myrand, NULL );
1435
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1436
- {
1393
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1437
1394
/* Do not consider this as a failure */
1438
1395
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1439
1396
ret = 0 ;
1440
1397
goto exit;
1441
- }
1442
- else if (ret != 0 ) {
1398
+ } else if (ret != 0 ) {
1443
1399
PRINT_ERROR (ret, " mbedtls_ecdh_gen_public()" );
1444
1400
goto exit;
1445
1401
}
1446
1402
1447
1403
ret = mbedtls_ecdh_gen_public (&ecdh.grp , &ecdh.d , &ecdh.Q , myrand, NULL );
1448
- if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1449
- {
1404
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
1450
1405
/* Do not consider this as a failure */
1451
1406
mbedtls_printf (HEADER_FORMAT " Feature unsupported\n " , title);
1452
1407
ret = 0 ;
1453
1408
goto exit;
1454
- }
1455
- else
1456
- if (ret != 0 ) {
1409
+ } else if (ret != 0 ) {
1457
1410
PRINT_ERROR (ret, " mbedtls_ecdh_gen_public()" );
1458
1411
goto exit;
1459
1412
}
0 commit comments