Skip to content

Commit ca7e604

Browse files
Ron EldorRon Eldor
authored andcommitted
Style fixes
Fix braces style to be like in mbed OS, K & R style.
1 parent 173c1a2 commit ca7e604

File tree

1 file changed

+63
-110
lines changed

1 file changed

+63
-110
lines changed

benchmark/main.cpp

Lines changed: 63 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ do { \
154154
mbedtls_printf(HEADER_FORMAT, TITLE); \
155155
fflush(stdout); \
156156
\
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++) { \
159158
ret = CODE; \
160159
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) { \
161160
mbedtls_printf("Feature unsupported\n"); \
@@ -171,34 +170,29 @@ do { \
171170
} \
172171
} while(0)
173172

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+
} \
202196
} while(0)
203197

204198
/* Clear some memory that was used to prepare the context */
@@ -703,14 +697,12 @@ MBED_NOINLINE static int benchmark_camellia()
703697
memset(tmp, 0, sizeof(tmp));
704698

705699
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) {
708701
/* Do not consider this as a failure */
709702
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
710703
ret = 0;
711704
continue;
712-
}
713-
else if (ret != 0) {
705+
} else if (ret != 0) {
714706
PRINT_ERROR(ret, "mbedtls_camellia_setkey_enc()");
715707
goto exit;
716708
}
@@ -758,15 +750,12 @@ MBED_NOINLINE static int benchmark_blowfish()
758750
memset(tmp, 0, sizeof(tmp));
759751

760752
ret = mbedtls_blowfish_setkey(blowfish, tmp, keysize);
761-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
762-
{
753+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
763754
/* Do not consider this as a failure */
764755
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
765756
ret = 0;
766757
continue;
767-
}
768-
else if (ret != 0)
769-
{
758+
} else if (ret != 0) {
770759
PRINT_ERROR(ret, "mbedtls_blowfish_setkey()");
771760
goto exit;
772761
}
@@ -934,14 +923,12 @@ MBED_NOINLINE static int benchmark_rsa()
934923

935924
ret = mbedtls_pk_parse_key(&pk, (const unsigned char *)rsa_keys[i],
936925
strlen(rsa_keys[i]) + 1, NULL, 0);
937-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
938-
{
926+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
939927
/* Do not consider this as a failure */
940928
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
941929
ret = 0;
942930
continue;
943-
}
944-
else if (ret != 0) {
931+
} else if (ret != 0) {
945932
PRINT_ERROR(ret, "mbedtls_pk_parse_key()");
946933
goto exit;
947934
}
@@ -1013,14 +1000,12 @@ MBED_NOINLINE static int benchmark_dhm()
10131000
dhm.len = mbedtls_mpi_size(&dhm.P);
10141001
ret = mbedtls_dhm_make_public(&dhm, (int) dhm.len, buf, dhm.len,
10151002
myrand, NULL);
1016-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1017-
{
1003+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
10181004
/* Do not consider this as a failure */
10191005
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
10201006
ret = 0;
10211007
continue;
1022-
}
1023-
else if (ret != 0) {
1008+
} else if (ret != 0) {
10241009
PRINT_ERROR(ret, "mbedtls_dhm_make_public()");
10251010
goto exit;
10261011
}
@@ -1098,14 +1083,12 @@ MBED_NOINLINE static int benchmark_ecdsa()
10981083
}
10991084

11001085
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) {
11031087
/* Do not consider this as a failure */
11041088
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
11051089
ret = 0;
11061090
continue;
1107-
}
1108-
else if (ret != 0) {
1091+
} else if (ret != 0) {
11091092
PRINT_ERROR(ret, "mbedtls_ecdsa_genkey()");
11101093
goto exit;
11111094
}
@@ -1129,14 +1112,12 @@ MBED_NOINLINE static int benchmark_ecdsa()
11291112
mbedtls_ecdsa_init(&ecdsa);
11301113

11311114
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) {
11341116
/* Do not consider this as a failure */
11351117
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
11361118
ret = 0;
11371119
continue;
1138-
}
1139-
else if (ret != 0) {
1120+
} else if (ret != 0) {
11401121
PRINT_ERROR(ret, "mbedtls_ecdsa_genkey()");
11411122
goto exit;
11421123
}
@@ -1145,14 +1126,12 @@ MBED_NOINLINE static int benchmark_ecdsa()
11451126
ret = mbedtls_ecdsa_write_signature(&ecdsa, MBEDTLS_MD_SHA256, buf,
11461127
hash_len, tmp, &sig_len, myrand,
11471128
NULL);
1148-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1149-
{
1129+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
11501130
/* Do not consider this as a failure */
11511131
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
11521132
ret = 0;
11531133
continue;
1154-
}
1155-
else if (ret != 0) {
1134+
} else if (ret != 0) {
11561135
PRINT_ERROR(ret, "mbedtls_ecdsa_write_signature()");
11571136
goto exit;
11581137
}
@@ -1194,14 +1173,12 @@ MBED_NOINLINE static int benchmark_ecdh()
11941173
mbedtls_ecdh_init(&ecdh);
11951174

11961175
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) {
11991177
/* Do not consider this as a failure */
12001178
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
12011179
ret = 0;
12021180
continue;
1203-
}
1204-
else if (ret != 0) {
1181+
} else if (ret != 0) {
12051182
PRINT_ERROR(ret, "mbedtls_ecp_group_load()");
12061183
goto exit;
12071184
}
@@ -1216,27 +1193,23 @@ MBED_NOINLINE static int benchmark_ecdh()
12161193

12171194
ret = mbedtls_ecdh_make_public(&ecdh, &olen, buf, sizeof(buf),
12181195
myrand, NULL);
1219-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1220-
{
1196+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
12211197
/* Do not consider this as a failure */
12221198
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
12231199
ret = 0;
12241200
continue;
1225-
}
1226-
else if (ret != 0) {
1201+
} else if (ret != 0) {
12271202
PRINT_ERROR(ret, "mbedtls_ecdh_make_public()");
12281203
goto exit;
12291204
}
12301205

12311206
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) {
12341208
/* Do not consider this as a failure */
12351209
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
12361210
ret = 0;
12371211
continue;
1238-
}
1239-
else if (ret != 0) {
1212+
} else if (ret != 0) {
12401213
PRINT_ERROR(ret, "mbedtls_ecp_copy()");
12411214
goto exit;
12421215
}
@@ -1268,14 +1241,12 @@ MBED_NOINLINE static int benchmark_ecdh()
12681241
mbedtls_ecdh_init(&ecdh);
12691242

12701243
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) {
12731245
/* Do not consider this as a failure */
12741246
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
12751247
ret = 0;
12761248
continue;
1277-
}
1278-
else if (ret != 0) {
1249+
} else if (ret != 0) {
12791250
PRINT_ERROR(ret, "mbedtls_ecp_group_load()");
12801251
goto exit;
12811252
}
@@ -1290,41 +1261,35 @@ MBED_NOINLINE static int benchmark_ecdh()
12901261

12911262
ret = mbedtls_ecdh_make_public(&ecdh, &olen, buf, sizeof(buf), myrand,
12921263
NULL);
1293-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1294-
{
1264+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
12951265
/* Do not consider this as a failure */
12961266
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
12971267
ret = 0;
12981268
continue;
1299-
}
1300-
else if (ret != 0) {
1269+
} else if (ret != 0) {
13011270
PRINT_ERROR(ret, "mbedtls_ecdh_make_public()");
13021271
goto exit;
13031272
}
13041273

13051274
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) {
13081276
/* Do not consider this as a failure */
13091277
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
13101278
ret = 0;
13111279
continue;
1312-
}
1313-
else if (ret != 0) {
1280+
} else if (ret != 0) {
13141281
PRINT_ERROR(ret, "mbedtls_ecp_copy()");
13151282
goto exit;
13161283
}
13171284

13181285
ret = mbedtls_ecdh_make_public(&ecdh, &olen, buf, sizeof(buf), myrand,
13191286
NULL);
1320-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1321-
{
1287+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
13221288
/* Do not consider this as a failure */
13231289
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
13241290
ret = 0;
13251291
continue;
1326-
}
1327-
else if (ret != 0) {
1292+
} else if (ret != 0) {
13281293
PRINT_ERROR(ret, "mbedtls_ecdh_make_public()");
13291294
goto exit;
13301295
}
@@ -1356,36 +1321,31 @@ MBED_NOINLINE static int benchmark_ecdh_curve22519()
13561321
mbedtls_mpi_init(&z);
13571322

13581323
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)) {
13611325
mbedtls_printf("Failed to compose title string using "
13621326
"mbedtls_snprintf(): %d\n", ret);
13631327
goto exit;
13641328
}
13651329

13661330
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) {
13691332
/* Do not consider this as a failure */
13701333
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
13711334
ret = 0;
13721335
goto exit;
1373-
}
1374-
else if (ret != 0) {
1336+
} else if (ret != 0) {
13751337
PRINT_ERROR(ret, "mbedtls_ecp_group_load()");
13761338
goto exit;
13771339
}
13781340

13791341
ret = mbedtls_ecdh_gen_public(&ecdh.grp, &ecdh.d, &ecdh.Qp, myrand,
13801342
NULL);
1381-
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED)
1382-
{
1343+
if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) {
13831344
/* Do not consider this as a failure */
13841345
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
13851346
ret = 0;
13861347
goto exit;
1387-
}
1388-
else if (ret != 0) {
1348+
} else if (ret != 0) {
13891349
PRINT_ERROR(ret, "mbedtls_ecdh_gen_public()");
13901350
goto exit;
13911351
}
@@ -1419,41 +1379,34 @@ MBED_NOINLINE static int benchmark_ecdh_curve22519()
14191379
goto exit;
14201380
}
14211381
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) {
14241383
/* Do not consider this as a failure */
14251384
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
14261385
ret = 0;
14271386
goto exit;
1428-
}
1429-
else if (ret != 0) {
1387+
} else if (ret != 0) {
14301388
PRINT_ERROR(ret, "mbedtls_ecp_group_load()");
14311389
goto exit;
14321390
}
14331391

14341392
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) {
14371394
/* Do not consider this as a failure */
14381395
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
14391396
ret = 0;
14401397
goto exit;
1441-
}
1442-
else if (ret != 0) {
1398+
} else if (ret != 0) {
14431399
PRINT_ERROR(ret, "mbedtls_ecdh_gen_public()");
14441400
goto exit;
14451401
}
14461402

14471403
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) {
14501405
/* Do not consider this as a failure */
14511406
mbedtls_printf(HEADER_FORMAT "Feature unsupported\n", title);
14521407
ret = 0;
14531408
goto exit;
1454-
}
1455-
else
1456-
if (ret != 0) {
1409+
} else if (ret != 0) {
14571410
PRINT_ERROR(ret, "mbedtls_ecdh_gen_public()");
14581411
goto exit;
14591412
}

0 commit comments

Comments
 (0)