gpt4 book ai didi

c++ - 如何在 CryptoPP 中使用 RabinMillerTest()?

转载 作者:太空宇宙 更新时间:2023-11-04 13:47:26 25 4
gpt4 key购买 nike

谁能分享一个有效的 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++ 编写的。

关于c++ - 如何在 CryptoPP 中使用 RabinMillerTest()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25319787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com