mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-11 00:58:14 +08:00
added crypto++ library and example authenticated encryption unit test (CCryptoTests)
This commit is contained in:
@@ -28,6 +28,7 @@ set(src
|
||||
synergy/CClipboardTests.cpp
|
||||
synergy/CKeyStateTests.cpp
|
||||
client/CServerProxyTests.cpp
|
||||
synergy/CCryptoTests.cpp
|
||||
)
|
||||
|
||||
set(inc
|
||||
@@ -42,6 +43,7 @@ set(inc
|
||||
../../lib/synergy
|
||||
../../../tools/gtest-1.6.0/include
|
||||
../../../tools/gmock-1.6.0/include
|
||||
../../../tools/cryptopp561
|
||||
io
|
||||
synergy
|
||||
)
|
||||
@@ -61,4 +63,4 @@ endif()
|
||||
include_directories(${inc})
|
||||
add_executable(unittests ${src})
|
||||
target_link_libraries(unittests
|
||||
arch base client common io net platform server synergy mt gtest gmock ${libs})
|
||||
arch base client common io net platform server synergy mt gtest gmock cryptopp ${libs})
|
||||
|
||||
61
src/test/unittests/synergy/CCryptoTests.cpp
Normal file
61
src/test/unittests/synergy/CCryptoTests.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012 Bolton Software Ltd.
|
||||
* Copyright (C) 2011 Nick Bolton
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "CClipboard.h"
|
||||
#include <string>
|
||||
#include "gcm.h"
|
||||
#include "aes.h"
|
||||
#include "filters.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace CryptoPP;
|
||||
|
||||
TEST(CCryptoTests, encrypt)
|
||||
{
|
||||
string plaintext = "hello", ciphertext;
|
||||
const byte key[] = "123456781234567";
|
||||
const byte iv[] = "123456781234567";
|
||||
|
||||
GCM<AES>::Encryption enc;
|
||||
enc.SetKeyWithIV(key, sizeof(key), iv, sizeof(iv));
|
||||
|
||||
AuthenticatedEncryptionFilter aef(enc, new StringSink(ciphertext));
|
||||
|
||||
aef.Put((const byte*)plaintext.data(), plaintext.size());
|
||||
aef.MessageEnd();
|
||||
|
||||
EXPECT_EQ("Vh\x86r\xF4\xD0\xD7\xE0\x95\xDE\xCB\xB7\xFA@\v\xFE\xEE\\\xF8\xE8V", ciphertext);
|
||||
}
|
||||
|
||||
TEST(CCryptoTests, decrypt)
|
||||
{
|
||||
string ciphertext = "Vh\x86r\xF4\xD0\xD7\xE0\x95\xDE\xCB\xB7\xFA@\v\xFE\xEE\\\xF8\xE8V", plaintext;
|
||||
const byte key[] = "123456781234567";
|
||||
const byte iv[] = "123456781234567";
|
||||
|
||||
GCM<AES>::Decryption dec;
|
||||
dec.SetKeyWithIV(key, sizeof(key), iv, sizeof(iv));
|
||||
|
||||
AuthenticatedDecryptionFilter adf(dec, new StringSink(plaintext));
|
||||
|
||||
adf.Put((const byte*)ciphertext.data(), ciphertext.size());
|
||||
adf.MessageEnd();
|
||||
|
||||
EXPECT_EQ("hello", plaintext);
|
||||
}
|
||||
Reference in New Issue
Block a user