Beispiel #1
0
static int pkey_gost2001_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
{
    struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
    EC_KEY *ec = NULL;

    if (!data || data->sign_param_nid == NID_undef) {
        GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
        return 0;
    }

    ec = EC_KEY_new();
    if (!fill_GOST_EC_params(ec, data->sign_param_nid)
        || !EVP_PKEY_assign(pkey, NID_id_GostR3410_2001, ec)) {
        EC_KEY_free(ec);
        return 0;
    }
    return 1;
}
Beispiel #2
0
static int pkey_gost2012_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
{
    struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
    EC_KEY *ec;
    int result = 0;

    if (!data || data->sign_param_nid == NID_undef) {
        GOSTerr(GOST_F_PKEY_GOST12_PARAMGEN, GOST_R_NO_PARAMETERS_SET);
        return 0;
    }

    ec = EC_KEY_new();
    if (!fill_GOST_EC_params(ec, data->sign_param_nid)) {
        EC_KEY_free(ec);
        return 0;
    }

    switch (data->sign_param_nid) {
    case NID_id_tc26_gost_3410_2012_512_paramSetA:
    case NID_id_tc26_gost_3410_2012_512_paramSetB:
        result =
            (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_512, ec)) ? 1 : 0;
        break;

    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:
    case NID_id_GostR3410_2001_TestParamSet:
        result =
            (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_256, ec)) ? 1 : 0;
        break;
    default:
        result = 0;
        break;
    }

    if (result == 0)
        EC_KEY_free(ec);

    return result;
}
Beispiel #3
0
static int gost_decode_nid_params(EVP_PKEY *pkey, int pkey_nid, int param_nid)
{
    void *key_ptr = EVP_PKEY_get0(pkey);

    switch (pkey_nid) {
    case NID_id_GostR3410_2012_256:
    case NID_id_GostR3410_2012_512:
    case NID_id_GostR3410_2001:
        if (!key_ptr) {
            key_ptr = EC_KEY_new();
            if (!EVP_PKEY_assign(pkey, pkey_nid, key_ptr)) {
                EC_KEY_free(key_ptr);
                break;
            }
        }
        return fill_GOST_EC_params(key_ptr, param_nid);
    }

    return 0;
}