本文整理汇总了C++中cryptopp::Integer::InverseMod方法的典型用法代码示例。如果您正苦于以下问题:C++ Integer::InverseMod方法的具体用法?C++ Integer::InverseMod怎么用?C++ Integer::InverseMod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptopp::Integer
的用法示例。
在下文中一共展示了Integer::InverseMod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verify
bool verify(CryptoPP::ECPPoint Q, byte *message, unsigned message_length, CryptoPP::Integer r, CryptoPP::Integer s){
auto ec = common::ec_parameters().GetCurve();
auto G = common::ec_parameters().GetSubgroupGenerator();
auto n = common::ec_parameters().GetGroupOrder();
Integer z = hash_m_to_int(message, message_length, n.ByteCount());
// verify
if (Q == ec.Identity()){
cerr << "Q == O" << endl;
return false;
}
if (!(ec.Multiply(n, Q) == ec.Identity())){
cerr << "n x Q != O" << endl;
return false;
}
if (r <= 0 || r >= n){
cerr << "incorrect r" << endl;
return false;
}
if (s <= 0 || s >= n){
cerr << "incorrect s" << endl;
return false;
}
Integer w = s.InverseMod(n);
Integer u1 = a_times_b_mod_c(z, w, n);
Integer u2 = a_times_b_mod_c(r, w, n);
ECPPoint P2 = ec.Add(ec.Multiply(u1, G), ec.Multiply(u2, Q));
if (P2.x != r){
cerr << "P2.x != r" << endl;
return false;
}
return true;
}
示例2: InvMod
SecureBinaryData CryptoECDSA::InvMod(const SecureBinaryData& m)
{
static BinaryData N = BinaryData::CreateFromHex(
"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
CryptoPP::Integer cppM;
CryptoPP::Integer cppModulo;
cppM.Decode(m.getPtr(), m.getSize(), UNSIGNED);
cppModulo.Decode(N.getPtr(), N.getSize(), UNSIGNED);
CryptoPP::Integer cppResult = cppM.InverseMod(cppModulo);
SecureBinaryData result(32);
cppResult.Encode(result.getPtr(), result.getSize(), UNSIGNED);
return result;
}