谁能分享一个有效的 RabinMillerTest() 示例?遗憾的是,我的 googlefu 不见了。
这是我的测试代码:
#include "integer.h"
#include "nbtheory.h"
#include "cryptlib.h"
#include "osrng.h"
#include <iostream>
int main(int argc,char *argv[])
{
CryptoPP::RandomNumberGenerator rng;
CryptoPP::Integer a("123456789");
CryptoPP::Integer b;
std::cout << a << std::endl;
std::cout << "is prime: " << IsPrime(a) << std::endl;
b=a+CryptoPP::Integer::Two();
std::cout << b << std::endl;
std::cout << "is prime: " << IsPrime(b) << std::endl;
int r=RabinMillerTest(rng,&b,2);
std::cout << "RabinMiller: " << r <<std::endl;
}
这是构建命令:
g++ bignum.cpp -I. -fpermissive libcryptopp.a
我能找到的唯一例子是:
http://www.cryptopp.com/wiki/Diffie-Hellman
我的代码每次运行都会崩溃,有一次崩溃非常严重,我不得不冷启动才能恢复。如果我删除对 RabinMillerTest() 的调用,那么它运行正常。我怀疑 C++ 语法问题是罪魁祸首,但我只是没有看到它。由于我不能正确使用它,我目前正在剥离 RabinMillerTest() 函数的内容以单独使用。
您为 MillerRabinTest
使用了错误的签名。这是它的内容(来自 nbtheory.h
):
CRYPTOPP_DLL bool CRYPTOPP_API RabinMillerTest(RandomNumberGenerator &rng,
const Integer &w, unsigned int rounds);
代替:
int r=RabinMillerTest(rng,&b,2);
尝试:
bool b=RabinMillerTest(rng, b, 2);
密码学堆栈交换中也有关于 Miller-Rabin 轮数的讨论 Trial divisions before Miller-Rabin checks? .它是用 OpenSSL 和 Crypto++ 编写的。
我是一名优秀的程序员,十分优秀!