本文整理汇总了C++中RSA_PKCS1_SSLeay函数的典型用法代码示例。如果您正苦于以下问题:C++ RSA_PKCS1_SSLeay函数的具体用法?C++ RSA_PKCS1_SSLeay怎么用?C++ RSA_PKCS1_SSLeay使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RSA_PKCS1_SSLeay函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: bind_helper
/* This internal function is used by ENGINE_cswift() and possibly by the
* "dynamic" ENGINE support too */
static int bind_helper(ENGINE *e)
{
#ifndef OPENSSL_NO_RSA
const RSA_METHOD *meth1;
#endif
#ifndef OPENSSL_NO_DH
const DH_METHOD *meth2;
#endif
if(!ENGINE_set_id(e, engine_cswift_id) ||
!ENGINE_set_name(e, engine_cswift_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &cswift_rsa) ||
#endif
#ifndef OPENSSL_NO_DSA
!ENGINE_set_DSA(e, &cswift_dsa) ||
#endif
#ifndef OPENSSL_NO_DH
!ENGINE_set_DH(e, &cswift_dh) ||
#endif
!ENGINE_set_RAND(e, &cswift_random) ||
!ENGINE_set_destroy_function(e, cswift_destroy) ||
!ENGINE_set_init_function(e, cswift_init) ||
!ENGINE_set_finish_function(e, cswift_finish) ||
!ENGINE_set_ctrl_function(e, cswift_ctrl) ||
!ENGINE_set_cmd_defns(e, cswift_cmd_defns))
return 0;
#ifndef OPENSSL_NO_RSA
/* We know that the "PKCS1_SSLeay()" functions hook properly
* to the cswift-specific mod_exp and mod_exp_crt so we use
* those functions. NB: We don't use ENGINE_openssl() or
* anything "more generic" because something like the RSAref
* code may not hook properly, and if you own one of these
* cards then you have the right to do RSA operations on it
* anyway! */
meth1 = RSA_PKCS1_SSLeay();
cswift_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
cswift_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
cswift_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
cswift_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
#endif
#ifndef OPENSSL_NO_DH
/* Much the same for Diffie-Hellman */
meth2 = DH_OpenSSL();
cswift_dh.generate_key = meth2->generate_key;
cswift_dh.compute_key = meth2->compute_key;
#endif
/* Ensure the cswift error handling is set up */
ERR_load_CSWIFT_strings();
return 1;
}
开发者ID:0culus,项目名称:openssl,代码行数:55,代码来源:e_cswift.c
示例2: OPENSSL_malloc
RSA *FIPS_rsa_new(void)
{
RSA *ret;
ret = OPENSSL_malloc(sizeof(RSA));
if (!ret)
return NULL;
memset(ret, 0, sizeof(RSA));
ret->meth = RSA_PKCS1_SSLeay();
if (ret->meth->init)
ret->meth->init(ret);
return ret;
}
开发者ID:alisw,项目名称:alice-openssl,代码行数:12,代码来源:fips_rsa_lib.c
示例3: RSA_PKCS1_SSLeay
const RSA_METHOD *RSA_get_default_method(void)
{
#ifndef OPERA_SMALL_VERSION
if (default_RSA_meth == NULL)
{
#ifdef RSA_NULL
default_RSA_meth=RSA_null_method();
#else
#if 0 /* was: #ifdef RSAref */
default_RSA_meth=RSA_PKCS1_RSAref();
#else
default_RSA_meth=RSA_PKCS1_SSLeay();
#endif
#endif
}
return default_RSA_meth;
#else
return RSA_PKCS1_SSLeay();
#endif
}
开发者ID:prestocore,项目名称:browser,代码行数:21,代码来源:rsa_lib.c
示例4:
const RSA_METHOD *RSA_get_default_method(void)
{
if (default_RSA_meth == NULL)
{
#ifdef RSA_NULL
default_RSA_meth=RSA_null_method();
#else
default_RSA_meth=RSA_PKCS1_SSLeay();
#endif
}
return default_RSA_meth;
}
开发者ID:benwh4,项目名称:libressl,代码行数:13,代码来源:rsa_lib.c
示例5: capi_init
static int capi_init(ENGINE *e)
{
CAPI_CTX *ctx;
const RSA_METHOD *ossl_rsa_meth;
const DSA_METHOD *ossl_dsa_meth;
capi_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL, 0);
cert_capi_idx = X509_get_ex_new_index(0, NULL, NULL, NULL, 0);
ctx = capi_ctx_new();
if (!ctx || (capi_idx < 0))
goto memerr;
ENGINE_set_ex_data(e, capi_idx, ctx);
/* Setup RSA_METHOD */
rsa_capi_idx = RSA_get_ex_new_index(0, NULL, NULL, NULL, 0);
ossl_rsa_meth = RSA_PKCS1_SSLeay();
capi_rsa_method.rsa_pub_enc = ossl_rsa_meth->rsa_pub_enc;
capi_rsa_method.rsa_pub_dec = ossl_rsa_meth->rsa_pub_dec;
capi_rsa_method.rsa_mod_exp = ossl_rsa_meth->rsa_mod_exp;
capi_rsa_method.bn_mod_exp = ossl_rsa_meth->bn_mod_exp;
/* Setup DSA Method */
dsa_capi_idx = DSA_get_ex_new_index(0, NULL, NULL, NULL, 0);
ossl_dsa_meth = DSA_OpenSSL();
capi_dsa_method.dsa_do_verify = ossl_dsa_meth->dsa_do_verify;
capi_dsa_method.dsa_mod_exp = ossl_dsa_meth->dsa_mod_exp;
capi_dsa_method.bn_mod_exp = ossl_dsa_meth->bn_mod_exp;
#ifdef OPENSSL_CAPIENG_DIALOG
{
HMODULE cryptui = LoadLibrary(TEXT("CRYPTUI.DLL"));
HMODULE kernel = GetModuleHandle(TEXT("KERNEL32.DLL"));
if (cryptui)
ctx->certselectdlg = (CERTDLG)GetProcAddress(cryptui, "CryptUIDlgSelectCertificateFromStore");
if (kernel)
ctx->getconswindow = (GETCONSWIN)GetProcAddress(kernel, "GetConsoleWindow");
if (cryptui && !OPENSSL_isservice())
ctx->client_cert_select = cert_select_dialog;
}
#endif
return 1;
memerr:
CAPIerr(CAPI_F_CAPI_INIT, ERR_R_MALLOC_FAILURE);
return 0;
return 1;
}
开发者ID:Groestlcoin,项目名称:foreign,代码行数:50,代码来源:e_capi.c
示例6: ubsec_mod_exp_mont
/*
* This function is aliased to mod_exp (with the mont stuff dropped).
*/
static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx,
BN_MONT_CTX *m_ctx)
{
int ret = 0;
/* Do in software if the key is too large for the hardware. */
if (BN_num_bits(m) > max_key_len) {
const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
ret = (*meth->bn_mod_exp) (r, a, p, m, ctx, m_ctx);
} else {
ret = ubsec_mod_exp(r, a, p, m, ctx);
}
return ret;
}
开发者ID:mwgoldsmith,项目名称:openssl,代码行数:19,代码来源:e_ubsec.c
示例7: RSA_zencod_rsa_mod_exp
static int RSA_zencod_rsa_mod_exp ( BIGNUM *r0, const BIGNUM *i, RSA *rsa )
{
CHEESE () ;
if ( !zencod_dso ) {
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP_CRT, ZENCOD_R_NOT_LOADED);
return 0;
}
if ( !rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp ) {
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP_CRT, ZENCOD_R_BAD_KEY_COMPONENTS);
return 0;
}
/* Do in software if argument is too large for hardware */
if ( RSA_size(rsa) * 8 > ZENBRIDGE_MAX_KEYSIZE_RSA_CRT ) {
const RSA_METHOD *meth;
meth = RSA_PKCS1_SSLeay();
return meth->rsa_mod_exp(r0, i, rsa);
} else {
zen_nb_t y, x, p, q, dmp1, dmq1, iqmp;
if ( !bn_expand(r0, RSA_size(rsa) * 8) ) {
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP_CRT, ZENCOD_R_BN_EXPAND_FAIL);
return 0;
}
r0->top = (RSA_size(rsa) * 8 + BN_BITS2 - 1) / BN_BITS2;
BIGNUM2ZEN ( &x, i ) ;
BIGNUM2ZEN ( &y, r0 ) ;
BIGNUM2ZEN ( &p, rsa->p ) ;
BIGNUM2ZEN ( &q, rsa->q ) ;
BIGNUM2ZEN ( &dmp1, rsa->dmp1 ) ;
BIGNUM2ZEN ( &dmq1, rsa->dmq1 ) ;
BIGNUM2ZEN ( &iqmp, rsa->iqmp ) ;
if ( ptr_zencod_rsa_mod_exp_crt ( &y, &x, &p, &q, &dmp1, &dmq1, &iqmp ) < 0 ) {
PERROR("zenbridge_rsa_mod_exp_crt");
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP_CRT, ZENCOD_R_REQUEST_FAILED);
return 0;
}
return 1;
}
}
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:47,代码来源:hw_zencod.c
示例8: aos_signature_init
int aos_signature_init(struct aos_signature *sign)
{
memset(sign, 0, sizeof(struct aos_signature));
sign->rsa = RSA_new();
if(sign->rsa == NULL)
return 0;
RSA_set_method(sign->rsa, RSA_PKCS1_SSLeay());
sign->rsa->e = BN_new();
if(sign->rsa->e == NULL)
return 0;
BN_set_word(sign->rsa->e, 3);
return 1;
}
开发者ID:kenrestivo,项目名称:aos-tools,代码行数:18,代码来源:crypto.c
示例9: tpm_rsa_pub_dec
static int tpm_rsa_pub_dec(int flen,
const unsigned char *from,
unsigned char *to,
RSA *rsa,
int padding)
{
int rv;
DBG("%s", __FUNCTION__);
if ((rv = RSA_PKCS1_SSLeay()->rsa_pub_dec(flen, from, to, rsa,
padding)) < 0) {
TSSerr(TPM_F_TPM_RSA_PUB_DEC, TPM_R_REQUEST_FAILED);
return 0;
}
return rv;
}
开发者ID:tavlima,项目名称:openssl-tpm-engine,代码行数:18,代码来源:e_tpm.c
示例10: aep_rsa_mod_exp
static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
{
int to_return = 0;
AEP_RV rv = AEP_R_OK;
if (!aep_dso)
{
AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_NOT_LOADED);
goto err;
}
/*See if we have all the necessary bits for a crt*/
if (rsa->q && rsa->dmp1 && rsa->dmq1 && rsa->iqmp)
{
rv = aep_mod_exp_crt(r0,I,rsa->p,rsa->q, rsa->dmp1,rsa->dmq1,rsa->iqmp,ctx);
if (rv == FAIL_TO_SW){
const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
to_return = (*meth->rsa_mod_exp)(r0, I, rsa, ctx);
goto err;
}
else if (rv != AEP_R_OK)
goto err;
}
else
{
if (!rsa->d || !rsa->n)
{
AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_MISSING_KEY_COMPONENTS);
goto err;
}
rv = aep_mod_exp(r0,I,rsa->d,rsa->n,ctx);
if (rv != AEP_R_OK)
goto err;
}
to_return = 1;
err:
return to_return;
}
开发者ID:jiangzhu1212,项目名称:oooii,代码行数:43,代码来源:e_aep.c
示例11: cswift_rsa_mod_exp
static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
{
BN_CTX *ctx;
int to_return = 0;
const RSA_METHOD * def_rsa_method;
/* Try the limits of RSA (2048 bits) */
if(BN_num_bytes(rsa->p) > 128 ||
BN_num_bytes(rsa->q) > 128 ||
BN_num_bytes(rsa->dmp1) > 128 ||
BN_num_bytes(rsa->dmq1) > 128 ||
BN_num_bytes(rsa->iqmp) > 128)
{
#ifdef RSA_NULL
def_rsa_method=RSA_null_method();
#else
#if 0
def_rsa_method=RSA_PKCS1_RSAref();
#else
def_rsa_method=RSA_PKCS1_SSLeay();
#endif
#endif
if(def_rsa_method)
return def_rsa_method->rsa_mod_exp(r0, I, rsa);
}
if((ctx = BN_CTX_new()) == NULL)
goto err;
if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
{
CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS);
goto err;
}
to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
rsa->dmq1, rsa->iqmp, ctx);
err:
if(ctx)
BN_CTX_free(ctx);
return to_return;
}
开发者ID:aosm,项目名称:OpenSSL097,代码行数:40,代码来源:hw_cswift.c
示例12: RSA_zencod_bn_mod_exp
/* This function is aliased to RSA_mod_exp (with the mont stuff dropped).
*/
static int RSA_zencod_bn_mod_exp ( BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx )
{
CHEESE () ;
if ( !zencod_dso ) {
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP, ZENCOD_R_NOT_LOADED);
return 0;
}
/* Do in software if argument is too large for hardware */
if ( BN_num_bits(m) > ZENBRIDGE_MAX_KEYSIZE_RSA ) {
const RSA_METHOD *meth;
meth = RSA_PKCS1_SSLeay();
return meth->bn_mod_exp(r, a, p, m, ctx, m_ctx);
} else {
zen_nb_t y, x, e, n;
if ( !bn_expand(r, BN_num_bits(m)) ) {
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP, ZENCOD_R_BN_EXPAND_FAIL);
return 0;
}
r->top = (BN_num_bits(m) + BN_BITS2 - 1) / BN_BITS2;
BIGNUM2ZEN ( &x, a ) ;
BIGNUM2ZEN ( &y, r ) ;
BIGNUM2ZEN ( &e, p ) ;
BIGNUM2ZEN ( &n, m ) ;
if ( ptr_zencod_rsa_mod_exp ( &y, &x, &n, &e ) < 0 ) {
PERROR("zenbridge_rsa_mod_exp");
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP, ZENCOD_R_REQUEST_FAILED);
return 0;
}
return 1;
}
}
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:42,代码来源:hw_zencod.c
示例13: ubsec_rsa_mod_exp
static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
BN_CTX *ctx)
{
int to_return = 0;
if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) {
UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP, UBSEC_R_MISSING_KEY_COMPONENTS);
goto err;
}
to_return = ubsec_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
rsa->dmq1, rsa->iqmp, ctx);
if (to_return == FAIL_TO_SOFTWARE) {
/*
* Do in software as hardware failed.
*/
const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
to_return = (*meth->rsa_mod_exp) (r0, I, rsa, ctx);
}
err:
return to_return;
}
开发者ID:mwgoldsmith,项目名称:openssl,代码行数:22,代码来源:e_ubsec.c
示例14: cryptodev_rsa_mod_exp
static int
cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
{
struct crypt_kop kop;
int ret = 1;
if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) {
/* XXX 0 means failure?? */
return (0);
}
memset(&kop, 0, sizeof kop);
kop.crk_op = CRK_MOD_EXP_CRT;
/* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */
if (bn2crparam(rsa->p, &kop.crk_param[0]))
goto err;
if (bn2crparam(rsa->q, &kop.crk_param[1]))
goto err;
if (bn2crparam(I, &kop.crk_param[2]))
goto err;
if (bn2crparam(rsa->dmp1, &kop.crk_param[3]))
goto err;
if (bn2crparam(rsa->dmq1, &kop.crk_param[4]))
goto err;
if (bn2crparam(rsa->iqmp, &kop.crk_param[5]))
goto err;
kop.crk_iparams = 6;
if (cryptodev_asym(&kop, BN_num_bytes(rsa->n), r0, 0, NULL) == -1) {
const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
ret = (*meth->rsa_mod_exp)(r0, I, rsa, ctx);
}
err:
zapparams(&kop);
return (ret);
}
开发者ID:repos-holder,项目名称:openbsd-patches,代码行数:36,代码来源:hw_cryptodev.c
示例15: cswift_mod_exp_mont
/* This function is aliased to mod_exp (with the mont stuff dropped). */
static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx,
BN_MONT_CTX *m_ctx)
{
const RSA_METHOD *def_rsa_method;
/* Try the limits of RSA (2048 bits) */
if (BN_num_bytes(r) > 256 ||
BN_num_bytes(a) > 256 || BN_num_bytes(m) > 256) {
# ifdef RSA_NULL
def_rsa_method = RSA_null_method();
# else
# if 0
def_rsa_method = RSA_PKCS1_RSAref();
# else
def_rsa_method = RSA_PKCS1_SSLeay();
# endif
# endif
if (def_rsa_method)
return def_rsa_method->bn_mod_exp(r, a, p, m, ctx, m_ctx);
}
return cswift_mod_exp(r, a, p, m, ctx);
}
开发者ID:119120119,项目名称:node,代码行数:25,代码来源:e_cswift.c
示例16: cryptodev_rsa_nocrt_mod_exp
static int
cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
BN_CTX *ctx)
{
return (RSA_PKCS1_SSLeay()->rsa_mod_exp)(r0, I, rsa, ctx);
}
开发者ID:repos-holder,项目名称:openbsd-patches,代码行数:6,代码来源:hw_cryptodev.c
示例17: ENGINE_load_cryptodev
void
ENGINE_load_cryptodev(void)
{
ENGINE *engine = ENGINE_new();
int fd;
if (engine == NULL)
return;
if ((fd = get_dev_crypto()) < 0) {
ENGINE_free(engine);
return;
}
/*
* find out what asymmetric crypto algorithms we support
*/
if (ioctl(fd, CIOCASYMFEAT, &cryptodev_asymfeat) == -1) {
close(fd);
ENGINE_free(engine);
return;
}
close(fd);
if (!ENGINE_set_id(engine, "cryptodev") ||
!ENGINE_set_name(engine, "BSD cryptodev engine") ||
!ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) ||
!ENGINE_set_digests(engine, cryptodev_engine_digests) ||
!ENGINE_set_ctrl_function(engine, cryptodev_ctrl) ||
!ENGINE_set_cmd_defns(engine, cryptodev_defns)) {
ENGINE_free(engine);
return;
}
if (ENGINE_set_RSA(engine, &cryptodev_rsa)) {
const RSA_METHOD *rsa_meth = RSA_PKCS1_SSLeay();
cryptodev_rsa.bn_mod_exp = rsa_meth->bn_mod_exp;
cryptodev_rsa.rsa_mod_exp = rsa_meth->rsa_mod_exp;
cryptodev_rsa.rsa_pub_enc = rsa_meth->rsa_pub_enc;
cryptodev_rsa.rsa_pub_dec = rsa_meth->rsa_pub_dec;
cryptodev_rsa.rsa_priv_enc = rsa_meth->rsa_priv_enc;
cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec;
if (cryptodev_asymfeat & CRF_MOD_EXP) {
cryptodev_rsa.bn_mod_exp = cryptodev_bn_mod_exp;
if (cryptodev_asymfeat & CRF_MOD_EXP_CRT)
cryptodev_rsa.rsa_mod_exp =
cryptodev_rsa_mod_exp;
else
cryptodev_rsa.rsa_mod_exp =
cryptodev_rsa_nocrt_mod_exp;
}
}
if (ENGINE_set_DSA(engine, &cryptodev_dsa)) {
const DSA_METHOD *meth = DSA_OpenSSL();
memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD));
if (cryptodev_asymfeat & CRF_DSA_SIGN)
cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign;
if (cryptodev_asymfeat & CRF_MOD_EXP) {
cryptodev_dsa.bn_mod_exp = cryptodev_dsa_bn_mod_exp;
cryptodev_dsa.dsa_mod_exp = cryptodev_dsa_dsa_mod_exp;
}
if (cryptodev_asymfeat & CRF_DSA_VERIFY)
cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify;
}
if (ENGINE_set_DH(engine, &cryptodev_dh)){
const DH_METHOD *dh_meth = DH_OpenSSL();
cryptodev_dh.generate_key = dh_meth->generate_key;
cryptodev_dh.compute_key = dh_meth->compute_key;
cryptodev_dh.bn_mod_exp = dh_meth->bn_mod_exp;
if (cryptodev_asymfeat & CRF_MOD_EXP) {
cryptodev_dh.bn_mod_exp = cryptodev_mod_exp_dh;
if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY)
cryptodev_dh.compute_key =
cryptodev_dh_compute_key;
}
}
ENGINE_add(engine);
ENGINE_free(engine);
ERR_clear_error();
}
开发者ID:repos-holder,项目名称:openbsd-patches,代码行数:85,代码来源:hw_cryptodev.c
示例18: westcos_pkcs15init_generate_key
/*
* Generate key
*/
static int westcos_pkcs15init_generate_key(sc_profile_t *profile,
sc_pkcs15_card_t *p15card,
sc_pkcs15_object_t *obj,
sc_pkcs15_pubkey_t *pubkey)
{
#ifndef ENABLE_OPENSSL
return SC_ERROR_NOT_SUPPORTED;
#else
int r = SC_ERROR_UNKNOWN;
long lg;
u8 *p;
sc_pkcs15_prkey_info_t *key_info = (sc_pkcs15_prkey_info_t *) obj->data;
RSA *rsa = NULL;
BIGNUM *bn = NULL;
BIO *mem = NULL;
sc_file_t *prkf = NULL;
if (obj->type != SC_PKCS15_TYPE_PRKEY_RSA) {
return SC_ERROR_NOT_SUPPORTED;
}
#if OPENSSL_VERSION_NUMBER>=0x00908000L
rsa = RSA_new();
bn = BN_new();
mem = BIO_new(BIO_s_mem());
if(rsa == NULL || bn == NULL || mem == NULL)
{
r = SC_ERROR_OUT_OF_MEMORY;
goto out;
}
if(!BN_set_word(bn, RSA_F4) ||
!RSA_generate_key_ex(rsa, key_info->modulus_length, bn, NULL))
#else
mem = BIO_new(BIO_s_mem());
if(mem == NULL)
{
r = SC_ERROR_OUT_OF_MEMORY;
goto out;
}
rsa = RSA_generate_key(key_info->modulus_length, RSA_F4, NULL, NULL);
if (!rsa)
#endif
{
r = SC_ERROR_UNKNOWN;
goto out;
}
rsa->meth = RSA_PKCS1_SSLeay();
if(pubkey != NULL)
{
if(!i2d_RSAPublicKey_bio(mem, rsa))
{
r = SC_ERROR_UNKNOWN;
goto out;
}
lg = BIO_get_mem_data(mem, &p);
pubkey->algorithm = SC_ALGORITHM_RSA;
r = sc_pkcs15_decode_pubkey(p15card->card->ctx, pubkey, p, lg);
}
(void) BIO_reset(mem);
if(!i2d_RSAPrivateKey_bio(mem, rsa))
{
r = SC_ERROR_UNKNOWN;
goto out;
}
lg = BIO_get_mem_data(mem, &p);
/* Get the private key file */
r = sc_profile_get_file_by_path(profile, &key_info->path, &prkf);
if (r < 0)
{
char pbuf[SC_MAX_PATH_STRING_SIZE];
r = sc_path_print(pbuf, sizeof(pbuf), &key_info->path);
if (r != SC_SUCCESS)
pbuf[0] = '\0';
goto out;
}
prkf->size = lg;
r = sc_pkcs15init_create_file(profile, p15card, prkf);
if(r) goto out;
//.........这里部分代码省略.........
开发者ID:exciler,项目名称:OpenSC,代码行数:101,代码来源:pkcs15-westcos.c
示例19: tpm_rsa_pub_enc
static int tpm_rsa_pub_enc(int flen,
const unsigned char *from,
unsigned char *to,
RSA *rsa,
int padding)
{
struct rsa_app_data *app_data = RSA_get_ex_data(rsa, ex_app_data);
TSS_RESULT result;
UINT32 out_len, in_len;
BYTE *out;
int rv;
DBG("%s", __FUNCTION__);
if (!app_data) {
DBG("No app data found for RSA object %p. Calling software.",
rsa);
if ((rv = RSA_PKCS1_SSLeay()->rsa_pub_enc(flen, from, to, rsa,
padding)) < 0) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC, TPM_R_REQUEST_FAILED);
}
return rv;
}
if (app_data->hKey == NULL_HKEY) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC, TPM_R_INVALID_KEY);
return 0;
}
if (app_data->hEncData == NULL_HENCDATA) {
if ((result = Tspi_Context_CreateObject(hContext,
TSS_OBJECT_TYPE_ENCDATA,
TSS_ENCDATA_BIND,
&app_data->hEncData))) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC, TPM_R_REQUEST_FAILED);
return 0;
}
DBG("Setting hEncData(0x%x) in RSA object", app_data->hEncData);
}
DBG("flen is %d", flen);
if (padding == RSA_PKCS1_PADDING) {
if (app_data->encScheme != TSS_ES_RSAESPKCSV15) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC,
TPM_R_INVALID_PADDING_TYPE);
DBG("encScheme(0x%x) in RSA object",
app_data->encScheme);
return 0;
}
if (flen > (RSA_size(rsa) - RSA_PKCS1_PADDING_SIZE)) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC,
RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
return 0;
}
} else if (padding == RSA_PKCS1_OAEP_PADDING) {
if (app_data->encScheme != TSS_ES_RSAESOAEP_SHA1_MGF1) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC,
TPM_R_INVALID_PADDING_TYPE);
DBG("encScheme(0x%x) in RSA object",
app_data->encScheme);
return 0;
}
/* subtract an extra 5 for the TCPA_BOUND_DATA structure */
if (flen > (RSA_size(rsa) - RSA_PKCS1_PADDING_SIZE - 5)) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC,
RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
return 0;
}
} else {
TSSerr(TPM_F_TPM_RSA_PUB_ENC, TPM_R_INVALID_ENC_SCHEME);
return 0;
}
in_len = flen;
DBG("Bind: hKey(0x%x) hEncData(0x%x) in_len(%u)", app_data->hKey,
app_data->hEncData, in_len);
if ((result = Tspi_Data_Bind(app_data->hEncData, app_data->hKey,
in_len, from))) {
TSSerr(TPM_F_TPM_RSA_PUB_ENC, TPM_R_REQUEST_FAILED);
DBG("result = 0x%x (%s)", result,
Trspi_Error_String(result));
return 0;
}
/* pull out the bound data and return it */
if ((result = Tspi_GetAttribData(app_data->hEncData,
TSS_TSPATTRIB_ENCDATA_BLOB,
TSS_TSPATTRIB_ENCDATABLOB_BLOB,
&out_len, &out))) {
TSSerr(TPM_F_TPM_RSA_KEYGEN, TPM_R_REQUEST_FAILED);
return 0;
}
DBG("%s: writing out %d bytes as bound data", __FUNCTION__, out_len);
//.........这里部分代码省略.........
开发者ID:tavlima,项目名称:openssl-tpm-engine,代码行数:101,代码来源:e_tpm.c
示例20: tpm_rsa_priv_dec
static int tpm_rsa_priv_dec(int flen,
const unsigned char *from,
unsigned char *to,
RSA *rsa,
int padding)
{
struct rsa_app_data *app_data = RSA_get_ex_data(rsa, ex_app_data);
TSS_RESULT result;
UINT32 out_len, in_len;
BYTE *out;
int rv;
DBG("%s", __FUNCTION__);
if (!app_data) {
DBG("No app data found for RSA object %p. Calling software.",
rsa);
if ((rv = RSA_PKCS1_SSLeay()->rsa_priv_dec(flen, from, to, rsa,
padding)) < 0) {
TSSerr(TPM_F_TPM_RSA_PRIV_DEC, TPM_R_REQUEST_FAILED);
}
return rv;
}
if (app_data->hKey == NULL_HKEY) {
TSSerr(TPM_F_TPM_RSA_PRIV_DEC, TPM_R_INVALID_KEY);
return 0;
}
if (app_data->hEncData == NULL_HENCDATA) {
if ((result = Tspi_Context_CreateObject(hContext,
TSS_OBJECT_TYPE_ENCDATA,
TSS_ENCDATA_BIND,
&app_data->hEncData))) {
TSSerr(TPM_F_TPM_RSA_PRIV_DEC, TPM_R_REQUEST_FAILED);
return 0;
}
}
if (padding == RSA_PKCS1_PADDING &&
app_data->encScheme != TSS_ES_RSAESPKCSV15) {
TSSerr(TPM_F_TPM_RSA_PRIV_DEC,
TPM_R_INVALID_PADDING_TYPE);
DBG("encScheme(0x%x) in RSA object", app_data->encScheme);
return 0;
} else if (padding == RSA_PKCS1_OAEP_PADDING &&
app_data->encScheme != TSS_ES_RSAESOAEP_SHA1_MGF1) {
TSSerr(TPM_F_TPM_RSA_PRIV_DEC,
TPM_R_INVALID_PADDING_TYPE);
DBG("encScheme(0x%x) in RSA object", app_data->encScheme);
return 0;
}
in_len = flen;
if ((result = Tspi_SetAttribData(app_data->hEncData,
TSS_TSPATTRIB_ENCDATA_BLOB,
TSS_TSPATTRIB_ENCDATABLOB_BLOB,
in_len, from))) {
TSSerr(TPM_F_TPM_RSA_PRIV_DEC, TPM_R_REQUEST_FAILED);
return 0;
}
if ((result = Tspi_Data_Unbind(app_data->hEncData, app_data->hKey,
&out_len, &out))) {
TSSerr(TPM_F_TPM_RSA_PRIV_DEC, TPM_R_REQUEST_FAILED);
return 0;
}
DBG("%s: writing out %d bytes as a signature", __FUNCTION__, out_len);
memcpy(to, out, out_len);
Tspi_Context_FreeMemory(hContext, out);
return out_len;
}
开发者ID:tavlima,项目名称:openssl-tpm-engine,代码行数:76,代码来源:e_tpm.c
注:本文中的RSA_PKCS1_SSLeay函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论