mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-11 07:10:36 +00:00
f4f5ab0109
- 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.
54 lines
1.1 KiB
C++
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);
|
|
}
|