PDA

View Full Version : uint8_t don't used in Qt



madawg
17th September 2018, 07:46
uint8_t *data = (uint8_t *) inputData.data();
uint8_t *key = (uint8_t *) keyData.data();

struct AES_ctx ctx;
AES_init_ctx(&ctx, key);
AES_ECB_encrypt(&ctx, data);

I got a message error:

error: undefined reference to `AES_init_ctx(AES_ctx*, unsigned char const*)'
error: undefined reference to `AES_ECB_encrypt(AES_ctx*, unsigned char*)'

I think that uint8_t changed unsigned char by Qt.
But uint8_t is member of stdint lib
#include <stdint.h>

tuli
17th September 2018, 07:55
more likely, you didnt add aes.c to your project.

Lesiok
17th September 2018, 07:59
Qt has nothing to do with it. This a line from stdint.h :

typedef unsigned char uint8_t;
You do not link the correct library.

madawg
17th September 2018, 08:20
But I see in source code of Tiny-AES-C:
void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key)
and author of lib also
#include <stdint.h>

I see a person used at link https://codejamming.org/text-encryption-in-qtc-with-tiny-aes-128bit/


#ifndef AESQT_H
#define AESQT_H

# tons of other includes
#include "../tiny-aes/aes.h"

namespace Encryption {

const uint8_t iv[] = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96,
0x87, 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x5e, 0xaf };

inline int getAlignedSize(int currSize, int alignment) {
int padding = (alignment - currSize % alignment) % alignment;
return currSize + padding;
}

QString encodeText(const QString &rawText, const QString &key) {
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(key.toUtf8());
QByteArray keyData = hash.result();

const ushort *rawData = rawText.utf16();
void *rawDataVoid = (void*)rawData;
const char *rawDataChar = static_cast(rawDataVoid);
QByteArray inputData;
// ushort is 2*uint8_t + 1 byte for '\0'
inputData.append(rawDataChar, rawText.size() * 2 + 1);

const int length = inputData.size();
int encryptionLength = getAlignedSize(length, 16);

QByteArray encodingBuffer(encryptionLength, 0);
inputData.resize(encryptionLength);

AES128_CBC_encrypt_buffer((uint8_t*)encodingBuffer .data(), (uint8_t*)inputData.data(),
encryptionLength, (const uint8_t*)keyData.data(), iv);

QByteArray data(encodingBuffer.data(), encryptionLength);
QString hex = QString::fromLatin1(data.toHex());
return hex;
}

QString decodeText(const QString &hexEncodedText, const QString &key) {
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(key.toUtf8());
QByteArray keyData = hash.result();

const int length = hexEncodedText.size();
int encryptionLength = getAlignedSize(length, 16);

QByteArray encodingBuffer(encryptionLength, 0);

QByteArray encodedText = QByteArray::fromHex(hexEncodedText.toLatin1());
encodedText.resize(encryptionLength);

AES128_CBC_decrypt_buffer((uint8_t*)encodingBuffer .data(), (uint8_t*)encodedText.data(),
encryptionLength, (const uint8_t*)keyData.data(), iv);

encodingBuffer.append("\0\0");
void *data = encodingBuffer.data();
const ushort *decodedData = static_cast(data);
QString result = QString::fromUtf16(decodedData);
return result;
}
}

#endif // AESQT_H

d_stranz
18th September 2018, 04:15
You aren't listening. Your problem has nothing to do with uint8_t. Your problem is that the linker cannot find any compiled code that contains the two AES_*() methods it is complaining about. As tuli said, it is probably because you are not compiling and linking the aes.c file into your build.