Ejemplo n.º 1
0
int
EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
{
	if ((NULL == in) || (NULL == in->md)) {
		/* EVPerr */
		return (0);
	}

	EVP_MD_CTX_cleanup(out);
	memcpy(out, in, sizeof(*out));

	if (out->md->ctx_size) {
		out->ptr = malloc(in->md->ctx_size);
		if (!out->ptr) {
			/* EVPerr */
			return (0);
		}
		memcpy(out->ptr, in->ptr, out->md->ctx_size);
	}

	if (out->engine) {
		ENGINE_up_ref(out->engine);
	}

	/*
	 * if (out->md->copy)
	 *      return out->md->copy(out, in);
	 */

	return (1);
}
Ejemplo n.º 2
0
RSA *
RSA_new_method(ENGINE *engine)
{
    RSA *rsa;

    rsa = calloc(1, sizeof(*rsa));
    if (rsa == NULL)
	return NULL;

    rsa->references = 1;

    if (engine) {
	ENGINE_up_ref(engine);
	rsa->engine = engine;
    } else {
	rsa->engine = ENGINE_get_default_RSA();
    }

    if (rsa->engine) {
	rsa->meth = ENGINE_get_RSA(rsa->engine);
	if (rsa->meth == NULL) {
	    ENGINE_finish(engine);
	    free(rsa);
	    return 0;
	}
    }

    if (rsa->meth == NULL)
	rsa->meth = rk_UNCONST(RSA_get_default_method());

    (*rsa->meth->init)(rsa);

    return rsa;
}
Ejemplo n.º 3
0
Archivo: dh.c Proyecto: Henauxg/minix
DH *
DH_new_method(ENGINE *engine)
{
    DH *dh;

    dh = calloc(1, sizeof(*dh));
    if (dh == NULL)
	return NULL;

    dh->references = 1;

    if (engine) {
	ENGINE_up_ref(engine);
	dh->engine = engine;
    } else {
	dh->engine = ENGINE_get_default_DH();
    }

    if (dh->engine) {
	dh->meth = ENGINE_get_DH(dh->engine);
	if (dh->meth == NULL) {
	    ENGINE_finish(engine);
	    free(dh);
	    return 0;
	}
    }

    if (dh->meth == NULL)
	dh->meth = DH_get_default_method();

    (*dh->meth->init)(dh);

    return dh;
}
Ejemplo n.º 4
0
int
RAND_set_rand_engine(ENGINE *engine)
{
    const RAND_METHOD *meth, *old = selected_meth;

    if (engine) {
	ENGINE_up_ref(engine);
	meth = ENGINE_get_RAND(engine);
	if (meth == NULL) {
	    ENGINE_finish(engine);
	    return 0;
	}
    } else {
	meth = NULL;
    }

    if (old)
	(*old->cleanup)();

    if (selected_engine)
	ENGINE_finish(selected_engine);

    selected_engine = engine;
    selected_meth = meth;

    return 1;
}
Ejemplo n.º 5
0
ENGINE *
ENGINE_by_id(const char *id)
{
    int i;

    for (i = 0; i < num_engines; i++) {
	if (strcmp(id, engines[i]->id) == 0) {
	    ENGINE_up_ref(engines[i]);
	    return engines[i];
	}
    }
    return NULL;
}
Ejemplo n.º 6
0
static VALUE
ossl_engine_s_engines(VALUE klass)
{
    ENGINE *e;
    VALUE ary, obj;

    ary = rb_ary_new();
    for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
	/* Need a ref count of two here because of ENGINE_free being
	 * called internally by OpenSSL when moving to the next ENGINE
	 * and by us when releasing the ENGINE reference */
	ENGINE_up_ref(e);
	WrapEngine(klass, obj, e);
        rb_ary_push(ary, obj);
    }

    return ary;
}
Ejemplo n.º 7
0
ENGINE *
ENGINE_by_dso(const char *path, const char *id)
{
#ifdef HAVE_DLOPEN
    ENGINE *engine;
    void *handle;
    int ret;

    engine = calloc(1, sizeof(*engine));
    if (engine == NULL)
	return NULL;

    handle = dlopen(path, RTLD_NOW);
    if (handle == NULL) {
	/* printf("error: %s\n", dlerror()); */
	free(engine);
	return NULL;
    }

    {
	unsigned long version;
	openssl_v_check v_check;

	v_check = (openssl_v_check)dlsym(handle, "v_check");
	if (v_check == NULL) {
	    dlclose(handle);
	    free(engine);
	    return NULL;
	}

	version = (*v_check)(OPENSSL_DYNAMIC_VERSION);
	if (version == 0) {
	    dlclose(handle);
	    free(engine);
	    return NULL;
	}
    }

    {
	openssl_bind_engine bind_engine;

	bind_engine = (openssl_bind_engine)dlsym(handle, "bind_engine");
	if (bind_engine == NULL) {
	    dlclose(handle);
	    free(engine);
	    return NULL;
	}

	ret = (*bind_engine)(engine, id, NULL); /* XXX fix third arg */
	if (ret != 1) {
	    dlclose(handle);
	    free(engine);
	    return NULL;
	}
    }

    ENGINE_up_ref(engine);

    ret = add_engine(engine);
    if (ret != 1) {
	dlclose(handle);
	ENGINE_finish(engine);
	return NULL;
    }

    return engine;
#else
    return NULL;
#endif
}