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

C++ EC_KEY_set_private_key函数代码示例

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

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



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

示例1: EC_KEY_new

static EC_KEY *pkcs11_get_ec(PKCS11_KEY *key)
{
	EC_KEY *ec;
	int no_params, no_point;

	ec = EC_KEY_new();
	if (ec == NULL)
		return NULL;

	/* For OpenSSL req we need at least the
	 * EC_KEY_get0_group(ec_key)) to return the group.
	 * Continue even if it fails, as the sign operation does not need
	 * it if the PKCS#11 module or the hardware can figure this out
	 */
	no_params = pkcs11_get_params(ec, key);
	no_point = pkcs11_get_point_key(ec, key);
	if (no_point && key->isPrivate) /* Retry with the public key */
		no_point = pkcs11_get_point_key(ec, pkcs11_find_key_from_key(key));
	if (no_point && key->isPrivate) /* Retry with the certificate */
		no_point = pkcs11_get_point_cert(ec, pkcs11_find_certificate(key));

	if (key->isPrivate && EC_KEY_get0_private_key(ec) == NULL) {
		BIGNUM *bn = BN_new();
		EC_KEY_set_private_key(ec, bn);
		BN_free(bn);
	}

	/* A public keys requires both the params and the point to be present */
	if (!key->isPrivate && (no_params || no_point)) {
		EC_KEY_free(ec);
		return NULL;
	}

	return ec;
}
开发者ID:OpenSC,项目名称:libp11,代码行数:35,代码来源:p11_ec.c


示例2: EVP_PKEY_get0

// Setters for the GOST private key components
void OSSLGOSTPrivateKey::setD(const ByteString& d)
{
	GOSTPrivateKey::setD(d);

	EC_KEY* ec = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
	if (ec == NULL)
	{
		ByteString der = dummyKey;
		const unsigned char *p = &der[0];
		if (d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p, (long) der.size()) == NULL)
		{
			ERROR_MSG("d2i_PrivateKey failed");

			return;
		}
		ec = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
	}

	const BIGNUM* priv = OSSL::byteString2bn(d);
	if (EC_KEY_set_private_key(ec, priv) <= 0)
	{
		ERROR_MSG("EC_KEY_set_private_key failed");
		return;
	}

#ifdef notyet
	if (gost2001_compute_public(ec) <= 0)
		ERROR_MSG("gost2001_compute_public failed");
#endif		
}
开发者ID:rene-post,项目名称:SoftHSMv2,代码行数:31,代码来源:OSSLGOSTPrivateKey.cpp


示例3: ecdsa_create_pkey

/*!
 * \brief Create ECDSA private key from key parameters.
 * \see rsa_create_pkey
 */
static int ecdsa_create_pkey(const knot_key_params_t *params, EVP_PKEY *key)
{
	assert(key);

	int curve;
	if (params->algorithm == KNOT_DNSSEC_ALG_ECDSAP256SHA256) {
		curve = NID_X9_62_prime256v1; // == secp256r1
	} else if (params->algorithm == KNOT_DNSSEC_ALG_ECDSAP384SHA384) {
		curve = NID_secp384r1;
	} else {
		return KNOT_DNSSEC_ENOTSUP;
	}

	EC_KEY *ec_key = EC_KEY_new_by_curve_name(curve);
	if (ec_key == NULL)
		return KNOT_ENOMEM;

	EC_KEY_set_private_key(ec_key, knot_b64_to_bignum(params->private_key));

	// EC_KEY_check_key() could be added, but fails without public key

	if (!EVP_PKEY_assign_EC_KEY(key, ec_key)) {
		EC_KEY_free(ec_key);
		return KNOT_DNSSEC_EASSIGN_KEY;
	}

	return KNOT_EOK;
}
开发者ID:stribika,项目名称:curveprotect,代码行数:32,代码来源:dnssec.c


示例4: EC_KEY_new_by_curve_name

static EC_KEY *self_test_ecdsa_key(void) {
  static const uint8_t kQx[] = {
      0xc8, 0x15, 0x61, 0xec, 0xf2, 0xe5, 0x4e, 0xde, 0xfe, 0x66, 0x17,
      0xdb, 0x1c, 0x7a, 0x34, 0xa7, 0x07, 0x44, 0xdd, 0xb2, 0x61, 0xf2,
      0x69, 0xb8, 0x3d, 0xac, 0xfc, 0xd2, 0xad, 0xe5, 0xa6, 0x81,
  };
  static const uint8_t kQy[] = {
      0xe0, 0xe2, 0xaf, 0xa3, 0xf9, 0xb6, 0xab, 0xe4, 0xc6, 0x98, 0xef,
      0x64, 0x95, 0xf1, 0xbe, 0x49, 0xa3, 0x19, 0x6c, 0x50, 0x56, 0xac,
      0xb3, 0x76, 0x3f, 0xe4, 0x50, 0x7e, 0xec, 0x59, 0x6e, 0x88,
  };
  static const uint8_t kD[] = {
      0xc6, 0xc1, 0xaa, 0xda, 0x15, 0xb0, 0x76, 0x61, 0xf8, 0x14, 0x2c,
      0x6c, 0xaf, 0x0f, 0xdb, 0x24, 0x1a, 0xff, 0x2e, 0xfe, 0x46, 0xc0,
      0x93, 0x8b, 0x74, 0xf2, 0xbc, 0xc5, 0x30, 0x52, 0xb0, 0x77,
  };

  EC_KEY *ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
  BIGNUM *qx = BN_bin2bn(kQx, sizeof(kQx), NULL);
  BIGNUM *qy = BN_bin2bn(kQy, sizeof(kQy), NULL);
  BIGNUM *d = BN_bin2bn(kD, sizeof(kD), NULL);
  if (ec_key == NULL || qx == NULL || qy == NULL || d == NULL ||
      !EC_KEY_set_public_key_affine_coordinates(ec_key, qx, qy) ||
      !EC_KEY_set_private_key(ec_key, d)) {
    EC_KEY_free(ec_key);
    ec_key = NULL;
  }

  BN_free(qx);
  BN_free(qy);
  BN_free(d);
  return ec_key;
}
开发者ID:linux-on-ibm-z,项目名称:boringssl,代码行数:33,代码来源:self_check.c


示例5: EVP_PKEY_get0

// Setters for the GOST private key components
void OSSLGOSTPrivateKey::setD(const ByteString& inD)
{
	GOSTPrivateKey::setD(inD);

	EC_KEY* inEC = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
	if (inEC == NULL)
	{
		const unsigned char* p = dummyKey;
		if (d2i_PrivateKey(NID_id_GostR3410_2001, &pkey, &p, (long) sizeof(dummyKey)) == NULL)
		{
			ERROR_MSG("d2i_PrivateKey failed");

			return;
		}
		inEC = (EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
	}

	const BIGNUM* priv = OSSL::byteString2bn(inD);
	if (EC_KEY_set_private_key(inEC, priv) <= 0)
	{
		ERROR_MSG("EC_KEY_set_private_key failed");
		return;
	}
	BN_clear_free((BIGNUM*)priv);

#ifdef notyet
	if (gost2001_compute_public(inEC) <= 0)
		ERROR_MSG("gost2001_compute_public failed");
#endif
}
开发者ID:bzero,项目名称:SoftHSMv2,代码行数:31,代码来源:OSSLGOSTPrivateKey.cpp


示例6: key_regenerate

static int key_regenerate(struct key *k, const BIGNUM *bn) {
  const EC_GROUP *grp;
  EC_KEY *key = k->key;
  EC_POINT *pub_key;
  BN_CTX *ctx;
  int res;

  ASSERT(key);

  grp = EC_KEY_get0_group(key);
  ctx = BN_CTX_new();

  ASSERT(grp);
  ASSERT(ctx);

  pub_key = EC_POINT_new(grp);
  ASSERT(pub_key);

  res = EC_POINT_mul(grp, pub_key, bn, NULL, NULL, ctx);
  ASSERT(res == 1);

  res = EC_KEY_set_private_key(key, bn);
  ASSERT(res == 1);

  res = EC_KEY_set_public_key(key, pub_key);
  ASSERT(res == 1);

  EC_POINT_free(pub_key);
  BN_CTX_free(ctx);

  return EC_KEY_check_key(k->key);
}
开发者ID:jma127,项目名称:bitc-rpc,代码行数:32,代码来源:key.c


示例7: EC_KEY_new_by_curve_name

static EC_KEY *mk_eckey(int nid, const unsigned char *p, size_t plen)
{
    int ok = 0;
    EC_KEY *k = NULL;
    BIGNUM *priv = NULL;
    EC_POINT *pub = NULL;
    const EC_GROUP *grp;
    k = EC_KEY_new_by_curve_name(nid);
    if (!k)
        goto err;
    priv = BN_bin2bn(p, plen, NULL);
    if (!priv)
        goto err;
    if (!EC_KEY_set_private_key(k, priv))
        goto err;
    grp = EC_KEY_get0_group(k);
    pub = EC_POINT_new(grp);
    if (!pub)
        goto err;
    if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL))
        goto err;
    if (!EC_KEY_set_public_key(k, pub))
        goto err;
    ok = 1;
 err:
    if (priv)
        BN_clear_free(priv);
    if (pub)
        EC_POINT_free(pub);
    if (ok)
        return k;
    else if (k)
        EC_KEY_free(k);
    return NULL;
}
开发者ID:derekmarcotte,项目名称:freebsd,代码行数:35,代码来源:ecdhtest.c


示例8: EC_KEY_new_by_curve_name

static EC_KEY *mk_eckey(int nid, const char *str)
{
    int ok = 0;
    EC_KEY *k = NULL;
    BIGNUM *priv = NULL;
    EC_POINT *pub = NULL;
    const EC_GROUP *grp;
    k = EC_KEY_new_by_curve_name(nid);
    if (!k)
        goto err;
    if(!BN_hex2bn(&priv, str))
        goto err;
    if (!priv)
        goto err;
    if (!EC_KEY_set_private_key(k, priv))
        goto err;
    grp = EC_KEY_get0_group(k);
    pub = EC_POINT_new(grp);
    if (!pub)
        goto err;
    if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL))
        goto err;
    if (!EC_KEY_set_public_key(k, pub))
        goto err;
    ok = 1;
 err:
    BN_clear_free(priv);
    EC_POINT_free(pub);
    if (ok)
        return k;
    EC_KEY_free(k);
    return NULL;
}
开发者ID:Voxer,项目名称:openssl,代码行数:33,代码来源:ecdhtest.c


示例9: EC_KEY_regenerate_key

		// Generate a private key from just the secret parameter
		bool EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
		{
			bool success = false;
			BN_CTX *ctx = nullptr;
			EC_POINT *pub_key = nullptr;

			if (!eckey)
				return 0;

			const EC_GROUP *group = EC_KEY_get0_group(eckey);

			ctx = BN_CTX_new();
			if (!ctx)
				goto error;

			pub_key = EC_POINT_new(group);
			if (!pub_key)
				goto error;

			if (!EC_POINT_mul(group, pub_key, priv_key, nullptr, nullptr, ctx))
				goto error;

			EC_KEY_set_private_key(eckey, priv_key);
			EC_KEY_set_public_key(eckey, pub_key);

			success = true;

		error:
			if (pub_key)
				EC_POINT_free(pub_key);
			if (ctx)
				BN_CTX_free(ctx);

			return success;
		}
开发者ID:ballisticwhisper,项目名称:decentralised,代码行数:36,代码来源:elliptic_curve_key.cpp


示例10: gost_set_priv_key

static int gost_set_priv_key(EVP_PKEY *pkey,BIGNUM *priv) 
	{
	switch (EVP_PKEY_base_id(pkey)) 
		{
		case NID_id_GostR3410_94:
		{
		DSA *dsa = EVP_PKEY_get0(pkey);
		if (!dsa) 
			{
			dsa = DSA_new();
			EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),dsa);
			}	
		dsa->priv_key = BN_dup(priv);
		if (!EVP_PKEY_missing_parameters(pkey)) 
			gost94_compute_public(dsa);
		break;
		}	
		case NID_id_GostR3410_2001:
		{
		EC_KEY *ec = EVP_PKEY_get0(pkey);
		if (!ec) 
			{
			ec = EC_KEY_new();
			EVP_PKEY_assign(pkey,EVP_PKEY_base_id(pkey),ec);
			}	
		if (!EC_KEY_set_private_key(ec,priv)) return 0;
		if (!EVP_PKEY_missing_parameters(pkey)) 
			gost2001_compute_public(ec);
		break;
		}
		}
	return 1;		
	}
开发者ID:0culus,项目名称:openssl,代码行数:33,代码来源:gost_ameth.c


示例11: EC_KEY_regenerate_key

// Generate a private key from just the secret parameter
int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
{
    int ok = 0;
    BN_CTX *ctx = NULL;
    EC_POINT *pub_key = NULL;

    if (!eckey) return 0;

    const EC_GROUP *group = EC_KEY_get0_group(eckey);

    if ((ctx = BN_CTX_new()) == NULL)
        goto err;

    pub_key = EC_POINT_new(group);

    if (pub_key == NULL)
        goto err;

    if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
        goto err;

    EC_KEY_set_private_key(eckey,priv_key);
    EC_KEY_set_public_key(eckey,pub_key);

    ok = 1;

err:

    if (pub_key)
        EC_POINT_free(pub_key);
    if (ctx != NULL)
        BN_CTX_free(ctx);

    return(ok);
}
开发者ID:uscoin,项目名称:uscoin,代码行数:36,代码来源:key.cpp


示例12: gost2001_keygen

/*
 *
 * Generates GOST R 34.10-2001 keypair
 *
 *
 */
int gost2001_keygen(EC_KEY *ec)
{
    BIGNUM *order = BN_new(), *d = BN_new();
    const EC_GROUP *group = EC_KEY_get0_group(ec);

    if (!group || !EC_GROUP_get_order(group, order, NULL)) {
        GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);
        BN_free(d);
        BN_free(order);
        return 0;
    }

    do {
        if (!BN_rand_range(d, order)) {
            GOSTerr(GOST_F_GOST2001_KEYGEN,
                    GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
            BN_free(d);
            BN_free(order);
            return 0;
        }
    }
    while (BN_is_zero(d));

    if (!EC_KEY_set_private_key(ec, d)) {
        GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);
        BN_free(d);
        BN_free(order);
        return 0;
    }
    BN_free(d);
    BN_free(order);
    return gost2001_compute_public(ec);
}
开发者ID:375670450,项目名称:openssl,代码行数:39,代码来源:gost2001.c


示例13: EC_KEY_new_by_curve_name

/* Interpret the 256 bits in buf as a private key and return an EC_KEY *. */
static EC_KEY *generate_key_from_buffer(const unsigned char buf[32])
{
    EC_KEY *key;
    BIGNUM *bn;
    int rc;

    key = NULL;
    bn = NULL;

    key = EC_KEY_new_by_curve_name(EC_GROUP_NID);
    if (key == NULL)
        goto err;

    bn = BN_bin2bn(buf, 32, NULL);
    if (bn == NULL)
        goto err;

    rc = EC_KEY_set_private_key(key, bn);
    if (rc != 1)
        goto err;

    BN_free(bn);

    return key;

err:
    if (key != NULL)
        EC_KEY_free(key);
    if (bn != NULL)
        BN_free(bn);
    return NULL;
}
开发者ID:sophiecooper,项目名称:mini-Bitcoin,代码行数:33,代码来源:genkey.c


示例14: EC_KEY_set_private_key

// Setters for the EC private key components
void OSSLECPrivateKey::setD(const ByteString& inD)
{
	ECPrivateKey::setD(inD);

	BIGNUM* pk = OSSL::byteString2bn(inD);
	EC_KEY_set_private_key(eckey, pk);
	BN_clear_free(pk);
}
开发者ID:bellgrim,项目名称:SoftHSMv2,代码行数:9,代码来源:OSSLECPrivateKey.cpp


示例15: EC_KEY_generate_key_part

static int EC_KEY_generate_key_part(EC_KEY *eckey)
{
  int ok = 0;
  BN_CTX  *ctx = NULL;
  BIGNUM  *priv_key = NULL, *order = NULL;
  EC_POINT *pub_key = NULL;
  const EC_GROUP *group;

  if (!eckey)
  {
    return 0;
  }
  group = EC_KEY_get0_group(eckey);

  if ((order = BN_new()) == NULL) goto err;
  if ((ctx = BN_CTX_new()) == NULL) goto err;
  priv_key = (BIGNUM*)EC_KEY_get0_private_key(eckey);

  if (priv_key == NULL)
  {
    goto err;
  }

  if (!EC_GROUP_get_order(group, order, ctx))
    goto err;

  if (BN_is_zero(priv_key))
    goto err;
  pub_key = (EC_POINT *)EC_KEY_get0_public_key(eckey);

  if (pub_key == NULL)
  {
    pub_key = EC_POINT_new(group);
    if (pub_key == NULL)
      goto err;
  }

  if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
    goto err;
  {
    EC_POINT_make_affine(EC_KEY_get0_group(eckey),
                         (EC_POINT *)EC_KEY_get0_public_key(eckey),
                         NULL);
  }
  EC_KEY_set_private_key(eckey, priv_key);
  EC_KEY_set_public_key(eckey, pub_key);

  ok = 1;

err:
  if (order)
    BN_free(order);

  if (ctx != NULL)
    BN_CTX_free(ctx);
  return (ok);
}
开发者ID:houzhenggang,项目名称:luajit-android,代码行数:57,代码来源:pkey.c


示例16: FIPS_selftest_ecdsa

int FIPS_selftest_ecdsa()
	{
	EC_KEY *ec = NULL;
	BIGNUM *x = NULL, *y = NULL, *d = NULL;
	EVP_PKEY pk;
	int rv = 0;
	size_t i;

	for (i = 0; i < sizeof(test_ec_data)/sizeof(EC_SELFTEST_DATA); i++)
		{
		EC_SELFTEST_DATA *ecd = test_ec_data + i;

		x = BN_bin2bn(ecd->x, ecd->xlen, x);
		y = BN_bin2bn(ecd->y, ecd->ylen, y);
		d = BN_bin2bn(ecd->d, ecd->dlen, d);

		if (!x || !y || !d)
			goto err;

		ec = EC_KEY_new_by_curve_name(ecd->curve);
		if (!ec)
			goto err;

		if (!EC_KEY_set_public_key_affine_coordinates(ec, x, y))
			goto err;

		if (!EC_KEY_set_private_key(ec, d))
			goto err;

		pk.type = EVP_PKEY_EC;
		pk.pkey.ec = ec;

		if (!fips_pkey_signature_test(FIPS_TEST_SIGNATURE, &pk, NULL, 0,
						NULL, 0, EVP_sha512(), 0,
						ecd->name))
			goto err;
		EC_KEY_free(ec);
		ec = NULL;
		}

	rv = 1;

	err:

	if (x)
		BN_clear_free(x);
	if (y)
		BN_clear_free(y);
	if (d)
		BN_clear_free(d);
	if (ec)
		EC_KEY_free(ec);

	return rv;

	}
开发者ID:leloulight,项目名称:eme,代码行数:56,代码来源:fips_ecdsa_selftest.c


示例17: opensslecdsa_parse

static isc_result_t
opensslecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
	dst_private_t priv;
	isc_result_t ret;
	EVP_PKEY *pkey;
	EC_KEY *eckey = NULL;
	BIGNUM *privkey;
	int group_nid;
	isc_mem_t *mctx = key->mctx;

	REQUIRE(key->key_alg == DST_ALG_ECDSA256 ||
		key->key_alg == DST_ALG_ECDSA384);

	if (key->key_alg == DST_ALG_ECDSA256)
		group_nid = NID_X9_62_prime256v1;
	else
		group_nid = NID_secp384r1;

	eckey = EC_KEY_new_by_curve_name(group_nid);
	if (eckey == NULL)
		return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));

	/* read private key file */
	ret = dst__privstruct_parse(key, DST_ALG_ECDSA256, lexer, mctx, &priv);
	if (ret != ISC_R_SUCCESS)
		goto err;

	privkey = BN_bin2bn(priv.elements[0].data,
			    priv.elements[0].length, NULL);
	if (privkey == NULL)
		DST_RET(ISC_R_NOMEMORY);
	if (!EC_KEY_set_private_key(eckey, privkey))
		DST_RET(ISC_R_NOMEMORY);
	if (ecdsa_check(eckey, pub) != ISC_R_SUCCESS)
		DST_RET(DST_R_INVALIDPRIVATEKEY);
	dst__privstruct_free(&priv, mctx);
	memset(&priv, 0, sizeof(priv));

	pkey = EVP_PKEY_new();
	if (pkey == NULL)
		DST_RET (ISC_R_NOMEMORY);
	if (!EVP_PKEY_set1_EC_KEY(pkey, eckey)) {
		EVP_PKEY_free(pkey);
		DST_RET (ISC_R_FAILURE);
	}
	key->keydata.pkey = pkey;
	ret = ISC_R_SUCCESS;

 err:
	if (eckey != NULL)
		EC_KEY_free(eckey);
	dst__privstruct_free(&priv, mctx);
	memset(&priv, 0, sizeof(priv));
	return (ret);
}
开发者ID:phonehold,项目名称:bind-9,代码行数:55,代码来源:opensslecdsa_link.c


示例18: CBKeySign

uint8_t CBKeySign(uint8_t * privKey, uint8_t * hash, uint8_t * signature){
	EC_KEY * key = EC_KEY_new_by_curve_name(NID_secp256k1);
	BIGNUM * bn = BN_bin2bn(privKey, 32, NULL);
	EC_KEY_set_private_key(key, bn);
	unsigned int sigSize;
	ECDSA_sign(0, hash, 32, signature, &sigSize, key);
	// Free key and BIGNUM
	EC_KEY_free(key);
	BN_free(bn);
	return sigSize;
}
开发者ID:cedrou,项目名称:cbitcoin,代码行数:11,代码来源:CBOpenSSLCrypto.c


示例19: key

openssl::Key BackendOpenSsl::internal_private_key(const ecdsa256::PrivateKey& generic) const
{
    openssl::Key key(NID_X9_62_prime256v1);
    openssl::BigNumber prv(generic.key);
    EC_KEY_set_private_key(key, prv);

    // OpenSSL requires public key, so we recreate it from private key
    openssl::BigNumberContext ctx;
    const EC_GROUP* group = EC_KEY_get0_group(key);
    openssl::Point pub(group);
    openssl::check(EC_POINT_mul(group, pub, prv, nullptr, nullptr, ctx));
    EC_KEY_set_public_key(key, pub);

    openssl::check(EC_KEY_check_key(key));
    return key;
}
开发者ID:riebl,项目名称:vanetza,代码行数:16,代码来源:backend_openssl.cpp


示例20: gost_ec_keygen

/*
 *
 * Generates GOST R 34.10-2001
 * or GOST R 34.10-2012 keypair
 *
 */
int gost_ec_keygen(EC_KEY *ec)
{
    BIGNUM *order = NULL, *d = NULL;
    const EC_GROUP *group = (ec) ? EC_KEY_get0_group(ec) : NULL;
    int ok = 0;

    if (!group) {
        GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_INTERNAL_ERROR);
        return 0;
    }

    order = BN_new();
    d = BN_new();
    if (!order || !d) {
        GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_MALLOC_FAILURE);
        goto end;
    }

    if (!EC_GROUP_get_order(group, order, NULL)) {
        GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_INTERNAL_ERROR);
        goto end;
    }

    do {
        if (!BN_rand_range(d, order)) {
            GOSTerr(GOST_F_GOST_EC_KEYGEN, GOST_R_RNG_ERROR);
            goto end;
        }
    }
    while (BN_is_zero(d));

    if (!EC_KEY_set_private_key(ec, d)) {
        GOSTerr(GOST_F_GOST_EC_KEYGEN, ERR_R_INTERNAL_ERROR);
        goto end;
    }

    ok = 1;
 end:
    if (d)
        BN_free(d);
    if (order)
        BN_free(order);

    return (ok) ? gost_ec_compute_public(ec) : 0;
}
开发者ID:MaXaMaR,项目名称:engine,代码行数:51,代码来源:gost_ec_sign.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ EC_KEY_set_public_key函数代码示例发布时间:2022-05-30
下一篇:
C++ EC_KEY_set_conv_form函数代码示例发布时间: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