Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit eb8d9e5

Browse files
committed
WIP
1 parent c6537e4 commit eb8d9e5

File tree

10 files changed

+79
-8
lines changed

10 files changed

+79
-8
lines changed

.qmake.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ CONFIG += warning_clean exceptions c++17
66
DEFINES += QT_DEPRECATED_WARNINGS QT_ASCII_CAST_WARNINGS
77

88
MODULE_VERSION_MAJOR = 4
9-
MODULE_VERSION_MINOR = 2
10-
MODULE_VERSION_PATCH = 3
9+
MODULE_VERSION_MINOR = 3
10+
MODULE_VERSION_PATCH = 0
1111
MODULE_VERSION_IMPORT = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}
1212
MODULE_VERSION = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}.$${MODULE_VERSION_PATCH}
1313

src/datasync/cryptocontroller.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
using namespace QtDataSync;
2626
using namespace CryptoPP;
27+
using namespace CryptoQQ;
2728
using std::tuple;
2829
using std::make_tuple;
2930
using Exception = QtDataSync::Exception;
@@ -1142,6 +1143,8 @@ void ClientCrypto::setSignatureKey(const QByteArray &name)
11421143
_signKey.reset(new EccKeyScheme<EcdsaScheme>());
11431144
else if(stdStr == EcnrScheme::StaticAlgorithmName())
11441145
_signKey.reset(new EccKeyScheme<EcnrScheme>());
1146+
else if(stdStr == "ed25519")
1147+
_signKey.reset(new EccKeyScheme<Ed25519Scheme>());
11451148
else
11461149
throw CryptoPP::Exception(CryptoPP::Exception::NOT_IMPLEMENTED, "Signature Scheme \"" + stdStr + "\" not supported");
11471150
}
@@ -1158,6 +1161,9 @@ void ClientCrypto::setSignatureKey(Setup::SignatureScheme scheme)
11581161
case Setup::ECNR_ECP_SHA3_512:
11591162
setSignatureKey(QByteArray::fromStdString(EcnrScheme::StaticAlgorithmName()));
11601163
break;
1164+
case Setup::ED25519:
1165+
setSignatureKey(QByteArray::fromStdString("ed25519"));
1166+
break;
11611167
default:
11621168
Q_UNREACHABLE();
11631169
break;

src/datasync/defaults.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ QVariant Defaults::defaultParam(Setup::SignatureScheme scheme)
105105
case Setup::ECDSA_ECP_SHA3_512:
106106
case Setup::ECNR_ECP_SHA3_512:
107107
return Setup::brainpoolP384r1;
108+
case Setup::ED25519:
109+
return QVariant{};
108110
default:
109111
Q_UNREACHABLE();
110112
break;

src/datasync/setup.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Setup &Setup::resetKeyStoreProvider()
385385

386386
Setup &Setup::resetSignatureScheme()
387387
{
388-
d->properties.insert(Defaults::SignScheme, ECDSA_ECP_SHA3_512);
388+
d->properties.insert(Defaults::SignScheme, ED25519);
389389
return *this;
390390
}
391391

@@ -634,7 +634,7 @@ SetupPrivate::SetupPrivate() :
634634
{Defaults::PersistDeleted, false},
635635
{Defaults::ConflictPolicy, Setup::PreferChanged},
636636
{Defaults::SslConfiguration, QVariant::fromValue(QSslConfiguration::defaultConfiguration())},
637-
{Defaults::SignScheme, Setup::ECDSA_ECP_SHA3_512},
637+
{Defaults::SignScheme, Setup::ED25519},
638638
{Defaults::CryptScheme, Setup::ECIES_ECP_SHA3_512},
639639
{Defaults::SymScheme, Setup::AES_EAX},
640640
{Defaults::EventLoggingMode, QVariant::fromValue(Setup::EventMode::Unchanged)}

src/datasync/setup.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class Q_DATASYNC_EXPORT Setup
113113
enum SignatureScheme {
114114
RSA_PSS_SHA3_512, //!< RSA in PSS mode with Sha3 hash of 512 bits
115115
ECDSA_ECP_SHA3_512, //!< ECDSA on prime curves with Sha3 hash of 512 bits
116-
ECNR_ECP_SHA3_512 //!< ECNR on prime curves with Sha3 hash of 512 bits
116+
ECNR_ECP_SHA3_512, //!< ECNR on prime curves with Sha3 hash of 512 bits
117+
ED25519 //!< ed25519 signature scheme based on the ed25519 curve (Requires at least crypto++ 8.0)
117118
};
118119
Q_ENUM(SignatureScheme)
119120

src/imports/datasync/plugins.qmltypes

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
44
// It is used for QML tooling purposes only.
55
//
66
// This file was auto-generated by:
7-
// 'qmlplugindump -nonrelocatable de.skycoder42.QtDataSync 4.2'
7+
// 'qmlplugindump -nonrelocatable de.skycoder42.QtDataSync 4.3'
88

99
Module {
1010
dependencies: ["QtQml 2.2", "QtQml.Models 2.2"]

src/imports/datasync/qtdatasync_plugin.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ void QtDataSyncDeclarativeModule::registerTypes(const char *uri)
6666
qmlRegisterSingletonType<QtDataSync::QQmlIosSyncSingleton>(uri, 4, 2, "IosSyncSingleton", createIosSyncSingletonInstance);
6767
#endif
6868

69+
//Version 4.3
70+
qmlRegisterModule(uri, 4, 3);
71+
6972
// Check to make shure no module update is forgotten
70-
static_assert(VERSION_MAJOR == 4 && VERSION_MINOR == 2, "QML module version needs to be updated");
73+
static_assert(VERSION_MAJOR == 4 && VERSION_MINOR == 3, "QML module version needs to be updated");
7174

7275
}

src/messages/asymmetriccrypto.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using namespace QtDataSync;
99
using namespace CryptoPP;
10+
using namespace CryptoQQ;
1011

1112
template <typename TScheme>
1213
class SignatureScheme : public AsymmetricCrypto::Signature
@@ -28,6 +29,15 @@ class EncryptionScheme : public AsymmetricCrypto::Encryption
2829
QSharedPointer<PK_Decryptor> decrypt(const PKCS8PrivateKey &pKey) const override;
2930
};
3031

32+
template <>
33+
QByteArray SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::name() const;
34+
template <>
35+
QSharedPointer<X509PublicKey> SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::createNullKey() const;
36+
template <>
37+
QSharedPointer<PK_Signer> SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::sign(const PKCS8PrivateKey &pKey) const;
38+
template <>
39+
QSharedPointer<PK_Verifier> SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::verify(const X509PublicKey &pubKey) const;
40+
3141
// ------------- Main Implementation -------------
3242

3343
AsymmetricCrypto::AsymmetricCrypto(const QByteArray &signatureScheme, const QByteArray &encryptionScheme, QObject *parent) :
@@ -143,6 +153,8 @@ void AsymmetricCrypto::setSignatureScheme(const QByteArray &name)
143153
_signature.reset(new SignatureScheme<EcdsaScheme>());
144154
else if(stdStr == EcnrScheme::StaticAlgorithmName())
145155
_signature.reset(new SignatureScheme<EcnrScheme>());
156+
else if(stdStr == "ed25519")
157+
_signature.reset(new SignatureScheme<Ed25519Scheme>());
146158
else
147159
throw Exception(Exception::NOT_IMPLEMENTED, "Signature Scheme \"" + stdStr + "\" not supported");
148160
}
@@ -234,6 +246,34 @@ QSharedPointer<PK_Verifier> SignatureScheme<TScheme>::verify(const X509PublicKey
234246
return QSharedPointer<typename TScheme::Verifier>::create(pubKey);
235247
}
236248

249+
template <>
250+
QByteArray SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::name() const
251+
{
252+
return "ed25519";
253+
}
254+
255+
template <>
256+
QSharedPointer<X509PublicKey> SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::createNullKey() const
257+
{
258+
return QSharedPointer<ed25519PublicKey>::create();
259+
}
260+
261+
template <>
262+
QSharedPointer<PK_Signer> SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::sign(const PKCS8PrivateKey &pKey) const
263+
{
264+
auto signer = QSharedPointer<AsymmetricCrypto::Ed25519Scheme::Signer>();
265+
signer->AccessPrivateKey().AssignFrom(pKey);
266+
return signer;
267+
}
268+
269+
template <>
270+
QSharedPointer<PK_Verifier> SignatureScheme<AsymmetricCrypto::Ed25519Scheme>::verify(const X509PublicKey &pubKey) const
271+
{
272+
auto verifier = QSharedPointer<AsymmetricCrypto::Ed25519Scheme::Verifier>();
273+
verifier->AccessKey().AssignFrom(pubKey);
274+
return verifier;
275+
}
276+
237277

238278

239279
template <typename TScheme>

src/messages/asymmetriccrypto_p.h

+10
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
#include <cryptopp/pssr.h>
99
#include <cryptopp/eccrypto.h>
1010
#include <cryptopp/sha3.h>
11+
#if CRYPTOPP_VERSION >= 800
12+
#include <cryptopp/xed25519.h>
13+
#endif
1114

1215
#include "message_p.h"
1316

17+
template <typename T>
18+
class SignatureScheme;
19+
1420
namespace QtDataSync {
1521

1622
class Q_DATASYNC_EXPORT AsymmetricCrypto : public QObject
@@ -84,6 +90,10 @@ class Q_DATASYNC_EXPORT AsymmetricCrypto : public QObject
8490
#if CRYPTOPP_VERSION >= 600
8591
using EciesScheme = CryptoPP::ECIES<CryptoPP::ECP, CryptoPP::SHA3_512>;
8692
#endif
93+
#if CRYPTOPP_VERSION >= 800
94+
using Ed25519Scheme = CryptoPP::ed25519;
95+
friend class SignatureScheme<Ed25519Scheme>;
96+
#endif
8797

8898
explicit AsymmetricCrypto(QObject *parent = nullptr);
8999

tests/auto/datasync/TestCryptoController/tst_cryptocontroller.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,23 @@ void TestCryptoController::cryptoData()
383383
<< QVariant(2048)
384384
#endif
385385
<< true
386-
<< false;
386+
<< true;
387387

388388
QTest::newRow("ECNR:secp256r1") << Setup::ECNR_ECP_SHA3_512
389389
<< QVariant(Setup::secp256r1)
390390
<< Setup::RSA_OAEP_SHA3_512
391391
<< QVariant(2048)
392392
<< true
393393
<< false;
394+
395+
#if CRYPTOPP_VERSION > 1000
396+
QTest::newRow("ECNR:secp256r1") << Setup::ED25519
397+
<< QVariant{}
398+
<< Setup::RSA_OAEP_SHA3_512
399+
<< QVariant(1024)
400+
<< true
401+
<< false;
402+
#endif
394403
}
395404

396405
void TestCryptoController::symData()

0 commit comments

Comments
 (0)