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

C++ EC_KEY_set_public_key函数代码示例

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

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



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

示例1: pkcs11_get_point_cert

/* Retrieve EC point from cert into ec
 * return nonzero on error */
static int pkcs11_get_point_cert(EC_KEY *ec, PKCS11_CERT *cert)
{
	EVP_PKEY *pubkey = NULL;
	EC_KEY *pubkey_ec;
	const EC_POINT *point;
	int rv = -1;

	if (cert == NULL)
		goto error;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
	pubkey = X509_get0_pubkey(cert->x509);
#else
	pubkey = X509_get_pubkey(cert->x509);
#endif
	if (pubkey == NULL)
		goto error;
	pubkey_ec = EVP_PKEY_get0_EC_KEY(pubkey);
	if (pubkey_ec == NULL)
		goto error;
	point = EC_KEY_get0_public_key(pubkey_ec);
	if (point == NULL)
		goto error;
	if (EC_KEY_set_public_key(ec, point) == 0)
		goto error;
	rv = 0;
error:
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
	EVP_PKEY_free(pubkey);
#endif
	return rv;
}
开发者ID:OpenSC,项目名称:libp11,代码行数:33,代码来源:p11_ec.c


示例2: 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


示例3: _libssh2_ecdsa_curve_name_with_octal_new

int
_libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx,
     const unsigned char *k,
     size_t k_len, libssh2_curve_type curve)
{

    int ret = 0;
    const EC_GROUP *ec_group = NULL;
    EC_KEY *ec_key = EC_KEY_new_by_curve_name(curve);
    EC_POINT *point = NULL;

    if(ec_key) {
        ec_group = EC_KEY_get0_group(ec_key);
        point = EC_POINT_new(ec_group);
        ret = EC_POINT_oct2point(ec_group, point, k, k_len, NULL);
        ret = EC_KEY_set_public_key(ec_key, point);

        if(point != NULL)
            EC_POINT_free(point);

        if(ec_ctx != NULL)
            *ec_ctx = ec_key;
    }

    return (ret == 1) ? 0 : -1;
}
开发者ID:stinb,项目名称:libssh2,代码行数:26,代码来源:openssl.c


示例4: 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


示例5: 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


示例6: 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


示例7: ecdsa_check

static isc_result_t
ecdsa_check(EC_KEY *eckey, dst_key_t *pub)
{
	isc_result_t ret = ISC_R_FAILURE;
	EVP_PKEY *pkey;
	EC_KEY *pubeckey = NULL;
	const EC_POINT *pubkey;

	if (pub == NULL)
		return (ISC_R_SUCCESS);
	pkey = pub->keydata.pkey;
	if (pkey == NULL)
		return (ISC_R_SUCCESS);
	pubeckey = EVP_PKEY_get1_EC_KEY(pkey);
	if (pubeckey == NULL)
		return (ISC_R_SUCCESS);
	pubkey = EC_KEY_get0_public_key(pubeckey);
	if (pubkey == NULL)
		DST_RET (ISC_R_SUCCESS);
	if (EC_KEY_set_public_key(eckey, pubkey) != 1)
		DST_RET (ISC_R_SUCCESS);
	if (EC_KEY_check_key(eckey) == 1)
		DST_RET (ISC_R_SUCCESS);

 err:
	if (pubeckey != NULL)
		EC_KEY_free(pubeckey);
	return (ret);
}
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:29,代码来源:opensslecdsa_link.c


示例8: eckey_pub_decode

static int eckey_pub_decode(EVP_PKEY *out, CBS *params, CBS *key) {
  // See RFC 5480, section 2.

  // The parameters are a named curve.
  EC_POINT *point = NULL;
  EC_KEY *eckey = NULL;
  EC_GROUP *group = EC_KEY_parse_curve_name(params);
  if (group == NULL || CBS_len(params) != 0) {
    OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
    goto err;
  }

  eckey = EC_KEY_new();
  if (eckey == NULL || !EC_KEY_set_group(eckey, group)) {
    goto err;
  }

  point = EC_POINT_new(group);
  if (point == NULL ||
      !EC_POINT_oct2point(group, point, CBS_data(key), CBS_len(key), NULL) ||
      !EC_KEY_set_public_key(eckey, point)) {
    goto err;
  }

  EC_GROUP_free(group);
  EC_POINT_free(point);
  EVP_PKEY_assign_EC_KEY(out, eckey);
  return 1;

err:
  EC_GROUP_free(group);
  EC_POINT_free(point);
  EC_KEY_free(eckey);
  return 0;
}
开发者ID:0x64616E69656C,项目名称:boringssl,代码行数:35,代码来源:p_ec_asn1.c


示例9: 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


示例10: sshbuf_get_eckey

int
sshbuf_get_eckey(struct sshbuf *buf, EC_KEY *v)
{
	EC_POINT *pt = EC_POINT_new(EC_KEY_get0_group(v));
	int r;
	const u_char *d;
	size_t len;

	if (pt == NULL) {
		SSHBUF_DBG(("SSH_ERR_ALLOC_FAIL"));
		return SSH_ERR_ALLOC_FAIL;
	}
	if ((r = sshbuf_peek_string_direct(buf, &d, &len)) < 0) {
		EC_POINT_free(pt);
		return r;
	}
	if ((r = get_ec(d, len, pt, EC_KEY_get0_group(v))) != 0) {
		EC_POINT_free(pt);
		return r;
	}
	if (EC_KEY_set_public_key(v, pt) != 1) {
		EC_POINT_free(pt);
		return SSH_ERR_ALLOC_FAIL; /* XXX assumption */
	}
	EC_POINT_free(pt);
	/* Skip string */
	if (sshbuf_get_string_direct(buf, NULL, NULL) != 0) {
		/* Shouldn't happen */
		SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR"));
		SSHBUF_ABORT();
		return SSH_ERR_INTERNAL_ERROR;
	}
	return 0;	
}
开发者ID:djmdjm,项目名称:libopenssh,代码行数:34,代码来源:sshbuf-getput-crypto.c


示例11: 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


示例12: pub_decode_gost01

static int pub_decode_gost01(EVP_PKEY *pk,X509_PUBKEY *pub)
	{
	X509_ALGOR *palg = NULL;
	const unsigned char *pubkey_buf = NULL;
	unsigned char *databuf;
	ASN1_OBJECT *palgobj = NULL;
	int pub_len,i,j;
	EC_POINT *pub_key;
	BIGNUM *X,*Y;
	ASN1_OCTET_STRING *octet= NULL;
	int len;
	const EC_GROUP *group;

	if (!X509_PUBKEY_get0_param(&palgobj,&pubkey_buf,&pub_len,
			&palg, pub)) return 0;
	EVP_PKEY_assign(pk,OBJ_obj2nid(palgobj),NULL);	
	if (!decode_gost_algor_params(pk,palg)) return 0;
	group = EC_KEY_get0_group(EVP_PKEY_get0(pk));
	octet = d2i_ASN1_OCTET_STRING(NULL,&pubkey_buf,pub_len);
	if (!octet) 
		{
		GOSTerr(GOST_F_PUB_DECODE_GOST01,ERR_R_MALLOC_FAILURE);
		return 0;
		}	
	databuf = OPENSSL_malloc(octet->length);
	for (i=0,j=octet->length-1;i<octet->length;i++,j--)
		{
		databuf[j]=octet->data[i];
		}
	len=octet->length/2;
	ASN1_OCTET_STRING_free(octet);	
	
	Y= getbnfrombuf(databuf,len);
	X= getbnfrombuf(databuf+len,len);
	OPENSSL_free(databuf);
	pub_key = EC_POINT_new(group);
	if (!EC_POINT_set_affine_coordinates_GFp(group
			,pub_key,X,Y,NULL))
		{
		GOSTerr(GOST_F_PUB_DECODE_GOST01,
			ERR_R_EC_LIB);
		EC_POINT_free(pub_key);
		BN_free(X);
		BN_free(Y);
		return 0;
		}	
	BN_free(X);
	BN_free(Y);
	if (!EC_KEY_set_public_key(EVP_PKEY_get0(pk),pub_key))
		{
		GOSTerr(GOST_F_PUB_DECODE_GOST01,
			ERR_R_EC_LIB);
		EC_POINT_free(pub_key);
		return 0;
		}	
	EC_POINT_free(pub_key);
	return 1;

	}
开发者ID:0culus,项目名称:openssl,代码行数:59,代码来源:gost_ameth.c


示例13: EC_KEY_get0_group

void OSSLECPublicKey::setQ(const ByteString& q)
{
	ECPublicKey::setQ(q);

	EC_POINT* pub = OSSL::byteString2pt(q, EC_KEY_get0_group(eckey));
	EC_KEY_set_public_key(eckey, pub);
	EC_POINT_free(pub);
}
开发者ID:GarysExperiments2014,项目名称:SoftHSMv2,代码行数:8,代码来源:OSSLECPublicKey.cpp


示例14: BN_bin2bn

// BCPKI
CKey CKey::GetDerivedKey(std::vector<unsigned char> ticket) const
{
  BIGNUM *bn = BN_bin2bn(&ticket[0],ticket.size(),BN_new());

  BN_CTX *ctx = NULL;
  if ((ctx = BN_CTX_new()) == NULL)
    throw key_error("CKey::DeriveKey() : BN_CTX_new failed");

  CKey key;
  if (HasPrivKey())
    { // privkey = privkey + ticket
      // snippet from ECDSA_SIG_recover_key_GFp
      // TODO check this again
      BIGNUM *order = NULL;
      if ((order = BN_new()) == NULL)
	throw key_error("CKey::DeriveKey() : BN_new failed");
      //      BN_CTX_start(ctx);
      //order = BN_CTX_get(ctx);
      if (!EC_GROUP_get_order(EC_KEY_get0_group(pkey), order, ctx)) 
      	throw key_error("CKey::DeriveKey() : EC_GROUP_get_order failed");
      if (!BN_mod_add(bn, bn, EC_KEY_get0_private_key(pkey), order, ctx))
      	throw key_error("CKey::DeriveKey() : BN_mod_add failed");
      if (!EC_KEY_regenerate_key(key.pkey,bn)) // sets private AND public key
        throw key_error("CKey::DeriveKey() : EC_KEY_regenerate_key failed");
      //      if (!EC_KEY_set_private_key(key.pkey, bn)) 
      //  throw key_error("CKey::DeriveKey() : EC_KEY_set_private_key failed");
      if (!EC_KEY_check_key(key.pkey))
	throw key_error("CKey::DeriveKey() : EC_KEY_check_key failed");
    }
  else
    { // add to pub key
      // begin snippet from EC_KEY_regenerate_key
      EC_POINT *pub_key = NULL;
      const EC_GROUP *group = EC_KEY_get0_group(pkey);

      pub_key = EC_POINT_new(group);
      if (pub_key == NULL)
        throw key_error("CKey::DeriveKey() : EC_POINT_new failed");

      if (!EC_POINT_mul(group, pub_key, bn, NULL, NULL, ctx))
        throw key_error("CKey::DeriveKey() : EC_POINT_mul failed");
      // end snippet from EC_KEY_regenerate_key
      // now pub_key = ticket * basepoint

      //const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);
      //int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
      if (!EC_POINT_add(group, pub_key, pub_key, EC_KEY_get0_public_key(pkey), ctx))
        throw key_error("CKey::DeriveKey() : EC_POINT_add failed");

      //int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);
      if (!EC_KEY_set_public_key(key.pkey, pub_key)) 
        throw key_error("CKey::DeriveKey() : EC_KEY_set_public_key failed");
    };

  key.fSet = true;
  key.SetCompressedPubKey();
  return key;
};
开发者ID:bcpki,项目名称:bitcoin,代码行数:59,代码来源:key.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: decode_user_key

u2fs_rc decode_user_key(const unsigned char *data, u2fs_EC_KEY_t ** key)
{

  if (key == NULL)
    return U2FS_MEMORY_ERROR;

  EC_GROUP *ecg = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
  *key = (u2fs_EC_KEY_t *) EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);

  EC_POINT *point = EC_POINT_new(ecg);
  point_conversion_form_t pcf = POINT_CONVERSION_UNCOMPRESSED;
  EC_GROUP_set_point_conversion_form(ecg, pcf);

  if (EC_POINT_oct2point(ecg, point, data, U2FS_PUBLIC_KEY_LEN, NULL) == 0) {
    if (debug) {
      unsigned long err = 0;
      err = ERR_get_error();
      fprintf(stderr, "Error: %s, %s, %s\n",
              ERR_lib_error_string(err),
              ERR_func_error_string(err), ERR_reason_error_string(err));
    }
    *key = NULL;
    EC_GROUP_free(ecg);
    ecg = NULL;
    EC_POINT_free(point);
    point = NULL;
    return U2FS_CRYPTO_ERROR;
  }

  EC_GROUP_free(ecg);
  ecg = NULL;

  if (EC_KEY_set_public_key((EC_KEY *) * key, point) == 0) {
    if (debug) {
      unsigned long err = 0;
      err = ERR_get_error();
      fprintf(stderr, "Error: %s, %s, %s\n",
              ERR_lib_error_string(err),
              ERR_func_error_string(err), ERR_reason_error_string(err));
    }
    *key = NULL;
    EC_POINT_free(point);
    point = NULL;
    return U2FS_CRYPTO_ERROR;
  }

  EC_POINT_free(point);
  point = NULL;

  return U2FS_OK;

}
开发者ID:Yubico,项目名称:libu2f-server-dpkg,代码行数:52,代码来源:openssl.c


示例17: SATOSHI_SCRIPT_checksig

static BOOL SATOSHI_SCRIPT_checksig(SATOSHI_OP_STACK_t * s, const unsigned char * message, uint32_t cbMessage)
{
	BOOL rc = FALSE;
	
	
	if(NULL == message || cbMessage == 0) return FALSE;
	
	SATOSHI_OP_STACK_DATA_t * pubkey = NULL, * sig = NULL;
	pubkey = SATOSHI_OP_STACK_pop(s);
	
	sig = SATOSHI_OP_STACK_pop(s);	
	
	if(NULL == pubkey || NULL == sig)
	{
		if(NULL != pubkey) SATOSHI_OP_STACK_DATA_free(pubkey);
		if(NULL != sig) SATOSHI_OP_STACK_DATA_free(sig);
		return FALSE;
	}
	
	// verify sig
	EC_KEY * p_key = EC_KEY_new_by_curve_name(NID_secp256k1);
	BN_CTX * ctx = BN_CTX_new();
	assert(NULL != p_key && NULL != ctx);
	const EC_GROUP * G = EC_KEY_get0_group(p_key);
	EC_POINT * Q = EC_POINT_new(G);
	EC_POINT_oct2point(G, Q, pubkey->data, pubkey->cb, ctx);
	EC_KEY_set_public_key(p_key, Q);
	
	rc = ECDSA_verify(0, message, cbMessage, sig->data, sig->cb, p_key);
	if(rc != 1)
	{
		if(-1 == rc)
		{
			// openssl error.
			ERR_print_errors_fp(stderr);		
		}
		rc = 0;
	}
	
	if(rc)
	{
		SATOSHI_OP_STACK_push_boolean(s, rc, sizeof(BOOL));		
	}
	
	EC_KEY_free(p_key);
	BN_CTX_free(ctx);
	
	SATOSHI_OP_STACK_DATA_free(pubkey);
	SATOSHI_OP_STACK_DATA_free(sig);
	return rc;
}
开发者ID:chehw,项目名称:bitcoin_programming_in_c,代码行数:51,代码来源:satoshi-script.c


示例18: serialize_ec_point

void serialize_ec_point (ec_point const& point, std::uint8_t* ptr)
{
    ec_key key = ec_key_new_secp256k1_compressed();

    if (EC_KEY_set_public_key((EC_KEY*) key.get(), point.get()) <= 0)
    {
        throw std::runtime_error ("EC_KEY_set_public_key() failed");
    }

    int const size = i2o_ECPublicKey ((EC_KEY*) key.get(), &ptr);

    assert (size <= 33);
    (void) size;
}
开发者ID:xdv,项目名称:divvyd,代码行数:14,代码来源:openssl.cpp


示例19: gost_ec_compute_public

/*
 * Computes GOST R 34.10-2001 public key
 * or GOST R 34.10-2012 public key
 *
 */
int gost_ec_compute_public(EC_KEY *ec)
{
    const EC_GROUP *group = (ec) ? EC_KEY_get0_group(ec) : NULL;
    EC_POINT *pub_key = NULL;
    const BIGNUM *priv_key = NULL;
    BN_CTX *ctx = NULL;
    int ok = 0;

    if (!group) {
        GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, GOST_R_KEY_IS_NOT_INITIALIZED);
        return 0;
    }

    ctx = BN_CTX_new();
    if (!ctx) {
        GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    BN_CTX_start(ctx);
    priv_key = EC_KEY_get0_private_key(ec);
    if (!priv_key) {
        GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_EC_LIB);
        goto err;
    }

    pub_key = EC_POINT_new(group);
    if (!pub_key) {
        GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_MALLOC_FAILURE);
        goto err;
    }

    if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx)) {
        GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_EC_LIB);
        goto err;
    }
    if (!EC_KEY_set_public_key(ec, pub_key)) {
        GOSTerr(GOST_F_GOST_EC_COMPUTE_PUBLIC, ERR_R_EC_LIB);
        goto err;
    }
    ok = 1;
 err:
    if (pub_key)
        EC_POINT_free(pub_key);
    BN_CTX_end(ctx);
    BN_CTX_free(ctx);
    return ok;
}
开发者ID:MaXaMaR,项目名称:engine,代码行数:53,代码来源:gost_ec_sign.c


示例20: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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