12 #if !defined(OPENSSL_NO_DSA) 14 #define GetPKeyDSA(obj, pkey) do { \ 15 GetPKey((obj), (pkey)); \ 16 if (EVP_PKEY_base_id(pkey) != EVP_PKEY_DSA) { \ 17 ossl_raise(rb_eRuntimeError, "THIS IS NOT A DSA!"); \ 20 #define GetDSA(obj, dsa) do { \ 22 GetPKeyDSA((obj), _pkey); \ 23 (dsa) = EVP_PKEY_get0_DSA(_pkey); \ 27 DSA_HAS_PRIVATE(DSA *dsa)
30 DSA_get0_key(dsa,
NULL, &bn);
35 DSA_PRIVATE(
VALUE obj, DSA *dsa)
50 dsa_instance(
VALUE klass, DSA *dsa)
59 if (!(pkey = EVP_PKEY_new())) {
62 if (!EVP_PKEY_assign_DSA(pkey, dsa)) {
77 obj = dsa_instance(
cDSA, DSA_new());
80 if (EVP_PKEY_base_id(pkey) != EVP_PKEY_DSA) {
105 dsa_blocking_gen(
void *arg)
114 dsa_generate(
int size)
118 DSA *
dsa = DSA_new();
137 if (cb_arg.
yield == 1) {
139 dsa_blocking_gen(&gen_arg);
159 if (!DSA_generate_key(dsa)) {
182 VALUE obj = dsa_instance(klass, dsa);
225 if (!(dsa = dsa_generate(
NUM2INT(arg)))) {
240 dsa = d2i_DSAPrivateKey_bio(in,
NULL);
244 dsa = d2i_DSA_PUBKEY_bio(in,
NULL);
248 #define PEM_read_bio_DSAPublicKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ 249 (d2i_of_void *)d2i_DSAPublicKey, PEM_STRING_DSA_PUBLIC, (bp), (void **)(x), (cb), (u)) 251 #undef PEM_read_bio_DSAPublicKey 259 if (!EVP_PKEY_assign_DSA(pkey, dsa)) {
268 ossl_dsa_initialize_copy(
VALUE self,
VALUE other)
274 if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE)
278 dsa_new = ASN1_dup((i2d_of_void *)i2d_DSAPrivateKey, (d2i_of_void *)d2i_DSAPrivateKey, (
char *)dsa);
282 EVP_PKEY_assign_DSA(pkey, dsa_new);
295 ossl_dsa_is_public(
VALUE self)
301 DSA_get0_key(dsa, &bn,
NULL);
314 ossl_dsa_is_private(
VALUE self)
345 const EVP_CIPHER *ciph =
NULL;
346 VALUE cipher, pass, str;
350 if (!
NIL_P(cipher)) {
354 if (!(out = BIO_new(BIO_s_mem()))) {
357 if (DSA_HAS_PRIVATE(dsa)) {
358 if (!PEM_write_bio_DSAPrivateKey(out, dsa, ciph,
NULL, 0,
364 if (!PEM_write_bio_DSA_PUBKEY(out, dsa)) {
382 ossl_dsa_to_der(
VALUE self)
385 int (*i2d_func)(DSA *,
unsigned char **);
391 if(DSA_HAS_PRIVATE(dsa))
392 i2d_func = (int (*)(DSA *,
unsigned char **))i2d_DSAPrivateKey;
394 i2d_func = i2d_DSA_PUBKEY;
395 if((len = i2d_func(dsa,
NULL)) <= 0)
399 if(i2d_func(dsa, &p) < 0)
416 ossl_dsa_get_params(
VALUE self)
423 DSA_get0_pqg(dsa, &p, &q, &g);
424 DSA_get0_key(dsa, &pub_key, &priv_key);
445 ossl_dsa_to_text(
VALUE self)
452 if (!(out = BIO_new(BIO_s_mem()))) {
455 if (!DSA_print(out, dsa, 0)) {
482 ossl_dsa_to_public_key(
VALUE self)
490 #define DSAPublicKey_dup(dsa) (DSA *)ASN1_dup( \ 491 (i2d_of_void *)i2d_DSAPublicKey, (d2i_of_void *)d2i_DSAPublicKey, (char *)(dsa)) 493 #undef DSAPublicKey_dup 526 unsigned int buf_len;
530 DSA_get0_pqg(dsa,
NULL, &dsa_q,
NULL);
533 if (!DSA_PRIVATE(
self, dsa))
#define DSAPublicKey_dup(dsa)
#define GetPKeyDSA(obj, pkey)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
#define SetPKey(obj, pkey)
#define ossl_str_adjust(str, p)
BIO * ossl_obj2bio(volatile VALUE *pobj)
void rb_str_set_len(VALUE, long)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
#define GetPKey(obj, pkey)
#define OSSL_PKEY_IS_PRIVATE(obj)
VALUE ossl_membio2str(BIO *bio)
#define OSSL_PKEY_BN_DEF2(_keytype, _type, _group, a1, a2)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_generate_cb_stop(void *ptr)
#define PEM_read_bio_DSAPublicKey(bp, x, cb, u)
void ossl_clear_error(void)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
RUBY_EXTERN VALUE rb_cObject
const EVP_CIPHER * ossl_evp_get_cipherbyname(VALUE obj)
#define OSSL_BIO_reset(bio)
#define DEF_OSSL_PKEY_BN(class, keytype, name)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd_)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
int ossl_generate_cb_2(int p, int n, BN_GENCB *cb)
#define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE ossl_pem_passwd_value(VALUE pass)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
VALUE ossl_dsa_new(EVP_PKEY *pkey)
void ossl_raise(VALUE exc, const char *fmt,...)
#define BN_GENCB_free(cb)
VALUE ossl_bn_new(const BIGNUM *bn)
#define RSTRING_LENINT(str)
#define RB_INTEGER_TYPE_P(obj)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new(const char *, long)