mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-11-27 00:04:24 -05:00
Add macros containing compilation information and print in test programs
Fixes #331
This commit is contained in:
parent
dfbcf78e33
commit
4d492b9270
@ -94,5 +94,8 @@
|
||||
#define OQS_KEM_DEFAULT OQS_KEM_alg_sike_p434
|
||||
#define OQS_SIG_DEFAULT OQS_SIG_alg_picnic_L1_FS
|
||||
|
||||
#define OQS_MASTER_BRANCH /**/
|
||||
#define OQS_VERSION_NUMBER 0x00200000L
|
||||
#define OQS_VERSION_TEXT "0.2.0-dev"
|
||||
|
||||
#endif
|
||||
|
||||
@ -111,4 +111,8 @@ case "$SIG_DEFAULT" in
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_DEFINE_UNQUOTED([OQS_COMPILE_CFLAGS], ["$CFLAGS $AM_CFLAGS"], [CFLAGS set during ./configure])
|
||||
AC_DEFINE_UNQUOTED([OQS_COMPILE_LDFLAGS], ["$LDFLAGS"], [LDFLAGS set during ./configure])
|
||||
AC_DEFINE_UNQUOTED([OQS_COMPILE_BUILD_TARGET], ["$build"], [build set during ./configure])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
16
scripts/git_commit.sh
Executable file
16
scripts/git_commit.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get the SHA-1 hash of the current git commit, if any
|
||||
# based on https://stackoverflow.com/questions/8215785/how-can-i-use-ac-revision-with-git
|
||||
|
||||
changes=`git status -s 2>&1`
|
||||
if [ $? -ne 0 ] ; then
|
||||
# not a git repository
|
||||
printf 'unknown'
|
||||
elif [ "x$changes" == "x" ] ; then
|
||||
# no changes since last commit
|
||||
printf '%s' `git rev-parse HEAD`
|
||||
else
|
||||
# changes since last commit
|
||||
printf '%s (+ local modifications)' `git rev-parse HEAD`
|
||||
fi
|
||||
@ -3,11 +3,14 @@ check_PROGRAMS = example_kem speed_kem test_kem kat_kem \
|
||||
example_sig speed_sig test_sig kat_sig \
|
||||
test_aes test_sha3 test_hash
|
||||
|
||||
commonflags = -L../.libs -loqs -lm
|
||||
commonldflags = -L../.libs -loqs -lm
|
||||
if USE_OPENSSL
|
||||
commonflags += -L${OPENSSL_DIR}/lib -lcrypto
|
||||
commonldflags += -L${OPENSSL_DIR}/lib -lcrypto
|
||||
endif
|
||||
|
||||
git_commit=$(shell ../scripts/git_commit.sh)
|
||||
CFLAGS += '-DOQS_COMPILE_GIT_COMMIT="${git_commit}"'
|
||||
|
||||
example_kem_SOURCES = example_kem.c
|
||||
example_sig_SOURCES = example_sig.c
|
||||
speed_kem_SOURCES = speed_kem.c
|
||||
@ -20,21 +23,21 @@ test_sig_SOURCES = test_sig.c
|
||||
kat_kem_SOURCES = kat_kem.c
|
||||
kat_sig_SOURCES = kat_sig.c
|
||||
|
||||
example_kem_LDFLAGS = ${commonflags}
|
||||
example_sig_LDFLAGS = ${commonflags}
|
||||
kat_kem_LDFLAGS = ${commonflags}
|
||||
kat_sig_LDFLAGS = ${commonflags}
|
||||
speed_kem_LDFLAGS = ${commonflags}
|
||||
speed_sig_LDFLAGS = ${commonflags}
|
||||
test_kem_LDFLAGS = ${commonflags}
|
||||
test_sig_LDFLAGS = ${commonflags}
|
||||
example_kem_LDFLAGS = ${commonldflags}
|
||||
example_sig_LDFLAGS = ${commonldflags}
|
||||
kat_kem_LDFLAGS = ${commonldflags}
|
||||
kat_sig_LDFLAGS = ${commonldflags}
|
||||
speed_kem_LDFLAGS = ${commonldflags}
|
||||
speed_sig_LDFLAGS = ${commonldflags}
|
||||
test_kem_LDFLAGS = ${commonldflags}
|
||||
test_sig_LDFLAGS = ${commonldflags}
|
||||
test_aes_LDFLAGS = -L../src/crypto/aes/.libs -laes # required since OQS_AES symbols are not part of OQS public API
|
||||
test_aes_LDFLAGS += ${commonflags}
|
||||
test_aes_LDFLAGS += ${commonldflags}
|
||||
test_hash_LDFLAGS = -L../src/crypto/sha2/.libs -lsha2 # required since OQS_SHA2 symbols are not part of OQS public API
|
||||
test_hash_LDFLAGS += -L../src/crypto/sha3/.libs -lsha3 # required since OQS_SHA3 symbols are not part of OQS public API
|
||||
test_hash_LDFLAGS += ${commonflags}
|
||||
test_hash_LDFLAGS += ${commonldflags}
|
||||
test_sha3_LDFLAGS = -L../src/crypto/sha3/.libs -lsha3 # required since OQS_SHA3 symbols are not part of OQS public API
|
||||
test_sha3_LDFLAGS += ${commonflags}
|
||||
test_sha3_LDFLAGS += ${commonldflags}
|
||||
|
||||
example_kem_DEPENDENCIES = ../liboqs.la
|
||||
example_sig_DEPENDENCIES = ../liboqs.la
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "system_info.c"
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
void OQS_print_hex_string(const char *label, const uint8_t *str, size_t len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
@ -144,6 +146,8 @@ int main(int argc, char **argv) {
|
||||
fprintf(stderr, "%s", OQS_KEM_alg_identifier(i));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
printf("\n");
|
||||
print_system_info();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "system_info.c"
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
void OQS_print_hex_string(const char *label, const uint8_t *str, size_t len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
@ -690,6 +692,8 @@ int main(int argc, char **argv) {
|
||||
fprintf(stderr, "%s", OQS_SIG_alg_identifier(i));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
printf("\n");
|
||||
print_system_info();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "ds_benchmark.h"
|
||||
#include "system_info.c"
|
||||
|
||||
static OQS_STATUS kem_speed_wrapper(const char *method_name, int duration, bool printInfo) {
|
||||
|
||||
@ -135,16 +136,7 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* TODO: Make autoconf generate these variables */
|
||||
// printf("Compiler setup\n");
|
||||
// printf("==============\n");
|
||||
// printf("Date: %s\n", OQS_COMPILE_DATE);
|
||||
// printf("Compiler: %s (%s)\n", OQS_COMPILE_CC, OQS_COMPILE_CC_VERSION);
|
||||
// printf("OS: %s\n", OQS_COMPILE_UNAME);
|
||||
// printf("CFLAGS: %s\n", OQS_COMPILE_CFLAGS);
|
||||
// printf("LDFLAGS: %s\n", OQS_COMPILE_LDFLAGS);
|
||||
// printf("RNG: OpenSSL\n");
|
||||
// printf("\n");
|
||||
print_system_info();
|
||||
|
||||
printf("Speed test\n");
|
||||
printf("==========\n");
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "ds_benchmark.h"
|
||||
#include "system_info.c"
|
||||
|
||||
static OQS_STATUS sig_speed_wrapper(const char *method_name, int duration, bool printInfo) {
|
||||
|
||||
@ -136,16 +137,7 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* TODO: Make autoconf generate these variables */
|
||||
// printf("Compiler setup\n");
|
||||
// printf("==============\n");
|
||||
// printf("Date: %s\n", OQS_COMPILE_DATE);
|
||||
// printf("Compiler: %s (%s)\n", OQS_COMPILE_CC, OQS_COMPILE_CC_VERSION);
|
||||
// printf("OS: %s\n", OQS_COMPILE_UNAME);
|
||||
// printf("CFLAGS: %s\n", OQS_COMPILE_CFLAGS);
|
||||
// printf("LDFLAGS: %s\n", OQS_COMPILE_LDFLAGS);
|
||||
// printf("RNG: OpenSSL\n");
|
||||
// printf("\n");
|
||||
print_system_info();
|
||||
|
||||
printf("Speed test\n");
|
||||
printf("==========\n");
|
||||
|
||||
79
tests/system_info.c
Normal file
79
tests/system_info.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// based on macros in https://sourceforge.net/p/predef/wiki/Compilers/
|
||||
static void print_compiler_info() {
|
||||
#if defined(__clang__)
|
||||
printf("Compiler: clang (%s)\n", __clang_version__);
|
||||
#elif defined(__GNUC_PATCHLEVEL__)
|
||||
printf("Compiler: gcc (%d.%d.%d)\n", __GNU_C__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
#elif defined(__GNUC_MINOR__)
|
||||
printf("Compiler: gcc (%d.%d)\n", __GNU_C__, __GNUC_MINOR__);
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
printf("Compiler: Intel C/C++ (%d)\n", __INTEL_COMPILER);
|
||||
#elif defined(_MSC_FULL_VER)
|
||||
printf("Compiler: Microsoft C/C++ (%d)\n", _MSC_FULL_VER);
|
||||
#else
|
||||
printf("Compiler: Unknown"\n);
|
||||
#endif
|
||||
}
|
||||
|
||||
// based on macros in https://sourceforge.net/p/predef/wiki/Architectures/
|
||||
static void print_platform_info() {
|
||||
#if defined(OQS_COMPILE_BUILD_TARGET)
|
||||
printf("Target platform: %s\n", OQS_COMPILE_BUILD_TARGET);
|
||||
#elif defined(_WIN64)
|
||||
printf("Target platform: Windows (64-bit)\n");
|
||||
#elif defined(_WIN32)
|
||||
printf("Target platform: Windows (32-bit)\n");
|
||||
#else
|
||||
printf("Target platform: Unknown\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(USE_OPENSSL)
|
||||
#include <openssl/crypto.h>
|
||||
#endif
|
||||
|
||||
static void print_oqs_configuration() {
|
||||
printf("OQS version: %s\n", OQS_VERSION_TEXT);
|
||||
#if defined(OQS_COMPILE_GIT_COMMIT)
|
||||
printf("Git commit: %s\n", OQS_COMPILE_GIT_COMMIT);
|
||||
#endif
|
||||
#if defined(USE_OPENSSL)
|
||||
printf("OpenSSL enabled: Yes (%08lx)\n", OpenSSL_version_num());
|
||||
#else
|
||||
printf("OpenSSL enabled: No\n");
|
||||
#endif
|
||||
#if defined(USE_AES_C)
|
||||
printf("AES: C\n");
|
||||
#elif defined(USE_AES_OPENSSL)
|
||||
printf("AES: OpenSSL\n");
|
||||
#endif
|
||||
#if defined(USE_SHA2_C)
|
||||
printf("SHA-2: C\n");
|
||||
#elif defined(USE_SHA2_OPENSSL)
|
||||
printf("SHA-2: OpenSSL\n");
|
||||
#endif
|
||||
#if defined(USE_SHA3_C)
|
||||
printf("SHA-3: C\n");
|
||||
#elif defined(USE_SHA3_OPENSSL)
|
||||
printf("SHA-3: OpenSSL\n");
|
||||
#endif
|
||||
#if defined(OQS_COMPILE_CFLAGS)
|
||||
printf("CFLAGS: %s\n", OQS_COMPILE_CFLAGS);
|
||||
#endif
|
||||
#if defined(OQS_COMPILE_LDFLAGS)
|
||||
printf("LDFLAGS: %s\n", OQS_COMPILE_LDFLAGS);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void print_system_info() {
|
||||
printf("Configuration info\n");
|
||||
printf("==================\n");
|
||||
print_platform_info();
|
||||
print_compiler_info();
|
||||
print_oqs_configuration();
|
||||
printf("\n");
|
||||
}
|
||||
@ -6,6 +6,8 @@
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "ds_benchmark.h"
|
||||
#include "system_info.c"
|
||||
|
||||
#include <oqs/aes.h>
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
@ -126,6 +128,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
print_system_info();
|
||||
|
||||
printf("=== test_aes correctness ===\n");
|
||||
if (test_aes128_correctness() != EXIT_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
#include <oqs/sha2.h>
|
||||
#include <oqs/sha3.h>
|
||||
|
||||
#include "system_info.c"
|
||||
|
||||
#define BUFFER_SIZE 10000
|
||||
|
||||
static int read_stdin(uint8_t **msg, size_t *msg_len) {
|
||||
@ -111,6 +113,8 @@ int main(int argc, char **argv) {
|
||||
fprintf(stderr, "Usage: test_hash algname\n");
|
||||
fprintf(stderr, " algname: sha256, sha384, sha512\n");
|
||||
fprintf(stderr, " test_hash reads input from stdin and outputs hash value as hex string to stdout");
|
||||
printf("\n");
|
||||
print_system_info();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "system_info.c"
|
||||
|
||||
/* Displays hexadecimal strings */
|
||||
void OQS_print_hex_string(const char *label, const uint8_t *str, size_t len) {
|
||||
printf("%-20s (%4zu bytes): ", label, len);
|
||||
@ -135,6 +137,8 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
print_system_info();
|
||||
|
||||
// Use system RNG in this program
|
||||
OQS_randombytes_switch_algorithm(OQS_RAND_alg_system);
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
|
||||
#include <oqs/sha3.h>
|
||||
|
||||
#include "system_info.c"
|
||||
|
||||
#if defined(WINDOWS)
|
||||
#define UNUSED
|
||||
#else
|
||||
@ -817,6 +819,9 @@ int cshake_simple_256_kat_test() {
|
||||
*/
|
||||
int main(UNUSED int argc, UNUSED char **argv) {
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
print_system_info();
|
||||
|
||||
if (sha3_256_kat_test() == EXIT_SUCCESS) {
|
||||
printf("Success! passed sha3-256 known answer tests \n");
|
||||
} else {
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
#include <oqs/oqs.h>
|
||||
|
||||
#include "system_info.c"
|
||||
|
||||
static OQS_STATUS sig_test_correctness(const char *method_name) {
|
||||
|
||||
OQS_SIG *sig = NULL;
|
||||
@ -99,6 +101,8 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
print_system_info();
|
||||
|
||||
// Use system RNG in this program
|
||||
OQS_randombytes_switch_algorithm(OQS_RAND_alg_system);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user