13 #if defined(OSSL_ENGINE_ENABLED)
15 #define WrapEngine(klass, obj, engine) do { \
17 ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
19 (obj) = Data_Wrap_Struct((klass), 0, ENGINE_free, (engine)); \
21 #define GetEngine(obj, engine) do { \
22 Data_Get_Struct((obj), ENGINE, (engine)); \
24 ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
27 #define SafeGetEngine(obj, engine) do { \
28 OSSL_Check_Kind((obj), cEngine); \
29 GetPKCS7((obj), (engine)); \
52 #define OSSL_ENGINE_LOAD_IF_MATCH(x) \
54 if(!strcmp(#x, RSTRING_PTR(name))){\
74 #if !defined(HAVE_ENGINE_LOAD_BUILTIN_ENGINES)
81 ENGINE_load_builtin_engines();
85 #ifndef OPENSSL_NO_STATIC_ENGINE
86 #if HAVE_ENGINE_LOAD_DYNAMIC
87 OSSL_ENGINE_LOAD_IF_MATCH(dynamic);
89 #if HAVE_ENGINE_LOAD_4758CCA
90 OSSL_ENGINE_LOAD_IF_MATCH(4758cca);
92 #if HAVE_ENGINE_LOAD_AEP
93 OSSL_ENGINE_LOAD_IF_MATCH(aep);
95 #if HAVE_ENGINE_LOAD_ATALLA
96 OSSL_ENGINE_LOAD_IF_MATCH(atalla);
98 #if HAVE_ENGINE_LOAD_CHIL
99 OSSL_ENGINE_LOAD_IF_MATCH(chil);
101 #if HAVE_ENGINE_LOAD_CSWIFT
102 OSSL_ENGINE_LOAD_IF_MATCH(cswift);
104 #if HAVE_ENGINE_LOAD_NURON
105 OSSL_ENGINE_LOAD_IF_MATCH(nuron);
107 #if HAVE_ENGINE_LOAD_SUREWARE
108 OSSL_ENGINE_LOAD_IF_MATCH(sureware);
110 #if HAVE_ENGINE_LOAD_UBSEC
111 OSSL_ENGINE_LOAD_IF_MATCH(ubsec);
113 #if HAVE_ENGINE_LOAD_PADLOCK
114 OSSL_ENGINE_LOAD_IF_MATCH(padlock);
116 #if HAVE_ENGINE_LOAD_CAPI
117 OSSL_ENGINE_LOAD_IF_MATCH(capi);
119 #if HAVE_ENGINE_LOAD_GMP
120 OSSL_ENGINE_LOAD_IF_MATCH(gmp);
122 #if HAVE_ENGINE_LOAD_GOST
123 OSSL_ENGINE_LOAD_IF_MATCH(gost);
125 #if HAVE_ENGINE_LOAD_CRYPTODEV
126 OSSL_ENGINE_LOAD_IF_MATCH(cryptodev);
128 #if HAVE_ENGINE_LOAD_AESNI
129 OSSL_ENGINE_LOAD_IF_MATCH(aesni);
132 #ifdef HAVE_ENGINE_LOAD_OPENBSD_DEV_CRYPTO
133 OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
135 OSSL_ENGINE_LOAD_IF_MATCH(openssl);
151 ossl_engine_s_cleanup(
VALUE self)
153 #if defined(HAVE_ENGINE_CLEANUP)
164 ossl_engine_s_engines(
VALUE klass)
170 for(e = ENGINE_get_first();
e; e = ENGINE_get_next(e)){
175 WrapEngine(klass, obj, e);
201 ossl_engine_s_load(1, &
id, klass);
204 WrapEngine(klass, obj, e);
208 ENGINE_ctrl(e, ENGINE_CTRL_SET_PASSWORD_CALLBACK,
216 ossl_engine_s_alloc(
VALUE klass)
221 if (!(e = ENGINE_new())) {
224 WrapEngine(klass, obj, e);
239 ossl_engine_get_id(
VALUE self)
257 ossl_engine_get_name(
VALUE self)
271 ossl_engine_finish(
VALUE self)
281 #if defined(HAVE_ENGINE_GET_CIPHER)
299 ossl_engine_get_cipher(
VALUE self,
VALUE name)
302 const EVP_CIPHER *ciph, *
tmp;
307 tmp = EVP_get_cipherbyname(s);
309 nid = EVP_CIPHER_nid(tmp);
311 ciph = ENGINE_get_cipher(e, nid);
317 #define ossl_engine_get_cipher rb_f_notimplement
320 #if defined(HAVE_ENGINE_GET_DIGEST)
338 ossl_engine_get_digest(
VALUE self,
VALUE name)
341 const EVP_MD *md, *
tmp;
346 tmp = EVP_get_digestbyname(s);
348 nid = EVP_MD_nid(tmp);
350 md = ENGINE_get_digest(e, nid);
356 #define ossl_engine_get_digest rb_f_notimplement
370 ossl_engine_load_privkey(
int argc,
VALUE *argv,
VALUE self)
381 #if OPENSSL_VERSION_NUMBER < 0x00907000L
382 pkey = ENGINE_load_private_key(e, sid, sdata);
384 pkey = ENGINE_load_private_key(e, sid,
NULL, sdata);
404 ossl_engine_load_pubkey(
int argc,
VALUE *argv,
VALUE self)
415 #if OPENSSL_VERSION_NUMBER < 0x00907000L
416 pkey = ENGINE_load_public_key(e, sid, sdata);
418 pkey = ENGINE_load_public_key(e, sid,
NULL, sdata);
449 ENGINE_set_default(e, f);
464 ossl_engine_ctrl_cmd(
int argc,
VALUE *argv,
VALUE self)
482 ossl_engine_cmd_flag_to_name(
int flag)
485 case ENGINE_CMD_FLAG_NUMERIC:
return rb_str_new2(
"NUMERIC");
486 case ENGINE_CMD_FLAG_STRING:
return rb_str_new2(
"STRING");
487 case ENGINE_CMD_FLAG_NO_INPUT:
return rb_str_new2(
"NO_INPUT");
488 case ENGINE_CMD_FLAG_INTERNAL:
return rb_str_new2(
"INTERNAL");
498 ossl_engine_get_cmds(
VALUE self)
501 const ENGINE_CMD_DEFN *defn, *
p;
506 if ((defn = ENGINE_get_cmd_defns(e)) !=
NULL){
507 for (p = defn; p->cmd_num > 0; p++){
511 rb_ary_push(tmp, ossl_engine_cmd_flag_to_name(p->cmd_flags));
524 ossl_engine_inspect(
VALUE self)
540 #define DefEngineConst(x) rb_define_const(cEngine, #x, INT2NUM(ENGINE_##x))
567 DefEngineConst(METHOD_RSA);
568 DefEngineConst(METHOD_DSA);
569 DefEngineConst(METHOD_DH);
570 DefEngineConst(METHOD_RAND);
571 #ifdef ENGINE_METHOD_BN_MOD_EXP
572 DefEngineConst(METHOD_BN_MOD_EXP);
574 #ifdef ENGINE_METHOD_BN_MOD_EXP_CRT
575 DefEngineConst(METHOD_BN_MOD_EXP_CRT);
577 #ifdef ENGINE_METHOD_CIPHERS
578 DefEngineConst(METHOD_CIPHERS);
580 #ifdef ENGINE_METHOD_DIGESTS
581 DefEngineConst(METHOD_DIGESTS);
583 DefEngineConst(METHOD_ALL);
584 DefEngineConst(METHOD_NONE);
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_obj_class(VALUE)
VALUE ossl_pkey_new(EVP_PKEY *pkey)
void rb_undef_method(VALUE klass, const char *name)
VALUE ossl_cipher_new(const EVP_CIPHER *cipher)
#define OSSL_PKEY_SET_PRIVATE(obj)
int rb_block_given_p(void)
#define StringValuePtr(v)
VALUE ossl_digest_new(const EVP_MD *md)
VALUE rb_str_cat2(VALUE, const char *)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
const char * rb_class2name(VALUE)
RUBY_EXTERN VALUE rb_cObject
void ossl_raise(VALUE exc, const char *fmt,...)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
void rb_warning(const char *fmt,...)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)