cleaning files, added test for 256b

This commit is contained in:
Matteo Brichese 2017-07-03 11:23:54 -07:00
parent dd17d8715b
commit 6e46cb3257
3 changed files with 31 additions and 10 deletions

View File

@ -16,7 +16,7 @@ QString print(QByteArray in)
return ret;
}
bool testECBDecrypt()
bool testECB128Decrypt()
{
QByteArray hexText, keyHex, outputHex;
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB);
@ -39,7 +39,7 @@ bool testECBDecrypt()
return false;
}
bool testECBCrypt()
bool testECB128Crypt()
{
QByteArray hexText, keyHex, outputHex;
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB);
@ -64,12 +64,39 @@ bool testECBCrypt()
return false;
}
bool testECB256Crypt()
{
QByteArray hexText, keyHex, outputHex;
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB);
uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 };
uint8_t text[16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
uint8_t output[16] = { 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c, 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8 };
for (int i=0; i<16 ; i++)
{
hexText.append(text[i]);
outputHex.append(output[i]);
}
for (int i=0; i<32 ; i++)
keyHex.append(key[i]);
QByteArray encodedHex = encryption.encode(hexText, keyHex);
encodedHex.truncate(16);
if (outputHex == encodedHex)
return true;
return false;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Q_ASSERT(testECBCrypt());
Q_ASSERT(testECBDecrypt());
Q_ASSERT(testECB128Crypt());
Q_ASSERT(testECB128Decrypt());
Q_ASSERT(testECB256Crypt());
return 0;
}

View File

@ -95,7 +95,6 @@ QByteArray QAESEncryption::expandKey(const QByteArray key)
{
// Function Subword()
{
qDebug() << "AES_256";
tempa[0] = getSBoxValue(tempa[0]);
tempa[1] = getSBoxValue(tempa[1]);
tempa[2] = getSBoxValue(tempa[2]);

View File

@ -10,7 +10,6 @@ CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
tiny-AES-C/aes.c \
qaesencryption.cpp
# The following define makes your compiler emit warnings if you use
@ -25,9 +24,5 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
HEADERS += \
tiny-AES-C/aes.h \
qaesencryption.h
DISTFILES += \
sample.txt