0
0
mirror of https://github.com/keepassxreboot/keepassxc.git synced 2024-09-19 20:02:18 +02:00

Use the libgcrypt SALSA20 cipher if available.

This commit is contained in:
Felix Geyer 2014-01-12 13:42:56 +01:00
parent eee909e948
commit 0b6b149351
5 changed files with 33 additions and 6 deletions

View File

@ -167,6 +167,10 @@ find_package(Qt4 4.6.0 REQUIRED ${QT_REQUIRED_MODULES})
include(${QT_USE_FILE})
find_package(Gcrypt REQUIRED)
if(NOT (${GCRYPT_VERSION_STRING} VERSION_LESS "1.6.0"))
message(STATUS "Gcrypt ${GCRYPT_VERSION_STRING} supports the SALSA20 cipher")
set(GCRYPT_HAS_SALSA20 1)
endif()
find_package(ZLIB REQUIRED)

View File

@ -53,15 +53,9 @@ set(keepassx_SOURCES
crypto/Crypto.cpp
crypto/CryptoHash.cpp
crypto/Random.cpp
crypto/salsa20/ecrypt-config.h
crypto/salsa20/ecrypt-machine.h
crypto/salsa20/ecrypt-portable.h
crypto/salsa20/ecrypt-sync.h
crypto/salsa20/salsa20.c
crypto/SymmetricCipher.cpp
crypto/SymmetricCipherBackend.h
crypto/SymmetricCipherGcrypt.cpp
crypto/SymmetricCipherSalsa20.cpp
format/KeePass1.h
format/KeePass1Reader.cpp
format/KeePass2.h
@ -117,6 +111,18 @@ set(keepassx_SOURCES
streams/SymmetricCipherStream.cpp
)
if(NOT GCRYPT_HAS_SALSA20)
set(keepassx_SOURCES
${keepassx_SOURCES}
crypto/salsa20/ecrypt-config.h
crypto/salsa20/ecrypt-machine.h
crypto/salsa20/ecrypt-portable.h
crypto/salsa20/ecrypt-sync.h
crypto/salsa20/salsa20.c
crypto/SymmetricCipherSalsa20.cpp
)
endif()
set(keepassx_SOURCES_MAINEXE
main.cpp
)

View File

@ -13,4 +13,6 @@
#cmakedefine HAVE_RLIMIT_CORE 1
#cmakedefine HAVE_PT_DENY_ATTACH 1
#cmakedefine GCRYPT_HAS_SALSA20
#endif // KEEPASSX_CONFIG_H

View File

@ -17,6 +17,7 @@
#include "SymmetricCipher.h"
#include "config-keepassx.h"
#include "crypto/SymmetricCipherGcrypt.h"
#include "crypto/SymmetricCipherSalsa20.h"
@ -39,10 +40,15 @@ SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorith
switch (algo) {
case SymmetricCipher::Aes256:
case SymmetricCipher::Twofish:
#if defined(GCRYPT_HAS_SALSA20)
case SymmetricCipher::Salsa20:
#endif
return new SymmetricCipherGcrypt(algo, mode, direction);
#if !defined(GCRYPT_HAS_SALSA20)
case SymmetricCipher::Salsa20:
return new SymmetricCipherSalsa20(algo, mode, direction);
#endif
default:
Q_ASSERT(false);

View File

@ -17,6 +17,7 @@
#include "SymmetricCipherGcrypt.h"
#include "config-keepassx.h"
#include "crypto/Crypto.h"
SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
@ -43,6 +44,11 @@ int SymmetricCipherGcrypt::gcryptAlgo(SymmetricCipher::Algorithm algo)
case SymmetricCipher::Twofish:
return GCRY_CIPHER_TWOFISH;
#ifdef GCRYPT_HAS_SALSA20
case SymmetricCipher::Salsa20:
return GCRY_CIPHER_SALSA20;
#endif
default:
Q_ASSERT(false);
return -1;
@ -58,6 +64,9 @@ int SymmetricCipherGcrypt::gcryptMode(SymmetricCipher::Mode mode)
case SymmetricCipher::Cbc:
return GCRY_CIPHER_MODE_CBC;
case SymmetricCipher::Stream:
return GCRY_CIPHER_MODE_STREAM;
default:
Q_ASSERT(false);
return -1;