Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
283bac0b
Commit
283bac0b
authored
Oct 02, 2014
by
Gavin Bisesi
Browse files
Merge pull request #339 from ctrlaltca/qt5_no_libgcrypt
Drop libgcrypt dependency for qt5
parents
55b20343
355de8fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
servatrice/CMakeLists.txt
View file @
283bac0b
...
@@ -4,8 +4,6 @@
...
@@ -4,8 +4,6 @@
PROJECT
(
servatrice
)
PROJECT
(
servatrice
)
FIND_PACKAGE
(
Libgcrypt REQUIRED
)
SET
(
servatrice_SOURCES
SET
(
servatrice_SOURCES
src/main.cpp
src/main.cpp
src/passwordhasher.cpp
src/passwordhasher.cpp
...
@@ -29,6 +27,10 @@ if(Qt4_FOUND)
...
@@ -29,6 +27,10 @@ if(Qt4_FOUND)
INCLUDE
(
${
QT_USE_FILE
}
)
INCLUDE
(
${
QT_USE_FILE
}
)
include_directories
(
${
QT_INCLUDES
}
)
include_directories
(
${
QT_INCLUDES
}
)
LIST
(
APPEND SERVATRICE_LIBS
${
QT_LIBRARIES
}
)
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
()
endif
()
# qt5 stuff
# qt5 stuff
...
@@ -60,7 +62,6 @@ SET(QT_DONT_USE_QTGUI TRUE)
...
@@ -60,7 +62,6 @@ SET(QT_DONT_USE_QTGUI TRUE)
# Include directories
# Include directories
INCLUDE_DIRECTORIES
(
../common
)
INCLUDE_DIRECTORIES
(
../common
)
INCLUDE_DIRECTORIES
(
${
LIBGCRYPT_INCLUDE_DIR
}
)
INCLUDE_DIRECTORIES
(
${
PROTOBUF_INCLUDE_DIR
}
)
INCLUDE_DIRECTORIES
(
${
PROTOBUF_INCLUDE_DIR
}
)
INCLUDE_DIRECTORIES
(
${
CMAKE_CURRENT_BINARY_DIR
}
/../common
)
INCLUDE_DIRECTORIES
(
${
CMAKE_CURRENT_BINARY_DIR
}
/../common
)
INCLUDE_DIRECTORIES
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
INCLUDE_DIRECTORIES
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
...
...
servatrice/src/passwordhasher.cpp
View file @
283bac0b
#include
"passwordhasher.h"
#include
"passwordhasher.h"
#include
<stdio.h>
#include
<string.h>
#if QT_VERSION < 0x050000
#include
<gcrypt.h>
#include
<stdio.h>
#include
<string.h>
#include
<gcrypt.h>
#else
#include
<QCryptographicHash>
#endif
void
PasswordHasher
::
initialize
()
void
PasswordHasher
::
initialize
()
{
{
// These calls are required by libgcrypt before we use any of its functions.
#if QT_VERSION < 0x050000
gcry_check_version
(
0
);
// These calls are required by libgcrypt before we use any of its functions.
gcry_control
(
GCRYCTL_DISABLE_SECMEM
,
0
);
gcry_check_version
(
0
);
gcry_control
(
GCRYCTL_INITIALIZATION_FINISHED
,
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
)
QString
PasswordHasher
::
computeHash
(
const
QString
&
password
,
const
QString
&
salt
)
{
{
const
int
algo
=
GCRY_MD_SHA512
;
const
int
algo
=
GCRY_MD_SHA512
;
const
int
rounds
=
1000
;
const
int
rounds
=
1000
;
QByteArray
passwordBuffer
=
(
salt
+
password
).
toUtf8
();
QByteArray
passwordBuffer
=
(
salt
+
password
).
toUtf8
();
int
hashLen
=
gcry_md_get_algo_dlen
(
algo
);
int
hashLen
=
gcry_md_get_algo_dlen
(
algo
);
char
*
hash
=
new
char
[
hashLen
],
*
tmp
=
new
char
[
hashLen
];
char
*
hash
=
new
char
[
hashLen
],
*
tmp
=
new
char
[
hashLen
];
gcry_md_hash_buffer
(
algo
,
hash
,
passwordBuffer
.
data
(),
passwordBuffer
.
size
());
gcry_md_hash_buffer
(
algo
,
hash
,
passwordBuffer
.
data
(),
passwordBuffer
.
size
());
for
(
int
i
=
1
;
i
<
rounds
;
++
i
)
{
for
(
int
i
=
1
;
i
<
rounds
;
++
i
)
{
memcpy
(
tmp
,
hash
,
hashLen
);
memcpy
(
tmp
,
hash
,
hashLen
);
gcry_md_hash_buffer
(
algo
,
hash
,
tmp
,
hashLen
);
gcry_md_hash_buffer
(
algo
,
hash
,
tmp
,
hashLen
);
}
}
QString
hashedPass
=
salt
+
QString
(
QByteArray
(
hash
,
hashLen
).
toBase64
());
QString
hashedPass
=
salt
+
QString
(
QByteArray
(
hash
,
hashLen
).
toBase64
());
delete
[]
tmp
;
delete
[]
tmp
;
delete
[]
hash
;
delete
[]
hash
;
return
hashedPass
;
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment