当前位置: 首页>>代码示例>>C++>>正文


C++ SetCompressedPubKey函数代码示例

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


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

示例1: ECDSA_SIG_new

// reconstruct public key from a compact signature
// This is only slightly more CPU intensive than just verifying it.
// If this function succeeds, the recovered public key is guaranteed to be valid
// (the signature is a valid signature of the given data for that key)
bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig)
{
    if (vchSig.size() != 65)
        return false;
    int nV = vchSig[0];
    if (nV<27 || nV>=35)
        return false;
    ECDSA_SIG *sig = ECDSA_SIG_new();
    BN_bin2bn(&vchSig[1],32,sig->r);
    BN_bin2bn(&vchSig[33],32,sig->s);

    EC_KEY_free(pkey);
    pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
    if (nV >= 31)
    {
        SetCompressedPubKey();
        nV -= 4;
    }
    if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), nV - 27, 0) == 1)
    {
        fSet = true;
        ECDSA_SIG_free(sig);
        return true;
    }
    ECDSA_SIG_free(sig);
    return false;
}
开发者ID:IngenierosWeb,项目名称:pokecoin,代码行数:31,代码来源:key.cpp

示例2: key_error

void CKey::MakeNewKey(bool fCompressed)
{
    if (!EC_KEY_generate_key(pkey))
        throw key_error("CKey::MakeNewKey() : EC_KEY_generate_key failed");
    if (fCompressed)
        SetCompressedPubKey();
    fSet = true;
}
开发者ID:uscoin,项目名称:uscoin,代码行数:8,代码来源:key.cpp

示例3: SetCompressedPubKey

bool CKey::SetPubKey(const CPubKey& vchPubKey)
{
    const unsigned char* pbegin = &vchPubKey.vchPubKey[0];
    if (!o2i_ECPublicKey(&pkey, &pbegin, vchPubKey.vchPubKey.size()))
        return false;
    fSet = true;
    if (vchPubKey.vchPubKey.size() == 33)
        SetCompressedPubKey();
    return true;
}
开发者ID:uscoin,项目名称:uscoin,代码行数:10,代码来源:key.cpp

示例4: SetCompressedPubKey

bool CCryptKey::SetPubKey(const CPubKey& vchPubKey)
{
    const unsigned char* pbegin = &vchPubKey.vchPubKey[0];
    if (o2i_ECPublicKey(&pkey, &pbegin, vchPubKey.vchPubKey.size()))
    {
        fSet = true;
        if (vchPubKey.vchPubKey.size() == 33)
            SetCompressedPubKey();
        return true;
    }
    pkey = NULL;
    Reset();
    return false;
}
开发者ID:CryptoDJ,项目名称:DarkSilk-Release-Candidate,代码行数:14,代码来源:cryptkey.cpp

示例5: EC_KEY_free

bool CKey::SetSecret(const std::vector<unsigned char>& vch)
{
    EC_KEY_free(pkey);
    pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
    if (pkey == NULL)
        throw key_error("CKey::SetSecret() : EC_KEY_new_by_curve_name failed");
    BIGNUM *bn = BN_bin2bn(&vch[0],vch.size(),BN_new());
    if (bn == NULL)
        throw key_error("CKey::SetSecret() : BN_bin2bn failed");
    if (!EC_KEY_regenerate_key(pkey,bn))
    {
        BN_clear_free(bn);
        throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
    }
    BN_clear_free(bn);
    fSet = true;
    SetCompressedPubKey();
    return true;
}
开发者ID:bcpki,项目名称:bitcoin,代码行数:19,代码来源:key.cpp

示例6: EC_KEY_free

bool CKey::SetSecret(const CSecret &vchSecret, bool fCompressed)
{
	EC_KEY_free(pkey);
	pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
	if (pkey == NULL)
		throw key_error("CKey::SetSecret() : EC_KEY_new_by_curve_name failed");
	if (vchSecret.size() != 32)
		throw key_error("CKey::SetSecret() : secret must be 32 bytes");
	BIGNUM *bn = BN_bin2bn(&vchSecret[0], 32, BN_new());
	if (bn == NULL)
		throw key_error("CKey::SetSecret() : BN_bin2bn failed");
	if (!EC_KEY_regenerate_key(pkey, bn)) {
		BN_clear_free(bn);
		throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
	}
	BN_clear_free(bn);
	fSet = true;
	if (fCompressed || fCompressedPubKey)
		SetCompressedPubKey();
	return true;
}
开发者ID:66maintainer,项目名称:66coin,代码行数:21,代码来源:key.cpp

示例7: ECDSA_SIG_new

// reconstruct public key from a compact signature
// This is only slightly more CPU intensive than just verifying it.
// If this function succeeds, the recovered public key is guaranteed to be valid
// (the signature is a valid signature of the given data for that key)
bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig)
{
    if (vchSig.size() != 65)
        return false;
    int nV = vchSig[0];
    if (nV<27 || nV>=35)
        return false;
    ECDSA_SIG *sig = ECDSA_SIG_new();
    if (!sig) return false;

    #if OPENSSL_VERSION_NUMBER > 0x1000ffffL
    // sig_r and sig_s are deallocated by ECDSA_SIG_free(sig);
    BIGNUM *sig_r = BN_bin2bn(&vchSig[1],32,BN_new());
    BIGNUM *sig_s = BN_bin2bn(&vchSig[33],32,BN_new());
    if (!sig_r || !sig_s) return false;
    // copy and transfer ownership to sig
    ECDSA_SIG_set0(sig, sig_r, sig_s);
    #else
    BN_bin2bn(&vchSig[1],32,sig->r);
    BN_bin2bn(&vchSig[33],32,sig->s);
    #endif

    EC_KEY_free(pkey);
    pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
    if (nV >= 31)
    {
        SetCompressedPubKey();
        nV -= 4;
    }
    if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), nV - 27, 0) == 1)
    {
        fSet = true;
        ECDSA_SIG_free(sig);
        return true;
    }
    ECDSA_SIG_free(sig);
    return false;
}
开发者ID:mikaelh2,项目名称:primecoin,代码行数:42,代码来源:key.cpp


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