open-quantum-safe / liboqs-cpp

C++ bindings for liboqs
https://openquantumsafe.org/
MIT License
33 stars 8 forks source link

Return shared_secret_server #9

Closed RohitArora7 closed 1 year ago

RohitArora7 commented 1 year ago

Hi Team ,

How can i return shared_secret_server ?

the below code will give me an error because function is int main () and i am returning byte value

#include <chrono>
#include <iostream>
#include <string>
#include <tuple>
#include <algorithm>
// liboqs C++ wrapper
#include "oqs_cpp.h"

using namespace std;

int main() {

    std::string kem_name = "Kyber512";
    oqs::KeyEncapsulation client{kem_name};

    oqs::bytes client_public_key = client.generate_keypair();

    oqs::KeyEncapsulation server{kem_name};

    oqs::bytes ciphertext, shared_secret_server;

    std::tie(ciphertext, shared_secret_server) =  server.encap_secret(client_public_key);

    std::cout << shared_secret_server;
    std::cout << "\n\nHEX_CHOP:\n" << oqs::hex_chop(shared_secret_server) << '\n';

    return shared_secret_server;
}
vsoftco commented 1 year ago

oqs::bytes is a typedef using bytes = std::vector<byte>; ///< vector of bytes (unsigned), defined here https://github.com/open-quantum-safe/liboqs-cpp/blob/0f757a73cb728d26177897395590742084ba5e5c/include/common.h#L26. main() should return an int. So there's a type incompatibility. main() cannot return anything else but int. You can print out the secret if you want, by doing std::cout << shared_secret_server << '\n';.