本文整理匯總了C++中ENGINE_by_id函數的典型用法代碼示例。如果您正苦於以下問題:C++ ENGINE_by_id函數的具體用法?C++ ENGINE_by_id怎麽用?C++ ENGINE_by_id使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ENGINE_by_id函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: tor_init_with_engine
void
tor_init_with_engine (const char* name, const char* path)
{
ENGINE* engine;
if (initialized) {
return;
}
tor_init();
if (path == NULL) {
engine = ENGINE_by_id(name);
}
else {
engine = ENGINE_by_id("dynamic");
if (!ENGINE_ctrl_cmd_string(engine, "ID", name, 0) ||
!ENGINE_ctrl_cmd_string(engine, "DIR_LOAD", "2", 0) ||
!ENGINE_ctrl_cmd_string(engine, "DIR_ADD", path, 0) ||
!ENGINE_ctrl_cmd_string(engine, "LOAD", NULL, 0)) {
ENGINE_free(engine);
engine = NULL;
}
}
if (engine) {
ENGINE_set_default(engine, ENGINE_METHOD_ALL);
}
}
示例2: sc_pkcs11_register_openssl_mechanisms
void
sc_pkcs11_register_openssl_mechanisms(struct sc_pkcs11_card *card)
{
#if OPENSSL_VERSION_NUMBER >= 0x10000000L && !defined(OPENSSL_NO_ENGINE)
void (*locking_cb)(int, int, const char *, int);
ENGINE *e;
locking_cb = CRYPTO_get_locking_callback();
if (locking_cb)
CRYPTO_set_locking_callback(NULL);
e = ENGINE_by_id("gost");
if (!e)
{
#if !defined(OPENSSL_NO_STATIC_ENGINE) && !defined(OPENSSL_NO_GOST)
ENGINE_load_gost();
e = ENGINE_by_id("gost");
#else
/* try to load dynamic gost engine */
e = ENGINE_by_id("dynamic");
if (!e) {
ENGINE_load_dynamic();
e = ENGINE_by_id("dynamic");
}
if (e && (!ENGINE_ctrl_cmd_string(e, "SO_PATH", "gost", 0) ||
!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))) {
ENGINE_free(e);
e = NULL;
}
#endif /* !OPENSSL_NO_STATIC_ENGINE && !OPENSSL_NO_GOST */
}
if (e) {
ENGINE_set_default(e, ENGINE_METHOD_ALL);
ENGINE_free(e);
}
if (locking_cb)
CRYPTO_set_locking_callback(locking_cb);
#endif /* OPENSSL_VERSION_NUMBER >= 0x10000000L && !defined(OPENSSL_NO_ENGINE) */
openssl_sha1_mech.mech_data = EVP_sha1();
sc_pkcs11_register_mechanism(card, &openssl_sha1_mech);
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
openssl_sha256_mech.mech_data = EVP_sha256();
sc_pkcs11_register_mechanism(card, &openssl_sha256_mech);
openssl_sha384_mech.mech_data = EVP_sha384();
sc_pkcs11_register_mechanism(card, &openssl_sha384_mech);
openssl_sha512_mech.mech_data = EVP_sha512();
sc_pkcs11_register_mechanism(card, &openssl_sha512_mech);
#endif
openssl_md5_mech.mech_data = EVP_md5();
sc_pkcs11_register_mechanism(card, &openssl_md5_mech);
openssl_ripemd160_mech.mech_data = EVP_ripemd160();
sc_pkcs11_register_mechanism(card, &openssl_ripemd160_mech);
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
openssl_gostr3411_mech.mech_data = EVP_get_digestbynid(NID_id_GostR3411_94);
sc_pkcs11_register_mechanism(card, &openssl_gostr3411_mech);
#endif
}
示例3: dnssec_loadengine
ENGINE*
dnssec_loadengine(const char* engine_name_const)
{
ENGINE* engine;
char* token_pointer = NULL;
char* engine_name = strdup(engine_name_const);
char* token = strtok_r(engine_name, ENGINE_COMMAND_DELIMITER, &token_pointer);
if(token == NULL)
{
engine = ENGINE_by_id(engine_name);
}
else
{
engine = ENGINE_by_id(token);
token = strtok_r(NULL, ENGINE_COMMAND_DELIMITER, &token_pointer);
}
if(engine == NULL)
{
log_err("ENGINE %s not available", engine_name);
DIE(DNSSEC_ERROR_NOENGINE);
}
while(token != NULL)
{
char* command_pointer;
char* command = strtok_r(token, "=", &command_pointer);
if(command == NULL)
{
log_err("bad command %s", command);
DIE(DNSSEC_ERROR_INVALIDENGINE);
}
char* command_value = strtok_r(NULL, "=", &command_pointer);
if(command_value == NULL)
{
log_err("bad command value %s", command_value);
DIE(DNSSEC_ERROR_INVALIDENGINE);
}
ENGINE_ctrl_cmd((ENGINE*)engine, command, atoi(command_value), NULL, NULL, 0);
token = strtok_r(NULL, ENGINE_COMMAND_DELIMITER, &token_pointer);
}
if(ENGINE_init((ENGINE*)engine) == 0)
{
log_err("ENGINE_init failed");
ENGINE_free((ENGINE*)engine); /* cfr: http://www.openssl.org/docs/crypto/engine.html */
DIE(DNSSEC_ERROR_INVALIDENGINE);
}
free(engine_name);
return engine;
}
示例4: main
int
main(int argc, char **argv)
{
ENGINE *engine = NULL;
int idx = 0;
setprogname(argv[0]);
if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &idx))
usage(1);
if (help_flag)
usage(0);
if(version_flag){
print_version(NULL);
exit(0);
}
argc -= idx;
argv += idx;
OpenSSL_add_all_algorithms();
#ifdef OPENSSL
ENGINE_load_openssl();
#endif
ENGINE_load_builtin_engines();
if (id_string) {
engine = ENGINE_by_id(id_string);
if (engine == NULL)
engine = ENGINE_by_dso(id_string, id_string);
} else {
engine = ENGINE_by_id("builtin");
}
if (engine == NULL)
errx(1, "ENGINE_by_dso failed");
printf("dh %s\n", ENGINE_get_DH(engine)->name);
{
struct prime *p = primes;
for (; p->name; ++p)
if (check_prime(engine, p))
printf("%s: shared secret OK\n", p->name);
else
printf("%s: shared secret FAILURE\n", p->name);
return 0;
}
return 0;
}
示例5: sldns_key_EVP_load_gost_id
int
sldns_key_EVP_load_gost_id(void)
{
static int gost_id = 0;
const EVP_PKEY_ASN1_METHOD* meth;
ENGINE* e;
if(gost_id) return gost_id;
/* see if configuration loaded gost implementation from other engine*/
meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
if(meth) {
EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
return gost_id;
}
/* see if engine can be loaded already */
e = ENGINE_by_id("gost");
if(!e) {
/* load it ourself, in case statically linked */
ENGINE_load_builtin_engines();
ENGINE_load_dynamic();
e = ENGINE_by_id("gost");
}
if(!e) {
/* no gost engine in openssl */
return 0;
}
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
ENGINE_finish(e);
ENGINE_free(e);
return 0;
}
meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
if(!meth) {
/* algo not found */
ENGINE_finish(e);
ENGINE_free(e);
return 0;
}
/* Note: do not ENGINE_finish and ENGINE_free the acquired engine
* on some platforms this frees up the meth and unloads gost stuff */
sldns_gost_engine = e;
EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
return gost_id;
}
示例6: DEBUG
CryptoDevEngine::CryptoDevEngine( int /* dummy */ )
{
DEBUG( "cryptodev: ctor: loading and configuring" );
ENGINE_load_cryptodev();
ENGINE * cde = ENGINE_by_id( "cryptodev" );
if ( ! cde )
throw Exception( "cryptodev: load failed" );
m_pEngine = cde;
DEBUG( "cryptodev: ctor: initializing " << m_pEngine );
if ( 1 != ENGINE_init( cde ) )
throw Exception( "cryptodev: init failed" );
#if USE_CRYPTODEV_RSA
DEBUG( "cryptodev: ctor: setting as rsa default" );
if ( 1 != ENGINE_set_default_RSA( cde ) )
throw Exception( "cryptodev: could not use for RSA" );
#endif // USE_CRYPTODEV_RSA
#if USE_CRYPTODEV_CIPHERS
DEBUG( "cryptodev: ctor: setting as cipher default" );
if ( 1 != ENGINE_set_default_ciphers( cde ) )
throw Exception( "cryptodev: could not use for ciphers" );
#endif // USE_CRYPTODEV_CIPHERS
#if USE_CRYPTODEV_DIGESTS
DEBUG( "cryptodev: ctor: setting as digest default" );
if ( 1 != ENGINE_set_default_digests( cde ) )
throw Exception( "cryptodev: could not use for digests" );
#endif // USE_CRYPTODEV_DIGESTS
DEBUG( "cryptodev: ctor: done" );
}
示例7: main
int main(int argc, char **argv) {
OpenSSL_add_all_algorithms();
int len = 128 * MB;
if (argc > 1) {
len = atoi(argv[1]) * MB;
}
unsigned char *buf = (unsigned char *) malloc(TOTAL_LEN);
if (!buf) {
fprintf(stderr, "Error Allocating Memory");
}
ENGINE_load_builtin_engines();
#ifdef OPENCL_ENGINE
ENGINE *e = ENGINE_by_id("dynamic");
if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", OPENCL_ENGINE, 0) ||
!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) {
fprintf(stderr, "Failed to load OpenCL engine!\n");
return -1;
}
ENGINE_set_default(e, ENGINE_METHOD_ALL);
#endif
run(argv[0], buf, len);
free(buf);
return 0;
}
示例8: LOGGER_FN
ENGINE *ENGINE_CTGOST_get_ptr(){
LOGGER_FN();
ENGINE *e = ENGINE_by_id("ctgostcp");
if (!e)
THROW_OPENSSL_EXCEPTION(0, Common, NULL, "ENGINE 'ctgostcp' is not loaded");
return e;
}
示例9: Curl_ossl_set_engine
/* Selects an OpenSSL crypto engine
*/
CURLcode Curl_ossl_set_engine(struct SessionHandle *data, const char *engine)
{
#if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
ENGINE *e = ENGINE_by_id(engine);
if (!e) {
failf(data, "SSL Engine '%s' not found", engine);
return (CURLE_SSL_ENGINE_NOTFOUND);
}
if (data->state.engine) {
ENGINE_finish(data->state.engine);
ENGINE_free(data->state.engine);
}
data->state.engine = NULL;
if (!ENGINE_init(e)) {
char buf[256];
ENGINE_free(e);
failf(data, "Failed to initialise SSL Engine '%s':\n%s",
engine, SSL_strerror(ERR_get_error(), buf, sizeof(buf)));
return (CURLE_SSL_ENGINE_INITFAILED);
}
data->state.engine = e;
return (CURLE_OK);
#else
(void)engine;
failf(data, "SSL Engine not supported");
return (CURLE_SSL_ENGINE_NOTFOUND);
#endif
}
示例10: ssl_init_Engine
void ssl_init_Engine(server_rec *s, apr_pool_t *p)
{
SSLModConfigRec *mc = myModConfig(s);
ENGINE *e;
if (mc->szCryptoDevice) {
if (!(e = ENGINE_by_id(mc->szCryptoDevice))) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
"Init: Failed to load Crypto Device API `%s'",
mc->szCryptoDevice);
ssl_log_ssl_error(APLOG_MARK, APLOG_ERR, s);
ssl_die();
}
if (strEQ(mc->szCryptoDevice, "chil")) {
ENGINE_ctrl(e, ENGINE_CTRL_CHIL_SET_FORKCHECK, 1, 0, 0);
}
if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
"Init: Failed to enable Crypto Device API `%s'",
mc->szCryptoDevice);
ssl_log_ssl_error(APLOG_MARK, APLOG_ERR, s);
ssl_die();
}
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,
"Init: loaded Crypto Device API `%s'",
mc->szCryptoDevice);
ENGINE_free(e);
}
}
示例11: ENGINE_load_builtin_engines
//ignore
unsigned char *HMACRSA(const EVP_MD *evp_md, const void *key, int key_len,const unsigned char *d, size_t n, unsigned char *md,unsigned int *md_len)
{
HMAC_CTX c;
static unsigned char m[EVP_MAX_MD_SIZE];
//TODO: get/set rsa engine struct
const char *engine_id = "rsa";
ENGINE_load_builtin_engines();
ENGINE *e = ENGINE_by_id(engine_id);//ENGINE_;
if(!e)
fprintf(stderr,"Engine not available\n");
ENGINE_init(e);
if (md == NULL)
md = m;
HMAC_CTX_init(&c);
if (!HMAC_Init_ex(&c, key, key_len, evp_md, NULL))
goto err;
if (!HMAC_Update(&c, d, n))
goto err;
if (!HMAC_Final(&c, md, md_len))
goto err;
HMAC_CTX_cleanup(&c);
ENGINE_free(e);
return md;
err:
HMAC_CTX_cleanup(&c);
ENGINE_free(e);
return NULL;
}
示例12: InitEnginePKCS11
static ENGINE *
InitEnginePKCS11( const char *pkcs11, const char *pin)
{
ENGINE *e;
ENGINE_load_dynamic();
e = ENGINE_by_id("dynamic");
if (!e){
SSL_Error(_d("Engine_by_id:\n %s"), GetSSLErrorString());
return NULL;
}
if(!ENGINE_ctrl_cmd_string(e, "SO_PATH", ENGINE_PKCS11_PATH, 0)||
!ENGINE_ctrl_cmd_string(e, "ID", "pkcs11", 0) ||
!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "1", 0) ||
!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0) ||
!ENGINE_ctrl_cmd_string(e, "MODULE_PATH", pkcs11, 0) ||
!ENGINE_ctrl_cmd_string(e, "PIN", pin, 0) ){
SSL_Error(_d("Engine_ctrl_cmd_string failure:\n %s"), GetSSLErrorString());
ENGINE_free(e);
return NULL;
}
if(!ENGINE_init(e)){
SSL_Error(_d("Engine_init failure:\n %s"), GetSSLErrorString());
ENGINE_free(e);
return NULL;
}
return e;
}
示例13: dst__opensslgost_init
isc_result_t
dst__opensslgost_init(dst_func_t **funcp) {
REQUIRE(funcp != NULL);
/* check if the gost engine works properly */
e = ENGINE_by_id("gost");
if (e == NULL)
return (DST_R_OPENSSLFAILURE);
if (ENGINE_init(e) <= 0) {
ENGINE_free(e);
e = NULL;
return (DST_R_OPENSSLFAILURE);
}
/* better than to rely on digest_gost symbol */
opensslgost_digest = ENGINE_get_digest(e, NID_id_GostR3411_94);
/* from openssl.cnf */
if ((opensslgost_digest == NULL) ||
(ENGINE_register_pkey_asn1_meths(e) <= 0) ||
(ENGINE_ctrl_cmd_string(e,
"CRYPT_PARAMS",
"id-Gost28147-89-CryptoPro-A-ParamSet",
0) <= 0)) {
ENGINE_finish(e);
ENGINE_free(e);
e = NULL;
return (DST_R_OPENSSLFAILURE);
}
if (*funcp == NULL)
*funcp = &opensslgost_functions;
return (ISC_R_SUCCESS);
}
示例14: load_engine
static int load_engine(void **ctx,MESSAGE *msg)
{
int i;
ENGINE **e=(ENGINE **)ctx;
ENGINE_load_dynamic();
if(!(*e=ENGINE_by_id("dynamic")))goto err1;
if(!ENGINE_ctrl_cmd_string(*e,"SO_PATH",msg->engine,0))goto err2;
for(i=0;pkcs11[i].name;i++)
if(!ENGINE_ctrl_cmd_string(*e,pkcs11[i].name,pkcs11[i].value,0))
goto err2;
if(!ENGINE_ctrl_cmd_string(*e,"MODULE_PATH",msg->pkcs11,0))goto err2;
if(msg->nopin)if(!ENGINE_ctrl_cmd_string(*e,"NOLOGIN","1",0))goto err2;
if(!ENGINE_ctrl_cmd_string(*e,"PIN",msg->nopin?"":msg->pin,0))goto err2;
if(!ENGINE_init(*e))
{
err2: ENGINE_free(*e);
err1: ENGINE_cleanup();
return ENGFAIL;
}
ENGINE_free(*e);
ENGINE_set_default(*e,ENGINE_METHOD_ALL&~ENGINE_METHOD_RAND);
return OK;
}
示例15: setup_engine
static ENGINE *
setup_engine (const char *engine)
{
ENGINE *e = NULL;
ENGINE_load_builtin_engines ();
if (engine)
{
if (strcmp (engine, "auto") == 0)
{
msg (M_INFO, "Initializing OpenSSL auto engine support");
ENGINE_register_all_complete ();
return NULL;
}
if ((e = ENGINE_by_id (engine)) == NULL
&& (e = try_load_engine (engine)) == NULL)
{
msg (M_FATAL, "OpenSSL error: cannot load engine '%s'", engine);
}
if (!ENGINE_set_default (e, ENGINE_METHOD_ALL))
{
msg (M_FATAL, "OpenSSL error: ENGINE_set_default failed on engine '%s'",
engine);
}
msg (M_INFO, "Initializing OpenSSL support for engine '%s'",
ENGINE_get_id (e));
}
return e;
}