【发布时间】:2020-12-20 00:03:41
【问题描述】:
我在使用 Botan 加密库的 c++ mc-eliece 实现时遇到问题。整个互联网上似乎只有一个例子,有一个链接。
https://www.cryptosource.de/docs/mceliece_in_botan.pdf
但是这个例子已经有 6 年历史了,因此它已经完全过时了,Botan 文档没有提供任何其他内容。
问题基本上是,不幸的是函数名称和规格随着时间的推移而改变,因此我在尝试使用它们时遇到了一些编译器错误。通过研究标头实现,我设法揭开了其中一些的神秘面纱。但坦率地说,我现在是在墙前。
如果任何熟悉 Botan MC-Eliece 实现的人能给我一个提示,如何调用当前函数,那就太好了。
这是我的带有标记的代码。我删除了很多不必要的代码和其他实现,使其更具可读性。如果没有必要的模块,您也将无法使其运行,但我会尝试以某种方式将其写下来,以便拥有 Botan 库的人应该能够运行它。
//to compile: g++ -o mc_eliece mc_eliece.cpp -Wall -I/usr/local/include/botan-2/ -I/home/pi/projects/RNG_final/ -ltss2-esys -ltss2-rc -lbotan-2
#include <iostream>
#include <botan/rng.h>
#include <botan/system_rng.h>
#include <botan/mceies.h>
#include <botan/mceliece.h>
int main() {
Botan::size_t n = 1632; // Parameters for key generation
Botan::size_t t = 33;
// initialize RNG type
Botan::System_RNG rng; // is a standard Botan RNG
// create a new MCEliece private key with code length n and error weigth t
Botan::McEliece_PrivateKey sk1(rng, n, t); // actually works!
// derive the corresponding public key
Botan::McEliece_PublicKey pk1(*dynamic_cast<Botan::McEliece_PublicKey*>(&sk1)); // actually works!
// encode the public key
std::vector<uint8_t> pk_enc = pk1.subject_public_key(); // actually works!
// encode the private key
Botan::secure_vector<uint8_t> sk_enc = sk1.private_key_bits(); // had to replace sk1.pkcs8_private_key()
// encryption side: decode a serialized public key
Botan::McEliece_PublicKey pk(pk_enc);
McEliece_KEM_Encryptor enc(pk); // does not work, can't find a working corresponding function in the header
// perform encryption -> will find out if it works after upper case had been solved
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: -> will find out if it works after upper case had been solved
// decode a serialized private key
McEliece_PrivateKey sk(sk_enc);
McEliece_KEM_Decryptor dec(sk);
// perform decryption -> will find out if it works after upper case had been solved
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.
return 0;
}
感谢您提前提供任何帮助。
【问题讨论】:
-
我不会使用文档和维护如此糟糕的库。
-
公钥基础设施的其他部分有更好的文档记录,并附有代码示例。不幸的是,我必须使用 MC-Eliece,因为我需要量子计算机抵抗加密密钥,这是 Botan 提供的唯一一个。 Botan 是目前使用最广泛的 c++ 密码库之一,它是开源的。
标签: c++ encryption botan