10 #if !defined(_OSSL_PKEY_H_) 18 #define OSSL_PKEY_SET_PRIVATE(obj) rb_iv_set((obj), "private", Qtrue) 19 #define OSSL_PKEY_SET_PUBLIC(obj) rb_iv_set((obj), "private", Qfalse) 20 #define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue) 22 #define NewPKey(klass) \ 23 TypedData_Wrap_Struct((klass), &ossl_evp_pkey_type, 0) 24 #define SetPKey(obj, pkey) do { \ 26 rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \ 28 RTYPEDDATA_DATA(obj) = (pkey); \ 29 OSSL_PKEY_SET_PUBLIC(obj); \ 31 #define GetPKey(obj, pkey) do {\ 32 TypedData_Get_Struct((obj), EVP_PKEY, &ossl_evp_pkey_type, (pkey)); \ 34 rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\ 91 #define OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, _name, _get) \ 96 static VALUE ossl_##_keytype##_get_##_name(VALUE self) \ 101 Get##_type(self, obj); \ 105 return ossl_bn_new(bn); \ 108 #define OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \ 109 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a1, \ 110 _type##_get0_##_group(obj, &bn, NULL, NULL)) \ 111 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \ 112 _type##_get0_##_group(obj, NULL, &bn, NULL)) \ 113 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a3, \ 114 _type##_get0_##_group(obj, NULL, NULL, &bn)) 116 #define OSSL_PKEY_BN_DEF_GETTER2(_keytype, _type, _group, a1, a2) \ 117 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a1, \ 118 _type##_get0_##_group(obj, &bn, NULL)) \ 119 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \ 120 _type##_get0_##_group(obj, NULL, &bn)) 122 #define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \ 127 static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2, VALUE v3) \ 130 BIGNUM *bn1 = NULL, *orig_bn1 = NIL_P(v1) ? NULL : GetBNPtr(v1);\ 131 BIGNUM *bn2 = NULL, *orig_bn2 = NIL_P(v2) ? NULL : GetBNPtr(v2);\ 132 BIGNUM *bn3 = NULL, *orig_bn3 = NIL_P(v3) ? NULL : GetBNPtr(v3);\ 134 Get##_type(self, obj); \ 135 if (orig_bn1 && !(bn1 = BN_dup(orig_bn1)) || \ 136 orig_bn2 && !(bn2 = BN_dup(orig_bn2)) || \ 137 orig_bn3 && !(bn3 = BN_dup(orig_bn3))) { \ 138 BN_clear_free(bn1); \ 139 BN_clear_free(bn2); \ 140 BN_clear_free(bn3); \ 141 ossl_raise(eBNError, NULL); \ 144 if (!_type##_set0_##_group(obj, bn1, bn2, bn3)) { \ 145 BN_clear_free(bn1); \ 146 BN_clear_free(bn2); \ 147 BN_clear_free(bn3); \ 148 ossl_raise(ePKeyError, #_type"_set0_"#_group); \ 153 #define OSSL_PKEY_BN_DEF_SETTER2(_keytype, _type, _group, a1, a2) \ 158 static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \ 161 BIGNUM *bn1 = NULL, *orig_bn1 = NIL_P(v1) ? NULL : GetBNPtr(v1);\ 162 BIGNUM *bn2 = NULL, *orig_bn2 = NIL_P(v2) ? NULL : GetBNPtr(v2);\ 164 Get##_type(self, obj); \ 165 if (orig_bn1 && !(bn1 = BN_dup(orig_bn1)) || \ 166 orig_bn2 && !(bn2 = BN_dup(orig_bn2))) { \ 167 BN_clear_free(bn1); \ 168 BN_clear_free(bn2); \ 169 ossl_raise(eBNError, NULL); \ 172 if (!_type##_set0_##_group(obj, bn1, bn2)) { \ 173 BN_clear_free(bn1); \ 174 BN_clear_free(bn2); \ 175 ossl_raise(ePKeyError, #_type"_set0_"#_group); \ 180 #define OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, _name) \ 185 static VALUE ossl_##_keytype##_set_##_name(VALUE self, VALUE bignum) \ 190 rb_warning("#"#_name"= is deprecated; use #set_"#_group); \ 191 Get##_type(self, obj); \ 192 if (NIL_P(bignum)) { \ 193 BN_clear_free(obj->_name); \ 198 bn = GetBNPtr(bignum); \ 199 if (obj->_name == NULL) \ 200 obj->_name = BN_new(); \ 201 if (obj->_name == NULL) \ 202 ossl_raise(eBNError, NULL); \ 203 if (BN_copy(obj->_name, bn) == NULL) \ 204 ossl_raise(eBNError, NULL); \ 208 #if defined(HAVE_OPAQUE_OPENSSL) 209 #define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3) \ 210 OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \ 211 OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) 213 #define OSSL_PKEY_BN_DEF2(_keytype, _type, _group, a1, a2) \ 214 OSSL_PKEY_BN_DEF_GETTER2(_keytype, _type, _group, a1, a2) \ 215 OSSL_PKEY_BN_DEF_SETTER2(_keytype, _type, _group, a1, a2) 217 #define DEF_OSSL_PKEY_BN(class, keytype, name) \ 218 rb_define_method((class), #name, ossl_##keytype##_get_##name, 0) 221 #define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3) \ 222 OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \ 223 OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \ 224 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a1) \ 225 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a2) \ 226 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a3) 228 #define OSSL_PKEY_BN_DEF2(_keytype, _type, _group, a1, a2) \ 229 OSSL_PKEY_BN_DEF_GETTER2(_keytype, _type, _group, a1, a2) \ 230 OSSL_PKEY_BN_DEF_SETTER2(_keytype, _type, _group, a1, a2) \ 231 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a1) \ 232 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a2) 234 #define DEF_OSSL_PKEY_BN(class, keytype, name) do { \ 235 rb_define_method((class), #name, ossl_##keytype##_get_##name, 0);\ 236 rb_define_method((class), #name "=", ossl_##keytype##_set_##name, 1);\
void Init_ossl_pkey(void)
VALUE ossl_dsa_new(EVP_PKEY *)
VALUE ossl_rsa_new(EVP_PKEY *)
VALUE ossl_dh_new(EVP_PKEY *)
const rb_data_type_t ossl_evp_pkey_type
int ossl_generate_cb_2(int p, int n, BN_GENCB *cb)
EVP_PKEY * GetPKeyPtr(VALUE)
EVP_PKEY * GetPrivPKeyPtr(VALUE)
EVP_PKEY * DupPKeyPtr(VALUE)
VALUE ossl_ec_new(EVP_PKEY *)
VALUE ossl_pkey_new(EVP_PKEY *)
void ossl_generate_cb_stop(void *ptr)