Drop libgcrypt dependency for qt5
This commit is contained in:
parent
7eed007f14
commit
355de8fba4
2 changed files with 46 additions and 24 deletions
|
@ -4,8 +4,6 @@
|
|||
|
||||
PROJECT(servatrice)
|
||||
|
||||
FIND_PACKAGE(Libgcrypt REQUIRED)
|
||||
|
||||
SET(servatrice_SOURCES
|
||||
src/main.cpp
|
||||
src/passwordhasher.cpp
|
||||
|
@ -29,6 +27,10 @@ if(Qt4_FOUND)
|
|||
INCLUDE(${QT_USE_FILE})
|
||||
include_directories(${QT_INCLUDES})
|
||||
LIST(APPEND SERVATRICE_LIBS ${QT_LIBRARIES})
|
||||
|
||||
# Libgcrypt is required only with Qt4 to support SHA512 hashing
|
||||
FIND_PACKAGE(Libgcrypt REQUIRED)
|
||||
INCLUDE_DIRECTORIES(${LIBGCRYPT_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# qt5 stuff
|
||||
|
@ -60,7 +62,6 @@ SET(QT_DONT_USE_QTGUI TRUE)
|
|||
|
||||
# Include directories
|
||||
INCLUDE_DIRECTORIES(../common)
|
||||
INCLUDE_DIRECTORIES(${LIBGCRYPT_INCLUDE_DIR})
|
||||
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../common)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
#include "passwordhasher.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <gcrypt.h>
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <gcrypt.h>
|
||||
#else
|
||||
#include <QCryptographicHash>
|
||||
#endif
|
||||
|
||||
void PasswordHasher::initialize()
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
// These calls are required by libgcrypt before we use any of its functions.
|
||||
gcry_check_version(0);
|
||||
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
|
||||
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
QString PasswordHasher::computeHash(const QString &password, const QString &salt)
|
||||
{
|
||||
const int algo = GCRY_MD_SHA512;
|
||||
|
@ -29,4 +37,17 @@ QString PasswordHasher::computeHash(const QString &password, const QString &salt
|
|||
delete[] hash;
|
||||
return hashedPass;
|
||||
}
|
||||
#else
|
||||
QString PasswordHasher::computeHash(const QString &password, const QString &salt)
|
||||
{
|
||||
QCryptographicHash::Algorithm algo = QCryptographicHash::Sha512;
|
||||
const int rounds = 1000;
|
||||
|
||||
QByteArray hash = (salt + password).toUtf8();
|
||||
for (int i = 0; i < rounds; ++i) {
|
||||
hash = QCryptographicHash::hash(hash, algo);
|
||||
}
|
||||
QString hashedPass = salt + QString(hash.toBase64());
|
||||
return hashedPass;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue