X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=test_curves.c;h=865ee8d2d4e3c2bb0bc3eb24f66229c04917e83a;hb=HEAD;hp=1ee15b0fab706e665f53258a5ac1f4799b18d463;hpb=b9935fbf77164cf491fb12df74f7a85e877813cd;p=openssl-gost%2Fengine.git diff --git a/test_curves.c b/test_curves.c index 1ee15b0..865ee8d 100644 --- a/test_curves.c +++ b/test_curves.c @@ -5,7 +5,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 @@ -16,11 +20,11 @@ #include #include -#define T(e) ({ if (!(e)) { \ - ERR_print_errors_fp(stderr); \ - OpenSSLDie(__FILE__, __LINE__, #e); \ - } \ - }) +#define T(e) \ + if (!(e)) { \ + ERR_print_errors_fp(stderr); \ + OpenSSLDie(__FILE__, __LINE__, #e); \ + } #define cRED "\033[1;31m" #define cDRED "\033[0;31m" @@ -29,10 +33,13 @@ #define cBLUE "\033[1;34m" #define cDBLUE "\033[0;34m" #define cNORM "\033[m" -#define TEST_ASSERT(e) {if ((test = (e))) \ - printf(cRED " Test FAILED\n" cNORM); \ - else \ - printf(cGREEN " Test passed\n" cNORM);} +#define TEST_ASSERT(e) { \ + test = e; \ + if (test) \ + printf(cRED " Test FAILED" cNORM "\n"); \ + else \ + printf(cGREEN " Test passed" cNORM "\n"); \ +} struct test_curve { int nid; @@ -43,28 +50,19 @@ struct test_curve { static struct test_curve test_curves[] = { #if 2001 { NID_id_GostR3410_2001_TestParamSet, }, +#endif { NID_id_GostR3410_2001_CryptoPro_A_ParamSet }, { NID_id_GostR3410_2001_CryptoPro_B_ParamSet }, { NID_id_GostR3410_2001_CryptoPro_C_ParamSet }, { NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet }, { NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet }, -#endif - { - NID_id_tc26_gost_3410_2012_512_paramSetA, - "id-tc26-gost-3410-2012-512-paramSetA", - }, - { - NID_id_tc26_gost_3410_2012_512_paramSetB, - "id-tc26-gost-3410-2012-512-paramSetB", - }, - { - NID_id_tc26_gost_3410_2012_512_paramSetC, - "id-tc26-gost-3410-2012-512-paramSetC", - }, - { - NID_id_tc26_gost_3410_2012_256_paramSetA, - "id-tc26-gost-3410-2012-256-paramSetA", - }, + { NID_id_tc26_gost_3410_2012_512_paramSetA, "id-tc26-gost-3410-2012-512-paramSetA", }, + { NID_id_tc26_gost_3410_2012_512_paramSetB, "id-tc26-gost-3410-2012-512-paramSetB", }, + { NID_id_tc26_gost_3410_2012_512_paramSetC, "id-tc26-gost-3410-2012-512-paramSetC", }, + { NID_id_tc26_gost_3410_2012_256_paramSetA, "id-tc26-gost-3410-2012-256-paramSetA", }, + { NID_id_tc26_gost_3410_2012_256_paramSetB, "id-tc26-gost-3410-2012-256-paramSetB", }, + { NID_id_tc26_gost_3410_2012_256_paramSetC, "id-tc26-gost-3410-2012-256-paramSetC", }, + { NID_id_tc26_gost_3410_2012_256_paramSetD, "id-tc26-gost-3410-2012-256-paramSetD", }, 0, }; @@ -99,7 +97,7 @@ static int parameter_test(struct test_curve *tc) printf("\n"); if (!OBJ_nid2obj(nid)) { - printf(cRED "NID %d not found\n" cNORM, nid); + printf(cRED "NID %d not found" cNORM "\n", nid); return 1; } @@ -115,7 +113,7 @@ static int parameter_test(struct test_curve *tc) EC_KEY *ec; T(ec = EC_KEY_new()); if (!fill_GOST_EC_params(ec, nid)) { - printf(cRED "fill_GOST_EC_params FAIL\n" cNORM); + printf(cRED "fill_GOST_EC_params FAIL" cNORM "\n"); ERR_print_errors_fp(stderr); return 1; } @@ -177,6 +175,15 @@ static int parameter_test(struct test_curve *tc) BN_mod_add(xxx, xxx, ax, p, ctx); BN_mod_add(xxx, xxx, b, p, ctx); T(BN_cmp(yy, xxx) == 0); + BN_free(yy); + BN_free(r); + BN_free(xxx); + BN_free(ax); + BN_free(p); + BN_free(a); + BN_free(b); + BN_free(x); + BN_free(y); /* Check order */ const BIGNUM *order; @@ -189,6 +196,7 @@ static int parameter_test(struct test_curve *tc) T(EC_POINT_mul(group, point, NULL, generator, order, ctx)); /* generator * order is the point at infinity? */ T(EC_POINT_is_at_infinity(group, point) == 1); + EC_POINT_free(point); /* Check if order is cyclic */ BIGNUM *k1 = BN_new(); @@ -200,12 +208,19 @@ static int parameter_test(struct test_curve *tc) BN_add(k2, k2, order); T(EC_POINT_mul(group, p1, NULL, generator, k1, ctx)); T(EC_POINT_mul(group, p2, NULL, generator, k2, ctx)); + T(EC_POINT_cmp(group, p1, p2, ctx) == 0); + BN_free(k1); + BN_free(k2); + EC_POINT_free(p1); + EC_POINT_free(p2); /* Cofactor is 1 or 4 */ const BIGNUM *c; T(c = EC_GROUP_get0_cofactor(group)); T(BN_is_word(c, 1) || BN_is_word(c, 4)); + BN_CTX_free(ctx); + EC_KEY_free(ec); TEST_ASSERT(0); return test; } @@ -220,8 +235,8 @@ int main(int argc, char **argv) } 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; }