[英]Unable initializing McEliece function in Botan with RNG
I want to use the McEliece function from Botan cryptolibrary within my code with a RNG.我想在我的代码中使用来自 Botan 密码库的 McEliece function 和 RNG。 The description at the Botan GitHub page is insufficient, with a reference to an old external usage example, which does not work at all.
Botan GitHub 页面上的描述不充分,参考了一个旧的外部使用示例,完全不起作用。
Hence i am new to this topic, i tried to call the classes and parse the required parameters, but i get errors.因此我是这个主题的新手,我试图调用类并解析所需的参数,但我得到了错误。 I assume there must be something wrong with the types.
我认为类型一定有问题。
Here is my code example:这是我的代码示例:
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;
And here are the errors:以下是错误:
~/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
And this is the original example, but ai mentioned, this is outdated and does not work at all:这是原来的例子,但ai提到,这是过时的,根本不起作用:
#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.
Thx for your help in advance.感谢您提前提供帮助。
"@Swift - Friday Pie" Yes, this was the mistakte. “@Swift - Friday Pie”是的,这是错误的。 But now there is another case.
但现在还有另一种情况。 Hence RandomNumberGenerator is an abstract class, i can't make any instances of it.
因此 RandomNumberGenerator 是一个抽象的 class,我不能创建它的任何实例。 Therefore i tried to use a class which inherits from RandomNumnerGenerator.
因此,我尝试使用继承自 RandomNumnerGenerator 的 class。 My Code:
我的代码:
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 }
It outputs the following errors:它输出以下错误:
:~/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
It somehow can't find the references, but the library is linked, and the headers are included.它以某种方式找不到引用,但库已链接,并且包含标题。 I have no clue why this is happening.
我不知道为什么会这样。
where you see 5?你在哪里看到 5? Error log says about 3 versions overloaded constructor that take 3 parameters, only one that accepts a polynomial uses 4 vectors in addition to it.
错误日志说大约 3 个版本的重载构造函数采用 3 个参数,只有一个接受多项式的版本除此之外还使用 4 个向量。 Required candidate looks like:
所需的候选人看起来像:
Botan::McEliece_PrivateKey::McEliece_PrivateKey(
Botan::RandomNumberGenerator&, std::size_t, std::size_t)
The likely reason is that you pass wrong arguments.可能的原因是您传递了错误的 arguments。 Your
rng
is a pointer (smart pointer), but first argument for random generator accepts a reference.您的
rng
是一个指针(智能指针),但随机生成器的第一个参数接受一个引用。
Botan::McEliece_PrivateKey sk1(*rng, n, t);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.