首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用RNG初始化Botan中的McEliece函数

无法使用RNG初始化Botan中的McEliece函数
EN

Stack Overflow用户
提问于 2020-08-09 02:01:41
回答 1查看 56关注 0票数 0

我想在我的代码中通过RNG使用Botan cryptolibrary中的McEliece函数。Botan GitHub页面上的描述是不够的,它引用了一个旧的外部用法示例,该示例根本不起作用。

因此,我是第一次接触这个主题,我试图调用类并解析所需的参数,但我得到了错误。我想一定是类型出了问题。

下面是我的代码示例:

代码语言:javascript
复制
  1 //#include <botan/botan.h>
  2 #include <botan/rng.h>
  3 #include <botan/system_rng.h>
  4 #include <botan/mceies.h>
  5 #include <botan/mceliece.h>
  6 #include <iostream>
  7
  8 int main() {
  9
 10    Botan::size_t n = 6624;
 11    Botan::size_t t = 115;
 12
 13    std::unique_ptr<Botan::RandomNumberGenerator> rng;
 14    //RandomNumberGenerator rng = RandomNumberGenerator();
 15
 16    //McEliece_PrivateKey sk1();
 17    //RandomNumberGenerator &system_rng();
 18
 19    Botan::McEliece_PrivateKey sk1(rng, n, t);
 20
 21    //std::cout << typeid(sk1).name() << std::endl;
 22    std::cout << typeid(rng).name() << std::endl;
 23    std::cout << rng->next_byte() << std::endl;
 24
 25    return 0;

下面是错误:

代码语言:javascript
复制
~/projects $ g++ mc_eliece2.cpp -o mc_eliece2 -I/usr/local/include/botan-2/ -L/usr/local/lib/
mc_eliece2.cpp: In function ‘int main()’:
mc_eliece2.cpp:19:44: error: no matching function for call to ‘Botan::McEliece_PrivateKey::McEliece_PrivateKey(std::unique_ptr<Botan::RandomNumberGenerator>&, std::size_t&, std::size_t&)’
    Botan::McEliece_PrivateKey sk1(rng, n, t);
                                            ^
In file included from mc_eliece2.cpp:5:
/usr/local/include/botan-2/botan/mceliece.h:91:7: note: candidate: ‘Botan::McEliece_PrivateKey::McEliece_PrivateKey(const Botan::polyn_gf2m&, const std::vector<unsigned int>&, const std::vector<Botan::polyn_gf2m>&, const std::vector<short unsigned int>&, const std::vector<unsigned char>&)’
       McEliece_PrivateKey(polyn_gf2m const& goppa_polyn,
       ^~~~~~~~~~~~~~~~~~~
/usr/local/include/botan-2/botan/mceliece.h:91:7: note:   candidate expects 5 arguments, 3 provided
/usr/local/include/botan-2/botan/mceliece.h:89:16: note: candidate: ‘Botan::McEliece_PrivateKey::McEliece_PrivateKey(Botan::secure_vector<unsigned char>&)’
       explicit McEliece_PrivateKey(const secure_vector<uint8_t>& key_bits);
                ^~~~~~~~~~~~~~~~~~~
/usr/local/include/botan-2/botan/mceliece.h:89:16: note:   candidate expects 1 argument, 3 provided
/usr/local/include/botan-2/botan/mceliece.h:87:7: note: candidate: ‘Botan::McEliece_PrivateKey::McEliece_PrivateKey(Botan::RandomNumberGenerator&, std::size_t, std::size_t)’
       McEliece_PrivateKey(RandomNumberGenerator& rng, size_t code_length, size_t t);
       ^~~~~~~~~~~~~~~~~~~
/usr/local/include/botan-2/botan/mceliece.h:87:7: note:   no known conversion for argument 1 from ‘std::unique_ptr<Botan::RandomNumberGenerator>’ to ‘Botan::RandomNumberGenerator&’
/usr/local/include/botan-2/botan/mceliece.h:70:29: note: candidate: ‘Botan::McEliece_PrivateKey::McEliece_PrivateKey(const Botan::McEliece_PrivateKey&)’
 class BOTAN_PUBLIC_API(2,0) McEliece_PrivateKey final : public virtual McEliece_PublicKey,
                             ^~~~~~~~~~~~~~~~~~~
/usr/local/include/botan-2/botan/mceliece.h:70:29: note:   candidate expects 1 argument, 3 provided
/usr/local/include/botan-2/botan/mceliece.h:70:29: note: candidate: ‘Botan::McEliece_PrivateKey::McEliece_PrivateKey(Botan::McEliece_PrivateKey&&)’
/usr/local/include/botan-2/botan/mceliece.h:70:29: note:   candidate expects 1 argument, 3 provided

这是原始的例子,但我提到过,这是过时的,根本不起作用:

代码语言:javascript
复制
#include <botan/mce_kem.h>

u32bit n = 6624;
u32bit t = 115;

// key generation:
// create a new McEliece private key with code length n and error weight t
McEliece_PrivateKey sk1(rng, n, t);

// derive the corresponding public key
McEliece_PublicKey pk1 (*dynamic_cast<McEliece_PublicKey*>(&sk1));

// encode the public key
std::vector<byte> pk_enc = pk1.x509_subject_public_key();

// encode the private key
secure_vector<byte> sk_enc = sk1.pkcs8_private_key();

// code used at the encrypting side:
// decode a serialized public key
McEliece_PublicKey pk(pk_enc);
McEliece_KEM_Encryptor enc(pk);

// perform encryption
std::pair<secure_vector<Botan::byte>,secure_vector<Botan::byte> >
ciphertext__sym_key = enc.encrypt(rng);
secure_vector<Botan::byte> sym_key_encr = ciphertext__sym_key.second;
secure_vector<Botan::byte> ciphertext = ciphertext__sym_key.first;

// code used at the decrypting side:
// decode a serialized private key
McEliece_PrivateKey sk(sk_enc);
McEliece_KEM_Decryptor dec(sk);

// perform decryption
secure_vector<Botan::byte> sym_key_decr = dec.decrypt(&ciphertext[0], ciphertext.size() );

// both sides now have the same 64-byte symmetric key.
// use this key to instantiate an authenticated encryption scheme.
// in case shorter keys are needed, they can simple be cut off.

提前感谢您的帮助。

"@Swift -星期五派“是的,这是个错误。但现在又出现了另一种情况。因此RandomNumberGenerator是一个抽象类,我不能创建它的任何实例。因此,我尝试使用从RandomNumnerGenerator继承的类。我的代码:

代码语言:javascript
复制
  1 //#include <botan/botan.h>
  2 #include <botan/rng.h>
  3 #include <botan/system_rng.h>
  4 #include <botan/auto_rng.h>
  5 #include <botan/mceies.h>
  6 #include <botan/mceliece.h>
  7 #include <iostream>
  8
  9 int main() {
 10
 11    Botan::size_t n = 6624;
 12    Botan::size_t t = 115;
 13
 14    //std::unique_ptr<Botan::RandomNumberGenerator> rng;
 15    //RandomNumberGenerator rng = RandomNumberGenerator();
 16
 17    //McEliece_PrivateKey sk1();
 18    Botan::System_RNG();
 19
 20    //Botan::McEliece_PrivateKey sk1(*system_rng, n, t);
 21
 22    //std::cout << typeid(sk1).name() << std::endl;
 23    //std::cout << typeid(rng).name() << std::endl;
 24    //std::cout << rng->next_byte() << std::endl;
 25
 26    return 0;
 27 }

它输出以下错误:

代码语言:javascript
复制
:~/projects $ g++ mc_eliece2.cpp -o mc_eliece2 -I/usr/local/include/botan-2/ -L/usr/local/lib
/usr/bin/ld: /tmp/cc2YcGqo.o: in function `Botan::RandomNumberGenerator::~RandomNumberGenerator()':
mc_eliece2.cpp:(.text._ZN5Botan21RandomNumberGeneratorD2Ev[_ZN5Botan21RandomNumberGeneratorD5Ev]+0x30): undefined reference to `vtable for Botan::RandomNumberGenerator'
/usr/bin/ld: /tmp/cc2YcGqo.o: in function `Botan::System_RNG::name[abi:cxx11]() const':
mc_eliece2.cpp:(.text._ZNK5Botan10System_RNG4nameB5cxx11Ev[_ZNK5Botan10System_RNG4nameB5cxx11Ev]+0x14): undefined reference to `Botan::system_rng()'
/usr/bin/ld: /tmp/cc2YcGqo.o: in function `Botan::System_RNG::randomize(unsigned char*, unsigned int)':
mc_eliece2.cpp:(.text._ZN5Botan10System_RNG9randomizeEPhj[_ZN5Botan10System_RNG9randomizeEPhj]+0x18): undefined reference to `Botan::system_rng()'
/usr/bin/ld: /tmp/cc2YcGqo.o: in function `Botan::System_RNG::add_entropy(unsigned char const*, unsigned int)':
mc_eliece2.cpp:(.text._ZN5Botan10System_RNG11add_entropyEPKhj[_ZN5Botan10System_RNG11add_entropyEPKhj]+0x18): undefined reference to `Botan::system_rng()'
/usr/bin/ld: /tmp/cc2YcGqo.o: in function `Botan::System_RNG::is_seeded() const':
mc_eliece2.cpp:(.text._ZNK5Botan10System_RNG9is_seededEv[_ZNK5Botan10System_RNG9is_seededEv]+0x10): undefined reference to `Botan::system_rng()'
/usr/bin/ld: /tmp/cc2YcGqo.o: in function `Botan::System_RNG::accepts_input() const':
mc_eliece2.cpp:(.text._ZNK5Botan10System_RNG13accepts_inputEv[_ZNK5Botan10System_RNG13accepts_inputEv]+0x10): undefined reference to `Botan::system_rng()'
/usr/bin/ld: /tmp/cc2YcGqo.o:mc_eliece2.cpp:(.text._ZN5Botan10System_RNG5clearEv[_ZN5Botan10System_RNG5clearEv]+0x10): more undefined references to `Botan::system_rng()' follow
/usr/bin/ld: /tmp/cc2YcGqo.o:(.rodata._ZTVN5Botan10System_RNGE[_ZTVN5Botan10System_RNGE]+0x1c): undefined reference to `Botan::RandomNumberGenerator::randomize_with_input(unsigned char*, unsigned int, unsigned char const*, unsigned int)'
/usr/bin/ld: /tmp/cc2YcGqo.o:(.rodata._ZTVN5Botan10System_RNGE[_ZTVN5Botan10System_RNGE]+0x20): undefined reference to `Botan::RandomNumberGenerator::randomize_with_ts_input(unsigned char*, unsigned int)'
/usr/bin/ld: /tmp/cc2YcGqo.o:(.rodata._ZTVN5Botan10System_RNGE[_ZTVN5Botan10System_RNGE]+0x30): undefined reference to `Botan::RandomNumberGenerator::reseed(Botan::Entropy_Sources&, unsigned int, std::chrono::duration<long long, std::ratio<1ll, 1000ll> >)'
/usr/bin/ld: /tmp/cc2YcGqo.o:(.rodata._ZTVN5Botan10System_RNGE[_ZTVN5Botan10System_RNGE]+0x34): undefined reference to `Botan::RandomNumberGenerator::reseed_from_rng(Botan::RandomNumberGenerator&, unsigned int)'
/usr/bin/ld: /tmp/cc2YcGqo.o:(.rodata._ZTIN5Botan10System_RNGE[_ZTIN5Botan10System_RNGE]+0x8): undefined reference to `typeinfo for Botan::RandomNumberGenerator'
collect2: error: ld returned 1 exit status

不知何故,它找不到引用,但库是链接的,并且包含了头文件。我不知道为什么会发生这样的事情。

EN

回答 1

Stack Overflow用户

发布于 2020-08-09 02:16:30

你在哪里看到了5?错误日志显示大约有3个版本的重载构造函数接受3个参数,只有一个接受多项式的版本使用了4个向量。所需候选人如下所示:

代码语言:javascript
复制
Botan::McEliece_PrivateKey::McEliece_PrivateKey(
          Botan::RandomNumberGenerator&, std::size_t, std::size_t)

可能的原因是您传递了错误的参数。你的rng是一个指针(智能指针),但是随机生成器的第一个参数接受一个引用。

代码语言:javascript
复制
Botan::McEliece_PrivateKey sk1(*rng, n, t);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63318666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档