]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
test_params: Avoid calls to fill_GOST_EC_params and bind_gost
authorVitaly Chikunov <vt@altlinux.org>
Sat, 26 Jan 2019 23:15:00 +0000 (02:15 +0300)
committerVitaly Chikunov <vt@altlinux.org>
Sun, 27 Jan 2019 00:59:25 +0000 (03:59 +0300)
Use external API to generate key with parameters instead of calling
fill_GOST_EC_params(). Use OPENSSL_CONF trick like in test_sign to avoid
calling bind_gost(). Reverting 1716316de77 ("Export bind_gost to allow
local engine init") as not needed anymore.

gost_eng.c
gost_lcl.h
test_params.c

index 74fe13e205209c984c5d6e146875d67cec425256..69f99757c2ae704a324930297ee71eef0502963e 100644 (file)
@@ -164,7 +164,7 @@ static int gost_engine_destroy(ENGINE* e) {
     return 1;
 }
 
-int bind_gost(ENGINE* e, const char* id) {
+static int bind_gost(ENGINE* e, const char* id) {
     int ret = 0;
     if (id != NULL && strcmp(id, engine_gost_id) != 0)
         return 0;
index 512d94746d6c1ce87195a4890733240f207e7efd..6623d6d3a6bb46fae1447678bc9e0270a188d8af 100644 (file)
@@ -301,7 +301,4 @@ int pack_sign_cp(ECDSA_SIG *s, int order, unsigned char *sig, size_t *siglen);
 /* Get private key as BIGNUM from both 34.10-2001 keys*/
 /* Returns pointer into EVP_PKEY structure */
 BIGNUM *gost_get0_priv_key(const EVP_PKEY *pkey);
-
-int bind_gost(ENGINE* e, const char* id);
-
 #endif
index b4776628150e9fa487f7dbd4cfbc095525d3481e..972af24196338e853093b655a21c78ac95154df5 100644 (file)
@@ -928,6 +928,28 @@ static int test_cert(struct test_cert *tc)
     return err != 1;
 }
 
+/* Generate EC_KEY with proper parameters using temporary PKEYs.
+ * This emulates fill_GOST_EC_params() call.
+ */
+static int EC_KEY_create(int type, int param_nid, EC_KEY *dst)
+{
+    EVP_PKEY *pkey;
+    T(pkey = EVP_PKEY_new());
+    T(EVP_PKEY_set_type(pkey, type));
+    EVP_PKEY_CTX *ctx;
+    T(ctx = EVP_PKEY_CTX_new(pkey, NULL));
+    T(EVP_PKEY_paramgen_init(ctx));
+    T(EVP_PKEY_CTX_ctrl(ctx, type, -1, EVP_PKEY_CTRL_GOST_PARAMSET, param_nid, NULL));
+    EVP_PKEY *pkey2 = NULL;
+    int err;
+    TE((err = EVP_PKEY_paramgen(ctx, &pkey2)) == 1);
+    T(EC_KEY_copy(dst, EVP_PKEY_get0(pkey2)));
+    EVP_PKEY_CTX_free(ctx);
+    EVP_PKEY_free(pkey);
+    EVP_PKEY_free(pkey2);
+    return err;
+}
+
 static int test_param(struct test_param *t)
 {
     int ret = 0, err = 0;
@@ -936,7 +958,6 @@ static int test_param(struct test_param *t)
     const char *sn = OBJ_nid2sn(t->param);
 
     printf(cBLUE "Test %s (cp):\n" cNORM, sn);
-    //T(pkey = EVP_PKEY_new_raw_public_key(NID_id_GostR3410_2001, NULL, t->pub_key, 64));
 
     switch (t->len) {
        case 256 / 8:
@@ -962,7 +983,7 @@ static int test_param(struct test_param *t)
     /* Manually construct public key */
     EC_KEY *ec;
     T(ec = EC_KEY_new());
-    T(fill_GOST_EC_params(ec, t->param));
+    T(EC_KEY_create(type, t->param, ec));
     const EC_GROUP *group;
     T(group = EC_KEY_get0_group(ec));
     unsigned char *pub_key;
@@ -1025,11 +1046,9 @@ int main(int argc, char **argv)
 {
     int ret = 0;
 
+    setenv("OPENSSL_CONF", "../example.conf", 0);
     OPENSSL_add_all_algorithms_conf();
     ERR_load_crypto_strings();
-    ENGINE *e = ENGINE_new();
-    bind_gost(e, "gost");
-    ENGINE_register_complete(e);
 
     struct test_param **tpp;
     for (tpp = test_params; *tpp; tpp++)