2018-08-13 23:22:31 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <llarp/crypto.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-09-02 18:25:42 +00:00
|
|
|
struct PQCryptoTest : public ::testing::Test
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2018-09-02 18:25:42 +00:00
|
|
|
llarp_crypto crypto;
|
|
|
|
PQKeyPair keys;
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
PQCryptoTest()
|
|
|
|
{
|
|
|
|
llarp_crypto_init(&crypto);
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
llarp_crypto*
|
|
|
|
Crypto()
|
|
|
|
{
|
|
|
|
return &crypto;
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
void
|
|
|
|
SetUp()
|
|
|
|
{
|
|
|
|
crypto.pqe_keygen(keys);
|
|
|
|
}
|
|
|
|
};
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
TEST_F(PQCryptoTest, TestCrypto)
|
|
|
|
{
|
|
|
|
PQCipherBlock block;
|
|
|
|
SharedSecret shared, otherShared;
|
|
|
|
auto c = Crypto();
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
ASSERT_TRUE(keys.size() == PQ_KEYPAIRSIZE);
|
|
|
|
ASSERT_TRUE(c->pqe_encrypt(block, shared, pq_keypair_to_public(keys)));
|
|
|
|
ASSERT_TRUE(c->pqe_decrypt(block, otherShared, pq_keypair_to_secret(keys)));
|
|
|
|
ASSERT_TRUE(otherShared == shared);
|
|
|
|
}
|
|
|
|
} // namespace llarp
|