• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ RSA_generate_key_ex函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中RSA_generate_key_ex函数的典型用法代码示例。如果您正苦于以下问题:C++ RSA_generate_key_ex函数的具体用法?C++ RSA_generate_key_ex怎么用?C++ RSA_generate_key_ex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RSA_generate_key_ex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: _pRSA

RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent):
	_pRSA(0)
{
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
	_pRSA = RSA_new();
	int ret = 0;
	BIGNUM* bn = 0;
	try
	{
		bn = BN_new();
		BN_set_word(bn, exponent);
		ret = RSA_generate_key_ex(_pRSA, keyLength, bn, 0);
		BN_free(bn);
	}
	catch (...)
	{
		BN_free(bn);
		throw;
	}
	if (!ret) throw Poco::InvalidArgumentException("Failed to create RSA context");
#else
	_pRSA = RSA_generate_key(keyLength, exponent, 0, 0);
	if (!_pRSA) throw Poco::InvalidArgumentException("Failed to create RSA context");
#endif
}
开发者ID:JerkWisdom,项目名称:zpublic,代码行数:25,代码来源:RSAKeyImpl.cpp


示例2: main

int main(void) 
{
    BIO*    bio_out;
    RSA*    key_pair            = NULL;
    BIGNUM* public_key_exponent = NULL;

    unsigned char   seed_data[ENTROPY_SIZE];
    
    /* Setup the output */
    bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);

    /* Before generating the keys, the pseudo-random number generator must be seeded */
    obtain_seed_data(seed_data, ENTROPY_SIZE);
    RAND_seed(seed_data, ENTROPY_SIZE);

    BIO_printf(bio_out, "\nGenereating key pair:\n");
    
    /* Generate a 2048-bit key pair with a public exponent of 65537 (RSA_F4) */
    public_key_exponent = BN_new();
    key_pair            = RSA_new();

    BN_set_word(public_key_exponent, RSA_F4);
    RSA_generate_key_ex(key_pair, 2048, public_key_exponent, NULL);

    BIO_printf(bio_out, "-----------------------\n\n");
    
    BIO_printf(bio_out, "Value for the modulus \"n\":\n");
    BN_print(bio_out, key_pair -> n); 
    BIO_printf(bio_out, "\n\n");

    BIO_printf(bio_out, "Value for the distinct prime, \"p\":\n");
    BN_print(bio_out, key_pair -> p);
    BIO_printf(bio_out, "\n\n");

    BIO_printf(bio_out, "Value for the distinct prime, \"q\":\n");
    BN_print(bio_out, key_pair -> q);
    BIO_printf(bio_out, "\n\n");

    BIO_printf(bio_out, "Value for \"dP\":\n");
    BN_print(bio_out, key_pair -> dmp1);
    BIO_printf(bio_out, "\n\n");

    BIO_printf(bio_out, "Value for \"dQ\":\n");
    BN_print(bio_out, key_pair -> dmq1);
    BIO_printf(bio_out, "\n\n");

    BIO_printf(bio_out, "Value for \"qInv\":\n");
    BN_print(bio_out, key_pair -> iqmp);
    BIO_printf(bio_out, "\n\n");

    BIO_printf(bio_out, "Value for the public key exponent \"e\":\n");
    BN_print(bio_out, key_pair -> e);
    BIO_printf(bio_out, "\n\n");

    BIO_printf(bio_out, "Value for the private key exponent \"d\":\n");
    BN_print(bio_out, key_pair -> d);
    BIO_printf(bio_out, "\n\n");

    return 0;
}
开发者ID:akandiah,项目名称:openssl-samples,代码行数:60,代码来源:rsa_keygen.c


示例3: CreatePrivateKey

unsigned char* CreatePrivateKey(size_t* len, size_t* pubLen) {
    //MOD, PUB_EXP, PRIV_EXP
    RSA* msa = RSA_new();
    BIGNUM* e = BN_new();
    BN_set_word(e, 65537);
    RSA_generate_key_ex(msa, 4096, e, 0);
    BN_free(e);
    size_t pubSize = 4+BN_num_bytes(msa->n)+4+BN_num_bytes(msa->e);
    size_t privSize = 4+BN_num_bytes(msa->d);
    unsigned char* retval = (unsigned char*)malloc(pubSize+privSize);
    unsigned char* izard = retval;
    uint32_t count = BN_num_bytes(msa->n);
    memcpy(izard, &count, 4);
    izard+=4;
    BN_bn2bin(msa->n, izard);
    izard+=count;
    count = BN_num_bytes(msa->e);
    memcpy(izard, &count, 4);
    izard+=4;
    BN_bn2bin(msa->e, izard);
    izard+=count;
    count = BN_num_bytes(msa->d);
    memcpy(izard, &count, 4);
    izard+=4;
    BN_bn2bin(msa->d, izard);
    *len = pubSize+privSize;
    *pubLen = pubSize;
    RSA_free(msa);
    return retval;
}
开发者ID:IDWMaster,项目名称:OpenNet,代码行数:30,代码来源:Platform.cpp


示例4: test_bad_key

static int test_bad_key(void) {
  RSA *key = RSA_new();
  BIGNUM e;

  BN_init(&e);
  BN_set_word(&e, RSA_F4);

  if (!RSA_generate_key_ex(key, 512, &e, NULL)) {
    fprintf(stderr, "RSA_generate_key_ex failed.\n");
    ERR_print_errors_fp(stderr);
    return 0;
  }

  if (!BN_add(key->p, key->p, BN_value_one())) {
    fprintf(stderr, "BN error.\n");
    ERR_print_errors_fp(stderr);
    return 0;
  }

  if (RSA_check_key(key)) {
    fprintf(stderr, "RSA_check_key passed with invalid key!\n");
    return 0;
  }

  ERR_clear_error();
  BN_free(&e);
  RSA_free(key);
  return 1;
}
开发者ID:project-zerus,项目名称:boringssl,代码行数:29,代码来源:rsa_test.c


示例5: Zeroize

/* Zeroize
*/
static int Zeroize()
    {
    RSA *key;
    BIGNUM *bn;
    unsigned char userkey[16] = 
	{ 0x48, 0x50, 0xf0, 0xa3, 0x3a, 0xed, 0xd3, 0xaf, 0x6e, 0x47, 0x7f, 0x83, 0x02, 0xb1, 0x09, 0x68 };
    int i, n;

    key = FIPS_rsa_new();
    bn = BN_new();
    if (!key || !bn)
	return 0;
    BN_set_word(bn, 65537);
    if (!RSA_generate_key_ex(key, 1024,bn,NULL))
	return 0;
    BN_free(bn);
    
    n = BN_num_bytes(key->d);
    printf(" Generated %d byte RSA private key\n", n);
    printf("\tBN key before overwriting:\n");
    do_bn_print(stdout, key->d);
    BN_rand(key->d,n*8,-1,0);
    printf("\tBN key after overwriting:\n");
    do_bn_print(stdout, key->d);

    printf("\tchar buffer key before overwriting: \n\t\t");
    for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
        printf("\n");
    RAND_bytes(userkey, sizeof userkey);
    printf("\tchar buffer key after overwriting: \n\t\t");
    for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
        printf("\n");

    return 1;
    }
开发者ID:peterlingoal,项目名称:openssl,代码行数:37,代码来源:fips_test_suite.c


示例6: generate_private_key

static EVP_PKEY * generate_private_key (void)
{
    RSA *rsa = RSA_new();
    BIGNUM *bn = BN_new();
    EVP_PKEY *pkey;

    /*
     * create an RSA keypair and assign them to a PKEY and return it.
     */
    BN_set_word(bn, 0x10001);
    RSA_generate_key_ex(rsa, 1024, bn, NULL);    

    pkey = EVP_PKEY_new();
    if (pkey==NULL) {
        printf("\nError allocating PKEY structure for new key pair\n");
        return NULL;
    }
    if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
        printf("\nError assigning RSA key pair to PKEY structure\n");
        return NULL;
    }        
    
    RSA_free(rsa);
    BN_free(bn);
    
    return (pkey);
}
开发者ID:JamesLinus,项目名称:libest,代码行数:27,代码来源:us898.c


示例7: lws_tls_openssl_rsa_new_key

static int
lws_tls_openssl_rsa_new_key(RSA **rsa, int bits)
{
	BIGNUM *bn = BN_new();
	int n;

	if (!bn)
		return 1;

	if (BN_set_word(bn, RSA_F4) != 1) {
		BN_free(bn);
		return 1;
	}

	*rsa = RSA_new();
	if (!*rsa) {
		BN_free(bn);
		return 1;
	}

	n = RSA_generate_key_ex(*rsa, bits, bn, NULL);
	BN_free(bn);
	if (n == 1)
		return 0;

	RSA_free(*rsa);
	*rsa = NULL;

	return 1;
}
开发者ID:PKRoma,项目名称:libwebsockets,代码行数:30,代码来源:openssl-server.c


示例8: pkey_rsa_keygen

static int pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
	{
	RSA *rsa = NULL;
	RSA_PKEY_CTX *rctx = ctx->data;
	BN_GENCB *pcb, cb;
	int ret;
	if (!rctx->pub_exp)
		{
		rctx->pub_exp = BN_new();
		if (!rctx->pub_exp || !BN_set_word(rctx->pub_exp, RSA_F4))
			return 0;
		}
	rsa = RSA_new();
	if (!rsa)
		return 0;
	if (ctx->pkey_gencb)
		{
		pcb = &cb;
		evp_pkey_set_cb_translate(pcb, ctx);
		}
	else
		pcb = NULL;
	ret = RSA_generate_key_ex(rsa, rctx->nbits, rctx->pub_exp, pcb);
	if (ret > 0)
		EVP_PKEY_assign_RSA(pkey, rsa);
	else
		RSA_free(rsa);
	return ret;
	}
开发者ID:piaoasd123,项目名称:ServerTest,代码行数:29,代码来源:rsa_pmeth.c


示例9: void

RSA *RSA_generate_key(int bits, unsigned long e_value,
	     void (*callback)(int,int,void *), void *cb_arg)
	{
	BN_GENCB cb;
	int i;
	RSA *rsa = RSA_new();
	BIGNUM *e = BN_new();

	if(!rsa || !e) goto err;

	/* The problem is when building with 8, 16, or 32 BN_ULONG,
	 * unsigned long can be larger */
	for (i=0; i<(int)sizeof(unsigned long)*8; i++)
		{
		if (e_value & (1UL<<i))
			BN_set_bit(e,i);
		}

	BN_GENCB_set_old(&cb, callback, cb_arg);

	if(RSA_generate_key_ex(rsa, bits, e, &cb)) {
		BN_free(e);
		return rsa;
	}
err:
	if(e) BN_free(e);
	if(rsa) RSA_free(rsa);
	return 0;
	}
开发者ID:MatiasNAmendola,项目名称:AuroraUX-SunOS,代码行数:29,代码来源:rsa_depr.c


示例10: rsa_genkey

static RSA*
rsa_genkey(u32 size)
{
    zassert(size >= DNSSEC_MINIMUM_KEY_SIZE && size <= DNSSEC_MAXIMUM_KEY_SIZE);

    BN_CTX *ctx;
    BIGNUM *e;
    RSA* rsa;

    ctx = BN_CTX_new();

    zassert(ctx != NULL);

    e = BN_new();
    BN_set_word(e, 0x10001);

    zassert(e != NULL);

    rsa = RSA_new();

    zassert(rsa != NULL);

    int err = RSA_generate_key_ex(rsa, size, e, NULL); /* no callback */

    if(err == 0)
    {
        RSA_free(rsa);
        rsa = NULL;
    }

    BN_free(e);
    BN_CTX_free(ctx);

    return rsa;
}
开发者ID:koodaamo,项目名称:yadifa,代码行数:35,代码来源:dnssec_rsa.c


示例11: GenerateRSAKeyPair

		bool GenerateRSAKeyPair(int numBits, std::string& privKey, std::string& pubKey)
		{
			// TODO: add some error checking
			RSA* rsa = RSA_new();
			BIGNUM* bn = BN_new();
			BN_GENCB cb;
			BIO* bio_err = NULL;
			BN_GENCB_set(&cb, genrsa_cb, bio_err);
			BN_set_word(bn, RSA_F4);
			RSA_generate_key_ex(rsa, numBits, bn, &cb);

			BIO* privKeyBuff = BIO_new(BIO_s_mem());
			BIO* pubKeyBuff = BIO_new(BIO_s_mem());
			PEM_write_bio_RSAPrivateKey(privKeyBuff, rsa, 0, 0, 0, 0, 0);
			PEM_write_bio_RSA_PUBKEY(pubKeyBuff, rsa); // RSA_PUBKEY includes some data that RSAPublicKey doesn't have

			char* privKeyData;
			char* pubKeyData;
			auto privKeySize = BIO_get_mem_data(privKeyBuff, &privKeyData);
			auto pubKeySize = BIO_get_mem_data(pubKeyBuff, &pubKeyData);

			privKey = std::string(privKeyData, privKeySize);
			pubKey = std::string(pubKeyData, pubKeySize);
			
			BIO_free_all(privKeyBuff);
			BIO_free_all(pubKeyBuff);
			BN_free(bn);
			RSA_free(rsa);
			return true;
		}
开发者ID:no1dead,项目名称:ElDorito,代码行数:30,代码来源:Cryptography.cpp


示例12: keygen_init

int keygen_init(void)
{
	m_bignumber = BN_new();
	if(!m_bignumber)
	{
		fprintf(stderr, "Failed to init bignumber\n");
		return -1;
	}
	m_rsa=RSA_new();
	if(!m_rsa)
	{
		fprintf(stderr, "Failed to create RSA context\n");
		return -1;
	}
	if(!BN_set_word(m_bignumber, RSA_F4) || !RSA_generate_key_ex(m_rsa,RSA_KEY_BITS,m_bignumber,NULL))
	{
		fprintf(stderr, "Failed to generate RSA key\n");
		return -1;
	}
	m_evpkey=EVP_PKEY_new();
	if(!EVP_PKEY_set1_RSA(m_evpkey, m_rsa))
	{
		fprintf(stderr, "Unable to convert RSA key to EVP key\n");
		return -1;
	}
	m_p8info=EVP_PKEY2PKCS8(m_evpkey);
	if(!m_p8info)
	{
		fprintf(stderr, "Failed to convert EVP to PKCS8\n");
		return -1;
	}
	return 0;
}
开发者ID:Detegr,项目名称:tapi2p,代码行数:33,代码来源:keygen.c


示例13: MakeKey

// Generate a key pair. Caller is responsible for freeing the returned object.
static EVP_PKEY* MakeKey() {
  LOG(LS_INFO) << "Making key pair";
  EVP_PKEY* pkey = EVP_PKEY_new();
#if OPENSSL_VERSION_NUMBER < 0x00908000l
  // Only RSA_generate_key is available. Use that.
  RSA* rsa = RSA_generate_key(KEY_LENGTH, 0x10001, NULL, NULL);
  if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
    EVP_PKEY_free(pkey);
    RSA_free(rsa);
    return NULL;
  }
#else
  // RSA_generate_key is deprecated. Use _ex version.
  BIGNUM* exponent = BN_new();
  RSA* rsa = RSA_new();
  if (!pkey || !exponent || !rsa ||
      !BN_set_word(exponent, 0x10001) ||  // 65537 RSA exponent
      !RSA_generate_key_ex(rsa, KEY_LENGTH, exponent, NULL) ||
      !EVP_PKEY_assign_RSA(pkey, rsa)) {
    EVP_PKEY_free(pkey);
    BN_free(exponent);
    RSA_free(rsa);
    return NULL;
  }
  // ownership of rsa struct was assigned, don't free it.
  BN_free(exponent);
#endif
  LOG(LS_INFO) << "Returning key pair";
  return pkey;
}
开发者ID:Abhi347,项目名称:s3eTxmpp,代码行数:31,代码来源:opensslidentity.cpp


示例14: seed_rng

static RSA *gen_rsa(void) {
  if (!RAND_status())
    seed_rng();
  int ret = 0;
  _Thread_local static int e_init = 0;
  _Thread_local static BIGNUM e;
  RSA *r = NULL;

  if (!e_init) {
    BN_init(&e);
    if (!BN_set_word(&e, 65537)) {
      warnx("BN_set_word");
      goto fail;
    }
    e_init = 1;
  }
  r = RSA_new();
  if (!r) {
    warnx("RSA_new");
    goto fail;
  }
  ret = RSA_generate_key_ex(r, 1024, &e, NULL);
  if (!ret) {
    warnx("RSA_generate_key");
    goto fail;
  }
  return r;
fail:
  if (r) {
    RSA_free(r);
    r = NULL;
  }
  return NULL;
}
开发者ID:epidemics-scepticism,项目名称:searchlol,代码行数:34,代码来源:rsa.c


示例15: genRsaKey

int genRsaKey(const int bits, char * privkey)
{
  BIO * out = BIO_new(BIO_s_mem());
  RSA * rsa = 0;
  BIGNUM * bn = 0;
  int err = 0;
  if (!(rsa = RSA_new())) return -1;
  if (!(bn = BN_new())) return -2;
  if (!(err = BN_set_word(bn,RSA_F4))) {
    BN_free(bn);
    return err;
  }
  if (!(err = RSA_generate_key_ex(rsa,bits,bn,NULL))) {
    BN_free(bn);
    RSA_free(rsa);
    return err;
  }
  if (!(err = PEM_write_bio_RSAPrivateKey(out, rsa, NULL, NULL, 0, NULL, NULL))) {
    BIO_free_all(out);
    BN_free(bn);
    RSA_free(rsa);
    return err;
  }
  if (!(err = BIO_read(out,privkey,bits) <= 0)) {
    BIO_free_all(out);
    BN_free(bn);
    RSA_free(rsa);
    return err;
  }
  return 0;
}
开发者ID:AlexWei2013,项目名称:Webinos-Platform,代码行数:31,代码来源:openssl_wrapper.cpp


示例16: void

RSA *RSA_generate_key(int bits, unsigned long e_value,
                      void (*callback) (int, int, void *), void *cb_arg)
{
    int i;
    BN_GENCB *cb = BN_GENCB_new();
    RSA *rsa = RSA_new();
    BIGNUM *e = BN_new();

    if (cb == NULL || rsa == NULL || e == NULL)
        goto err;

    /*
     * The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long
     * can be larger
     */
    for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
        if (e_value & (1UL << i))
            if (BN_set_bit(e, i) == 0)
                goto err;
    }

    BN_GENCB_set_old(cb, callback, cb_arg);

    if (RSA_generate_key_ex(rsa, bits, e, cb)) {
        BN_free(e);
        BN_GENCB_free(cb);
        return rsa;
    }
 err:
    BN_free(e);
    RSA_free(rsa);
    BN_GENCB_free(cb);
    return 0;
}
开发者ID:Voxer,项目名称:openssl,代码行数:34,代码来源:rsa_depr.c


示例17: tlso_tmp_rsa_cb

static RSA *
tlso_tmp_rsa_cb( SSL *ssl, int is_export, int key_length )
{
	RSA *tmp_rsa;
	/* FIXME:  Pregenerate the key on startup */
	/* FIXME:  Who frees the key? */
#if OPENSSL_VERSION_NUMBER >= 0x00908000
	BIGNUM *bn = BN_new();
	tmp_rsa = NULL;
	if ( bn ) {
		if ( BN_set_word( bn, RSA_F4 )) {
			tmp_rsa = RSA_new();
			if ( tmp_rsa && !RSA_generate_key_ex( tmp_rsa, key_length, bn, NULL )) {
				RSA_free( tmp_rsa );
				tmp_rsa = NULL;
			}
		}
		BN_free( bn );
	}
#else
	tmp_rsa = RSA_generate_key( key_length, RSA_F4, NULL, NULL );
#endif

	if ( !tmp_rsa ) {
		Debug( LDAP_DEBUG_ANY,
			"TLS: Failed to generate temporary %d-bit %s RSA key\n",
			key_length, is_export ? "export" : "domestic", 0 );
	}
	return tmp_rsa;
}
开发者ID:cptaffe,项目名称:openldap,代码行数:30,代码来源:tls_o.c


示例18: make_openssl_rsa_private_key

std::unique_ptr<RSA_PrivateKey>
make_openssl_rsa_private_key(RandomNumberGenerator& rng, size_t rsa_bits)
   {
   if (rsa_bits > INT_MAX)
      throw Internal_Error("rsa_bits overflow");

   secure_vector<uint8_t> seed(BOTAN_SYSTEM_RNG_POLL_REQUEST);
   rng.randomize(seed.data(), seed.size());
   RAND_seed(seed.data(), seed.size());

   std::unique_ptr<BIGNUM, std::function<void (BIGNUM*)>> bn(BN_new(), BN_free);
   if(!bn)
      throw OpenSSL_Error("BN_new");
   if(!BN_set_word(bn.get(), RSA_F4))
      throw OpenSSL_Error("BN_set_word");

   std::unique_ptr<RSA, std::function<void (RSA*)>> rsa(RSA_new(), RSA_free);
   if(!rsa)
      throw OpenSSL_Error("RSA_new");
   if(!RSA_generate_key_ex(rsa.get(), rsa_bits, bn.get(), nullptr))
      throw OpenSSL_Error("RSA_generate_key_ex");

   uint8_t* der = nullptr;
   int bytes = i2d_RSAPrivateKey(rsa.get(), &der);
   if(bytes < 0)
      throw OpenSSL_Error("i2d_RSAPrivateKey");

   const secure_vector<uint8_t> keydata(der, der + bytes);
   memset(der, 0, bytes);
   free(der);
   return std::unique_ptr<Botan::RSA_PrivateKey>
      (new RSA_PrivateKey(AlgorithmIdentifier(), keydata));
   }
开发者ID:fxdupont,项目名称:botan,代码行数:33,代码来源:openssl_rsa.cpp


示例19: generate_rsa_keypair

static int generate_rsa_keypair(EVP_PKEY* pkey, const keymaster_rsa_keygen_params_t* rsa_params) {
    Unique_BIGNUM bn(BN_new());
    if (bn.get() == NULL) {
        logOpenSSLError("generate_rsa_keypair");
        return -1;
    }

    if (BN_set_word(bn.get(), rsa_params->public_exponent) == 0) {
        logOpenSSLError("generate_rsa_keypair");
        return -1;
    }

    /* initialize RSA */
    Unique_RSA rsa(RSA_new());
    if (rsa.get() == NULL) {
        logOpenSSLError("generate_rsa_keypair");
        return -1;
    }

    if (!RSA_generate_key_ex(rsa.get(), rsa_params->modulus_size, bn.get(), NULL) ||
        RSA_check_key(rsa.get()) < 0) {
        logOpenSSLError("generate_rsa_keypair");
        return -1;
    }

    if (EVP_PKEY_assign_RSA(pkey, rsa.get()) == 0) {
        logOpenSSLError("generate_rsa_keypair");
        return -1;
    }
    release_because_ownership_transferred(rsa);

    return 0;
}
开发者ID:LordNerevar,项目名称:system_security,代码行数:33,代码来源:keymaster_openssl.cpp


示例20: rsa_generate_key

static ERL_NIF_TERM rsa_generate_key(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{/* (ModulusSize, PublicExponent) */
    int modulus_bits;
    BIGNUM *pub_exp, *three;
    RSA *rsa;
    int success;
    ERL_NIF_TERM result;
    BN_GENCB *intr_cb;
#ifndef HAVE_OPAQUE_BN_GENCB
    BN_GENCB intr_cb_buf;
#endif

    if (!enif_get_int(env, argv[0], &modulus_bits) || modulus_bits < 256) {
	return enif_make_badarg(env);
    }

    if (!get_bn_from_bin(env, argv[1], &pub_exp)) {
	return enif_make_badarg(env);
    }

    /* Make sure the public exponent is large enough (at least 3).
     * Without this, RSA_generate_key_ex() can run forever. */
    three = BN_new();
    BN_set_word(three, 3);
    success = BN_cmp(pub_exp, three);
    BN_free(three);
    if (success < 0) {
	BN_free(pub_exp);
	return enif_make_badarg(env);
    }

    /* For large keys, prime generation can take many seconds. Set up
     * the callback which we use to test whether the process has been
     * interrupted. */
#ifdef HAVE_OPAQUE_BN_GENCB
    intr_cb = BN_GENCB_new();
#else
    intr_cb = &intr_cb_buf;
#endif
    BN_GENCB_set(intr_cb, check_erlang_interrupt, env);

    rsa = RSA_new();
    success = RSA_generate_key_ex(rsa, modulus_bits, pub_exp, intr_cb);
    BN_free(pub_exp);

#ifdef HAVE_OPAQUE_BN_GENCB
    BN_GENCB_free(intr_cb);
#endif

    if (!success) {
        RSA_free(rsa);
	return atom_error;
    }

    result = put_rsa_private_key(env, rsa);
    RSA_free(rsa);

    return result;
}
开发者ID:KennethL,项目名称:otp,代码行数:59,代码来源:rsa.c



注:本文中的RSA_generate_key_ex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ RSA_get_ex_data函数代码示例发布时间:2022-05-30
下一篇:
C++ RSA_generate_key函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap