X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=test_sign.c;h=63ae3b56877d5ffdabcf88f52d2f737c672c7793;hb=refs%2Fheads%2Fmaster;hp=d785b75b2dc49c5256a4e25584b7e3884bedea70;hpb=f3e84b52d2c5bf6774070b758714b90845d722d2;p=openssl-gost%2Fengine.git diff --git a/test_sign.c b/test_sign.c index d785b75..fee6d6e 100644 --- a/test_sign.c +++ b/test_sign.c @@ -7,6 +7,11 @@ * See https://www.openssl.org/source/license.html for details */ +#ifdef _MSC_VER +# pragma warning(push, 3) +# include +# pragma warning(pop) +#endif #include "gost_lcl.h" #include #include @@ -20,17 +25,17 @@ #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" @@ -47,7 +52,7 @@ struct test_sign { const char *name; - unsigned int nid; + int nid; size_t bits; const char *paramset; }; @@ -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) { @@ -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; @@ -259,6 +267,50 @@ static int test_sign(struct test_sign *t) EVP_PKEY_CTX_free(ctx1); EVP_PKEY_free(key1); + /* Extract public key in raw format. + * Should contain X||Y in little endian. + */ + size_t publen; + unsigned char *pub; + err = EVP_PKEY_get_raw_public_key(priv_key, NULL, &publen); + T(pub = OPENSSL_zalloc(publen)); + err &= EVP_PKEY_get_raw_public_key(priv_key, pub, &publen); + printf("\tEVP_PKEY_get_raw_public_key:"); + print_test_tf(err, err, "success", "failure"); + ret |= err != 1; + + unsigned char *pub2 = NULL; + int pub2len = EVP_PKEY_get1_encoded_public_key(priv_key, &pub2); + err = (publen == pub2len) && pub2 && !memcmp(pub, pub2, publen); + printf("\tEVP_PKEY_get1_encoded_public_key:\t"); + print_test_tf(err, err, "success", "failure"); + ret |= err != 1; + if (pub2) + OPENSSL_free(pub2); + + EVP_PKEY *copy_key; + T(copy_key = EVP_PKEY_new()); + T(EVP_PKEY_copy_parameters(copy_key, priv_key)); + err = EVP_PKEY_set1_encoded_public_key(copy_key, pub, publen); + printf("\tEVP_PKEY_set1_encoded_public_key:\t"); + print_test_tf(err, err, "success", "failure"); + EVP_PKEY_free(copy_key); + OPENSSL_free(pub); + ret |= err != 1; + + /* Extract private key in raw format. + * Should contain d on little endian form. + */ + size_t privlen; + unsigned char *priv; + err = EVP_PKEY_get_raw_private_key(priv_key, NULL, &privlen); + T(priv = OPENSSL_zalloc(privlen)); + err &= EVP_PKEY_get_raw_private_key(priv_key, priv, &privlen); + printf("\tEVP_PKEY_get_raw_private_key:\t"); + print_test_tf(err, err, "success", "failure"); + OPENSSL_free(priv); + ret |= err != 1; + /* * Prepare for sign testing. */