0

I want to use the McEliece function from Botan cryptolibrary within my code with a 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.

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 a i mentioned, this is outdated and does not work at all:

#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. But now there is another case. Hence RandomNumberGenerator is an abstract class, i can't make any instances of it. Therefore i tried to use a class which inherits from RandomNumnerGenerator. 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.

Leopolis
  • 35
  • 6
  • that's a second question ! and possibly a dupe, linker error means you didn't link something with your program. Be sure that it's proper libraries and of proper format, inspect the library file to make sure it exports those symbols. if it doesn't, something is wrong with it – Swift - Friday Pie Aug 09 '20 at 01:51

1 Answers1

0

where you see 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. 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. Your rng is a pointer (smart pointer), but first argument for random generator accepts a reference.

Botan::McEliece_PrivateKey sk1(*rng, n, t);
Swift - Friday Pie
  • 12,777
  • 2
  • 19
  • 42