11 #if !defined(OPENSSL_NO_RSA)
15 #define GetPKeyRSA(obj, pkey) do { \
16 GetPKey((obj), (pkey)); \
17 if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_RSA) { \
18 ossl_raise(rb_eRuntimeError, "THIS IS NOT A RSA!") ; \
22 #define RSA_HAS_PRIVATE(rsa) ((rsa)->p && (rsa)->q)
23 #define RSA_PRIVATE(obj,rsa) (RSA_HAS_PRIVATE(rsa)||OSSL_PKEY_IS_PRIVATE(obj))
43 if (!(pkey = EVP_PKEY_new())) {
46 if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
64 if (EVP_PKEY_type(pkey->type) != EVP_PKEY_RSA) {
82 return RSA_generate_key(size, exp,
165 rsa = d2i_RSAPrivateKey_bio(in,
NULL);
169 rsa = d2i_RSA_PUBKEY_bio(in,
NULL);
177 rsa = d2i_RSAPublicKey_bio(in,
NULL);
184 if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
241 const EVP_CIPHER *ciph =
NULL;
243 VALUE cipher, pass, str;
249 if (!
NIL_P(cipher)) {
255 if (!(out = BIO_new(BIO_s_mem()))) {
259 if (!PEM_write_bio_RSAPrivateKey(out, pkey->pkey.rsa, ciph,
265 if (!PEM_write_bio_RSA_PUBKEY(out, pkey->pkey.rsa)) {
285 int (*i2d_func)
_((
const RSA*,
unsigned char**));
292 i2d_func = i2d_RSAPrivateKey;
294 i2d_func = (int (*)(
const RSA*,
unsigned char**))i2d_RSA_PUBKEY;
295 if((len = i2d_func(pkey->pkey.rsa,
NULL)) <= 0)
299 if(i2d_func(pkey->pkey.rsa, &p) < 0)
306 #define ossl_rsa_buf_size(pkey) (RSA_size((pkey)->pkey.rsa)+16)
321 VALUE str, buffer, padding;
325 pad = (argc == 1) ? RSA_PKCS1_PADDING :
NUM2INT(padding);
350 VALUE str, buffer, padding;
354 pad = (argc == 1) ? RSA_PKCS1_PADDING :
NUM2INT(padding);
379 VALUE str, buffer, padding;
386 pad = (argc == 1) ? RSA_PKCS1_PADDING :
NUM2INT(padding);
411 VALUE str, buffer, padding;
418 pad = (argc == 1) ? RSA_PKCS1_PADDING :
NUM2INT(padding);
481 if (!(out = BIO_new(BIO_s_mem()))) {
484 if (!RSA_print(out, pkey->pkey.rsa, 0)) {
508 rsa = RSAPublicKey_dup(pkey->pkey.rsa);
557 #define DefRSAConst(x) rb_define_const(cRSA, #x,INT2FIX(RSA_##x))
static VALUE ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
#define OSSL_PKEY_BN(keytype, name)
#define ossl_str_adjust(str, p)
#define RSTRING_PTR(string)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
#define GetPKey(obj, pkey)
VALUE ossl_rsa_new(EVP_PKEY *pkey)
VALUE ossl_membio2str(BIO *bio)
static VALUE ossl_rsa_to_public_key(VALUE self)
void ossl_generate_cb(int p, int n, void *arg)
#define RSA_HAS_PRIVATE(rsa)
VALUE ossl_to_der_if_possible(VALUE obj)
int rb_block_given_p(void)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
#define ossl_rsa_buf_size(pkey)
static VALUE ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
#define OSSL_BIO_reset(bio)
#define DEF_OSSL_PKEY_BN(class, keytype, name)
static VALUE ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
const EVP_CIPHER * GetCipherPtr(VALUE obj)
static VALUE ossl_rsa_is_private(VALUE self)
static VALUE ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
static VALUE ossl_rsa_is_public(VALUE self)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
#define WrapPKey(klass, obj, pkey)
static VALUE ossl_rsa_to_text(VALUE self)
BIO * ossl_obj2bio(VALUE obj)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define GetPKeyRSA(obj, pkey)
register unsigned int len
static VALUE rsa_instance(VALUE klass, RSA *rsa)
VALUE rb_define_module_under(VALUE outer, const char *name)
static VALUE ossl_rsa_s_generate(int argc, VALUE *argv, VALUE klass)
static VALUE ossl_rsa_to_der(VALUE self)
#define rb_str_set_len(str, length)
#define RSA_PRIVATE(obj, rsa)
static VALUE ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
void ossl_raise(VALUE exc, const char *fmt,...)
static VALUE ossl_rsa_export(int argc, VALUE *argv, VALUE self)
static unsigned int hash(const char *str, unsigned int len)
VALUE ossl_bn_new(const BIGNUM *bn)
#define StringValuePtr(v)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
#define RSTRING_LENINT(str)
VALUE rb_define_module(const char *name)
static RSA * rsa_generate(int size, int exp)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static VALUE ossl_rsa_get_params(VALUE self)
VALUE rb_str_new2(const char *)
VALUE rb_str_new(const char *, long)