summaryrefslogtreecommitdiffstats
path: root/apps/speed.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-06-21 08:55:50 +0200
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-11-17 15:48:34 +0100
commit2ff286c26c29b69b02ca99656d26d2f8cfd54682 (patch)
tree71a01c51c47d0dd9528ff14357615d71420ba5a1 /apps/speed.c
parenta6838c8d52087f2b0494bbab8486e10944aff7f7 (diff)
Add and use HAS_PREFIX() and CHECK_AND_SKIP_PREFIX() for checking if string has literal prefix
Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15847)
Diffstat (limited to 'apps/speed.c')
-rw-r--r--apps/speed.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/apps/speed.c b/apps/speed.c
index ada559228d..0ee7347f5b 100644
--- a/apps/speed.c
+++ b/apps/speed.c
@@ -1638,8 +1638,8 @@ int speed_main(int argc, char **argv)
if (strcmp(algo, "openssl") == 0) /* just for compatibility */
continue;
#endif
- if (strncmp(algo, "rsa", 3) == 0) {
- if (algo[3] == '\0') {
+ if (HAS_PREFIX(algo, "rsa")) {
+ if (algo[sizeof("rsa") - 1] == '\0') {
memset(rsa_doit, 1, sizeof(rsa_doit));
continue;
}
@@ -1649,8 +1649,8 @@ int speed_main(int argc, char **argv)
}
}
#ifndef OPENSSL_NO_DH
- if (strncmp(algo, "ffdh", 4) == 0) {
- if (algo[4] == '\0') {
+ if (HAS_PREFIX(algo, "ffdh")) {
+ if (algo[sizeof("ffdh") - 1] == '\0') {
memset(ffdh_doit, 1, sizeof(ffdh_doit));
continue;
}
@@ -1660,8 +1660,8 @@ int speed_main(int argc, char **argv)
}
}
#endif
- if (strncmp(algo, "dsa", 3) == 0) {
- if (algo[3] == '\0') {
+ if (HAS_PREFIX(algo, "dsa")) {
+ if (algo[sizeof("dsa") - 1] == '\0') {
memset(dsa_doit, 1, sizeof(dsa_doit));
continue;
}
@@ -1678,8 +1678,8 @@ int speed_main(int argc, char **argv)
doit[D_CBC_128_CML] = doit[D_CBC_192_CML] = doit[D_CBC_256_CML] = 1;
continue;
}
- if (strncmp(algo, "ecdsa", 5) == 0) {
- if (algo[5] == '\0') {
+ if (HAS_PREFIX(algo, "ecdsa")) {
+ if (algo[sizeof("ecdsa") - 1] == '\0') {
memset(ecdsa_doit, 1, sizeof(ecdsa_doit));
continue;
}
@@ -1688,8 +1688,8 @@ int speed_main(int argc, char **argv)
continue;
}
}
- if (strncmp(algo, "ecdh", 4) == 0) {
- if (algo[4] == '\0') {
+ if (HAS_PREFIX(algo, "ecdh")) {
+ if (algo[sizeof("ecdh") - 1] == '\0') {
memset(ecdh_doit, 1, sizeof(ecdh_doit));
continue;
}
@@ -3458,20 +3458,19 @@ static int do_multi(int multi, int size_num)
continue;
}
printf("Got: %s from %d\n", buf, n);
- if (strncmp(buf, "+F:", 3) == 0) {
+ p = buf;
+ if (CHECK_AND_SKIP_PREFIX(p, "+F:")) {
int alg;
int j;
- p = buf + 3;
alg = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
for (j = 0; j < size_num; ++j)
results[alg][j] += atof(sstrsep(&p, sep));
- } else if (strncmp(buf, "+F2:", 4) == 0) {
+ } else if (CHECK_AND_SKIP_PREFIX(p, "+F2:")) {
int k;
double d;
- p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
@@ -3480,11 +3479,10 @@ static int do_multi(int multi, int size_num)
d = atof(sstrsep(&p, sep));
rsa_results[k][1] += d;
- } else if (strncmp(buf, "+F3:", 4) == 0) {
+ } else if (CHECK_AND_SKIP_PREFIX(p, "+F3:")) {
int k;
double d;
- p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
@@ -3493,11 +3491,10 @@ static int do_multi(int multi, int size_num)
d = atof(sstrsep(&p, sep));
dsa_results[k][1] += d;
- } else if (strncmp(buf, "+F4:", 4) == 0) {
+ } else if (CHECK_AND_SKIP_PREFIX(p, "+F4:")) {
int k;
double d;
- p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
@@ -3506,21 +3503,19 @@ static int do_multi(int multi, int size_num)
d = atof(sstrsep(&p, sep));
ecdsa_results[k][1] += d;
- } else if (strncmp(buf, "+F5:", 4) == 0) {
+ } else if (CHECK_AND_SKIP_PREFIX(p, "+F5:")) {
int k;
double d;
- p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
d = atof(sstrsep(&p, sep));
ecdh_results[k][0] += d;
- } else if (strncmp(buf, "+F6:", 4) == 0) {
+ } else if (CHECK_AND_SKIP_PREFIX(p, "+F6:")) {
int k;
double d;
- p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
sstrsep(&p, sep);
@@ -3531,11 +3526,10 @@ static int do_multi(int multi, int size_num)
d = atof(sstrsep(&p, sep));
eddsa_results[k][1] += d;
# ifndef OPENSSL_NO_SM2
- } else if (strncmp(buf, "+F7:", 4) == 0) {
+ } else if (CHECK_AND_SKIP_PREFIX(p, "+F7:")) {
int k;
double d;
- p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
sstrsep(&p, sep);
@@ -3547,18 +3541,17 @@ static int do_multi(int multi, int size_num)
sm2_results[k][1] += d;
# endif /* OPENSSL_NO_SM2 */
# ifndef OPENSSL_NO_DH
- } else if (strncmp(buf, "+F8:", 4) == 0) {
+ } else if (CHECK_AND_SKIP_PREFIX(p, "+F8:")) {
int k;
double d;
- p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
d = atof(sstrsep(&p, sep));
ffdh_results[k][0] += d;
# endif /* OPENSSL_NO_DH */
- } else if (strncmp(buf, "+H:", 3) == 0) {
+ } else if (HAS_PREFIX(buf, "+H:")) {
;
} else {
BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf,