Я хочу использовать функцию McEliece из криптобиблиотеки Botan в моем коде с RNG. Описание на странице Botan GitHub недостаточно, со ссылкой на старый пример внешнего использования, который вообще не работает.
Следовательно, я новичок в этой теме, я пытался вызывать классы и анализировать необходимые параметры, но получаю ошибки. Я предполагаю, что должно быть что-то не так с типами.
Вот мой пример кода:
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;
И вот ошибки:
~/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
И это оригинальный пример, но, как я уже упоминал, он устарел и вообще не работает:
#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 - Friday Pie Да, это была ошибка. Но сейчас другой случай. Следовательно, RandomNumberGenerator - это абстрактный класс, я не могу создавать его экземпляры. Поэтому я попытался использовать класс, который наследуется от RandomNumnerGenerator. Мой код:
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 }
Выдает следующие ошибки:
:~/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
Ссылки почему-то не находит, но библиотека подключена, и заголовки включены. Я понятия не имею, почему это происходит.