Skip to content

Commit

Permalink
Merge pull request #54 from QuasarApp/NameSpace
Browse files Browse the repository at this point in the history
Move INT to QRSAEncryption namespace
  • Loading branch information
EndrII authored Oct 21, 2019
2 parents 3e5cb00 + 6240b43 commit 4df74b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
19 changes: 12 additions & 7 deletions src/Qt-RSA/qrsaencryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
#include <ctime>
#include <chrono>

INT eulerFunc(const INT &p, const INT &q) {
#define KEY_GEN_LIMIT 10

const QString SIGN_MARKER = "-SIGN-";
const int signMarkerLength = SIGN_MARKER.length();

QRSAEncryption::INT eulerFunc(const QRSAEncryption::INT &p, const QRSAEncryption::INT &q) {
return (p - 1) * (q - 1);
}

Expand Down Expand Up @@ -46,7 +51,7 @@ QRSAEncryption::Rsa QRSAEncryption::getBitsSize(const QByteArray &key) const {
return QRSAEncryption::Rsa::Invalid;
}

INT QRSAEncryption::fromArray(const QByteArray &array) const {
QRSAEncryption::INT QRSAEncryption::fromArray(const QByteArray &array) const {
INT res = 0;
res.fromHex(array.toHex().toStdString());
return res;
Expand All @@ -67,7 +72,7 @@ QByteArray QRSAEncryption::toArray(const INT &i, short sizeBlok) {
return res.left(sizeBlok);
}

INT QRSAEncryption::randomNumber(bool fullFill) const {
QRSAEncryption::INT QRSAEncryption::randomNumber(bool fullFill) const {

srand(std::chrono::duration_cast<std::chrono::nanoseconds>
(std::chrono::system_clock::now().time_since_epoch()).count()
Expand All @@ -93,7 +98,7 @@ INT QRSAEncryption::randomNumber(bool fullFill) const {
return res;
}

INT QRSAEncryption::toPrime(INT n) const {
QRSAEncryption::INT QRSAEncryption::toPrime(INT n) const {
if (!(n % 2)) {
++n;
}
Expand All @@ -112,7 +117,7 @@ INT QRSAEncryption::toPrime(INT n) const {
}
}

INT QRSAEncryption::randomPrimeNumber(INT no) const {
QRSAEncryption::INT QRSAEncryption::randomPrimeNumber(INT no) const {
srand(static_cast<unsigned int>(time(nullptr)));

// max INT
Expand All @@ -124,7 +129,7 @@ INT QRSAEncryption::randomPrimeNumber(INT no) const {
return p;
}

INT QRSAEncryption::extEuclid(INT a, INT b) const {
QRSAEncryption::INT QRSAEncryption::extEuclid(INT a, INT b) const {
INT x = 0, y = 1, u = 1, v = 0, gcd = b, m, n, q, r;
while (a != 0) {
q = gcd / a;
Expand Down Expand Up @@ -255,7 +260,7 @@ bool QRSAEncryption::generatePairKey(QByteArray &pubKey, QByteArray &privKey) {
e -= 2;
} while((!isMutuallyPrime(eilor, e)));

d = extEuclid(eilor , e);;
d = extEuclid(eilor , e);

while(d < 0 ) {
d += eilor;
Expand Down
10 changes: 2 additions & 8 deletions src/Qt-RSA/qrsaencryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@

#include <bigint.h>

typedef BigInt INT;

#define KEY_GEN_LIMIT 10

static const QString SIGN_MARKER = "-SIGN-";
static const int signMarkerLength = SIGN_MARKER.length();

typedef QCryptographicHash::Algorithm HashAlgorithm;

class Qt_SECRETSHARED_EXPORT QRSAEncryption
{
public:
typedef BigInt INT;
typedef QCryptographicHash::Algorithm HashAlgorithm;

enum Rsa {
Invalid = 0,
Expand Down

0 comments on commit 4df74b4

Please sign in to comment.