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

C++ EC_GROUP_new_by_curve_name函数代码示例

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

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



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

示例1: generate_ec_keypair

static int generate_ec_keypair(EVP_PKEY* pkey, const keymaster_ec_keygen_params_t* ec_params) {
    Unique_EC_GROUP group;
    switch (ec_params->field_size) {
    case 224:
        group.reset(EC_GROUP_new_by_curve_name(NID_secp224r1));
        break;
    case 256:
        group.reset(EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
        break;
    case 384:
        group.reset(EC_GROUP_new_by_curve_name(NID_secp384r1));
        break;
    case 521:
        group.reset(EC_GROUP_new_by_curve_name(NID_secp521r1));
        break;
    default:
        break;
    }

    if (group.get() == NULL) {
        logOpenSSLError("generate_ec_keypair");
        return -1;
    }

#if !defined(OPENSSL_IS_BORINGSSL)
    EC_GROUP_set_point_conversion_form(group.get(), POINT_CONVERSION_UNCOMPRESSED);
    EC_GROUP_set_asn1_flag(group.get(), OPENSSL_EC_NAMED_CURVE);
#endif

    /* initialize EC key */
    Unique_EC_KEY eckey(EC_KEY_new());
    if (eckey.get() == NULL) {
        logOpenSSLError("generate_ec_keypair");
        return -1;
    }

    if (EC_KEY_set_group(eckey.get(), group.get()) != 1) {
        logOpenSSLError("generate_ec_keypair");
        return -1;
    }

    if (EC_KEY_generate_key(eckey.get()) != 1 || EC_KEY_check_key(eckey.get()) < 0) {
        logOpenSSLError("generate_ec_keypair");
        return -1;
    }

    if (EVP_PKEY_assign_EC_KEY(pkey, eckey.get()) == 0) {
        logOpenSSLError("generate_ec_keypair");
        return -1;
    }
    release_because_ownership_transferred(eckey);

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


示例2: openssl_ec_crypt

void openssl_ec_crypt()
{
	BIO *berr;
	EC_KEY *key1, *key2;
	unsigned int sig_len;
	int clen, len1, len2;
	EC_builtin_curve *curves;
	EC_GROUP *group1, *group2;
	const EC_KEY *key3, *key4;
	const EC_GROUP *group3, *group4;
	const EC_POINT *pubkey1, *pubkey2;
	unsigned char shareKey1[COMM_LEN], shareKey2[COMM_LEN];
	unsigned char *signature, cont[COMM_LEN] = "123456";

	key1 = EC_KEY_new();
	key2 = EC_KEY_new();
	clen = EC_get_builtin_curves(NULL, 0);
	curves = (EC_builtin_curve *) malloc(sizeof(EC_builtin_curve) * clen);
	EC_get_builtin_curves(curves, clen);
	group1 = EC_GROUP_new_by_curve_name(curves[25].nid);
	group2 = EC_GROUP_new_by_curve_name(curves[25].nid);
	group3 = group1;
	group4 = group2;
	EC_KEY_set_group(key1, group3);
	EC_KEY_set_group(key2, group4);
	EC_KEY_generate_key(key1);
	EC_KEY_generate_key(key2);
	EC_KEY_check_key(key1);

	key3 = key1;
	key4 = key2;
	printf("\nECDSA_size: %d\n", ECDSA_size(key3));
	signature = (unsigned char *)malloc(ECDSA_size(key3));
	ERR_load_crypto_strings();
	berr = BIO_new(BIO_s_file());
	BIO_set_fp(berr, stdout, BIO_NOCLOSE);
	ECDSA_sign(0, cont, 8, signature, &sig_len, key1);
	ECDSA_verify(0, cont, 8, signature, sig_len, key1);

	pubkey1 = EC_KEY_get0_public_key(key1);
	pubkey2 = EC_KEY_get0_public_key(key2);
	len1 = ECDH_compute_key(shareKey1, COMM_LEN, pubkey2, key1, NULL);
	len2 = ECDH_compute_key(shareKey2, COMM_LEN, pubkey1, key1, NULL);
	if (len1 != len2 || memcmp(shareKey1, shareKey2, len1) != 0) {
		printf("ECDH_compute_key err!\n");
		return;
	}

	BIO_free(berr);
	EC_KEY_free(key1);
	EC_KEY_free(key2);
	free(signature);
	free(curves);
}
开发者ID:beike2020,项目名称:source,代码行数:54,代码来源:openssl_base.c


示例3: get_sequence

secret_parameter deterministic_wallet::generate_secret(
    size_t n, bool for_change) const
{
    if (seed_.empty())
        return null_hash;

    ssl_bignum z;
    hash_digest sequence = get_sequence(n, for_change);
    BN_bin2bn(sequence.data(), sequence.size(), z);

    ec_group group(EC_GROUP_new_by_curve_name(NID_secp256k1));
    ssl_bignum order;
    bn_ctx ctx(BN_CTX_new());
    EC_GROUP_get_order(group, order, ctx);

    // secexp = (stretched_seed + z) % order
    ssl_bignum secexp;
    BN_bin2bn(stretched_seed_.data(), stretched_seed_.size(), secexp);
    BN_add(secexp, secexp, z);
    BN_mod(secexp, secexp, order, ctx);

    secret_parameter secret;
    int secexp_bytes_size = BN_num_bytes(secexp);
    BITCOIN_ASSERT(secexp_bytes_size >= 0 &&
        static_cast<size_t>(BN_num_bytes(secexp)) <= secret.size());
    // If bignum value begins with 0x00, then
    // SSL will skip to the first significant digit.
    size_t copy_offset = secret.size() - BN_num_bytes(secexp);
    BN_bn2bin(secexp, secret.data() + copy_offset);
    // Zero out beginning 0x00 bytes (if they exist).
    std::fill(secret.begin(), secret.begin() + copy_offset, 0x00);
    return secret;
}
开发者ID:jestin,项目名称:libbitcoin-old,代码行数:33,代码来源:deterministic_wallet.cpp


示例4: ERR_load_BIO_strings

	void crypt_ec_helper::save_key_pair(std::string path, EC_KEY *keypair)
	{
		BIO *out;
		int i;
		FILE* outfile;
		EVP_PKEY          *pkey = NULL;

		ERR_load_BIO_strings();
		ERR_load_crypto_strings();

		pkey = EVP_PKEY_new();
		EVP_PKEY_assign_EC_KEY(pkey, keypair);

		EC_GROUP *ecgroup = EC_GROUP_new_by_curve_name(NID_secp256k1);

		outfile = fopen(path.c_str(), "w");

		out = BIO_new(BIO_s_file());
		out = BIO_new_fp(outfile, BIO_NOCLOSE);

		EC_KEY_set_asn1_flag(keypair, OPENSSL_EC_NAMED_CURVE);

		i = PEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, 0, NULL);

		fclose(outfile);

		EC_GROUP_free(ecgroup);
		EVP_PKEY_free(pkey);
		BIO_free_all(out);
	}
开发者ID:decentralised-project,项目名称:dc-gui,代码行数:30,代码来源:crypt_ec_helper.cpp


示例5: e

blob WSService::pubkey_from_cert(X509* x509) {
	std::runtime_error e("Certificate error");

	EC_GROUP* ec_group = EC_GROUP_new_by_curve_name(OBJ_sn2nid("prime256v1"));
	BN_CTX* bn_ctx = BN_CTX_new();

	std::vector<uint8_t> raw_public(33);

	try {
		if(ec_group == NULL || bn_ctx == NULL) throw e;

		EVP_PKEY* remote_pkey = X509_get_pubkey(x509);	if(remote_pkey == NULL) throw e;
		EC_KEY* remote_eckey = EVP_PKEY_get1_EC_KEY(remote_pkey);	if(remote_eckey == NULL) throw e;
		const EC_POINT* remote_pubkey = EC_KEY_get0_public_key(remote_eckey);	if(remote_pubkey == NULL) throw e;

		EC_POINT_point2oct(ec_group, remote_pubkey, POINT_CONVERSION_COMPRESSED, raw_public.data(), raw_public.size(), bn_ctx);
	}catch(...){
		BN_CTX_free(bn_ctx); EC_GROUP_free(ec_group);
		bn_ctx = NULL; ec_group = NULL;

		throw;
	}

	BN_CTX_free(bn_ctx); EC_GROUP_free(ec_group);

	return raw_public;
}
开发者ID:arno01,项目名称:librevault,代码行数:27,代码来源:WSService.cpp


示例6: BN_CTX_new

bool CECKey::TweakSecret(unsigned char vchSecretOut[32], const unsigned char vchSecretIn[32], const unsigned char vchTweak[32])
{
    bool ret = true;
    BN_CTX *ctx = BN_CTX_new();
    BN_CTX_start(ctx);
    BIGNUM *bnSecret = BN_CTX_get(ctx);
    BIGNUM *bnTweak = BN_CTX_get(ctx);
    BIGNUM *bnOrder = BN_CTX_get(ctx);
    EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
    EC_GROUP_get_order(group, bnOrder, ctx); // what a grossly inefficient way to get the (constant) group order...
    BN_bin2bn(vchTweak, 32, bnTweak);
    if (BN_cmp(bnTweak, bnOrder) >= 0)
        ret = false; // extremely unlikely
    BN_bin2bn(vchSecretIn, 32, bnSecret);
    BN_add(bnSecret, bnSecret, bnTweak);
    BN_nnmod(bnSecret, bnSecret, bnOrder, ctx);
    if (BN_is_zero(bnSecret))
        ret = false; // ridiculously unlikely
    int nBits = BN_num_bits(bnSecret);
    memset(vchSecretOut, 0, 32);
    BN_bn2bin(bnSecret, &vchSecretOut[32-(nBits+7)/8]);
    EC_GROUP_free(group);
    BN_CTX_end(ctx);
    BN_CTX_free(ctx);
    return ret;
}
开发者ID:flirtcoin,项目名称:flirtcoin,代码行数:26,代码来源:ecwrapper.cpp


示例7: HDW_public_data_from_private_data

int HDW_public_data_from_private_data(uint8_t *key_data, size_t key_data_len, BIGNUM *public_compressed_key) {

    int res = 1;

    EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
    BIGNUM *priv = BN_new();
    EC_POINT *ec_point = EC_POINT_new(group);

    FCHK_SET(BN_bin2bn(key_data, (int) key_data_len, priv), ==0, res, fail, 0);

    // Generate public key.
    FCHK(EC_POINT_mul(group, ec_point, priv, NULL, NULL, NULL), ==0, res, fail);

    FCHK_SET(EC_POINT_point2bn(group, ec_point, POINT_CONVERSION_COMPRESSED, public_compressed_key, NULL), ==0, res,
             fail, 0);

    FCHK_SET(BN_num_bytes(public_compressed_key), !=33, res, fail, 0);


    fail:
    if (res == 0) {
        BN_zero(public_compressed_key);
    }
    EC_POINT_free(ec_point);
    BN_free(priv);
    EC_GROUP_free(group);
    return res;

}
开发者ID:marctrem,项目名称:BIP32c,代码行数:29,代码来源:hdwallet.c


示例8: verify_x962_octets_are_on_p256

int verify_x962_octets_are_on_p256(const unsigned char* octets, size_t len) {
  assert(octets);
  assert(len);

  EC_GROUP* p256group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
  if (!p256group) {
    fprintf(stderr, "error: EC_GROUP_new_by_curve_name() failed.\n");
    return 4;
  }

  EC_POINT* point = EC_POINT_new(p256group);
  if (!point) {
    fprintf(stderr, "error: EC_POINT_new() failed.\n");
    EC_GROUP_free(p256group);
    return 4;
  }

  if (0 == EC_POINT_oct2point(p256group, point, octets, len, NULL)) {
    fprintf(stderr, "error: EC_POINT_oct2point() failed.\n");
    EC_POINT_free(point);
    EC_GROUP_free(p256group);
    return 4;
  }

  if (0 == EC_POINT_is_on_curve(p256group, point, NULL)) {
    fprintf(stderr, "error: Public key point isn't on P-256 curve.\n");
    EC_POINT_free(point);
    EC_GROUP_free(p256group);
    return 4;
  }

  EC_POINT_free(point);
  EC_GROUP_free(p256group);
  return 0;
}
开发者ID:0963682490,项目名称:omaha,代码行数:35,代码来源:eckeytool.c


示例9: EC_GROUP_new_by_curve_name

EC_KEY *EC_KEY_new_by_curve_name_NID_secp256k1(void)
{
	static EC_GROUP *group = NULL;
	EC_KEY *ret = NULL;

	if (group == NULL) {
#ifdef HAVE_NID_secp256k1
		group = EC_GROUP_new_by_curve_name(NID_secp256k1);
#else
		group = ec_group_new_from_data(&EC_SECG_PRIME_256K1.h);
#endif
		if (group == NULL) {
			return NULL;
		}
	}

	ret = EC_KEY_new();
	if (ret == NULL) {
		return NULL;
	}

	EC_KEY_set_group(ret, group);

	return ret;
}
开发者ID:matja,项目名称:bitcoin-tool,代码行数:25,代码来源:keys.c


示例10: get_sequence

secret_parameter deterministic_wallet::generate_secret(
    size_t n, bool for_change)
{
    if (seed_.empty())
        return null_hash;

    ssl_bignum z;
    hash_digest sequence = get_sequence(n, for_change);
    BN_bin2bn(sequence.data(), sequence.size(), z);

    ec_group group(EC_GROUP_new_by_curve_name(NID_secp256k1));
    ssl_bignum order;
    bn_ctx ctx(BN_CTX_new());
    EC_GROUP_get_order(group, order, ctx);

    // secexp = (stretched_seed + z) % order
    ssl_bignum secexp;
    BN_bin2bn(stretched_seed_.data(), stretched_seed_.size(), secexp);
    BN_add(secexp, secexp, z);
    BN_mod(secexp, secexp, order, ctx);

    secret_parameter secret;
    BITCOIN_ASSERT(BN_num_bytes(secexp) == secret.size());
    BN_bn2bin(secexp, secret.data());
    return secret;
}
开发者ID:Phallanx,项目名称:libbitcoin,代码行数:26,代码来源:deterministic_wallet.cpp


示例11: main

int main(void) {
    int i;
    secp256k1_pubkey pubkey;
    secp256k1_ecdsa_signature sig;
    benchmark_verify_t data;

    data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);

    for (i = 0; i < 32; i++) {
        data.msg[i] = 1 + i;
    }
    for (i = 0; i < 32; i++) {
        data.key[i] = 33 + i;
    }
    data.siglen = 72;
    CHECK(secp256k1_ecdsa_sign(data.ctx, &sig, data.msg, data.key, NULL, NULL));
    CHECK(secp256k1_ecdsa_signature_serialize_der(data.ctx, data.sig, &data.siglen, &sig));
    CHECK(secp256k1_ec_pubkey_create(data.ctx, &pubkey, data.key));
    data.pubkeylen = 33;
    CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1);

    run_benchmark("ecdsa_verify", benchmark_verify, NULL, NULL, &data, 10, 20000);
#ifdef ENABLE_OPENSSL_TESTS
    data.ec_group = EC_GROUP_new_by_curve_name(NID_secp256k1);
    run_benchmark("ecdsa_verify_openssl", benchmark_verify_openssl, NULL, NULL, &data, 10, 20000);
    EC_GROUP_free(data.ec_group);
#endif

    secp256k1_context_destroy(data.ctx);
    return 0;
}
开发者ID:Emercoin,项目名称:emercoin,代码行数:31,代码来源:bench_verify.c


示例12: verification

int verification(
    const unsigned char m[SHORTHASH_BYTES],const unsigned long long mlen,
    const unsigned char sm[SIGNATURE_BYTES],const unsigned long long smlen,
    const unsigned char pk[PUBLICKEY_BYTES],const unsigned long long pklen
    )
{
  unsigned char h[20];
  EC_GROUP *group;
  EC_KEY *k;
  EC_POINT *kxy;
  BIGNUM *kx;
  BIGNUM *ky;
  ECDSA_SIG *rs;
  int len;

  if (smlen != SIGNATURE_BYTES) return -1;
  if (mlen > SHORTHASH_BYTES) return -1;
  SHA1(m,mlen,h);

  group = EC_GROUP_new_by_curve_name(NID);
  if (!group) return -1;

  kx = BN_new(); if (!kx) return -1;
  ky = BN_new(); if (!ky) { BN_free(kx); return -1; }
  kxy = EC_POINT_new(group); if (!kxy) { BN_free(ky); BN_free(kx); return -1; }
  k = EC_KEY_new(); if (!k) { EC_POINT_free(kxy); BN_free(ky); BN_free(kx); return -1; }
  rs = ECDSA_SIG_new(); if (!rs) { EC_KEY_free(k); EC_POINT_free(kxy); BN_free(ky); BN_free(kx); return -1; }

  if (!EC_KEY_set_group(k,group)) goto error;
  if (!BN_bin2bn(pk,PRIME_BYTES,kx)) goto error; pk += PRIME_BYTES;
  if (!BN_bin2bn(pk,PRIME_BYTES,ky)) goto error;
#ifdef PRIME_FIELD
  if (!EC_POINT_set_affine_coordinates_GFp(group,kxy,kx,ky,0)) goto error;
#else
  if (!EC_POINT_set_affine_coordinates_GF2m(group,kxy,kx,ky,0)) goto error;
#endif
  if (!EC_KEY_set_public_key(k,kxy)) goto error;

  if (!BN_bin2bn(sm,PRIME_BYTES,rs->r)) goto error; sm += PRIME_BYTES;
  if (!BN_bin2bn(sm,PRIME_BYTES,rs->s)) goto error;

  len = ECDSA_do_verify(h,20,rs,k);
  ECDSA_SIG_free(rs);
  EC_KEY_free(k);
  EC_POINT_free(kxy);
  BN_free(ky);
  BN_free(kx);

  if (len == 1) return 0;
  if (len == 0) return -100;
  return -1;
  
error:
  ECDSA_SIG_free(rs);
  EC_KEY_free(k);
  EC_POINT_free(kxy);
  BN_free(ky);
  BN_free(kx);
  return -1;
}
开发者ID:JacobBarthelmeh,项目名称:supercop,代码行数:60,代码来源:verification.c


示例13: ecdsa_private_key_import

static int
ecdsa_private_key_import(hx509_context context,
                         const AlgorithmIdentifier *keyai,
                         const void *data,
                         size_t len,
                         hx509_key_format_t format,
                         hx509_private_key private_key)
{
    const unsigned char *p = data;
    EC_KEY **pkey = NULL;
    EC_KEY *key;

    if (keyai->parameters) {
        EC_GROUP *group;
        int groupnid;
        int ret;

        ret = parse_ECParameters(context, keyai->parameters, &groupnid);
        if (ret)
            return ret;

        key = EC_KEY_new();
        if (key == NULL)
            return ENOMEM;

        group = EC_GROUP_new_by_curve_name(groupnid);
        if (group == NULL) {
            EC_KEY_free(key);
            return ENOMEM;
        }
        EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
        if (EC_KEY_set_group(key, group) == 0) {
            EC_KEY_free(key);
            EC_GROUP_free(group);
            return ENOMEM;
        }
        EC_GROUP_free(group);
        pkey = &key;
    }

    switch (format) {
    case HX509_KEY_FORMAT_DER:

        private_key->private_key.ecdsa = d2i_ECPrivateKey(pkey, &p, len);
        if (private_key->private_key.ecdsa == NULL) {
            hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
                                   "Failed to parse EC private key");
            return HX509_PARSING_KEY_FAILED;
        }
        private_key->signature_alg = ASN1_OID_ID_ECDSA_WITH_SHA256;
        break;

    default:
        return HX509_CRYPTO_KEY_FORMAT_UNSUPPORTED;
    }

    return 0;
}
开发者ID:heimdal,项目名称:heimdal,代码行数:58,代码来源:crypto-ec.c


示例14: while

	const EC_POINT* crypt_ec_helper::from_base58(std::string base58)
	{
		const char* psz = base58.c_str();
		std::vector<unsigned char> vch;

		// Skip leading spaces.
		while (*psz && isspace(*psz))
			psz++;
		// Skip and count leading '1's.
		int zeroes = 0;
		while (*psz == '1') {
			zeroes++;
			psz++;
		}
		// Allocate enough space in big-endian base256 representation.
		std::vector<unsigned char> b256(strlen(psz) * 733 / 1000 + 1); // log(58) / log(256), rounded up.
		// Process the characters.
		while (*psz && !isspace(*psz)) {
			// Decode base58 character
			const char* ch = strchr(pszBase58, *psz);
			if (ch == NULL)	
				return NULL;

			// Apply "b256 = b256 * 58 + ch".
			int carry = ch - pszBase58;
			for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); it != b256.rend(); it++) {
				carry += 58 * (*it);
				*it = carry % 256;
				carry /= 256;
			}
			assert(carry == 0);
			psz++;
		}
		// Skip trailing spaces.
		while (isspace(*psz))
			psz++;
		if (*psz != 0)
			return NULL;

		// Skip leading zeroes in b256.
		std::vector<unsigned char>::iterator it = b256.begin();
		while (it != b256.end() && *it == 0)
			it++;
		// Copy result into output vector.
		vch.reserve(zeroes + (b256.end() - it));
		vch.assign(zeroes, 0x00);
		while (it != b256.end())
			vch.push_back(*(it++));

		EC_GROUP *ecgrp = EC_GROUP_new_by_curve_name(NID_secp256k1);
		pub = EC_POINT_new(ecgrp);

		size_t len = EC_POINT_oct2point(ecgrp, pub, vch.data(), vch.size(), NULL);

		EC_GROUP_free(ecgrp);

		return pub;
	}
开发者ID:decentralised-project,项目名称:dc-gui,代码行数:58,代码来源:crypt_ec_helper.cpp


示例15: EC_KEY_new

	EC_KEY* crypt_ec_helper::generate_key_pair()
	{
		eckey = EC_KEY_new();
		EC_GROUP *ecgroup = EC_GROUP_new_by_curve_name(NID_secp256k1);
		EC_KEY_set_group(eckey, ecgroup);
		EC_KEY_generate_key(eckey);

		EC_GROUP_free(ecgroup);

		return eckey;
	}
开发者ID:decentralised-project,项目名称:dc-gui,代码行数:11,代码来源:crypt_ec_helper.cpp


示例16: internal_curve_test

void internal_curve_test(void)
	{
	EC_builtin_curve *curves = NULL;
	size_t crv_len = 0, n = 0;
	int    ok = 1;

	crv_len = EC_get_builtin_curves(NULL, 0);

	curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);

	if (curves == NULL)
		return;

	if (!EC_get_builtin_curves(curves, crv_len))
		{
		OPENSSL_free(curves);
		return;
		}

	fprintf(stdout, "testing internal curves: ");
		
	for (n = 0; n < crv_len; n++)
		{
		EC_GROUP *group = NULL;
		int nid = curves[n].nid;
		if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL)
			{
			ok = 0;
			fprintf(stdout, "\nEC_GROUP_new_curve_name() failed with"
				" curve %s\n", OBJ_nid2sn(nid));
			/* try next curve */
			continue;
			}
		if (!EC_GROUP_check(group, NULL))
			{
			ok = 0;
			fprintf(stdout, "\nEC_GROUP_check() failed with"
				" curve %s\n", OBJ_nid2sn(nid));
			EC_GROUP_free(group);
			/* try the next curve */
			continue;
			}
		fprintf(stdout, ".");
		fflush(stdout);
		EC_GROUP_free(group);
		}
	if (ok)
		fprintf(stdout, " ok\n");
	else
		fprintf(stdout, " failed\n");
	OPENSSL_free(curves);
	return;
	}
开发者ID:174high,项目名称:openssl-0.9.8e_linux_porting,代码行数:53,代码来源:ectest.c


示例17: CBKeyGetPublicKey

void CBKeyGetPublicKey(uint8_t * privKey, uint8_t * pubKey){
	BIGNUM * privBn = BN_bin2bn(privKey, 32, NULL);
	EC_GROUP * group = EC_GROUP_new_by_curve_name(NID_secp256k1);
	EC_POINT * point = EC_POINT_new(group);
	BN_CTX * ctx = BN_CTX_new();
	EC_POINT_mul(group, point, privBn, NULL, NULL, ctx);
	EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED, pubKey, 33, ctx);
	BN_CTX_free(ctx);
	EC_POINT_free(point);
	EC_GROUP_free(group);
	BN_free(privBn);
}
开发者ID:cedrou,项目名称:cbitcoin,代码行数:12,代码来源:CBOpenSSLCrypto.c


示例18: param_decode_gost01

static int
param_decode_gost01(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
{
	ASN1_OBJECT *obj = NULL;
	int nid;
	GOST_KEY *ec;
	EC_GROUP *group;
	int ret;

	/* New format */
	if ((V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED) == **pder)
		return decode_gost01_algor_params(pkey, pder, derlen);

	/* Compatibility */
	if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) {
		GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE);
		return 0;
	}
	nid = OBJ_obj2nid(obj);
	ASN1_OBJECT_free(obj);

	ec = GOST_KEY_new();
	if (ec == NULL) {
		GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE);
		return 0;
	}
	group = EC_GROUP_new_by_curve_name(nid);
	if (group == NULL) {
		GOSTerr(GOST_F_PARAM_DECODE_GOST01,
		    EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
		GOST_KEY_free(ec);
		return 0;
	}

	EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
	if (GOST_KEY_set_group(ec, group) == 0) {
		GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_EC_LIB);
		EC_GROUP_free(group);
		GOST_KEY_free(ec);
		return 0;
	}
	EC_GROUP_free(group);
	if (GOST_KEY_set_digest(ec,
	    NID_id_GostR3411_94_CryptoProParamSet) == 0) {
		GOSTerr(GOST_F_PARAM_DECODE_GOST01, GOST_R_INVALID_DIGEST_TYPE);
		GOST_KEY_free(ec);
		return 0;
	}
	ret = EVP_PKEY_assign_GOST(pkey, ec);
	if (ret == 0)
		GOST_KEY_free(ec);
	return ret;
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:53,代码来源:gostr341001_ameth.c


示例19: EC_KEY_new

EC_KEY *EC_KEY_new_by_curve_name(int nid)
{
    EC_KEY *ret = EC_KEY_new();
    if (ret == NULL)
        return NULL;
    ret->group = EC_GROUP_new_by_curve_name(nid);
    if (ret->group == NULL) {
        EC_KEY_free(ret);
        return NULL;
    }
    return ret;
}
开发者ID:GrayKing,项目名称:Leakfix-on-OpenSSL,代码行数:12,代码来源:ec_key.c


示例20: eccx08_eckey_convert

/**
 *  eccx08_eckey_convert()
 *
 * \brief Converts raw 64 bytes of public key (ATECC508 format) to the
 *  openssl EC_KEY structure. It allocates EC_KEY structure and
 *  does not free it (must be a caller to free)
 *
 * \param[out] p_eckey Pointer to EC_KEY with Public Key on success
 * \param[in] raw_pubkey Raw public key, 64 bytes length 32-byte X following with 32-byte Y
 * \param[in] serial_number 9 bytes of ATECCX08 serial number
 * \param[in] serial_len Size of the ATECCX08 serial number buffer
 * \return 1 on success, 0 on error
 */
int eccx08_eckey_convert(EC_KEY **p_eckey, uint8_t *raw_pubkey, uint8_t *serial_number, int serial_len)
{
    int rc = 0;
    int ret = 0;
    EC_GROUP *ecgroup = NULL, *ecgroup_old = NULL;
    EC_KEY *eckey = *p_eckey;
    EC_POINT *ecpoint = NULL;
    BN_CTX *bnctx = NULL;
    int asn1_flag = OPENSSL_EC_NAMED_CURVE;
    point_conversion_form_t form = POINT_CONVERSION_UNCOMPRESSED;
    char tmp_buf[MEM_BLOCK_SIZE * 2 + 1];


    /* Openssl raw key has a leading byte with conversion form id */
    tmp_buf[0] = POINT_CONVERSION_UNCOMPRESSED;
    memcpy(&tmp_buf[1], raw_pubkey, MEM_BLOCK_SIZE * 2);

    if (!eckey) {
        eckey = EC_KEY_new();
        if (!eckey) goto done;
    }
    ecgroup = eckey->group;
    if (!ecgroup) {
        ecgroup = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
        if (!ecgroup) goto done;
        EC_GROUP_set_point_conversion_form(ecgroup, form);
        EC_GROUP_set_asn1_flag(ecgroup, asn1_flag);
    }

    if (!eckey->group) {
        ret = EC_KEY_set_group(eckey, ecgroup);
        if (!ret) goto done;
    }

    ret = eccx08_generate_key(eckey, serial_number, serial_len);
    if (!ret) goto done;

    ecgroup = eckey->group;
    ecpoint = eckey->pub_key;

    if (!ecpoint) {
        ecpoint = EC_POINT_new(ecgroup);
        if (!ecpoint) goto done;
    }

    ret = EC_POINT_oct2point(ecgroup, ecpoint, tmp_buf, MEM_BLOCK_SIZE * 2 + 1, NULL);
    if (!ret) goto done;

    *p_eckey = eckey;
    rc = 1;
done:
    return (rc);
}
开发者ID:TacoComfort,项目名称:cryptoauth-openssl-engine,代码行数:66,代码来源:eccx08_common.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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