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)); \ 41 #define OSSL_ENGINE_LOAD_IF_MATCH(x) \ 43 if(!strcmp(#x, RSTRING_PTR(name))){\ 52 #if !defined(HAVE_ENGINE_LOAD_BUILTIN_ENGINES) 59 ENGINE_load_builtin_engines();
63 #ifndef OPENSSL_NO_STATIC_ENGINE 64 #if HAVE_ENGINE_LOAD_DYNAMIC 65 OSSL_ENGINE_LOAD_IF_MATCH(dynamic);
67 #if HAVE_ENGINE_LOAD_4758CCA 68 OSSL_ENGINE_LOAD_IF_MATCH(4758cca);
70 #if HAVE_ENGINE_LOAD_AEP 71 OSSL_ENGINE_LOAD_IF_MATCH(aep);
73 #if HAVE_ENGINE_LOAD_ATALLA 74 OSSL_ENGINE_LOAD_IF_MATCH(atalla);
76 #if HAVE_ENGINE_LOAD_CHIL 77 OSSL_ENGINE_LOAD_IF_MATCH(chil);
79 #if HAVE_ENGINE_LOAD_CSWIFT 80 OSSL_ENGINE_LOAD_IF_MATCH(cswift);
82 #if HAVE_ENGINE_LOAD_NURON 83 OSSL_ENGINE_LOAD_IF_MATCH(nuron);
85 #if HAVE_ENGINE_LOAD_SUREWARE 86 OSSL_ENGINE_LOAD_IF_MATCH(sureware);
88 #if HAVE_ENGINE_LOAD_UBSEC 89 OSSL_ENGINE_LOAD_IF_MATCH(ubsec);
91 #if HAVE_ENGINE_LOAD_PADLOCK 92 OSSL_ENGINE_LOAD_IF_MATCH(padlock);
94 #if HAVE_ENGINE_LOAD_CAPI 95 OSSL_ENGINE_LOAD_IF_MATCH(capi);
97 #if HAVE_ENGINE_LOAD_GMP 98 OSSL_ENGINE_LOAD_IF_MATCH(gmp);
100 #if HAVE_ENGINE_LOAD_GOST 101 OSSL_ENGINE_LOAD_IF_MATCH(gost);
103 #if HAVE_ENGINE_LOAD_CRYPTODEV 104 OSSL_ENGINE_LOAD_IF_MATCH(cryptodev);
106 #if HAVE_ENGINE_LOAD_AESNI 107 OSSL_ENGINE_LOAD_IF_MATCH(aesni);
110 #ifdef HAVE_ENGINE_LOAD_OPENBSD_DEV_CRYPTO 111 OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
113 OSSL_ENGINE_LOAD_IF_MATCH(openssl);
120 ossl_engine_s_cleanup(
VALUE self)
122 #if defined(HAVE_ENGINE_CLEANUP) 129 ossl_engine_s_engines(
VALUE klass)
135 for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
140 WrapEngine(klass, obj, e);
154 ossl_engine_s_load(1, &
id, klass);
157 WrapEngine(klass, obj, e);
161 ENGINE_ctrl(e, ENGINE_CTRL_SET_PASSWORD_CALLBACK,
169 ossl_engine_s_alloc(
VALUE klass)
174 if (!(e = ENGINE_new())) {
177 WrapEngine(klass, obj, e);
183 ossl_engine_get_id(
VALUE self)
191 ossl_engine_get_name(
VALUE self)
199 ossl_engine_finish(
VALUE self)
209 #if defined(HAVE_ENGINE_GET_CIPHER) 214 const EVP_CIPHER *ciph, *tmp;
219 tmp = EVP_get_cipherbyname(s);
221 nid = EVP_CIPHER_nid(tmp);
223 ciph = ENGINE_get_cipher(e, nid);
229 #define ossl_engine_get_cipher rb_f_notimplement 232 #if defined(HAVE_ENGINE_GET_DIGEST) 237 const EVP_MD *md, *tmp;
242 tmp = EVP_get_digestbyname(s);
244 nid = EVP_MD_nid(tmp);
246 md = ENGINE_get_digest(e, nid);
252 #define ossl_engine_get_digest rb_f_notimplement 267 #if OPENSSL_VERSION_NUMBER < 0x00907000L 268 pkey = ENGINE_load_private_key(e, sid, sdata);
270 pkey = ENGINE_load_private_key(e, sid,
NULL, sdata);
291 #if OPENSSL_VERSION_NUMBER < 0x00907000L 292 pkey = ENGINE_load_public_key(e, sid, sdata);
294 pkey = ENGINE_load_public_key(e, sid,
NULL, sdata);
302 ossl_engine_set_default(
VALUE self,
VALUE flag)
308 ENGINE_set_default(e,
f);
332 ossl_engine_cmd_flag_to_name(
int flag)
335 case ENGINE_CMD_FLAG_NUMERIC:
return rb_str_new2(
"NUMERIC");
336 case ENGINE_CMD_FLAG_STRING:
return rb_str_new2(
"STRING");
337 case ENGINE_CMD_FLAG_NO_INPUT:
return rb_str_new2(
"NO_INPUT");
338 case ENGINE_CMD_FLAG_INTERNAL:
return rb_str_new2(
"INTERNAL");
344 ossl_engine_get_cmds(
VALUE self)
347 const ENGINE_CMD_DEFN *defn, *
p;
352 if ((defn = ENGINE_get_cmd_defns(e)) !=
NULL){
353 for (
p = defn;
p->cmd_num > 0;
p++){
357 rb_ary_push(tmp, ossl_engine_cmd_flag_to_name(
p->cmd_flags));
366 ossl_engine_inspect(
VALUE self)
372 rb_obj_class(
self), ENGINE_get_id(e), ENGINE_get_name(e));
375 #define DefEngineConst(x) rb_define_const(cEngine, #x, INT2NUM(ENGINE_##x)) 402 DefEngineConst(METHOD_RSA);
403 DefEngineConst(METHOD_DSA);
404 DefEngineConst(METHOD_DH);
405 DefEngineConst(METHOD_RAND);
406 #ifdef ENGINE_METHOD_BN_MOD_EXP 407 DefEngineConst(METHOD_BN_MOD_EXP);
409 #ifdef ENGINE_METHOD_BN_MOD_EXP_CRT 410 DefEngineConst(METHOD_BN_MOD_EXP_CRT);
412 #ifdef ENGINE_METHOD_CIPHERS 413 DefEngineConst(METHOD_CIPHERS);
415 #ifdef ENGINE_METHOD_DIGESTS 416 DefEngineConst(METHOD_DIGESTS);
418 DefEngineConst(METHOD_ALL);
419 DefEngineConst(METHOD_NONE);
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
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.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
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)
RUBY_EXTERN VALUE rb_cObject
VALUE ossl_digest_new(const EVP_MD *md)
VALUE rb_sprintf(const char *format,...)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void ossl_raise(VALUE exc, const char *fmt,...)
#define StringValuePtr(v)
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)
VALUE rb_str_new2(const char *)
VALUE rb_obj_class(VALUE)