static int pub_decode_gost94(EVP_PKEY *pk, X509_PUBKEY *pub)
{
    X509_ALGOR *palg = NULL;
    const unsigned char *pubkey_buf = NULL;
    unsigned char *databuf;
    ASN1_OBJECT *palgobj = NULL;
    int pub_len, i, j;
    DSA *dsa;
    ASN1_OCTET_STRING *octet = NULL;

    if (!X509_PUBKEY_get0_param(&palgobj, &pubkey_buf, &pub_len, &palg, pub))
        return 0;
    EVP_PKEY_assign(pk, OBJ_obj2nid(palgobj), NULL);
    if (!decode_gost_algor_params(pk, palg))
        return 0;
    octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len);
    if (!octet) {
        GOSTerr(GOST_F_PUB_DECODE_GOST94, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    databuf = OPENSSL_malloc(octet->length);
    if (databuf == NULL) {
        GOSTerr(GOST_F_PUB_DECODE_GOST94, ERR_R_MALLOC_FAILURE);
        ASN1_OCTET_STRING_free(octet);
        return 0;
    }
    for (i = 0, j = octet->length - 1; i < octet->length; i++, j--) {
        databuf[j] = octet->data[i];
    }
    dsa = EVP_PKEY_get0(pk);
    dsa->pub_key = BN_bin2bn(databuf, octet->length, NULL);
    ASN1_OCTET_STRING_free(octet);
    OPENSSL_free(databuf);
    return 1;

}