lokinet/test/test_llarp_encrypted_frame.cpp
Jason Rhinelander f4f5ab0109 "Refactor" aka delete Crypto/CryptoManager
- Get rid of CryptoManager.
- Get rid of Crypto.
- Move all the Crypto instance methods to llarp::crypto functions.
  (None of them needed to be methods at all, so this is simple).
- Move sodium/ntru initialization into static initialization.
- Add llarp::csrng, which is an available llarp::CSRNG instance which is
  a bit easier than needing to construct a `CSRNG rng{};` in various
  places.
- Various related small simplifications/cleanups.
2023-10-24 08:40:18 -07:00

54 lines
1.1 KiB
C++

#include "llarp_test.hpp"
#include "test_util.hpp"
#include <llarp/crypto/encrypted_frame.hpp>
#include <llarp/crypto/crypto.hpp>
#include <llarp/messages/relay_commit.hpp>
#include <catch2/catch.hpp>
using namespace ::llarp;
using EncryptedFrame = EncryptedFrame;
using SecretKey = SecretKey;
using PubKey = PubKey;
using LRCR = LR_CommitRecord;
class FrameTest
{
public:
FrameTest() : test::LlarpTest<>{}
{
crypto::encryption_keygen(alice);
crypto::encryption_keygen(bob);
}
SecretKey alice, bob;
};
TEST_CASE_METHOD(FrameTest, "Frame crypto")
{
EncryptedFrame f{256};
f.Fill(0);
LRCR record{};
record.nextHop.Fill(1);
record.tunnelNonce.Fill(2);
record.rxid.Fill(3);
record.txid.Fill(4);
auto buf = f.Buffer();
buf->cur = buf->base + EncryptedFrameOverheadSize;
REQUIRE(record.BEncode(buf));
// rewind buffer
buf->cur = buf->base + EncryptedFrameOverheadSize;
// encrypt to alice
REQUIRE(f.EncryptInPlace(alice, bob.toPublic()));
// decrypt from alice
REQUIRE(f.DecryptInPlace(bob));
LRCR otherRecord;
REQUIRE(otherRecord.BDecode(buf));
REQUIRE(otherRecord == record);
}