mirror of
https://github.com/QuasarApp/Qt-AES.git
synced 2025-04-29 23:24:31 +00:00
first try on OFB - not tested
This commit is contained in:
parent
6fc1d88485
commit
4ce12493f6
@ -398,13 +398,16 @@ QByteArray QAESEncryption::encode(const QByteArray &rawText, const QByteArray &k
|
|||||||
QByteArray expandedKey = expandKey(key);
|
QByteArray expandedKey = expandKey(key);
|
||||||
QByteArray alignedText(rawText);
|
QByteArray alignedText(rawText);
|
||||||
QByteArray ivTemp(iv);
|
QByteArray ivTemp(iv);
|
||||||
|
QByteArray ofbTemp;
|
||||||
|
|
||||||
//Fill array with padding
|
//Fill array with padding
|
||||||
alignedText.append(getPadding(rawText.size(), m_blocklen));
|
alignedText.append(getPadding(rawText.size(), m_blocklen));
|
||||||
|
|
||||||
//Preparation for CFB
|
//Preparation for CFB
|
||||||
if (m_mode == CFB)
|
if (m_mode == CFB || m_mode == OFB)
|
||||||
ret.append(byteXor(alignedText.mid(0, m_blocklen), cipher(expandedKey, iv)));
|
ret.append(byteXor(alignedText.mid(0, m_blocklen), cipher(expandedKey, iv)));
|
||||||
|
if (m_mode == OFB)
|
||||||
|
ofbTemp.append(cipher(expandedKey, iv));
|
||||||
|
|
||||||
//Looping thru all blocks
|
//Looping thru all blocks
|
||||||
for(int i=0; i < alignedText.size(); i+= m_blocklen){
|
for(int i=0; i < alignedText.size(); i+= m_blocklen){
|
||||||
@ -423,6 +426,15 @@ QByteArray QAESEncryption::encode(const QByteArray &rawText, const QByteArray &k
|
|||||||
ret.append(byteXor(alignedText.mid(i+m_blocklen, m_blocklen),
|
ret.append(byteXor(alignedText.mid(i+m_blocklen, m_blocklen),
|
||||||
cipher(expandedKey, ret.mid(i, m_blocklen))));
|
cipher(expandedKey, ret.mid(i, m_blocklen))));
|
||||||
break;
|
break;
|
||||||
|
case OFB:
|
||||||
|
if (i+m_blocklen < alignedText.size())
|
||||||
|
{
|
||||||
|
ret.append(byteXor(alignedText.mid(i+m_blocklen, m_blocklen),
|
||||||
|
cipher(expandedKey, ofbTemp.mid(i-m_blocklen, m_blocklen))));
|
||||||
|
ofbTemp.append(cipher(expandedKey, ofbTemp.mid(i-m_blocklen, m_blocklen)));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
//do nothing
|
//do nothing
|
||||||
break;
|
break;
|
||||||
|
@ -17,7 +17,8 @@ public:
|
|||||||
enum Mode {
|
enum Mode {
|
||||||
ECB,
|
ECB,
|
||||||
CBC,
|
CBC,
|
||||||
CFB
|
CFB,
|
||||||
|
OFB
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Padding {
|
enum Padding {
|
||||||
@ -132,9 +133,9 @@ private:
|
|||||||
|
|
||||||
// The round constant word array, Rcon[i], contains the values given by
|
// The round constant word array, Rcon[i], contains the values given by
|
||||||
// x to th e power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
|
// x to th e power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
|
||||||
//Only the first 14 elements are needed
|
// Only the first 14 elements are needed
|
||||||
const quint8 Rcon[256] = {
|
const quint8 Rcon[256] = {
|
||||||
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, /*0x4d, 0x9a,
|
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab/*, 0x4d, 0x9a,
|
||||||
0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39,
|
0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39,
|
||||||
0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
|
0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
|
||||||
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8,
|
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user