X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=test_sign.c;h=63ae3b56877d5ffdabcf88f52d2f737c672c7793;hb=624bf7d20c0d1258391bda222d16f099241ad1c1;hp=c76855c0d8bfec71058fb7a7706a9e7f69331b09;hpb=b008f2a0ffa1797943c3d08c3b3eee31229a56d3;p=openssl-gost%2Fengine.git diff --git a/test_sign.c b/test_sign.c index c76855c..63ae3b5 100644 --- a/test_sign.c +++ b/test_sign.c @@ -7,7 +7,11 @@ * See https://www.openssl.org/source/license.html for details */ -#include "e_gost_err.h" +#ifdef _MSC_VER +# pragma warning(push, 3) +# include +# pragma warning(pop) +#endif #include "gost_lcl.h" #include #include @@ -17,20 +21,21 @@ #include #include #include +#include #include #include -#define T(e) ({ if (!(e)) { \ - ERR_print_errors_fp(stderr); \ - OpenSSLDie(__FILE__, __LINE__, #e); \ - } \ - }) -#define TE(e) ({ if (!(e)) { \ - ERR_print_errors_fp(stderr); \ - fprintf(stderr, "Error at %s:%d %s\n", __FILE__, __LINE__, #e); \ - return -1; \ - } \ - }) +#define T(e) \ + if (!(e)) { \ + ERR_print_errors_fp(stderr); \ + OpenSSLDie(__FILE__, __LINE__, #e); \ + } +#define TE(e) \ + if (!(e)) { \ + ERR_print_errors_fp(stderr); \ + fprintf(stderr, "Error at %s:%d %s\n", __FILE__, __LINE__, #e); \ + return -1; \ + } #define cRED "\033[1;31m" #define cDRED "\033[0;31m" @@ -41,13 +46,13 @@ #define cCYAN "\033[1;36m" #define cNORM "\033[m" #define TEST_ASSERT(e) {if ((test = (e))) \ - printf(cRED " Test FAILED\n" cNORM); \ + printf(cRED " Test FAILED" cNORM "\n"); \ else \ - printf(cGREEN " Test passed\n" cNORM);} + printf(cGREEN " Test passed" cNORM "\n");} struct test_sign { const char *name; - unsigned int nid; + int nid; size_t bits; const char *paramset; }; @@ -83,17 +88,17 @@ static void hexdump(const void *ptr, size_t len) static void print_test_tf(int err, int val, const char *t, const char *f) { if (err == 1) - printf(cGREEN "%s\n" cNORM, t); + printf(cGREEN "%s" cNORM "\n", t); else - printf(cRED "%s [%d]\n" cNORM, f, val); + printf(cRED "%s [%d]" cNORM "\n", f, val); } static void print_test_result(int err) { if (err == 1) - printf(cGREEN "success\n" cNORM); + printf(cGREEN "success" cNORM "\n"); else if (err == 0) - printf(cRED "failure\n" cNORM); + printf(cRED "failure" cNORM "\n"); else ERR_print_errors_fp(stderr); } @@ -103,7 +108,7 @@ static int test_sign(struct test_sign *t) int ret = 0, err; size_t len = t->bits / 8; - printf(cBLUE "Test %s:\n" cNORM, t->name); + printf(cBLUE "Test %s:" cNORM "\n", t->name); /* Signature type from size. */ int type = 0; @@ -116,6 +121,9 @@ static int test_sign(struct test_sign *t) case 512: type = NID_id_GostR3410_2012_512; algname = "gost2012_512"; + break; + default: + return -1; } /* Keygen. */ @@ -177,7 +185,7 @@ static int test_sign(struct test_sign *t) fflush(stdout); pkey = NULL; OSSL_STORE_CTX *cts; - T(cts = OSSL_STORE_attach(bp, "file", NULL, NULL, NULL, NULL, NULL, NULL)); + T(cts = OSSL_STORE_attach(bp, "file", NULL, NULL, NULL, NULL, NULL, NULL, NULL)); for (;;) { OSSL_STORE_INFO *info = OSSL_STORE_load(cts); if (!info) { @@ -197,7 +205,7 @@ static int test_sign(struct test_sign *t) ret |= err; EVP_PKEY_free(pkey); } else - printf(cCYAN "skipped\n" cNORM); + printf(cCYAN "skipped" cNORM "\n"); BIO_free(bp); /* Convert to DER and back, using memory API. */ @@ -239,7 +247,7 @@ static int test_sign(struct test_sign *t) const EC_GROUP *group = EC_KEY_get0_group(ec); int curve_name = EC_GROUP_get_curve_name(group); err = curve_name == t->nid; - printf("\tcurve_name (%u):\t", t->nid); + printf("\tcurve_name (%d):\t", t->nid); print_test_tf(err, curve_name, "match", "mismatch"); ret |= !err; @@ -318,24 +326,15 @@ int main(int argc, char **argv) { int ret = 0; - setenv("OPENSSL_ENGINES", ENGINE_DIR, 0); OPENSSL_add_all_algorithms_conf(); - ERR_load_crypto_strings(); - ENGINE *eng; - T(eng = ENGINE_by_id("gost")); - T(ENGINE_init(eng)); - T(ENGINE_set_default(eng, ENGINE_METHOD_ALL)); struct test_sign *sp; for (sp = test_signs; sp->name; sp++) ret |= test_sign(sp); - ENGINE_finish(eng); - ENGINE_free(eng); - if (ret) - printf(cDRED "= Some tests FAILED!\n" cNORM); + printf(cDRED "= Some tests FAILED!" cNORM "\n"); else - printf(cDGREEN "= All tests passed!\n" cNORM); + printf(cDGREEN "= All tests passed!" cNORM "\n"); return ret; }