static void
print_help(void)
{
- printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n\n"
+ printf("usage: atheme-services [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n\n"
"-c <file> Specify the config file\n"
"-d Start in debugging mode\n"
"-h Print this message and exit\n"
"-n Don't fork into the background (log screen + log file)\n"
"-p <file> Specify the pid file (will be overwritten)\n"
"-D <dir> Specify the data directory\n"
- "-t Don't run the integrated digest test suite\n"
- "-T Exit after running the integrated digest test suite\n"
"-v Print version information and exit\n");
}
/* *INDENT-ON* */
atheme_main(int argc, char *argv[])
{
int daemonize_pipe[2] = { -1, -1 };
- bool run_testsuite = true;
- bool exit_after_testsuite = false;
bool have_conf = false;
bool have_log = false;
bool have_datadir = false;
atheme_bootstrap();
/* do command-line options */
- while ((r = mowgli_getopt_long(argc, argv, "c:bdhrtTl:np:D:v", long_opts, NULL)) != -1)
+ while ((r = mowgli_getopt_long(argc, argv, "c:bdhrl:np:D:v", long_opts, NULL)) != -1)
{
switch (r)
{
case 'n':
runflags |= RF_LIVE;
break;
- case 't':
- run_testsuite = false;
- break;
- case 'T':
- exit_after_testsuite = true;
- break;
case 'p':
pidfilename = mowgli_optarg;
break;
print_version();
exit(EXIT_SUCCESS);
default:
- fprintf(stderr, "usage: atheme [-bdhnvr] [-t|-T] [-c conf] [-l logfile] [-p pidfile]\n");
+ fprintf(stderr, "usage: atheme-services [-bdhnvr] [-c conf] [-l logfile] [-p pidfile]\n");
exit(EXIT_FAILURE);
}
}
- if (! run_testsuite && exit_after_testsuite)
- {
- fprintf(stderr, "Error: specify exactly one of -t / -T\n");
- exit(EXIT_FAILURE);
- }
-
if (!have_conf)
config_file = sstrdup(SYSCONFDIR "/atheme.conf");
atheme_init(argv[0], log_p);
slog(LG_INFO, "%s is starting up...", PACKAGE_STRING);
- slog(LG_INFO, "Using Digest API frontend: %s", digest_get_frontend_info());
- slog(LG_INFO, "Using Random API frontend: %s", random_get_frontend_info());
/* check for pid file */
#ifndef MOWGLI_OS_WIN
}
#endif
- if (run_testsuite)
- {
- (void) slog(LG_INFO, "running digest testsuite...");
+ (void) slog(LG_INFO, "Using Digest API frontend: %s", digest_get_frontend_info());
+ (void) slog(LG_INFO, "Using Random API frontend: %s", random_get_frontend_info());
- if (! digest_testsuite_run())
- {
- (void) slog(LG_ERROR, "digest testsuite failed");
- exit(EXIT_FAILURE);
- }
-
- (void) slog(LG_INFO, "digest testsuite passed");
+ (void) slog(LG_INFO, "running digest testsuite...");
- if (exit_after_testsuite)
- {
- (void) slog(LG_INFO, "exiting due to -T");
- exit(EXIT_SUCCESS);
- }
+ if (! digest_testsuite_run())
+ {
+ (void) slog(LG_ERROR, "digest testsuite failed");
+ exit(EXIT_FAILURE);
}
- else
- (void) slog(LG_INFO, "digest testsuite skipped due to -t");
+
+ (void) slog(LG_INFO, "digest testsuite passed");
if (!(runflags & RF_LIVE))
daemonize(daemonize_pipe);
"${MAKE}"
"${MAKE}" install
-"${ATHEME_PREFIX}"/bin/atheme-services -dnT
-"${ATHEME_PREFIX}"/bin/atheme-crypto-benchmark -io
+"${ATHEME_PREFIX}"/bin/atheme-crypto-benchmark -T
"${ATHEME_PREFIX}"/bin/atheme-ecdh-x25519-tool -T
include ../../extra.mk
PROG = ${PACKAGE_TARNAME}-crypto-benchmark${PROG_SUFFIX}
-SRCS = benchmark.c main.c optimal.c
+SRCS = benchmark.c main.c optimal.c selftests.c
include ../../buildsys.mk
#define BENCH_MIN(a, b) (((a) <= (b)) ? (a) : (b))
#define BENCH_RUN_OPTIONS_NONE 0x0000U
-#define BENCH_RUN_OPTIONS_OPTIMAL 0x0001U
-#define BENCH_RUN_OPTIONS_ARGON2 0x0002U
-#define BENCH_RUN_OPTIONS_SCRYPT 0x0004U
-#define BENCH_RUN_OPTIONS_PBKDF2 0x0008U
+#define BENCH_RUN_OPTIONS_TESTONLY 0x0001U
+#define BENCH_RUN_OPTIONS_OPTIMAL 0x0002U
+#define BENCH_RUN_OPTIONS_ARGON2 0x0004U
+#define BENCH_RUN_OPTIONS_SCRYPT 0x0008U
+#define BENCH_RUN_OPTIONS_PBKDF2 0x0010U
#if defined(HAVE_LIBARGON2) || defined(HAVE_LIBSODIUM_SCRYPT)
# define HAVE_ANY_MEMORY_HARD_ALGORITHM 1
#include "benchmark.h" // (everything else)
#include "optimal.h" // do_optimal_benchmarks()
+#include "selftests.h" // do_crypto_selftests()
#define BENCH_ARRAY_SIZE(x) ((sizeof((x))) / (sizeof((x)[0])))
{ "help", no_argument, NULL, 'h', 0 },
{ "version", no_argument, NULL, 'v', 0 },
+ { "run-selftests-only", no_argument, NULL, 'T', 0 },
{ "run-optimal-benchmarks", no_argument, NULL, 'o', 0 },
{ "optimal-clock-limit", required_argument, NULL, 'g', 0 },
"\n"
" -h/--help Display this help information and exit\n"
" -v/--version Display program version and exit\n"
+ " -T/--run-selftests-only Exit after testing all supported algorithms\n"
"\n"
" -o/--run-optimal-benchmarks Perform an automatic parameter tuning benchmark:\n"
" -g/--optimal-clock-limit Wall clock time limit for optimal benchmarks\n"
// Version string was already printed at program startup
exit(EXIT_SUCCESS);
+ case 'T':
+ run_options |= BENCH_RUN_OPTIONS_TESTONLY;
+ break;
+
case 'o':
run_options |= BENCH_RUN_OPTIONS_OPTIMAL;
break;
(void) bench_print("");
(void) bench_print("");
(void) bench_print(_("Beginning customizable Argon2 benchmark ..."));
+
(void) argon2_print_colheaders();
for (size_t b_argon2_type = 0; b_argon2_type < b_argon2_types_count; b_argon2_type++)
(void) bench_print("");
(void) bench_print("");
(void) bench_print(_("Beginning customizable scrypt benchmark ..."));
+
(void) scrypt_print_colheaders();
for (size_t b_scrypt_memlimit = 0; b_scrypt_memlimit < b_scrypt_memlimits_count; b_scrypt_memlimit++)
(void) bench_print("");
(void) bench_print(_("Using digest frontend: %s"), digest_get_frontend_info());
+ if (! do_crypto_selftests())
+ {
+ (void) bench_print("");
+ (void) bench_print(_("One or more self-tests FAILED (BUG!). Exiting now..."));
+ return EXIT_FAILURE;
+ }
+
+ if ((run_options & BENCH_RUN_OPTIONS_TESTONLY))
+ return EXIT_SUCCESS;
+
if ((run_options & BENCH_RUN_OPTIONS_OPTIMAL) &&
! do_optimal_benchmarks(optimal_clocklimit, optimal_memlimit, optimal_memlimit_given, with_sasl_scram))
// This function logs error messages on failure
--- /dev/null
+/*
+ * SPDX-License-Identifier: ISC
+ * SPDX-URL: https://spdx.org/licenses/ISC.html
+ *
+ * Copyright (C) 2020 Aaron M. D. Jones <aaronmdjones@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#include <atheme/attributes.h> // ATHEME_FATTR_WUR
+#include <atheme/digest.h> // digest_testsuite_run()
+#include <atheme/i18n.h> // _() (gettext)
+#include <atheme/stdheaders.h> // (everything else)
+
+#include "benchmark.h" // bench_print()
+#include "selftests.h" // self-declarations
+
+bool ATHEME_FATTR_WUR
+do_crypto_selftests(void)
+{
+ bool retval = true;
+
+ if (! digest_testsuite_run())
+ {
+ (void) bench_print(_("The Digest API testsuite FAILED!"));
+ retval = false;
+ }
+ else
+ (void) bench_print(_("The Digest API testsuite passed."));
+
+ return retval;
+}
--- /dev/null
+/*
+ * SPDX-License-Identifier: ISC
+ * SPDX-URL: https://spdx.org/licenses/ISC.html
+ *
+ * Copyright (C) 2020 Aaron M. D. Jones <aaronmdjones@gmail.com>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#ifndef ATHEME_SRC_CRYPTO_BENCHMARK_SELFTESTS_H
+#define ATHEME_SRC_CRYPTO_BENCHMARK_SELFTESTS_H 1
+
+#include <atheme/attributes.h> // ATHEME_FATTR_WUR
+#include <atheme/stdheaders.h> // bool
+
+bool do_crypto_selftests(void) ATHEME_FATTR_WUR;
+
+#endif /* !ATHEME_SRC_CRYPTO_BENCHMARK_SELFTESTS_H */