Qt/QCA: AES-Verschlüsselung mit 192bit im CFB-Modus -> falsches Ergebnis

proprogger

Mitglied
Hallo!

Ich benötige in einer Anwengung bei einer Übertragung AES-Verschlüsselung mit 192 Bit im CFB Modus (Cipher Feedback).
Ich hatte bisher ein Pythonscript, was funktioniert hat. Ich möchte es aber als eine einzige Anwendung ohne Python machen und habe das ganze dann in C++ (mit Qt) mit der Bibliothek QCA gemacht. Dort bekomme ich aber bei den selben Einstellungen (gleicher Key, gleicher IV, gleicher Modus) ein anderes Ergebnis!
Was mache ich falsch?
Vielleicht entsprechen die Einstellungen in C++ doch nicht denen in Python?

Hier sind beide Programme und ihre Ausgaben:

Python:
Code:
#!/usr/bin/env python

import binascii
from Crypto.Cipher import AES
import sys


Key = binascii.unhexlify('000000000000000000000000000000000000000000000000')
IV = binascii.unhexlify('00000000000000000000000000000000')


original = 'hallo'
print 'original:      ' + original


obj = AES.new(Key,AES.MODE_CFB,IV)

encoded = obj.encrypt(original)
print 'encoded (hex): ' + binascii.hexlify(encoded)


obj = AES.new(Key,AES.MODE_CFB,IV)

decoded = obj.decrypt(encoded)
print 'decoded:       ' + decoded

Ausgabe:
Code:
original:      hallo
encoded (hex): c29b046fab
decoded:       hallo

C++:
(nur main.cpp)
Code:
#include <iostream>

#include <QCoreApplication>
#include <QByteArray>
#include <QString>
#include <QtCrypto>

using namespace std;
using namespace QCA;

int main(int argc, char *argv[])
{
   QCoreApplication app(argc, argv);
   
   Initializer init;
   Cipher *cipher;
   
   SecureArray _qca_key(QByteArray::fromHex("000000000000000000000000000000000000000000000000"));
   SymmetricKey qca_key(_qca_key);
   SecureArray _qca_iv(QByteArray::fromHex("00000000000000000000000000000000"));
   InitializationVector qca_iv(_qca_iv);
   
   //ORIGINAL
   SecureArray original(QString("hallo").toAscii());
   
   //ENCODE
   cipher = new Cipher( QString("aes192"),
                        Cipher::CFB,
                        Cipher::DefaultPadding,
                        Encode,
                        qca_key, qca_iv );
   SecureArray encoded = cipher->process(original);
   if (!cipher->ok())
   {
      qDebug("encoding error");
      return 1;
   }
   
   //ENCODE
   cipher = new Cipher( QString("aes192"),
                        Cipher::CFB,
                        Cipher::DefaultPadding,
                        Decode,
                        qca_key, qca_iv );
   SecureArray decoded = cipher->process(encoded);
   if (!cipher->ok())
   {
      qDebug("decoding error");
      return 1;
   }
   
      
   //OUTPUT
   cout << "Original:            " << original.data() << endl;
   cout << "Encoded (hex):       " << encoded.toByteArray().toHex().data() << endl;
   cout << "Decoded:             " << decoded.data() << endl;
   cout << endl;
   cout << "Encoded sollte sein: " << "c29b046fab" << endl;

   return 0;
}

Ausgabe:
Code:
Original:            hallo
Encoded (hex):       c28105fec3
Decoded:             hallo

Encoded sollte sein: c29b046fab

Wer weiß wo der Fehler liegen kann?
Gibt es eine andere Implementierung von AES in C oder C++, die auch den CFB-Modus beinhaltet? Andere Implementierungen die ich gefunden habe, haben diesen Modus nicht.

Grüße
 
Zurück