Example #1
0
/*
 * Parses GOST algorithm parameters from X509_ALGOR and modifies pkey setting
 * NID and parameters
 */
static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg)
{
    ASN1_OBJECT *palg_obj = NULL;
    int ptype = V_ASN1_UNDEF;
    int pkey_nid = NID_undef, param_nid = NID_undef;
    void *_pval;
    ASN1_STRING *pval = NULL;
    const unsigned char *p;
    GOST_KEY_PARAMS *gkp = NULL;

    X509_ALGOR_get0(&palg_obj, &ptype, &_pval, palg);
    pval = _pval;
    if (ptype != V_ASN1_SEQUENCE) {
        GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
                GOST_R_BAD_KEY_PARAMETERS_FORMAT);
        return 0;
    }
    p = pval->data;
    pkey_nid = OBJ_obj2nid(palg_obj);

    gkp = d2i_GOST_KEY_PARAMS(NULL, &p, pval->length);
    if (!gkp) {
        GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,
                GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
        return 0;
    }
    param_nid = OBJ_obj2nid(gkp->key_params);
    GOST_KEY_PARAMS_free(gkp);
    if(!EVP_PKEY_set_type(pkey, pkey_nid)) {
        GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS, ERR_R_INTERNAL_ERROR);
        return 0;
    }
    switch (pkey_nid) {
    case NID_id_GostR3410_94:
        {
            DSA *dsa = EVP_PKEY_get0(pkey);
            if (!dsa) {
                dsa = DSA_new();
                if (!EVP_PKEY_assign(pkey, pkey_nid, dsa))
                    return 0;
            }
            if (!fill_GOST94_params(dsa, param_nid))
                return 0;
            break;
        }
    case NID_id_GostR3410_2001:
        {
            EC_KEY *ec = EVP_PKEY_get0(pkey);
            if (!ec) {
                ec = EC_KEY_new();
                if (!EVP_PKEY_assign(pkey, pkey_nid, ec))
                    return 0;
            }
            if (!fill_GOST2001_params(ec, param_nid))
                return 0;
        }
    }

    return 1;
}
Example #2
0
File: gost_pmeth.c Project: 5y/node
static int pkey_gost94_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
{
    struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
    DSA *dsa = NULL;
    if (data->sign_param_nid == NID_undef) {
        GOSTerr(GOST_F_PKEY_GOST94_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
        return 0;
    }
    dsa = DSA_new();
    if (!fill_GOST94_params(dsa, data->sign_param_nid)) {
        DSA_free(dsa);
        return 0;
    }
    EVP_PKEY_assign(pkey, NID_id_GostR3410_94, dsa);
    return 1;
}
Example #3
0
static int gost94_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
{
	ASN1_OBJECT *obj=NULL;
	DSA *dsa = EVP_PKEY_get0(pkey);
	int nid;
	if (d2i_ASN1_OBJECT(&obj,pder,derlen)==NULL) {
		return 0;
	}
	nid = OBJ_obj2nid(obj);
	ASN1_OBJECT_free(obj);
	if (!dsa) 
		{
		dsa=DSA_new();
		if (!EVP_PKEY_assign(pkey,NID_id_GostR3410_94,dsa)) return 0;
		}
	if (!fill_GOST94_params(dsa,nid)) return 0;
	return 1;
}