]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Allow key creation using TC26 (2012) parameters
authorVitaly Chikunov <vt@altlinux.org>
Thu, 24 Jan 2019 01:32:28 +0000 (04:32 +0300)
committerVitaly Chikunov <vt@altlinux.org>
Fri, 25 Jan 2019 22:52:06 +0000 (01:52 +0300)
1323565.1.023-2018 forbids encoding hash oid into TC26 (2012)
parameters in AlgorithmIdentifier, so this is removed.

New "paramset" names for 256-bit TC26 parameters: TCA, TCB, TCC, TCD,
for 512-bit parameter: C.

Using these new OIDs for gost2012_256:
  NID_id_tc26_gost_3410_2012_256_paramSetA = TCA
  NID_id_tc26_gost_3410_2012_256_paramSetB = TCB
  NID_id_tc26_gost_3410_2012_256_paramSetC = TCC
  NID_id_tc26_gost_3410_2012_256_paramSetD = TCD
for gost2012_512:
  NID_id_tc26_gost_3410_2012_512_paramSetC = C

Resolves #84.

README.gost
gost_ameth.c
gost_ec_sign.c
gost_pmeth.c

index db6b4b90d1994107763c878b18535b2589abdfae..3579665ba23fbfae128adb49beead98c7697eb18 100644 (file)
@@ -70,8 +70,8 @@ USAGE WITH COMMAND LINE openssl UTILITY
   Use -pkeyopt option to pass paramset to algorithm. The following paramsets
   are supported by 
        gost2001:     0,A,B,C,XA,XB
-       gost2012_256: 0,A,B,C,XA,XB
-       gost2012_512:   A,B
+       gost2012_256: 0,A,B,C,XA,XB,TCA,TCB,TCC,TCD
+       gost2012_512:   A,B,C
   You can also use numeric representation of OID as to destinate
   paramset.
 
index df595207fadc43d5f7e5a53aa7ac7bb639383a34..6ae278655881c330797711047991da3d9d58dc7f 100644 (file)
@@ -67,11 +67,18 @@ static ASN1_STRING *encode_gost_algor_params(const EVP_PKEY *key)
     switch (EVP_PKEY_base_id(key)) {
     case NID_id_GostR3410_2012_256:
         pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(key_ptr));
-        gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_2012_256);
+       switch (pkey_param_nid) {
+           case NID_id_GostR3410_2001_TestParamSet:
+           case NID_id_GostR3410_2001_CryptoPro_A_ParamSet:
+           case NID_id_GostR3410_2001_CryptoPro_B_ParamSet:
+           case NID_id_GostR3410_2001_CryptoPro_C_ParamSet:
+           case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet:
+           case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet:
+               gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_2012_256);
+       }
         break;
     case NID_id_GostR3410_2012_512:
         pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(key_ptr));
-        gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_2012_512);
         break;
     case NID_id_GostR3410_2001:
         pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(key_ptr));
index ba12783959e36ec31b1ea1c98da1678c78ed30df..3db118af1481d2680aa8f468176a7a4cc8d0935e 100644 (file)
@@ -146,7 +146,7 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid)
         GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
         goto end;
     }
-    EC_GROUP_set_curve_name(grp, params->nid);
+    EC_GROUP_set_curve_name(grp, nid);
     if (!EC_KEY_set_group(eckey, grp)) {
         GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR);
         goto end;
index b2e0a4956a545a79a3f0df031017c7c68d3cb724..41bda944cd6176db841973e263565959461de882 100644 (file)
@@ -208,6 +208,25 @@ static int pkey_gost_ec_ctrl_str_256(EVP_PKEY_CTX *ctx,
             default:
                 return 0;
             }
+       } else if ((strlen(value) == 3)
+           && (toupper((unsigned char)value[0]) == 'T')
+           && (toupper((unsigned char)value[1]) == 'C')) {
+            switch (toupper((unsigned char)value[2])) {
+            case 'A':
+                param_nid = NID_id_tc26_gost_3410_2012_256_paramSetA;
+                break;
+            case 'B':
+                param_nid = NID_id_tc26_gost_3410_2012_256_paramSetB;
+                break;
+            case 'C':
+                param_nid = NID_id_tc26_gost_3410_2012_256_paramSetC;
+                break;
+            case 'D':
+                param_nid = NID_id_tc26_gost_3410_2012_256_paramSetD;
+                break;
+            default:
+                return 0;
+            }
         } else {
             R3410_ec_params *p = R3410_2001_paramset;
             param_nid = OBJ_txt2nid(value);
@@ -252,6 +271,10 @@ static int pkey_gost_ec_ctrl_str_512(EVP_PKEY_CTX *ctx,
             param_nid = NID_id_tc26_gost_3410_2012_512_paramSetB;
             break;
 
+        case 'C':
+            param_nid = NID_id_tc26_gost_3410_2012_512_paramSetC;
+            break;
+
         default:
             return 0;
         }
@@ -320,6 +343,7 @@ static int pkey_gost2012_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
     switch (data->sign_param_nid) {
     case NID_id_tc26_gost_3410_2012_512_paramSetA:
     case NID_id_tc26_gost_3410_2012_512_paramSetB:
+    case NID_id_tc26_gost_3410_2012_512_paramSetC:
         result =
             (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_512, ec)) ? 1 : 0;
         break;
@@ -330,6 +354,10 @@ static int pkey_gost2012_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
     case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet:
     case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet:
     case NID_id_GostR3410_2001_TestParamSet:
+    case NID_id_tc26_gost_3410_2012_256_paramSetA:
+    case NID_id_tc26_gost_3410_2012_256_paramSetB:
+    case NID_id_tc26_gost_3410_2012_256_paramSetC:
+    case NID_id_tc26_gost_3410_2012_256_paramSetD:
         result =
             (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_256, ec)) ? 1 : 0;
         break;