Qt World Summit: Register Today!

[Solved]Using QCA results in segmentation fault

  • Im trying to get QCA (Qt Cryptographic Arcetecture) to work on Qt 5.0 on Ubuntu 13.04 32bit. But when I build the program I get a Segmentation fault as soon as the function that uses QCA is called.

    I installed openssl, libqca-dev, and qca-plugin for openssl from the ubuntu repos.
    I copied qca-plugin for openssl and pasted it in my project's directory inside a folder named crypto
    I added include path and LIBS to my pro file:

    Here is my project.pro file
    @folder_01.source = qml/umail
    folder_01.target = qml

    Additional import path used to resolve QML modules in Creator's code model


    If your application uses the Qt Mobility libraries, uncomment the following

    lines and add the respective components to the MOBILITY variable.

    CONFIG += mobility


    The .cpp file which was generated for your project. Feel free to hack it.

    SOURCES += main.cpp

    Installation path

    target.path =

    Please do not modify the following two lines. Required for deployment.


    HEADERS +=


    INCLUDEPATH += /usr/include/QtCrypto

    LIBS += -L$$PWD/usr/lib/i386-linux-gnu -lqca

    Here is the function which causes the segmentation fault(It is a method of CryptoHash class):

    @void CryptoHash::encryptSomeData()
    * I get segmentation fault at
    * QCA::Initializer init = QCA::Initializer();
    //initialize QCA
    QCA::Initializer init = QCA::Initializer();
    //generate a random symmetric 16-bytes key
    QCA::SymmetricKey key = QCA::SymmetricKey(16);
    //generate a random 16-bytes initialization vector
    QCA::InitializationVector iv = QCA::InitializationVector(16);
    //initialize the cipher for aes128 algorithm, using CBC mode,
    //with padding enabled (by default), in encoding mode,
    //using the given key and initialization vector
    QCA::Cipher cipher = QCA::Cipher(QString("aes128"), QCA::Cipher::CBC,
    QCA::Cipher::DefaultPadding, QCA::Encode,
    key, iv);
    //check if aes128 is available
    if (!QCA::isSupported("aes128-cbc-pkcs7"))
    qDebug() << "AES128 CBC PKCS7 not supported - "
    "please check if qca-ossl plugin"
    "installed correctly !";
    //the string we want to encrypt
    QString s = "Hello, world !";
    //we use SecureArray: read more here:
    //QCA secure array details
    QCA::SecureArray secureData = s.toLatin1();
    //we encrypt the data
    QCA::SecureArray encryptedData = cipher.process(secureData);
    //check if encryption succeded
    if (!cipher.ok())
    qDebug() << "Encryption failed !";
    //display the result
    qDebug() << QString(qPrintable(QCA::arrayToHex(encryptedData.toByteArray())));
    //set the cipher mode to encryption
    cipher.setup(QCA::Decode, key, iv);
    //decrypt the encrypted data
    QCA::SecureArray decryptedData = cipher.process(encryptedData);
    //check if decryption succeded
    if (!cipher.ok())
    qDebug() << "Decryption failed !";
    //display the decrypted data (it should be "Hello, world !")
    qDebug() << QString(decryptedData.data());

    Please help me figure out what is wrong. My whole project depends on cryptography. BTW Im a cryptography noob.

    Thank you....

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    After a quick read of an example:


    @QCA::Initializer init = QCA::Initializer();@


    @QCA::Initializer init;@

    Hope it helps

  • Thank you for the quick reply... however I tried
    @QCA::Initializer init;@
    And even
    @QCA::Initializer * init = new QCA::Initializer();@
    But the same erroe is happening.

    Another interesting thing is that even if I remove the
    @LIBS += -L$$PWD/usr/lib/i386-linux-gnu -lqca@
    from the .pro file the same thing is happening. Does this mean that the library is not loading?

  • Lifetime Qt Champion

    Another thing, are you sure that all libraries are found when you start your program ?

  • This is the compiler output
    @03:02:29: Running steps for project umail...
    03:02:29: Starting: "/usr/bin/qmake" '/home/kaziwaseef/QML/Ubuntu Phone App/umail/umail/umail.pro' -r -spec linux-g++ CONFIG+=debug CONFIG+=declarative_debug CONFIG+=qml_debug
    03:02:29: The process "/usr/bin/qmake" exited normally.
    03:02:29: Starting: "/usr/bin/make"
    Copying application data...
    03:02:29: The process "/usr/bin/make" exited normally.
    03:02:29: Elapsed time: 00:00.@

    Everything seems to compile ok.... any other tests that I can perform???

    Thank you.

  • Lifetime Qt Champion

    Not the compilation, the application itself, check that it can find all libraries when starting (not the same as when linking) i.e using ldd

  • Errr... could you please tell me how to do that?

    • This is the first time I'm manually linking to external libraries...

  • Lifetime Qt Champion

    run ldd youApplicationExecutable and look at the output for missing libraries

  • Thank you for the help. This is the output of ldd. Line 2 shows that libqca loads but I was expecting libqca.so.2.0.3

    @linux-gate.so.1 => (0xb7729000)
    libqca.so.2 => /usr/lib/i386-linux-gnu/libqca.so.2 (0xb7613000)
    libQt5Quick.so.5 => /usr/lib/i386-linux-gnu/libQt5Quick.so.5 (0xb72d9000)
    libQt5Qml.so.5 => /usr/lib/i386-linux-gnu/libQt5Qml.so.5 (0xb7099000)
    libQt5Network.so.5 => /usr/lib/i386-linux-gnu/libQt5Network.so.5 (0xb6f5d000)
    libQt5Gui.so.5 => /usr/lib/i386-linux-gnu/libQt5Gui.so.5 (0xb6b7f000)
    libQt5Core.so.5 => /usr/lib/i386-linux-gnu/libQt5Core.so.5 (0xb674b000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb6662000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb6644000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6491000)
    libQtCore.so.4 => /usr/lib/i386-linux-gnu/libQtCore.so.4 (0xb61a9000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb618e000)
    libQt5V8.so.5 => /usr/lib/i386-linux-gnu/libQt5V8.so.5 (0xb5d71000)
    libGL.so.1 => /usr/lib/nvidia-313-updates/libGL.so.1 (0xb5c90000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb5c4d000)
    libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb5c34000)
    libpng12.so.0 => /lib/i386-linux-gnu/libpng12.so.0 (0xb5c0b000)
    libicui18n.so.48 => /usr/lib/i386-linux-gnu/libicui18n.so.48 (0xb5a37000)
    libicuuc.so.48 => /usr/lib/i386-linux-gnu/libicuuc.so.48 (0xb58d1000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb58cc000)
    libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0xb57cb000)
    librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb57c2000)
    /lib/ld-linux.so.2 (0xb772a000)
    libnvidia-tls.so.313.30 => /usr/lib/nvidia-313-updates/tls/libnvidia-tls.so.313.30 (0xb57be000)
    libnvidia-glcore.so.313.30 => /usr/lib/nvidia-313-updates/libnvidia-glcore.so.313.30 (0xb3a7b000)
    libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0xb3944000)
    libXext.so.6 => /usr/lib/i386-linux-gnu/libXext.so.6 (0xb3932000)
    libicudata.so.48 => /usr/lib/i386-linux-gnu/libicudata.so.48 (0xb27c1000)
    libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb2780000)
    libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0xb275d000)
    libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0xb2759000)
    libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0xb2752000)@

  • I really dont know what is wrong. Will try to fix it if I I have time... In the meantime I got crypto++ working so I'll use that :)

    However, I wish to find out what went wrong with QCA, for knowledge's sake...

  • Lifetime Qt Champion

    Haaaaaaaaaaaaaaa ! I've forgot that you where using Qt 5...
    Then the answer is simple:
    You are building your software using Qt 5 and you are linking to your system's qca which is built with Qt 4 so what you get is a binary that will load Qt 5 and Qt 4 in the same address space so they will collide and then the crash.

    If you take a closer look at ldd's output (i.e using | grep libQt) you'll see this:
    libQtCore.so.4 <- There's the clue

    So you have two solutions:

    build your own qca with your Qt 5 and use that one

    build your software with Qt 4

    Hope it shed some lights :)

Log in to reply