#include <XrdCryptosslRSA.hh>
|
| | XrdCryptosslRSA (const char *pub, int lpub=0) |
| |
| | XrdCryptosslRSA (const XrdCryptosslRSA &r) |
| |
| | XrdCryptosslRSA (EVP_PKEY *key, bool check=1) |
| |
| | XrdCryptosslRSA (int bits=XrdCryptoMinRSABits, int exp=XrdCryptoDefRSAExp) |
| |
| virtual | ~XrdCryptosslRSA () |
| |
| int | DecryptPrivate (const char *in, int lin, char *out, int lout) |
| |
| int | DecryptPublic (const char *in, int lin, char *out, int lout) |
| |
| void | Dump () |
| |
| int | EncryptPrivate (const char *in, int lin, char *out, int lout) |
| |
| int | EncryptPublic (const char *in, int lin, char *out, int lout) |
| |
| int | ExportPrivate (char *out, int lout) |
| |
| int | ExportPublic (char *out, int lout) |
| |
| int | GetOutlen (int lin) |
| |
| int | GetPrilen () |
| |
| int | GetPublen () |
| |
| int | ImportPrivate (const char *in, int lin) |
| |
| int | ImportPublic (const char *in, int lin) |
| |
| XrdCryptoRSAdata | Opaque () |
| |
| | XrdCryptoRSA () |
| |
| virtual | ~XrdCryptoRSA () |
| |
| int | DecryptPrivate (XrdSutBucket &buck) |
| |
| int | DecryptPublic (XrdSutBucket &buck) |
| |
| int | EncryptPrivate (XrdSutBucket &buck) |
| |
| int | EncryptPublic (XrdSutBucket &buck) |
| |
| int | ExportPrivate (XrdOucString &exp) |
| |
| int | ExportPublic (XrdOucString &exp) |
| |
| bool | IsValid () |
| |
| const char * | Status (ERSAStatus t=kInvalid) const |
| |
Definition at line 46 of file XrdCryptosslRSA.hh.
◆ XrdCryptosslRSA() [1/4]
Definition at line 58 of file XrdCryptosslRSA.cc.
64 EPNAME(
"RSA::XrdCryptosslRSA");
76 DEBUG(
"bits: "<<bits<<
", exp: "<<exp);
81 DEBUG(
"cannot allocate new exponent");
87 EVP_PKEY_CTX *pkctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, 0);
88 EVP_PKEY_keygen_init(pkctx);
89 EVP_PKEY_CTX_set_rsa_keygen_bits(pkctx, bits);
90 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
91 EVP_PKEY_CTX_set1_rsa_keygen_pubexp(pkctx, e);
94 EVP_PKEY_CTX_set_rsa_keygen_pubexp(pkctx, e);
96 EVP_PKEY_keygen(pkctx, &fEVP);
97 EVP_PKEY_CTX_free(pkctx);
103 DEBUG(
"basic length: "<<EVP_PKEY_size(fEVP)<<
" bytes");
105 DEBUG(
"WARNING: generated key is invalid");
#define XrdCryptoMinRSABits
#define XrdCryptoDefRSAExp
#define XrdCryptoDefRSABits
static int XrdCheckRSA(EVP_PKEY *pkey)
References DEBUG, EPNAME, XrdCryptoRSA::kComplete, XrdCryptoRSA::status, XrdCheckRSA(), XrdCryptoDefRSABits, XrdCryptoDefRSAExp, and XrdCryptoMinRSABits.
◆ XrdCryptosslRSA() [2/4]
| XrdCryptosslRSA::XrdCryptosslRSA |
( |
const char * |
pub, |
|
|
int |
lpub = 0 |
|
) |
| |
◆ XrdCryptosslRSA() [3/4]
| XrdCryptosslRSA::XrdCryptosslRSA |
( |
EVP_PKEY * |
key, |
|
|
bool |
check = 1 |
|
) |
| |
◆ XrdCryptosslRSA() [4/4]
Definition at line 165 of file XrdCryptosslRSA.cc.
168 EPNAME(
"RSA::XrdCryptosslRSA_copy");
175 DEBUG(
"input key is empty");
180 #if OPENSSL_VERSION_NUMBER >= 0x30000000L
181 BIGNUM *d = BN_new();
183 (EVP_PKEY_get_bn_param(r.fEVP, OSSL_PKEY_PARAM_RSA_D, &d) != 1);
187 RSA_get0_key(EVP_PKEY_get0_RSA(r.fEVP), 0, 0, &d);
188 bool publiconly = (d == 0);
192 BIO *bcpy = BIO_new(BIO_s_mem());
197 ok = (PEM_write_bio_PUBKEY(bcpy, r.fEVP) != 0);
200 ok = (PEM_write_bio_PrivateKey(bcpy,r.fEVP,0,0,0,0,0) != 0);
205 if ((fEVP = PEM_read_bio_PUBKEY(bcpy, 0, 0, 0))) {
209 if ((fEVP = PEM_read_bio_PrivateKey(bcpy,0,0,0))) {
References DEBUG, EPNAME, XrdCryptoRSA::kComplete, XrdCryptoRSA::kPublic, XrdCryptoRSA::status, and XrdCheckRSA().
◆ ~XrdCryptosslRSA()
| XrdCryptosslRSA::~XrdCryptosslRSA |
( |
| ) |
|
|
virtual |
◆ DecryptPrivate()
| int XrdCryptosslRSA::DecryptPrivate |
( |
const char * |
in, |
|
|
int |
lin, |
|
|
char * |
out, |
|
|
int |
lout |
|
) |
| |
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 578 of file XrdCryptosslRSA.cc.
584 EPNAME(
"RSA::DecryptPrivate");
587 if (!in || lin <= 0) {
588 DEBUG(
"input buffer undefined");
593 if (!out || loutmax <= 0) {
594 DEBUG(
"output buffer undefined");
600 size_t lcmax = EVP_PKEY_size(fEVP);
606 EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
607 EVP_PKEY_decrypt_init(ctx);
608 EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
609 while (len > 0 && ke <=
int(loutmax - lout)) {
611 if (EVP_PKEY_decrypt(ctx, (
unsigned char *)&out[ke], &lout,
612 (
unsigned char *)&in[kk], lcmax) <= 0) {
613 EVP_PKEY_CTX_free(ctx);
615 ERR_error_string(ERR_get_error(), serr);
616 DEBUG(
"error: " <<serr);
623 EVP_PKEY_CTX_free(ctx);
624 if (len > 0 && ke >
int(loutmax - lout))
625 PRINT(
"buffer truncated");
References DEBUG, EPNAME, and PRINT.
◆ DecryptPublic()
| int XrdCryptosslRSA::DecryptPublic |
( |
const char * |
in, |
|
|
int |
lin, |
|
|
char * |
out, |
|
|
int |
lout |
|
) |
| |
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 632 of file XrdCryptosslRSA.cc.
638 EPNAME(
"RSA::DecryptPublic");
641 if (!in || lin <= 0) {
642 DEBUG(
"input buffer undefined");
647 if (!out || loutmax <= 0) {
648 DEBUG(
"output buffer undefined");
654 size_t lcmax = EVP_PKEY_size(fEVP);
660 EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
661 EVP_PKEY_verify_recover_init(ctx);
662 EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING);
663 while (len > 0 && ke <=
int(loutmax - lout)) {
665 if (EVP_PKEY_verify_recover(ctx, (
unsigned char *)&out[ke], &lout,
666 (
unsigned char *)&in[kk], lcmax) <= 0) {
667 EVP_PKEY_CTX_free(ctx);
669 ERR_error_string(ERR_get_error(), serr);
670 PRINT(
"error: " <<serr);
677 EVP_PKEY_CTX_free(ctx);
678 if (len > 0 && ke >
int(loutmax - lout))
679 PRINT(
"buffer truncated");
References DEBUG, EPNAME, and PRINT.
◆ Dump()
| void XrdCryptosslRSA::Dump |
( |
| ) |
|
|
virtual |
◆ EncryptPrivate()
| int XrdCryptosslRSA::EncryptPrivate |
( |
const char * |
in, |
|
|
int |
lin, |
|
|
char * |
out, |
|
|
int |
lout |
|
) |
| |
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 468 of file XrdCryptosslRSA.cc.
474 EPNAME(
"RSA::EncryptPrivate");
477 if (!in || lin <= 0) {
478 DEBUG(
"input buffer undefined");
483 if (!out || loutmax <= 0) {
484 DEBUG(
"output buffer undefined");
490 size_t lcmax = EVP_PKEY_size(fEVP) - 11;
496 EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
497 EVP_PKEY_sign_init(ctx);
498 EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING);
499 while (len > 0 && ke <=
int(loutmax - lout)) {
500 size_t lc = (len > lcmax) ? lcmax : len;
502 if (EVP_PKEY_sign(ctx, (
unsigned char *)&out[ke], &lout,
503 (
unsigned char *)&in[kk], lc) <= 0) {
504 EVP_PKEY_CTX_free(ctx);
506 ERR_error_string(ERR_get_error(), serr);
507 DEBUG(
"error: " <<serr);
514 EVP_PKEY_CTX_free(ctx);
515 if (len > 0 && ke >
int(loutmax - lout))
516 DEBUG(
"buffer truncated");
References DEBUG, and EPNAME.
◆ EncryptPublic()
| int XrdCryptosslRSA::EncryptPublic |
( |
const char * |
in, |
|
|
int |
lin, |
|
|
char * |
out, |
|
|
int |
lout |
|
) |
| |
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 523 of file XrdCryptosslRSA.cc.
529 EPNAME(
"RSA::EncryptPublic");
532 if (!in || lin <= 0) {
533 DEBUG(
"input buffer undefined");
538 if (!out || loutmax <= 0) {
539 DEBUG(
"output buffer undefined");
545 size_t lcmax = EVP_PKEY_size(fEVP) - 42;
551 EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(fEVP, 0);
552 EVP_PKEY_encrypt_init(ctx);
553 EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
554 while (len > 0 && ke <=
int(loutmax - lout)) {
555 size_t lc = (len > lcmax) ? lcmax : len;
557 if (EVP_PKEY_encrypt(ctx, (
unsigned char *)&out[ke], &lout,
558 (
unsigned char *)&in[kk], lc) <= 0) {
559 EVP_PKEY_CTX_free(ctx);
561 ERR_error_string(ERR_get_error(), serr);
562 DEBUG(
"error: " <<serr);
569 EVP_PKEY_CTX_free(ctx);
570 if (len > 0 && ke >
int(loutmax - lout))
571 DEBUG(
"buffer truncated");
References DEBUG, and EPNAME.
◆ ExportPrivate()
| int XrdCryptosslRSA::ExportPrivate |
( |
char * |
out, |
|
|
int |
lout |
|
) |
| |
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 423 of file XrdCryptosslRSA.cc.
429 EPNAME(
"RSA::ExportPrivate");
433 DEBUG(
"key not valid");
439 DEBUG(
"output buffer undefined!");
444 BIO *bkey = BIO_new(BIO_s_mem());
447 PEM_write_bio_PrivateKey(bkey,fEVP,0,0,0,0,0);
451 int lbio = (int) BIO_get_mem_data(bkey, &cbio);
452 if (lbio <= 0 || !cbio) {
453 DEBUG(
"problems attaching to BIO content");
458 memcpy(out, cbio, lbio);
461 DEBUG(
"("<<lbio<<
" bytes) "<< std::endl <<out);
References DEBUG, EPNAME, and XrdCryptoRSA::IsValid().
◆ ExportPublic()
| int XrdCryptosslRSA::ExportPublic |
( |
char * |
out, |
|
|
int |
lout |
|
) |
| |
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 360 of file XrdCryptosslRSA.cc.
366 EPNAME(
"RSA::ExportPublic");
370 DEBUG(
"key not valid");
376 DEBUG(
"output buffer undefined!");
381 BIO *bkey = BIO_new(BIO_s_mem());
384 PEM_write_bio_PUBKEY(bkey,fEVP);
388 int lbio = (int) BIO_get_mem_data(bkey, &cbio);
389 if (lbio <= 0 || !cbio) {
390 DEBUG(
"problems attaching to BIO content");
395 memcpy(out, cbio, lbio);
398 DEBUG(
"("<<lbio<<
" bytes) "<< std::endl <<out);
References DEBUG, EPNAME, and XrdCryptoRSA::IsValid().
Referenced by Dump().
◆ GetOutlen()
| int XrdCryptosslRSA::GetOutlen |
( |
int |
lin | ) |
|
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 235 of file XrdCryptosslRSA.cc.
239 int lcmax = EVP_PKEY_size(fEVP) - 42;
241 return ((lin / lcmax) + 1) * EVP_PKEY_size(fEVP);
◆ GetPrilen()
| int XrdCryptosslRSA::GetPrilen |
( |
| ) |
|
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 405 of file XrdCryptosslRSA.cc.
411 BIO *bkey = BIO_new(BIO_s_mem());
413 PEM_write_bio_PrivateKey(bkey,fEVP,0,0,0,0,0);
416 prilen = (int) BIO_get_mem_data(bkey, &cbio);
◆ GetPublen()
| int XrdCryptosslRSA::GetPublen |
( |
| ) |
|
|
virtual |
Reimplemented from XrdCryptoRSA.
Definition at line 343 of file XrdCryptosslRSA.cc.
349 BIO *bkey = BIO_new(BIO_s_mem());
351 PEM_write_bio_PUBKEY(bkey,fEVP);
354 publen = (int) BIO_get_mem_data(bkey, &cbio);
Referenced by Dump().
◆ ImportPrivate()
| int XrdCryptosslRSA::ImportPrivate |
( |
const char * |
in, |
|
|
int |
lin |
|
) |
| |
|
virtual |
◆ ImportPublic()
| int XrdCryptosslRSA::ImportPublic |
( |
const char * |
in, |
|
|
int |
lin |
|
) |
| |
|
virtual |
◆ Opaque()
The documentation for this class was generated from the following files: