12 #if !defined(OPENSSL_NO_RSA) 
   14 #define GetPKeyRSA(obj, pkey) do { \ 
   15     GetPKey((obj), (pkey)); \ 
   16     if (EVP_PKEY_base_id(pkey) != EVP_PKEY_RSA) {  \ 
   17         ossl_raise(rb_eRuntimeError, "THIS IS NOT A RSA!") ; \ 
   20 #define GetRSA(obj, rsa) do { \ 
   22     GetPKeyRSA((obj), _pkey); \ 
   23     (rsa) = EVP_PKEY_get0_RSA(_pkey); \ 
   27 RSA_HAS_PRIVATE(RSA *rsa)
 
   31     RSA_get0_key(rsa, 
NULL, &e, &d);
 
   36 RSA_PRIVATE(
VALUE obj, RSA *rsa)
 
   99             if (EVP_PKEY_base_id(tmp) != EVP_PKEY_RSA)
 
  101                          OBJ_nid2sn(EVP_PKEY_base_id(tmp)));
 
  102             rsa = EVP_PKEY_get1_RSA(tmp);
 
  111             rsa = d2i_RSAPublicKey_bio(in, 
NULL);
 
  119     if (!EVP_PKEY_assign_RSA(
pkey, rsa)) {
 
  128 ossl_rsa_initialize_copy(
VALUE self, 
VALUE other)
 
  134     if (EVP_PKEY_base_id(
pkey) != EVP_PKEY_NONE)
 
  138     rsa_new = ASN1_dup((i2d_of_void *)i2d_RSAPrivateKey, (d2i_of_void *)d2i_RSAPrivateKey, (
char *)rsa);
 
  142     EVP_PKEY_assign_RSA(
pkey, rsa_new);
 
  155 ossl_rsa_is_public(
VALUE self)
 
  174 ossl_rsa_is_private(
VALUE self)
 
  184 can_export_rsaprivatekey(
VALUE self)
 
  187     const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp;
 
  191     RSA_get0_key(rsa, &n, &e, &d);
 
  192     RSA_get0_factors(rsa, &p, &q);
 
  193     RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
 
  195     return n && e && d && p && q && dmp1 && dmq1 && iqmp;
 
  211     if (can_export_rsaprivatekey(
self))
 
  224 ossl_rsa_to_der(
VALUE self)
 
  226     if (can_export_rsaprivatekey(
self))
 
  268     VALUE digest, data, options, kwargs[2], signature;
 
  269     static ID kwargs_ids[2];
 
  271     EVP_PKEY_CTX *pkey_ctx;
 
  272     const EVP_MD *md, *mgf1md;
 
  277     if (!kwargs_ids[0]) {
 
  278         kwargs_ids[0] = rb_intern_const(
"salt_length");
 
  279         kwargs_ids[1] = rb_intern_const(
"mgf1_hash");
 
  292     buf_len = EVP_PKEY_size(
pkey);
 
  301     if (EVP_DigestSignInit(md_ctx, &pkey_ctx, md, 
NULL, 
pkey) != 1)
 
  304     if (EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) != 1)
 
  307     if (EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, salt_len) != 1)
 
  310     if (EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, mgf1md) != 1)
 
  316     if (EVP_DigestSignFinal(md_ctx, (
unsigned char *)
RSTRING_PTR(signature), &buf_len) != 1)
 
  355     VALUE digest, signature, data, options, kwargs[2];
 
  356     static ID kwargs_ids[2];
 
  358     EVP_PKEY_CTX *pkey_ctx;
 
  359     const EVP_MD *md, *mgf1md;
 
  361     int result, salt_len;
 
  363     if (!kwargs_ids[0]) {
 
  364         kwargs_ids[0] = rb_intern_const(
"salt_length");
 
  365         kwargs_ids[1] = rb_intern_const(
"mgf1_hash");
 
  386     if (EVP_DigestVerifyInit(md_ctx, &pkey_ctx, md, 
NULL, 
pkey) != 1)
 
  389     if (EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) != 1)
 
  392     if (EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, salt_len) != 1)
 
  395     if (EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, mgf1md) != 1)
 
  401     result = EVP_DigestVerifyFinal(md_ctx,
 
  434 ossl_rsa_get_params(
VALUE self)
 
  438     const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp;
 
  441     RSA_get0_key(rsa, &n, &e, &d);
 
  442     RSA_get0_factors(rsa, &p, &q);
 
  443     RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
 
  488 #define DefRSAConst(x) rb_define_const(cRSA, #x, INT2NUM(RSA_##x))