Ruby
2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
|
Go to the documentation of this file.
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!");\
92 #define OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, _name, _get) \
97 static VALUE ossl_##_keytype##_get_##_name(VALUE self) \
102 Get##_type(self, obj); \
106 return ossl_bn_new(bn); \
109 #define OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \
110 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a1, \
111 _type##_get0_##_group(obj, &bn, NULL, NULL)) \
112 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \
113 _type##_get0_##_group(obj, NULL, &bn, NULL)) \
114 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a3, \
115 _type##_get0_##_group(obj, NULL, NULL, &bn))
117 #define OSSL_PKEY_BN_DEF_GETTER2(_keytype, _type, _group, a1, a2) \
118 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a1, \
119 _type##_get0_##_group(obj, &bn, NULL)) \
120 OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \
121 _type##_get0_##_group(obj, NULL, &bn))
123 #define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \
128 static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2, VALUE v3) \
131 BIGNUM *bn1 = NULL, *orig_bn1 = NIL_P(v1) ? NULL : GetBNPtr(v1);\
132 BIGNUM *bn2 = NULL, *orig_bn2 = NIL_P(v2) ? NULL : GetBNPtr(v2);\
133 BIGNUM *bn3 = NULL, *orig_bn3 = NIL_P(v3) ? NULL : GetBNPtr(v3);\
135 Get##_type(self, obj); \
136 if ((orig_bn1 && !(bn1 = BN_dup(orig_bn1))) || \
137 (orig_bn2 && !(bn2 = BN_dup(orig_bn2))) || \
138 (orig_bn3 && !(bn3 = BN_dup(orig_bn3)))) { \
139 BN_clear_free(bn1); \
140 BN_clear_free(bn2); \
141 BN_clear_free(bn3); \
142 ossl_raise(eBNError, NULL); \
145 if (!_type##_set0_##_group(obj, bn1, bn2, bn3)) { \
146 BN_clear_free(bn1); \
147 BN_clear_free(bn2); \
148 BN_clear_free(bn3); \
149 ossl_raise(ePKeyError, #_type"_set0_"#_group); \
154 #define OSSL_PKEY_BN_DEF_SETTER2(_keytype, _type, _group, a1, a2) \
159 static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \
162 BIGNUM *bn1 = NULL, *orig_bn1 = NIL_P(v1) ? NULL : GetBNPtr(v1);\
163 BIGNUM *bn2 = NULL, *orig_bn2 = NIL_P(v2) ? NULL : GetBNPtr(v2);\
165 Get##_type(self, obj); \
166 if ((orig_bn1 && !(bn1 = BN_dup(orig_bn1))) || \
167 (orig_bn2 && !(bn2 = BN_dup(orig_bn2)))) { \
168 BN_clear_free(bn1); \
169 BN_clear_free(bn2); \
170 ossl_raise(eBNError, NULL); \
173 if (!_type##_set0_##_group(obj, bn1, bn2)) { \
174 BN_clear_free(bn1); \
175 BN_clear_free(bn2); \
176 ossl_raise(ePKeyError, #_type"_set0_"#_group); \
181 #define OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, _name) \
186 static VALUE ossl_##_keytype##_set_##_name(VALUE self, VALUE bignum) \
191 rb_warning("#"#_name"= is deprecated; use #set_"#_group); \
192 Get##_type(self, obj); \
193 if (NIL_P(bignum)) { \
194 BN_clear_free(obj->_name); \
199 bn = GetBNPtr(bignum); \
200 if (obj->_name == NULL) \
201 obj->_name = BN_new(); \
202 if (obj->_name == NULL) \
203 ossl_raise(eBNError, NULL); \
204 if (BN_copy(obj->_name, bn) == NULL) \
205 ossl_raise(eBNError, NULL); \
209 #if defined(HAVE_OPAQUE_OPENSSL)
210 #define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3) \
211 OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \
212 OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3)
214 #define OSSL_PKEY_BN_DEF2(_keytype, _type, _group, a1, a2) \
215 OSSL_PKEY_BN_DEF_GETTER2(_keytype, _type, _group, a1, a2) \
216 OSSL_PKEY_BN_DEF_SETTER2(_keytype, _type, _group, a1, a2)
218 #define DEF_OSSL_PKEY_BN(class, keytype, name) \
219 rb_define_method((class), #name, ossl_##keytype##_get_##name, 0)
222 #define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3) \
223 OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \
224 OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \
225 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a1) \
226 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a2) \
227 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a3)
229 #define OSSL_PKEY_BN_DEF2(_keytype, _type, _group, a1, a2) \
230 OSSL_PKEY_BN_DEF_GETTER2(_keytype, _type, _group, a1, a2) \
231 OSSL_PKEY_BN_DEF_SETTER2(_keytype, _type, _group, a1, a2) \
232 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a1) \
233 OSSL_PKEY_BN_DEF_SETTER_OLD(_keytype, _type, _group, a2)
235 #define DEF_OSSL_PKEY_BN(class, keytype, name) do { \
236 rb_define_method((class), #name, ossl_##keytype##_get_##name, 0);\
237 rb_define_method((class), #name "=", ossl_##keytype##_set_##name, 1);\
void ossl_generate_cb_stop(void *ptr)
int ossl_generate_cb_2(int p, int n, BN_GENCB *cb)
EVP_PKEY * GetPKeyPtr(VALUE)
VALUE ossl_pkey_new(EVP_PKEY *)
VALUE ossl_dh_new(EVP_PKEY *)
VALUE ossl_ec_new(EVP_PKEY *)
EVP_PKEY * GetPrivPKeyPtr(VALUE)
VALUE ossl_dsa_new(EVP_PKEY *)
const rb_data_type_t ossl_evp_pkey_type
void ossl_pkey_check_public_key(const EVP_PKEY *)
void Init_ossl_pkey(void)
EVP_PKEY * DupPKeyPtr(VALUE)
VALUE ossl_rsa_new(EVP_PKEY *)