You are not logged in.

#1 2013-12-05 23:11:50

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 885

TinyAES - A very small AES encryption library for Qt 5.x

I was looking for some small AES ecryption library that I could embedd into my own code and use to encrypt some small amount of data with Qt 5.x. The obvious solution was QCA (Qt Cryptographic Architecture), but to my knowledge a stable version is not available for Qt 5.x yet. Besides that, QCA offers alot more than simple AES encryption, and I didn't need all the bells and whistles.

Few days ago I stumbled upon this AES implementation in C. I stripped the code I found there to bare minimum requried for simple AES encryption. I used this code for basic encryption and decryption, and implemented PKCS#7 padding and automatic IV prepending.

The result was a simple Qt class that has all you need to encrypt your data. The function prototypes are as follows:

// Automatically generates and prepends/removes IV. Returns encrypted/decrypted QByteArray.
QByteArray Encrypt(QByteArray input, QByteArray key);
QByteArray Decrypt(QByteArray input, QByteArray key);

// Use custom IV. Returns encrypted/decrypted QByteArray.
QByteArray Encrypt(QByteArray input, QByteArray key, QByteArray iv);
QByteArray Decrypt(QByteArray input, QByteArray key, QByteArray iv);

You can download the library source code (Qt project) here.
You can download an example source code (Qt project) which demonstrates the usage of the library here.

License on all source code is BSD, with respect to original code license and copyright notice.

Last edited by karabaja4 (2014-03-19 16:23:00)

Offline

#2 2013-12-06 09:04:42

Svenstaro
Developer
From: Germany
Registered: 2008-11-19
Posts: 378

Re: TinyAES - A very small AES encryption library for Qt 5.x

You should probably put this up on Github if you want people to use it more.

Offline

#3 2014-03-18 20:40:07

jacobp100
Member
Registered: 2014-03-18
Posts: 2

Re: TinyAES - A very small AES encryption library for Qt 5.x

Hi,

I would like to use this library, but the links aren't working! Any chance of a mirror/github?

Thanks!

Offline

#4 2014-03-19 16:23:57

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 885

Re: TinyAES - A very small AES encryption library for Qt 5.x

I edited the links.

Beware, there was a bug report about this code not working with large data, you might need to do some coding. If you fix this, please post here, thanks.

Offline

#5 2014-03-20 11:14:18

jacobp100
Member
Registered: 2014-03-18
Posts: 2

Re: TinyAES - A very small AES encryption library for Qt 5.x

Will do! Thanks for the updated links.

Offline

#6 2014-05-26 11:45:33

axed
Member
From: Vienna
Registered: 2010-04-05
Posts: 14

Re: TinyAES - A very small AES encryption library for Qt 5.x

Thank you for sharing your class big_smile

Even though it crashes everytime for me - regardless what i encrypt.
Crash in tinyaes.cpp on line 357.
GDB says there is no "ctx->rnd" only "ksch" and even "ksch" is on "0x0".

EDIT: works superb on Linux'n'Windowz - the described problem only occurs on OSX

Last edited by axed (2014-05-26 13:42:39)

Offline

#7 2014-07-21 10:08:20

axed
Member
From: Vienna
Registered: 2010-04-05
Posts: 14

Re: TinyAES - A very small AES encryption library for Qt 5.x

Since some weeks, the class stopped working under Ubuntu 14.04.

It crashes on runtime within tinyAES::Encrpyt and tinyAES::Decrypt with the message:

*** stack smashing detected ***: /opt/build-TinyAES_example-Desktop-Debug/TinyAES_example terminated

Any ideas?
lovely regards

Last edited by axed (2014-07-21 10:09:39)

Offline

#8 2014-08-13 16:00:58

axed
Member
From: Vienna
Registered: 2010-04-05
Posts: 14

Re: TinyAES - A very small AES encryption library for Qt 5.x

As mentioned above, TinyAES has some "big" (lol) problems with bigger data.
After some tests i found out, that the limit is 1.05MB - everything bigger will fuck things up.
So i added some little chunking mechanism, that splits the load into 500KB blocks.
So we got: [IV], [BLOCK1], [BLOCK2], [BLOCK3], [BLOCK4], [BLOCK5], [PADDING]
For example, block 1-4 have 500KB and block 5 only contains 120KB - anyways we exceeded the 1.05MB limit and after so many hours of debuging, i'm happy now.
The code is more a proof of concept, just needs more work with pointers.

TinyAES.h

/*
 ---------------------------------------------------------------------------
 Copyright (c) 2013, Igor Saric. All rights reserved.

 LICENSE TERMS

 The redistribution and use of this software (with or without changes)
 is allowed without the payment of fees or royalties provided that:

  1. source code distributions include the above copyright notice, this
     list of conditions and the following disclaimer;

  2. binary distributions include the above copyright notice, this list
     of conditions and the following disclaimer in their documentation;

  3. the name of the copyright holder is not used to endorse products
     built using this software without specific written permission.

 DISCLAIMER

 This software is provided 'as is' with no explicit or implied warranties
 in respect of its properties, including, but not limited to, correctness
 and/or fitness for purpose.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.

 LICENSE TERMS

 The redistribution and use of this software (with or without changes)
 is allowed without the payment of fees or royalties provided that:

  1. source code distributions include the above copyright notice, this
     list of conditions and the following disclaimer;

  2. binary distributions include the above copyright notice, this list
     of conditions and the following disclaimer in their documentation;

  3. the name of the copyright holder is not used to endorse products
     built using this software without specific written permission.

 DISCLAIMER

 This software is provided 'as is' with no explicit or implied warranties
 in respect of its properties, including, but not limited to, correctness
 and/or fitness for purpose.
 ---------------------------------------------------------------------------
 */

#ifndef BigAES_H
#define BigAES_H

#include <QByteArray>
#include <QString>
#include <QUuid>

#define N_ROW                   4
#define N_COL                   4
#define N_BLOCK   (N_ROW * N_COL)
#define N_MAX_ROUNDS           14

#define WPOLY   0x011b
#define BPOLY     0x1b
#define DPOLY   0x008d

#define f1(x)   (x)
#define f2(x)   ((x << 1) ^ (((x >> 7) & 1) * WPOLY))
#define f4(x)   ((x << 2) ^ (((x >> 6) & 1) * WPOLY) ^ (((x >> 6) & 2) * WPOLY))
#define f8(x)   ((x << 3) ^ (((x >> 5) & 1) * WPOLY) ^ (((x >> 5) & 2) * WPOLY) \
                          ^ (((x >> 5) & 4) * WPOLY))
#define d2(x)   (((x) >> 1) ^ ((x) & 1 ? DPOLY : 0))

#define f3(x)   (f2(x) ^ x)
#define f9(x)   (f8(x) ^ x)
#define fb(x)   (f8(x) ^ f2(x) ^ x)
#define fd(x)   (f8(x) ^ f4(x) ^ x)
#define fe(x)   (f8(x) ^ f4(x) ^ f2(x))

#define s_box(x)     sbox[(x)]
#define is_box(x)    isbox[(x)]
#define gfm2_sb(x)   gfm2_sbox[(x)]
#define gfm3_sb(x)   gfm3_sbox[(x)]
#define gfm_9(x)     gfmul_9[(x)]
#define gfm_b(x)     gfmul_b[(x)]
#define gfm_d(x)     gfmul_d[(x)]
#define gfm_e(x)     gfmul_e[(x)]

#define block_copy_nn(d, s, l)    memcpy(d, s, l)
#define block_copy(d, s)          memcpy(d, s, N_BLOCK)

#define sb_data(w) {    /* S Box data values */                            \
    w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
    w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
    w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
    w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
    w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
    w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
    w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
    w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
    w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
    w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
    w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
    w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
    w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
    w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
    w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
    w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
    w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
    w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
    w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
    w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
    w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
    w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
    w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
    w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
    w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
    w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
    w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
    w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
    w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
    w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
    w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
    w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }

#define isb_data(w) {   /* inverse S Box data values */                    \
    w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\
    w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\
    w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\
    w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\
    w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\
    w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\
    w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\
    w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\
    w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\
    w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\
    w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\
    w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\
    w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\
    w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\
    w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\
    w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\
    w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\
    w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\
    w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\
    w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\
    w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\
    w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\
    w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\
    w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\
    w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\
    w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\
    w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\
    w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\
    w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\
    w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\
    w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\
    w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) }

#define mm_data(w) {    /* basic data for forming finite field tables */   \
    w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\
    w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\
    w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\
    w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\
    w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\
    w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\
    w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\
    w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\
    w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\
    w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\
    w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\
    w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\
    w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\
    w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\
    w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\
    w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\
    w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\
    w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\
    w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\
    w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\
    w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\
    w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\
    w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\
    w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\
    w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\
    w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\
    w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\
    w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\
    w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\
    w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\
    w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\
    w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) }

typedef quint8 uint_8t;
typedef quint32 uint_32t;
typedef uint_8t aes_result;

static const uint_8t sbox[256]  =  sb_data(f1);
static const uint_8t isbox[256] = isb_data(f1);

static const uint_8t gfm2_sbox[256] = sb_data(f2);
static const uint_8t gfm3_sbox[256] = sb_data(f3);

static const uint_8t gfmul_9[256] = mm_data(f9);
static const uint_8t gfmul_b[256] = mm_data(fb);
static const uint_8t gfmul_d[256] = mm_data(fd);
static const uint_8t gfmul_e[256] = mm_data(fe);

class BigAES
{
    public:

        BigAES();

        // public functions
        QByteArray Encrypt(QByteArray p_input, QByteArray p_key);
        QByteArray Decrypt(QByteArray p_input, QByteArray p_key);
        QByteArray Encrypt(QByteArray b_input, QByteArray p_key, QByteArray p_iv);
        QByteArray Decrypt(QByteArray b_input, QByteArray p_key, QByteArray p_iv);
        QByteArray HexStringToByte(QString key);

    private:

        typedef struct
        {
            uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
            uint_8t rnd;
        } aes_context;

        // QT helper functions
        void QByteArrayToUCharArray(QByteArray src, unsigned char *dest);
        QByteArray UCharArrayToQByteArray(unsigned char *src, int p_size);
        void RemovePadding(QByteArray *input);
        void AddPadding(QByteArray *input);
        QByteArray GenerateRandomBytes(int length);

        // encryption functions
        aes_result aes_set_key(const unsigned char key[], int keylen, aes_context ctx[1] );
        aes_result aes_encrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] );
        aes_result aes_decrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] );
        aes_result aes_cbc_encrypt(const unsigned char *in, unsigned char *out, unsigned long size, unsigned char iv[N_BLOCK], const aes_context ctx[1] );
        aes_result aes_cbc_decrypt(const unsigned char *in, unsigned char *out, unsigned long size, unsigned char iv[N_BLOCK], const aes_context ctx[1] );

        // helper functions
        void xor_block( void *d, const void *s );
        void copy_and_key( void *d, const void *s, const void *k );
        void add_round_key( uint_8t d[N_BLOCK], const uint_8t k[N_BLOCK] );
        void shift_sub_rows( uint_8t st[N_BLOCK] );
        void inv_shift_sub_rows( uint_8t st[N_BLOCK] );
        void mix_sub_columns( uint_8t dt[N_BLOCK] );
        void inv_mix_sub_columns( uint_8t dt[N_BLOCK] );
};

#endif // BigAES_H

TinyAES.cpp

/*
 ---------------------------------------------------------------------------
 Copyright (c) 2013, Igor Saric. All rights reserved.

 LICENSE TERMS

 The redistribution and use of this software (with or without changes)
 is allowed without the payment of fees or royalties provided that:

  1. source code distributions include the above copyright notice, this
     list of conditions and the following disclaimer;

  2. binary distributions include the above copyright notice, this list
     of conditions and the following disclaimer in their documentation;

  3. the name of the copyright holder is not used to endorse products
     built using this software without specific written permission.

 DISCLAIMER

 This software is provided 'as is' with no explicit or implied warranties
 in respect of its properties, including, but not limited to, correctness
 and/or fitness for purpose.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.

 LICENSE TERMS

 The redistribution and use of this software (with or without changes)
 is allowed without the payment of fees or royalties provided that:

  1. source code distributions include the above copyright notice, this
     list of conditions and the following disclaimer;

  2. binary distributions include the above copyright notice, this list
     of conditions and the following disclaimer in their documentation;

  3. the name of the copyright holder is not used to endorse products
     built using this software without specific written permission.

 DISCLAIMER

 This software is provided 'as is' with no explicit or implied warranties
 in respect of its properties, including, but not limited to, correctness
 and/or fitness for purpose.
 ---------------------------------------------------------------------------
 */

#include "tinyAES.h"
#include <QDebug>

BigAES::BigAES()
{
}

// encryption with IV
QByteArray BigAES::Encrypt(QByteArray p_input, QByteArray p_key)
{
    if (p_input.isEmpty()) {
        qDebug() << "BigAES::Encrypt(..): cannot encrypt empty input";
        return QByteArray();
    }

    QByteArray iv = QUuid::createUuid().toRfc4122();
    //QByteArray input = p_input.prepend(iv);
    return Encrypt(p_input, p_key, iv);
}

QByteArray BigAES::Decrypt(QByteArray p_input, QByteArray p_key)
{
    if (p_input.isEmpty()) {
        qDebug() << "BigAES::Decrypt(..): cannot decrypt empty input";
        return QByteArray();
    }
    QByteArray iv = p_input.left(16);
    QByteArray input = p_input.remove(0, 16);
    return Decrypt(input, p_key, iv);
}

// basic encryption
//QByteArray BigAES::Encrypt(QByteArray p_input, QByteArray p_key, QByteArray p_iv)
//{


//    int keySize = p_key.size();
//    int ivSize = p_iv.size();

//    if (keySize != 16 && keySize != 24 && keySize != 32)
//        return QByteArray();

//    if (ivSize != 16)
//        return QByteArray();

//    // add padding
//    QByteArray input = AddPadding(p_input);
//    int inputSize = input.size();

//    unsigned char key[keySize];
//    QByteArrayToUCharArray(p_key, key);

//    unsigned char iv[ivSize];
//    QByteArrayToUCharArray(p_iv, iv);

//    unsigned char decrypted[inputSize];
//    QByteArrayToUCharArray(input, decrypted);

//    unsigned char encrypted[inputSize]; // encrypted text

//    aes_context context;
//    aes_set_key(key, keySize * 8, &context);
//    aes_cbc_encrypt(decrypted, encrypted, inputSize, iv, &context);

//    QByteArray result = UCharArrayToQByteArray(encrypted, inputSize);
//    return result;
//}

//QByteArray BigAES::Decrypt(QByteArray p_input, QByteArray p_key, QByteArray p_iv)
//{
//    int inputSize = p_input.size();
//    int keySize = p_key.size();
//    int ivSize = p_iv.size();

//    if (keySize != 16 && keySize != 24 && keySize != 32)
//        return QByteArray();

//    if (ivSize != 16)
//        return QByteArray();

//    unsigned char key[keySize];
//    QByteArrayToUCharArray(p_key, key);

//    unsigned char iv[ivSize];
//    QByteArrayToUCharArray(p_iv, iv);

//    unsigned char encrypted[inputSize];
//    QByteArrayToUCharArray(p_input, encrypted);

//    unsigned char decrypted[inputSize]; // decrypted text

//    aes_context context;
//    aes_set_key(key, keySize * 8, &context);
//    aes_cbc_decrypt(encrypted, decrypted, inputSize, iv, &context);

//    QByteArray result = RemovePadding(UCharArrayToQByteArray(decrypted, inputSize));
//    return result;
//}

QByteArray BigAES::Encrypt(QByteArray b_input, QByteArray p_key, QByteArray p_iv)
{
    if (b_input.isEmpty()) {
        qDebug() << "BigAES::Encrypt(...): cannot encrypt empty input";
        return QByteArray();
    }

    AddPadding(&b_input);

    QByteArray result;

    int keySize = p_key.size();
    int ivSize = p_iv.size();

    if (keySize != 16 && keySize != 24 && keySize != 32) {
        qDebug() << "BigAES::Encrypt(): INVALID KEYSIZE";
        return QByteArray();
    }

    if (ivSize != 16) {
        qDebug() << "BigAES::Encrypt(): INVALID IVSIZE";
        return QByteArray();
    }

    // chunks have to stay < 1MB (1.050MB to be exactly)
    // -> how many chunks do we have? b_input/1.000.000 +1

    qint64 chunksCount = (b_input.size()/500000) + 1;

    for (int part = 0; part < chunksCount; part++) {
        // out of range checks
        if (part*500000 > b_input.size()) {
            qDebug() << "BigAES::Encrypt(): skipped: buffer overflow";
            continue;
        }

        QByteArray p_chunk = b_input.mid(part*500000, 500000);
        int inputSize = p_chunk.size();

        unsigned char key[keySize];
        QByteArrayToUCharArray(p_key, key);

        unsigned char iv[ivSize];
        QByteArrayToUCharArray(p_iv, iv);

        unsigned char decrypted[inputSize];
        QByteArrayToUCharArray(p_chunk, decrypted);

        unsigned char encrypted[inputSize]; // encrypted text

        aes_context context;
        aes_set_key(key, keySize * 8, &context);
        aes_cbc_encrypt(decrypted, encrypted, inputSize, iv, &context);

        result.append( UCharArrayToQByteArray(encrypted, inputSize));
    }

    result.prepend(p_iv);
    return result;
}

QByteArray BigAES::Decrypt(QByteArray b_input, QByteArray p_key, QByteArray p_iv)
{
    if (b_input.isEmpty()) {
        qDebug() << "BigAES::Decrypt(...): cannot decrypt empty input";
        return QByteArray();
    }

    QByteArray result;

    int keySize = p_key.size();
    int ivSize = p_iv.size();

    if (keySize != 16 && keySize != 24 && keySize != 32) {
        qDebug() << "BigAES::Encrypt(): INVALID KEYSIZE";
        return QByteArray();
    }

    if (ivSize != 16) {
        qDebug() << "BigAES::Encrypt(): INVALID IVSIZE";
        return QByteArray();
    }

    // chunks have to stay < 1MB (1.050MB to be exactly)
    // -> how many chunks do we have? b_input/1.000.000 +1

    // now with 500KB blocks
    qint64 chunksCount = (b_input.size()/500000) + 1;

    for (int part = 0; part < chunksCount; part++) {
        // out of range checks
        if (part*500000 > b_input.size()) {
            qDebug() << "BigAES::Encrypt(): skipped: buffer overflow";
            continue;
        }

        QByteArray p_chunk = b_input.mid(part*500000, 500000);

        int inputSize = p_chunk.size();

        unsigned char key[keySize];
        QByteArrayToUCharArray(p_key, key);

        unsigned char iv[ivSize];
        QByteArrayToUCharArray(p_iv, iv);

        unsigned char encrypted[inputSize];
        QByteArrayToUCharArray(p_chunk, encrypted);

        unsigned char decrypted[inputSize]; // decrypted text

        aes_context context;
        aes_set_key(key, keySize * 8, &context);
        aes_cbc_decrypt(encrypted, decrypted, inputSize, iv, &context);

        QByteArray temp_result = UCharArrayToQByteArray(decrypted, inputSize);

//        qDebug() << temp_result;
        result.append( temp_result);
    }

    RemovePadding(&result);
    return result;
}


// helper functions
QByteArray BigAES::HexStringToByte(QString key) {
    return QByteArray::fromHex(QString(key).toLatin1());
}

void BigAES::QByteArrayToUCharArray(QByteArray src, unsigned char *dest) {
    for (int i = 0; i < src.size(); i++) {
        dest[i] = src.at(i);
    }
}

QByteArray BigAES::UCharArrayToQByteArray(unsigned char *src, int p_size) {
    QByteArray array((char*)src, p_size);
    return array;
}

// pkcs#7 padding
void BigAES::RemovePadding(QByteArray *input) {
    int padding = input->at(input->size() - 1);

    for(int i = 0; i < padding; i++) {
        if (input->at(input->size() - 1) == padding) {
            input->chop(1);
        }
    }
}

void BigAES::AddPadding(QByteArray* input) {
    int size = input->size();
    int padding = 16 - (size % 16);

    for(int i = 0; i < padding; i++) {
        input->append(padding);
    }
}

// algorithm
void BigAES::xor_block( void *d, const void *s ) {
    ((uint_32t*)d)[ 0] ^= ((uint_32t*)s)[ 0];
    ((uint_32t*)d)[ 1] ^= ((uint_32t*)s)[ 1];
    ((uint_32t*)d)[ 2] ^= ((uint_32t*)s)[ 2];
    ((uint_32t*)d)[ 3] ^= ((uint_32t*)s)[ 3];
}

void BigAES::copy_and_key( void *d, const void *s, const void *k )
{
    ((uint_32t*)d)[ 0] = ((uint_32t*)s)[ 0] ^ ((uint_32t*)k)[ 0];
    ((uint_32t*)d)[ 1] = ((uint_32t*)s)[ 1] ^ ((uint_32t*)k)[ 1];
    ((uint_32t*)d)[ 2] = ((uint_32t*)s)[ 2] ^ ((uint_32t*)k)[ 2];
    ((uint_32t*)d)[ 3] = ((uint_32t*)s)[ 3] ^ ((uint_32t*)k)[ 3];
}

void BigAES::add_round_key( uint_8t d[N_BLOCK], const uint_8t k[N_BLOCK] )
{
    xor_block(d, k);
}

void BigAES::shift_sub_rows( uint_8t st[N_BLOCK] )
{
    uint_8t tt;

    st[ 0] = s_box(st[ 0]); st[ 4] = s_box(st[ 4]);
    st[ 8] = s_box(st[ 8]); st[12] = s_box(st[12]);

    tt = st[1]; st[ 1] = s_box(st[ 5]); st[ 5] = s_box(st[ 9]);
    st[ 9] = s_box(st[13]); st[13] = s_box( tt );

    tt = st[2]; st[ 2] = s_box(st[10]); st[10] = s_box( tt );
    tt = st[6]; st[ 6] = s_box(st[14]); st[14] = s_box( tt );

    tt = st[15]; st[15] = s_box(st[11]); st[11] = s_box(st[ 7]);
    st[ 7] = s_box(st[ 3]); st[ 3] = s_box( tt );
}

void BigAES::inv_shift_sub_rows( uint_8t st[N_BLOCK] )
{
    uint_8t tt;

    st[ 0] = is_box(st[ 0]); st[ 4] = is_box(st[ 4]);
    st[ 8] = is_box(st[ 8]); st[12] = is_box(st[12]);

    tt = st[13]; st[13] = is_box(st[9]); st[ 9] = is_box(st[5]);
    st[ 5] = is_box(st[1]); st[ 1] = is_box( tt );

    tt = st[2]; st[ 2] = is_box(st[10]); st[10] = is_box( tt );
    tt = st[6]; st[ 6] = is_box(st[14]); st[14] = is_box( tt );

    tt = st[3]; st[ 3] = is_box(st[ 7]); st[ 7] = is_box(st[11]);
    st[11] = is_box(st[15]); st[15] = is_box( tt );
}

void BigAES::mix_sub_columns( uint_8t dt[N_BLOCK] )
{
    uint_8t st[N_BLOCK];
    block_copy(st, dt);

    dt[ 0] = gfm2_sb(st[0]) ^ gfm3_sb(st[5]) ^ s_box(st[10]) ^ s_box(st[15]);
    dt[ 1] = s_box(st[0]) ^ gfm2_sb(st[5]) ^ gfm3_sb(st[10]) ^ s_box(st[15]);
    dt[ 2] = s_box(st[0]) ^ s_box(st[5]) ^ gfm2_sb(st[10]) ^ gfm3_sb(st[15]);
    dt[ 3] = gfm3_sb(st[0]) ^ s_box(st[5]) ^ s_box(st[10]) ^ gfm2_sb(st[15]);

    dt[ 4] = gfm2_sb(st[4]) ^ gfm3_sb(st[9]) ^ s_box(st[14]) ^ s_box(st[3]);
    dt[ 5] = s_box(st[4]) ^ gfm2_sb(st[9]) ^ gfm3_sb(st[14]) ^ s_box(st[3]);
    dt[ 6] = s_box(st[4]) ^ s_box(st[9]) ^ gfm2_sb(st[14]) ^ gfm3_sb(st[3]);
    dt[ 7] = gfm3_sb(st[4]) ^ s_box(st[9]) ^ s_box(st[14]) ^ gfm2_sb(st[3]);

    dt[ 8] = gfm2_sb(st[8]) ^ gfm3_sb(st[13]) ^ s_box(st[2]) ^ s_box(st[7]);
    dt[ 9] = s_box(st[8]) ^ gfm2_sb(st[13]) ^ gfm3_sb(st[2]) ^ s_box(st[7]);
    dt[10] = s_box(st[8]) ^ s_box(st[13]) ^ gfm2_sb(st[2]) ^ gfm3_sb(st[7]);
    dt[11] = gfm3_sb(st[8]) ^ s_box(st[13]) ^ s_box(st[2]) ^ gfm2_sb(st[7]);

    dt[12] = gfm2_sb(st[12]) ^ gfm3_sb(st[1]) ^ s_box(st[6]) ^ s_box(st[11]);
    dt[13] = s_box(st[12]) ^ gfm2_sb(st[1]) ^ gfm3_sb(st[6]) ^ s_box(st[11]);
    dt[14] = s_box(st[12]) ^ s_box(st[1]) ^ gfm2_sb(st[6]) ^ gfm3_sb(st[11]);
    dt[15] = gfm3_sb(st[12]) ^ s_box(st[1]) ^ s_box(st[6]) ^ gfm2_sb(st[11]);
  }

void BigAES::inv_mix_sub_columns( uint_8t dt[N_BLOCK] )
{
    uint_8t st[N_BLOCK];
    block_copy(st, dt);

    dt[ 0] = is_box(gfm_e(st[ 0]) ^ gfm_b(st[ 1]) ^ gfm_d(st[ 2]) ^ gfm_9(st[ 3]));
    dt[ 5] = is_box(gfm_9(st[ 0]) ^ gfm_e(st[ 1]) ^ gfm_b(st[ 2]) ^ gfm_d(st[ 3]));
    dt[10] = is_box(gfm_d(st[ 0]) ^ gfm_9(st[ 1]) ^ gfm_e(st[ 2]) ^ gfm_b(st[ 3]));
    dt[15] = is_box(gfm_b(st[ 0]) ^ gfm_d(st[ 1]) ^ gfm_9(st[ 2]) ^ gfm_e(st[ 3]));

    dt[ 4] = is_box(gfm_e(st[ 4]) ^ gfm_b(st[ 5]) ^ gfm_d(st[ 6]) ^ gfm_9(st[ 7]));
    dt[ 9] = is_box(gfm_9(st[ 4]) ^ gfm_e(st[ 5]) ^ gfm_b(st[ 6]) ^ gfm_d(st[ 7]));
    dt[14] = is_box(gfm_d(st[ 4]) ^ gfm_9(st[ 5]) ^ gfm_e(st[ 6]) ^ gfm_b(st[ 7]));
    dt[ 3] = is_box(gfm_b(st[ 4]) ^ gfm_d(st[ 5]) ^ gfm_9(st[ 6]) ^ gfm_e(st[ 7]));

    dt[ 8] = is_box(gfm_e(st[ 8]) ^ gfm_b(st[ 9]) ^ gfm_d(st[10]) ^ gfm_9(st[11]));
    dt[13] = is_box(gfm_9(st[ 8]) ^ gfm_e(st[ 9]) ^ gfm_b(st[10]) ^ gfm_d(st[11]));
    dt[ 2] = is_box(gfm_d(st[ 8]) ^ gfm_9(st[ 9]) ^ gfm_e(st[10]) ^ gfm_b(st[11]));
    dt[ 7] = is_box(gfm_b(st[ 8]) ^ gfm_d(st[ 9]) ^ gfm_9(st[10]) ^ gfm_e(st[11]));

    dt[12] = is_box(gfm_e(st[12]) ^ gfm_b(st[13]) ^ gfm_d(st[14]) ^ gfm_9(st[15]));
    dt[ 1] = is_box(gfm_9(st[12]) ^ gfm_e(st[13]) ^ gfm_b(st[14]) ^ gfm_d(st[15]));
    dt[ 6] = is_box(gfm_d(st[12]) ^ gfm_9(st[13]) ^ gfm_e(st[14]) ^ gfm_b(st[15]));
    dt[11] = is_box(gfm_b(st[12]) ^ gfm_d(st[13]) ^ gfm_9(st[14]) ^ gfm_e(st[15]));
  }

// Set the cipher key for the pre-keyed version
aes_result BigAES::aes_set_key( const unsigned char key[], int keylen, aes_context ctx[1] )
{
    uint_8t cc, rc, hi;

    switch( keylen )
    {
    case 128:
        keylen = 16;
        break;
    case 192:
        keylen = 24;
        break;
    case 256:
        keylen = 32;
        break;
    default:
        ctx->rnd = 0;
        return -1;
    }
    block_copy_nn(ctx->ksch, key, keylen);
    hi = (keylen + 28) << 2;
    ctx->rnd = (hi >> 4) - 1;
    for( cc = keylen, rc = 1; cc < hi; cc += 4 )
    {   uint_8t tt, t0, t1, t2, t3;

        t0 = ctx->ksch[cc - 4];
        t1 = ctx->ksch[cc - 3];
        t2 = ctx->ksch[cc - 2];
        t3 = ctx->ksch[cc - 1];
        if( cc % keylen == 0 )
        {
            tt = t0;
            t0 = s_box(t1) ^ rc;
            t1 = s_box(t2);
            t2 = s_box(t3);
            t3 = s_box(tt);
            rc = f2(rc);
        }
        else if( keylen > 24 && cc % keylen == 16 )
        {
            t0 = s_box(t0);
            t1 = s_box(t1);
            t2 = s_box(t2);
            t3 = s_box(t3);
        }
        tt = cc - keylen;
        ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0;
        ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1;
        ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2;
        ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3;
    }
    return 0;
}

// Encrypt a single block of 16 bytes
aes_result BigAES::aes_encrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] )
{
    if( ctx->rnd )
    {
        uint_8t s1[N_BLOCK], r;
        copy_and_key( s1, in, ctx->ksch );

        for( r = 1 ; r < ctx->rnd ; ++r )
        {
            mix_sub_columns( s1 );
            add_round_key( s1, ctx->ksch + r * N_BLOCK);
        }
        shift_sub_rows( s1 );
        copy_and_key( out, s1, ctx->ksch + r * N_BLOCK );
    }
    else
        return -1;
    return 0;
}

// CBC encrypt a number of blocks (input and return an IV)
aes_result BigAES::aes_cbc_encrypt(const unsigned char *in, unsigned char *out, unsigned long size, unsigned char iv[N_BLOCK], const aes_context ctx[1] )
{
    if (size % 16 != 0)
        return EXIT_FAILURE;

    unsigned long n_block = size / 16;

    while(n_block--)
    {
        xor_block(iv, in);
        if(aes_encrypt(iv, iv, ctx) != EXIT_SUCCESS)
            return EXIT_FAILURE;
        memcpy(out, iv, N_BLOCK);
        in += N_BLOCK;
        out += N_BLOCK;
    }
    return EXIT_SUCCESS;
}

// Decrypt a single block of 16 bytes
aes_result BigAES::aes_decrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] )
{
    if( ctx->rnd )
    {
        uint_8t s1[N_BLOCK], r;
        copy_and_key( s1, in, ctx->ksch + ctx->rnd * N_BLOCK );
        inv_shift_sub_rows( s1 );

        for( r = ctx->rnd ; --r ; )
        {
            add_round_key( s1, ctx->ksch + r * N_BLOCK );
            inv_mix_sub_columns( s1 );
        }
        copy_and_key( out, s1, ctx->ksch );
    }
    else
        return -1;
    return 0;
}

// CBC decrypt a number of blocks (input and return an IV)
aes_result BigAES::aes_cbc_decrypt( const unsigned char *in, unsigned char *out, unsigned long size, unsigned char iv[N_BLOCK], const aes_context ctx[1] )
{
    if (size % 16 != 0)
        return EXIT_FAILURE;

    unsigned long n_block = size / 16;

    while (n_block--)
    {
        uint_8t tmp[N_BLOCK];

        memcpy(tmp, in, N_BLOCK);
        if(aes_decrypt(in, out, ctx) != EXIT_SUCCESS)
            return EXIT_FAILURE;
        xor_block(out, iv);
        memcpy(iv, tmp, N_BLOCK);
        in += N_BLOCK;
        out += N_BLOCK;
    }
    return EXIT_SUCCESS;
}

test-main.cpp

#include <QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QCryptographicHash>

#include "include/tinyaes.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    // for arguments like:
    // -i="C:/tmp/wow.plaintext"  //input file
    // -p="71251811672021910893"  // plain-text-password (converted to MD5 hash later)
    // no arguments given? -> generic test MB generation
    QString fileTestName = "";
    QString plainPassword = "";
    for (int i = 0; i < qApp->arguments().count(); i++) {
        if (qApp->arguments().at(i).startsWith("-i=")) {
            fileTestName = qApp->arguments()[i].mid(3).remove("\"");
        }
        else if (qApp->arguments().at(i).startsWith("-p=")) {
            plainPassword = qApp->arguments()[i].mid(3).remove("\"");
        }
    }

    if (fileTestName.isEmpty()) {
        TinyAES aes;
        QByteArray input;
        QByteArray encrypted;
        QByteArray decrypted;
        QByteArray password = "d4af1bc61f60a73064e4f599da1fb378";

        for (quint64 i = 9000; i < 10000; i=i+100) {
            if (i < 1000)
                qDebug() << "Encrypting " << i << "KB";
            else
                qDebug() << "Encrypting " << (qreal)i/1000 << "MB";

            input.clear();
            encrypted.clear();
            decrypted.clear();

            input.fill('x', i*1000);

            encrypted = aes.Encrypt(input, password);
            decrypted = aes.Decrypt(encrypted, password);

            if (input != decrypted) {
                qDebug() << "ENCRYPTION ERROR @" << ((i < 1000) ? QString::number(i) + "KB"
                                                                 : QString::number((qreal)i/1000) + "MB" );
                qDebug() << "INPUT: (" << input.size() << ")" << input;
                qDebug() << "ENCRYPTED: (" << encrypted.size() << ")" << encrypted;
                qDebug() << "DECRYPTED: (" << decrypted.size() << ")" << decrypted;
                exit(-1);
            }
        }
    }
    else {
        if (plainPassword.isEmpty()) {
            qDebug() << "no passwd given";
            return 0;
        }

        TinyAES aes;
        QByteArray password = QCryptographicHash::hash(plainPassword.toLatin1(), QCryptographicHash::Md5).toHex();

        QFile f_in(fileTestName);
        qDebug() << "opening" << f_in.fileName();
        f_in.open(QIODevice::ReadOnly);
        QByteArray input = f_in.readAll();
        QByteArray encrypted = aes.Encrypt(input, password);
        QByteArray decrypted = aes.Decrypt(encrypted, password);

        if (input != decrypted) {
            qDebug() << "FEHLER.";
            qDebug() << "INPUT: (" << input.size() << ")";
            qDebug() << "ENCRYPTED: (" << encrypted.size() << ")";
            qDebug() << "DECRYPTED: (" << decrypted.size() << ")";

            qDebug() << "DIFF:";
            for (int i = 0; i < decrypted.count(); i++) {
                if (decrypted[i] != input[i]) {
                    qDebug() << i << decrypted[i];
                }
            }
        }
        else {
            qDebug() << "Cool man, cool ....";
        }
    }
}

Note to myself: next time better learn the math behind the algorithm, before messing with the padding again...

Last edited by axed (2014-08-13 16:03:19)

Offline

#9 2016-08-19 07:49:54

SwallowfieldRocketeer
Member
Registered: 2016-08-18
Posts: 1

Re: TinyAES - A very small AES encryption library for Qt 5.x

Hi this is an old post but since I work with Qt, need a simple AES function it looked interesting.
But can you explain how these padding functions work?

It looks to me as though you pad with increasing numbers and remove padding by looking for decreasing numbers.

Have you tested this with cases where the content is a sequence of increasing numbers, that by coincidence happen to be exactly the same as the padding?,
Or just by bad luck, the last character happens to match what the padding number would have been?

Offline

#10 2016-08-19 14:18:25

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 885

Re: TinyAES - A very small AES encryption library for Qt 5.x

SwallowfieldRocketeer wrote:

But can you explain how these padding functions work? ?

I cannot, sorry.

This was three years ago for some micro-project I've been messing around with so I don't remember, and even back then I didn't write the actual AES implementation myself, it was a borrowed C implementation from the URL in the first post (which seems broken now, as do my example files). Sorry. sad

Offline

Board footer

Powered by FluxBB