- byte_array d(BN_num_bytes(_key->d));
- int ret = BN_bn2bin(_key->d, d.access());
- byte_array p(BN_num_bytes(_key->p));
- ret = BN_bn2bin(_key->p, p.access());
- byte_array q(BN_num_bytes(_key->q));
- ret = BN_bn2bin(_key->q, q.access());
- byte_array dmp1(BN_num_bytes(_key->dmp1));
- ret = BN_bn2bin(_key->dmp1, dmp1.access());
- byte_array dmq1(BN_num_bytes(_key->dmq1));
- ret = BN_bn2bin(_key->dmq1, dmq1.access());
- byte_array iqmp(BN_num_bytes(_key->iqmp));
- ret = BN_bn2bin(_key->iqmp, iqmp.access());
+ //const BIGNUM **the_n = NIL, **the_e = NIL, **the_d = NIL;
+ BIGNUM **the_n = new BIGNUM *, **the_e = new BIGNUM *, **the_d = new BIGNUM *;
+ BIGNUM **the_p = new BIGNUM *, **the_q = new BIGNUM *;
+ BIGNUM **the_dmp1 = new BIGNUM *, **the_dmq1 = new BIGNUM *, **the_iqmp = new BIGNUM *;
+#ifdef NEWER_OPENSSL
+ RSA_get0_key(_key, (const BIGNUM **)the_n, (const BIGNUM **)the_e, (const BIGNUM **)the_d);
+ RSA_get0_factors(_key, (const BIGNUM **)the_p, (const BIGNUM **)the_q);
+ RSA_get0_crt_params(_key, (const BIGNUM **)the_dmp1, (const BIGNUM **)the_dmq1, (const BIGNUM **)the_iqmp);
+#else
+ *the_n = _key->n; *the_e = _key->e; *the_d = _key->d;
+ *the_p = _key->p; *the_q = _key->q;
+ *the_dmp1 = _key->dmp1; *the_dmq1 = _key->dmq1; *the_iqmp = _key->iqmp;
+#endif
+ byte_array d(BN_num_bytes(*the_d));
+ int ret = BN_bn2bin(*the_d, d.access());
+ byte_array p(BN_num_bytes(*the_p));
+ ret = BN_bn2bin(*the_p, p.access());
+ byte_array q(BN_num_bytes(*the_q));
+ ret = BN_bn2bin(*the_q, q.access());
+ byte_array dmp1(BN_num_bytes(*the_dmp1));
+ ret = BN_bn2bin(*the_dmp1, dmp1.access());
+ byte_array dmq1(BN_num_bytes(*the_dmq1));
+ ret = BN_bn2bin(*the_dmq1, dmq1.access());
+ byte_array iqmp(BN_num_bytes(*the_iqmp));
+ ret = BN_bn2bin(*the_iqmp, iqmp.access());