mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-27 00:30:26 +08:00
crypto++ -- upgraded to 5.6.2 and added zip to svn instead of individual source files (easier to manage). also added unit test to prove that linking works well on windows.
This commit is contained in:
42
src/lib/synergy/CCrypto.cpp
Normal file
42
src/lib/synergy/CCrypto.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012 Bolton Software Ltd.
|
||||
* Copyright (C) 2002 Chris Schoeneman
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CCrypto.h"
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include "default.h"
|
||||
#include "modes.h"
|
||||
#include "aes.h"
|
||||
#include "randpool.h"
|
||||
#include "files.h"
|
||||
#include "hex.h"
|
||||
#include "rsa.h"
|
||||
#include <time.h>
|
||||
|
||||
using namespace CryptoPP;
|
||||
|
||||
static OFB_Mode<AES>::Encryption s_globalRNG;
|
||||
|
||||
void CCrypto::test()
|
||||
{
|
||||
std::string seed = IntToString(time(NULL));
|
||||
seed.resize(16);
|
||||
s_globalRNG.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
|
||||
}
|
||||
24
src/lib/synergy/CCrypto.h
Normal file
24
src/lib/synergy/CCrypto.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012 Bolton Software Ltd.
|
||||
* Copyright (C) 2002 Chris Schoeneman
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class CCrypto {
|
||||
public:
|
||||
void test();
|
||||
};
|
||||
@@ -50,6 +50,7 @@ set(inc
|
||||
IAppUtil.h
|
||||
CEventGameDevice.h
|
||||
CVncClient.h
|
||||
CCrypto.h
|
||||
)
|
||||
|
||||
set(src
|
||||
@@ -80,7 +81,8 @@ set(src
|
||||
CArgsBase.cpp
|
||||
CEventGameDevice.cpp
|
||||
CVncClient.cpp
|
||||
CGameDevice.cpp
|
||||
CGameDevice.cpp
|
||||
CCrypto.cpp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
@@ -112,7 +114,7 @@ set(inc
|
||||
../server
|
||||
../synergy
|
||||
../..
|
||||
../../vnc/common
|
||||
../../../tools/cryptopp562
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
@@ -129,5 +131,5 @@ include_directories(${inc})
|
||||
add_library(synergy STATIC ${src})
|
||||
|
||||
if (UNIX)
|
||||
target_link_libraries(synergy arch client ipc net base platform mt server)
|
||||
target_link_libraries(synergy arch client ipc net base platform mt server cryptopp)
|
||||
endif()
|
||||
|
||||
@@ -28,7 +28,7 @@ set(src
|
||||
synergy/CClipboardTests.cpp
|
||||
synergy/CKeyStateTests.cpp
|
||||
client/CServerProxyTests.cpp
|
||||
# synergy/CCryptoTests.cpp
|
||||
synergy/CCryptoTests.cpp
|
||||
)
|
||||
|
||||
set(inc
|
||||
@@ -63,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})
|
||||
|
||||
@@ -17,44 +17,12 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
#include "gcm.h"
|
||||
#include "aes.h"
|
||||
#include "filters.h"
|
||||
#include "CCrypto.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace CryptoPP;
|
||||
|
||||
TEST(CCryptoTests, encrypt)
|
||||
TEST(CCryptoTests, test)
|
||||
{
|
||||
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);
|
||||
CCrypto crypto;
|
||||
crypto.test();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user