Results 1 to 5 of 5

Thread: uint8_t don't used in Qt

  1. #1
    Join Date
    May 2018
    Posts
    19
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default uint8_t don't used in Qt

    Qt Code:
    1. uint8_t *data = (uint8_t *) inputData.data();
    2. uint8_t *key = (uint8_t *) keyData.data();
    3.  
    4. struct AES_ctx ctx;
    5. AES_init_ctx(&ctx, key);
    6. AES_ECB_encrypt(&ctx, data);
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. #include <stdint.h>
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: uint8_t don't used in Qt

    more likely, you didnt add aes.c to your project.

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: uint8_t don't used in Qt

    Qt has nothing to do with it. This a line from stdint.h :
    Qt Code:
    1. typedef unsigned char uint8_t;
    To copy to clipboard, switch view to plain text mode 
    You do not link the correct library.

  4. #4
    Join Date
    May 2018
    Posts
    19
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: uint8_t don't used in Qt

    But I see in source code of Tiny-AES-C:
    Qt Code:
    1. void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key)
    To copy to clipboard, switch view to plain text mode 
    and author of lib also
    Qt Code:
    1. #include <stdint.h>
    To copy to clipboard, switch view to plain text mode 

    I see a person used at link https://codejamming.org/text-encrypt...ny-aes-128bit/
    Qt Code:
    1. #ifndef AESQT_H
    2. #define AESQT_H
    3.  
    4. # tons of other includes
    5. #include "../tiny-aes/aes.h"
    6.  
    7. namespace Encryption {
    8.  
    9. const uint8_t iv[] = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96,
    10. 0x87, 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x5e, 0xaf };
    11.  
    12. inline int getAlignedSize(int currSize, int alignment) {
    13. int padding = (alignment - currSize % alignment) % alignment;
    14. return currSize + padding;
    15. }
    16.  
    17. QString encodeText(const QString &rawText, const QString &key) {
    18. QCryptographicHash hash(QCryptographicHash::Md5);
    19. hash.addData(key.toUtf8());
    20. QByteArray keyData = hash.result();
    21.  
    22. const ushort *rawData = rawText.utf16();
    23. void *rawDataVoid = (void*)rawData;
    24. const char *rawDataChar = static_cast(rawDataVoid);
    25. QByteArray inputData;
    26. // ushort is 2*uint8_t + 1 byte for '\0'
    27. inputData.append(rawDataChar, rawText.size() * 2 + 1);
    28.  
    29. const int length = inputData.size();
    30. int encryptionLength = getAlignedSize(length, 16);
    31.  
    32. QByteArray encodingBuffer(encryptionLength, 0);
    33. inputData.resize(encryptionLength);
    34.  
    35. AES128_CBC_encrypt_buffer((uint8_t*)encodingBuffer.data(), (uint8_t*)inputData.data(),
    36. encryptionLength, (const uint8_t*)keyData.data(), iv);
    37.  
    38. QByteArray data(encodingBuffer.data(), encryptionLength);
    39. QString hex = QString::fromLatin1(data.toHex());
    40. return hex;
    41. }
    42.  
    43. QString decodeText(const QString &hexEncodedText, const QString &key) {
    44. QCryptographicHash hash(QCryptographicHash::Md5);
    45. hash.addData(key.toUtf8());
    46. QByteArray keyData = hash.result();
    47.  
    48. const int length = hexEncodedText.size();
    49. int encryptionLength = getAlignedSize(length, 16);
    50.  
    51. QByteArray encodingBuffer(encryptionLength, 0);
    52.  
    53. QByteArray encodedText = QByteArray::fromHex(hexEncodedText.toLatin1());
    54. encodedText.resize(encryptionLength);
    55.  
    56. AES128_CBC_decrypt_buffer((uint8_t*)encodingBuffer.data(), (uint8_t*)encodedText.data(),
    57. encryptionLength, (const uint8_t*)keyData.data(), iv);
    58.  
    59. encodingBuffer.append("\0\0");
    60. void *data = encodingBuffer.data();
    61. const ushort *decodedData = static_cast(data);
    62. QString result = QString::fromUtf16(decodedData);
    63. return result;
    64. }
    65. }
    66.  
    67. #endif // AESQT_H
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: uint8_t don't used in Qt

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.