int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
                unsigned char *md, unsigned int *len)
{
    int i;
    unsigned char *str, *p;

    i = i2d(data, NULL);
    if ((str = OPENSSL_malloc(i)) == NULL) {
        ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
        return (0);
    }
    p = str;
    i2d(data, &p);

    if (!EVP_Digest(str, i, md, len, type, NULL))
        return 0;
    OPENSSL_free(str);
    return (1);
}