summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/libgcryptif.cpp
Side-by-side diff
Diffstat (limited to 'pwmanager/pwmanager/libgcryptif.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/libgcryptif.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/pwmanager/pwmanager/libgcryptif.cpp b/pwmanager/pwmanager/libgcryptif.cpp
index ff94bf6..15f6cef 100644
--- a/pwmanager/pwmanager/libgcryptif.cpp
+++ b/pwmanager/pwmanager/libgcryptif.cpp
@@ -38,13 +38,15 @@
PwMerror LibGCryptIf::encrypt(unsigned char **outBuf,
size_t *outBufLen,
unsigned char *inBuf,
size_t inBufLen,
const unsigned char *key,
size_t keylen,
- char _algo)
+ char _algo,
+ char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
+ )
{
PwMerror ret = e_success;
gcry_error_t err;
gcry_cipher_hd_t handle;
size_t blklen;
size_t unpaddedLen = inBufLen;
@@ -102,13 +104,13 @@ PwMerror LibGCryptIf::encrypt(unsigned char **outBuf,
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// hash the "key" to a fixed size hash matching "cipherKeylen"
hashedKey = new unsigned char[cipherKeylen];
- hashPassphrase(key, keylen, salt, hashedKey, cipherKeylen, true);
+ hashPassphrase(key, keylen, salt, hashedKey, cipherKeylen, true, _hashalgo);
// so now set the hashed key
err = gcry_cipher_setkey(handle, hashedKey, cipherKeylen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doEncrypt(): gcry_cipher_setkey() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
@@ -149,13 +151,15 @@ out:
PwMerror LibGCryptIf::decrypt(unsigned char **outBuf,
size_t *outBufLen,
const unsigned char *inBuf,
size_t inBufLen,
const unsigned char *key,
size_t keylen,
- char _algo)
+ char _algo,
+ char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
+)
{
PwMerror ret = e_success;
gcry_error_t err;
gcry_cipher_hd_t handle;
size_t cipherKeylen;
unsigned char *hashedKey;
@@ -198,13 +202,13 @@ PwMerror LibGCryptIf::decrypt(unsigned char **outBuf,
+ gcry_strerror(err));
ret = e_cryptNotImpl;
goto out;
}
// hash the "key" to a fixed size hash matching "cipherKeylen"
hashedKey = new unsigned char[cipherKeylen];
- hashPassphrase(key, keylen, salt, hashedKey, cipherKeylen, false);
+ hashPassphrase(key, keylen, salt, hashedKey, cipherKeylen, false, _hashalgo);
// so now set the hashed key
err = gcry_cipher_setkey(handle, hashedKey, cipherKeylen);
if (err != GPG_ERR_NO_ERROR) {
printDebug(string("LibGCryptIf::doDecrypt(): gcry_cipher_setkey() failed: ")
+ gcry_strerror(err));
ret = e_cryptNotImpl;
@@ -311,21 +315,26 @@ int LibGCryptIf::mapHashId(char algo)
bool LibGCryptIf::hashPassphrase(const unsigned char *pw,
size_t pwlen,
unsigned char *salt,
unsigned char *key,
size_t keylen,
- bool create)
+ bool create,
+ char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
+)
{
DEK dek;
STRING2KEY s2k;
bool ret;
dek.keylen = keylen;
s2k.mode = 1;
- s2k.hash_algo = mapHashId(conf()->confGlobHashAlgo());
+ //US bug: do not use the global hash algo here. Use the passed ago instead. The hashalgo stored in the file can
+ // be different from the one in the configuration.
+ s2k.hash_algo = mapHashId(_hashalgo //conf()->confGlobHashAlgo()
+ );
s2k.count = 0;
if (!create)
memcpy(s2k.salt, salt, STRING2KEY_SALTLEN);
ret = doHashPassphrase(&dek,
pw,
pwlen,
@@ -436,19 +445,19 @@ void LibGCryptIf::unpadData(const unsigned char *buf,
size_t *bufLen)
{
size_t pos;
BUG_ON(*bufLen % 8);
pos = *bufLen - 1;
while (buf[pos] != static_cast<char>(0x01)) {
- qDebug("pos %d %d %d", pos, buf[pos], static_cast<char>(0x01) );
+ //qDebug("pos %d %d %d", pos, buf[pos], static_cast<char>(0x01) );
BUG_ON(!pos);
//LR BUG we should terminte the loop if p == 0
if ( pos == 0 )
break;
--pos;
}
*bufLen = pos;
- qDebug("ente ");
+ //qDebug("ente ");
}
#endif // CONFIG_PWMANAGER_GCRY