mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-27 00:30:26 +08:00
unit tests for IV change.
This commit is contained in:
@@ -154,7 +154,7 @@ CClient::connect()
|
||||
|
||||
if (s_cryptoEnabled) {
|
||||
CCryptoStream* cryptoStream = new CCryptoStream(*EVENTQUEUE, m_stream, true);
|
||||
cryptoStream->setKeyWithIV(g_key, sizeof(g_key), g_iv);
|
||||
cryptoStream->setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
m_stream = cryptoStream;
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ CClientListener::handleClientConnecting(const CEvent&, void*)
|
||||
|
||||
if (s_cryptoEnabled) {
|
||||
CCryptoStream* cryptoStream = new CCryptoStream(*EVENTQUEUE, stream, true);
|
||||
cryptoStream->setKeyWithIV(g_key, sizeof(g_key), g_iv);
|
||||
cryptoStream->setKeyWithIv(g_key, sizeof(g_key), g_iv);
|
||||
stream = cryptoStream;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace CryptoPP;
|
||||
using namespace CryptoPP;
|
||||
|
||||
CCryptoStream::CCryptoStream(IEventQueue& eventQueue, synergy::IStream* stream, bool adoptStream) :
|
||||
CStreamFilter(eventQueue, stream, adoptStream),
|
||||
@@ -73,9 +73,11 @@ CCryptoStream::write(const void* in, UInt32 n)
|
||||
}
|
||||
|
||||
void
|
||||
CCryptoStream::setKeyWithIV(const byte* key, size_t length, const byte* iv)
|
||||
CCryptoStream::setKeyWithIv(const byte* key, size_t length, const byte* iv)
|
||||
{
|
||||
LOG((CLOG_DEBUG "crypto: key=%s (%i) iv=%s", key, length, iv));
|
||||
logBuffer("iv", key, length);
|
||||
logBuffer("key", iv, CRYPTO_IV_SIZE);
|
||||
|
||||
m_encryption.SetKeyWithIV(key, length, iv);
|
||||
m_decryption.SetKeyWithIV(key, length, iv);
|
||||
|
||||
@@ -84,13 +86,20 @@ CCryptoStream::setKeyWithIV(const byte* key, size_t length, const byte* iv)
|
||||
}
|
||||
|
||||
void
|
||||
CCryptoStream::setIV(const byte* iv)
|
||||
CCryptoStream::setIv(const byte* iv)
|
||||
{
|
||||
assert(m_key != NULL);
|
||||
LOG((CLOG_DEBUG "crypto: new iv=%s", iv));
|
||||
logBuffer("iv", iv, CRYPTO_IV_SIZE);
|
||||
m_encryption.SetKeyWithIV(m_key, m_keyLength, iv);
|
||||
m_decryption.SetKeyWithIV(m_key, m_keyLength, iv);
|
||||
}
|
||||
|
||||
void
|
||||
CCryptoStream::newIv(byte* out)
|
||||
{
|
||||
m_autoSeedRandomPool.GenerateBlock(out, CRYPTO_IV_SIZE);
|
||||
setIv(out);
|
||||
}
|
||||
|
||||
void
|
||||
CCryptoStream::logBuffer(const char* name, const byte* buf, int length)
|
||||
|
||||
@@ -19,9 +19,12 @@
|
||||
|
||||
#include "BasicTypes.h"
|
||||
#include "CStreamFilter.h"
|
||||
#include "cryptopp562/gcm.h"
|
||||
#include "cryptopp562/modes.h"
|
||||
#include "cryptopp562/aes.h"
|
||||
#include <cryptopp562/gcm.h>
|
||||
#include <cryptopp562/modes.h>
|
||||
#include <cryptopp562/aes.h>
|
||||
#include <cryptopp562/osrng.h>
|
||||
|
||||
#define CRYPTO_IV_SIZE CryptoPP::AES::BLOCKSIZE
|
||||
|
||||
//! Bidirectional encrypted stream
|
||||
/*!
|
||||
@@ -49,10 +52,17 @@ public:
|
||||
virtual void write(const void* in, UInt32 n);
|
||||
|
||||
//! Set the key and IV
|
||||
void setKeyWithIV(const byte* key, size_t length, const byte* iv);
|
||||
void setKeyWithIv(const byte* key, size_t length, const byte* iv);
|
||||
|
||||
//! Set the IV
|
||||
void setIV(const byte* iv);
|
||||
void setIv(const byte* iv);
|
||||
|
||||
//! Get a new IV
|
||||
/*!
|
||||
Writes a new IV to the \c out buffer, and also uses the IV for further
|
||||
crypto.
|
||||
*/
|
||||
void newIv(byte* out);
|
||||
|
||||
private:
|
||||
// TODO: allow user to change the block cypher mode.
|
||||
@@ -71,7 +81,8 @@ private:
|
||||
//CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption m_decryption;
|
||||
|
||||
void logBuffer(const char* name, const byte* buf, int length);
|
||||
|
||||
|
||||
const byte* m_key;
|
||||
size_t m_keyLength;
|
||||
CryptoPP::AutoSeededRandomPool m_autoSeedRandomPool;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user