2018-08-13 23:22:31 +00:00
|
|
|
#include <gtest/gtest.h>
|
2018-12-12 00:38:58 +00:00
|
|
|
#include <crypto.hpp>
|
2018-08-13 23:22:31 +00:00
|
|
|
#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
|
|
|
{
|
2019-01-02 01:04:03 +00:00
|
|
|
llarp::Crypto crypto;
|
2018-09-02 18:25:42 +00:00
|
|
|
PQKeyPair keys;
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2019-01-02 01:04:03 +00:00
|
|
|
PQCryptoTest() : crypto(llarp::Crypto::sodium{})
|
2018-09-02 18:25:42 +00:00
|
|
|
{
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
|
2018-12-11 00:53:11 +00:00
|
|
|
llarp::Crypto*
|
2018-09-02 18:25:42 +00:00
|
|
|
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);
|
2019-01-02 01:04:06 +00:00
|
|
|
ASSERT_TRUE(
|
|
|
|
c->pqe_encrypt(block, shared, PQPubKey(pq_keypair_to_public(keys))));
|
2018-09-02 18:25:42 +00:00
|
|
|
ASSERT_TRUE(c->pqe_decrypt(block, otherShared, pq_keypair_to_secret(keys)));
|
|
|
|
ASSERT_TRUE(otherShared == shared);
|
|
|
|
}
|
|
|
|
} // namespace llarp
|