From 9b37abbca967d9edd7bd5bf7ba6e4aee5a897d82 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 15 Jan 2006 05:48:00 +0000 Subject: [PATCH] Fix handling for two key 3DES, and an bug in the keylength reporting for AES192. svn path=/trunk/kdesupport/qca/; revision=498257 --- plugins/qca-gcrypt/qca-gcrypt.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/qca-gcrypt/qca-gcrypt.cpp b/plugins/qca-gcrypt/qca-gcrypt.cpp index 6329e600..cb496509 100644 --- a/plugins/qca-gcrypt/qca-gcrypt.cpp +++ b/plugins/qca-gcrypt/qca-gcrypt.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Justin Karneges - * Copyright (C) 2004-2005 Brad Hards + * Copyright (C) 2004-2006 Brad Hards * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -164,7 +164,16 @@ public: m_direction = dir; err = gcry_cipher_open( &context, m_cryptoAlgorithm, m_mode, 0 ); check_error( "gcry_cipher_open", err ); - err = gcry_cipher_setkey( context, key.data(), key.size() ); + if ( ( GCRY_CIPHER_3DES == m_cryptoAlgorithm ) && (key.size() == 16) ) { + // this is triple DES with two keys, and gcrypt wants three + QCA::SymmetricKey keyCopy(key); + QSecureArray thirdKey(key); + thirdKey.resize(8); + keyCopy += thirdKey; + err = gcry_cipher_setkey( context, keyCopy.data(), keyCopy.size() ); + } else { + err = gcry_cipher_setkey( context, key.data(), key.size() ); + } check_error( "gcry_cipher_setkey", err ); err = gcry_cipher_setiv( context, iv.data(), iv.size() ); check_error( "gcry_cipher_setiv", err ); @@ -223,8 +232,10 @@ public: case GCRY_CIPHER_AES128: return QCA::KeyLength( 16, 16, 1); case GCRY_CIPHER_AES192: + return QCA::KeyLength( 24, 24, 1); case GCRY_CIPHER_3DES: - return QCA::KeyLength( 24, 24, 1); + // we do two and three key versions + return QCA::KeyLength( 16, 24, 8); case GCRY_CIPHER_AES256: return QCA::KeyLength( 32, 32, 1); case GCRY_CIPHER_BLOWFISH: