本文整理汇总了C++中uint256::toVch方法的典型用法代码示例。如果您正苦于以下问题:C++ uint256::toVch方法的具体用法?C++ uint256::toVch怎么用?C++ uint256::toVch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uint256
的用法示例。
在下文中一共展示了uint256::toVch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Verify
bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
{
// decode the vchSig
Integer sigE, sigS;
if (vchSig.size() != (SCHNORR_SIG_SIZE * 2))
return false;
// extract bytes
std::vector<unsigned char> sigEVec(&vchSig[0], &vchSig[SCHNORR_SIG_SIZE]);
std::vector<unsigned char> sigSVec(&vchSig[SCHNORR_SIG_SIZE], &vchSig[1 + SCHNORR_SIG_SIZE * 2]);
// vectors -> Integers
sigE.Decode(&sigEVec[0], SCHNORR_SIG_SIZE);
sigS.Decode(&sigSVec[0], SCHNORR_SIG_SIZE);
// verify the hash
ECPPoint R;
R = ec.CascadeScalarMultiply(G, sigS, Q, sigE);
// encode hash as byte[]
std::vector<unsigned char> vchHash = hash.toVch();
Integer sigEd = HashPointMessage(R, &vchHash[0], sizeof(hash)) % q;
return (sigE == sigEd);
}
示例2: Sign
bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
{
// sign the hash
Integer k;
ECPPoint R;
Integer sigE, sigS;
k = Integer(rng, 256) % q;
R = ec.ScalarMultiply(G, k);
// encode hash as byte[]
std::vector<unsigned char> vchHash = hash.toVch();
sigE = HashPointMessage(R, &vchHash[0], sizeof(hash)) % q;
sigS = (k - secretKey*sigE) % q;
// encode the vch format
vchSig.resize(SCHNORR_SIG_SIZE * 2);
if (sigE.MinEncodedSize() > SCHNORR_SIG_SIZE || sigS.MinEncodedSize() > SCHNORR_SIG_SIZE)
return false;
sigE.Encode(&vchSig[0], SCHNORR_SIG_SIZE);
sigS.Encode(&vchSig[SCHNORR_SIG_SIZE], SCHNORR_SIG_SIZE);
return true;
}