Openssl internal error assertion failed

Recently I finally (with help of stackoverflow's user, @WhozCraig) got to work AES in CBC mode. Now, I would like to do exact same thing but with AES IGE. I took a look at openssl-1.0.1e/test/igete...

Recently I finally (with help of stackoverflow’s user, @WhozCraig) got to work AES in CBC mode. Now, I would like to do exact same thing but with AES IGE. I took a look at openssl-1.0.1e/test/igetest.c and tried to build my own test. But once again, I have a problem with inputs and outputs proper sizes. Everything else is good, because I copied it from my previous code: AES (aes-cbc-128, aes-cbc-192, aes-cbc-256) encryption/decryption with openssl C.

Now, when I pass an inputs length which is less than 32, it says:

Give a key length [only 128 or 192 or 256!]:
256
Give an input's length:
3
aes_ige.c(88): OpenSSL internal error, assertion failed: (length%AES_BLOCK_SIZE) == 0
 (core dumped)

But when the lenght is bigger than 32, Im also not so sure if its all ok:

Give a key length [only 128 or 192 or 256!]:
256
Give an input's length:
48
original:       58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 
encrypt:        A4 1F C4 E8 42 5E E5 62 1A B6 C1 47 D2 2F 8D 98 D0 0B 32 77 4E 36 84 25 15 5B BA 60 EA A9 64 D2 53 D1 98 78 83 21 90 90 74 44 C7 AA 3E AD 9B 26 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
decrypt:        58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 

Heres the code:

    #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
#include <openssl/rand.h>

// a simple hex-print routine. could be modified to print 16 bytes-per-line
static void hex_print(const void* pv, size_t len)
{
    const unsigned char * p = (const unsigned char*)pv;
    if (NULL == pv)
        printf("NULL");
    else
    {
        size_t i = 0;
        for (; i<len;++i)
            printf("%02X ", *p++);
    }
    printf("n");
}

// main entrypoint
int main(int argc, char **argv)
{
    int keylength;
    printf("Give a key length [only 128 or 192 or 256!]:n");
    scanf("%d", &keylength);

    /* generate a key with a given length */
    unsigned char aes_key[keylength/8];
    memset(aes_key, 0, keylength/8);
    if (!RAND_bytes(aes_key, keylength/8))
        exit(-1);

    size_t inputslength = 0;
    printf("Give an input's length:n");
    scanf("%lu", &inputslength);

    /* generate input with a given length */
    unsigned char aes_input[inputslength];
    memset(aes_input, 'X', inputslength);

    const size_t ivsize = AES_BLOCK_SIZE*2;

    /* init vector */
    unsigned char iv_enc[ivsize], iv_dec[ivsize];
    RAND_bytes(iv_enc, ivsize);
    memcpy(iv_dec, iv_enc, ivsize);

    // buffers for encryption and decryption
    const size_t encslength = (inputslength/AES_BLOCK_SIZE + 1) * AES_BLOCK_SIZE;//((inputslength + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
    unsigned char enc_out[encslength];
    unsigned char dec_out[inputslength];
    memset(enc_out, 0, sizeof(enc_out));
    memset(dec_out, 0, sizeof(dec_out));

    AES_KEY enc_key, dec_key;
    AES_set_encrypt_key(aes_key, keylength, &enc_key);
    AES_set_decrypt_key(aes_key, keylength, &dec_key);

    AES_ige_encrypt(aes_input, enc_out, inputslength, &enc_key, iv_enc, AES_ENCRYPT);

    AES_ige_encrypt(enc_out, dec_out, encslength, &dec_key, iv_dec, AES_DECRYPT);

    printf("original:t");
    hex_print(aes_input, sizeof(aes_input));

    printf("encrypt:t");
    hex_print(enc_out, sizeof(enc_out));

    printf("decrypt:t");
    hex_print(dec_out, sizeof(dec_out));

    return 0;
}

FINALLY! Got it working (hope so).But I would be veeery grateful if someone can say, that this code below is 100% good ;)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
#include <openssl/rand.h>

// a simple hex-print routine. could be modified to print 16 bytes-per-line
static void hex_print(const void* pv, size_t len)
{
    const unsigned char * p = (const unsigned char*)pv;
    if (NULL == pv)
        printf("NULL");
    else
    {
        size_t i = 0;
        for (; i<len;++i)
            printf("%02X ", *p++);
    }
    printf("n");
}

// main entrypoint
int main(int argc, char **argv)
{
    int keylength = 256;
    //printf("Give a key length [only 128 or 192 or 256!]:n");
    //scanf("%d", &keylength);

    /* generate a key with a given length */
    unsigned char aes_key[keylength/8];
    memset(aes_key, 0, keylength/8);
    if (!RAND_bytes(aes_key, keylength/8))
        exit(-1);

    size_t inputslength = 0;
    printf("Give an input's length:n");
    scanf("%lu", &inputslength);

    /* generate input with a given length */
    unsigned char aes_input[inputslength];
    memset(aes_input, 'X', inputslength);

    const size_t ivsize = AES_BLOCK_SIZE*2;
    /* init vector */
    unsigned char iv_enc[ivsize], iv_dec[ivsize];
    RAND_bytes(iv_enc, ivsize);
    memcpy(iv_dec, iv_enc, ivsize);

    // buffers for encryption and decryption
    const size_t encslength = ((inputslength + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
    unsigned char enc_out[encslength];
    unsigned char dec_out[inputslength];
    memset(enc_out, 0, sizeof(enc_out));
    memset(dec_out, 0, sizeof(dec_out));

    // so i can do with this aes-cbc-128 aes-cbc-192 aes-cbc-256
    AES_KEY enc_key, dec_key;
    AES_set_encrypt_key(aes_key, keylength, &enc_key);
    AES_ige_encrypt(aes_input, enc_out, encslength, &enc_key, iv_enc, AES_ENCRYPT);

    AES_set_decrypt_key(aes_key, keylength, &dec_key);
    AES_ige_encrypt(enc_out, dec_out, encslength, &dec_key, iv_dec, AES_DECRYPT);

    printf("original:t");
    hex_print(aes_input, sizeof(aes_input));

    printf("encrypt:t");
    hex_print(enc_out, sizeof(enc_out));

    printf("decrypt:t");
    hex_print(dec_out, sizeof(dec_out));

    return 0;
}

I only changed this:

AES_ige_encrypt(aes_input, enc_out, **inputslength**, &enc_key, iv_enc, AES_ENCRYPT);

into that:

AES_ige_encrypt(aes_input, enc_out, **encslength**, &enc_key, iv_enc, AES_ENCRYPT);

is it correct?

EDIT No.2 ;)

Ok guys, did another example, with your advices added some padding to the input. Hope its ok now?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
#include <openssl/rand.h>

// a simple hex-print routine. could be modified to print 16 bytes-per-line
static void hex_print(const void* pv, size_t len)
{
    const unsigned char * p = (const unsigned char*)pv;
    if (NULL == pv)
        printf("NULL");
    else
    {
        size_t i = 0;
        for (; i<len;++i)
            printf("%02X ", *p++);
    }
    printf("n");
}

// main entrypoint
int main(int argc, char **argv)
{
    int keylength = 256;
    //printf("Give a key length [only 128 or 192 or 256!]:n");
    //scanf("%d", &keylength);

    /* generate a key with a given length */
    unsigned char aes_key[keylength/8];
    memset(aes_key, 0, keylength/8);
    if (!RAND_bytes(aes_key, keylength/8))
        exit(-1);

    size_t inputslength = 0;
    printf("Give an input's length:n");
    scanf("%lu", &inputslength);

    /* generate input with a given length */
    unsigned char aes_input[inputslength];
    memset(aes_input, 'X', inputslength);

    const size_t ivsize = AES_BLOCK_SIZE*2;
    /* init vector */
    unsigned char iv_enc[ivsize], iv_dec[ivsize];
    RAND_bytes(iv_enc, ivsize);
    memcpy(iv_dec, iv_enc, ivsize);

    // buffers for encryption and decryption
    const size_t encslength = ((inputslength + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;

    unsigned char paddedinput[encslength];
    memset(paddedinput, 0, encslength);
    memcpy(paddedinput, aes_input, inputslength);

    unsigned char enc_out[encslength];
    unsigned char dec_out[inputslength];
    memset(enc_out, 0, sizeof(enc_out));
    memset(dec_out, 0, sizeof(dec_out));

    AES_KEY enc_key, dec_key;
    AES_set_encrypt_key(aes_key, keylength, &enc_key);
    AES_ige_encrypt(paddedinput, enc_out, encslength, &enc_key, iv_enc, AES_ENCRYPT);

    AES_set_decrypt_key(aes_key, keylength, &dec_key);
    AES_ige_encrypt(enc_out, dec_out, encslength, &dec_key, iv_dec, AES_DECRYPT);

    printf("original:t");
    hex_print(aes_input, sizeof(aes_input));

    printf("encrypt:t");
    hex_print(enc_out, sizeof(enc_out));

    printf("decrypt:t");
    hex_print(dec_out, sizeof(dec_out));

    return 0;
}

This document (7017949) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 11 Service Pack 2 (SLES 11 SP2)

Situation

Attempting to start sshd returns the following:

Starting SSH daemonfips.c(154): Openssl internal error, assertion Failed: FATAL FIPS SELFTEST FAILURE 
startproc: signal catched /usr/sbin/sshd: Aborted

The command cat /proc/cmdline shows that fips is not included on kernel command line.
The command cat /proc/sys/crypto/fips_enabled returns 0.
The command rpm -qa| grep openssl shows:

libopenssl0_9_8-hmac-0.9.8j-0.70.1
openssl-doc-0.9.8j-0.70.1lib
openssl0_9_8-0.9.8j-0.89.1.lib
openssl0_9_8-32bit-0.9.8j-0.89.1.lib
openssl0_9_8-hmac-32bit-0.9.8j-0.70.1
openssl-0.9.8j-0.89.1

Resolution

Upgrade the following files to version 0.9.8j-0.89 and then restart sshd:

rpm -Uvh libopenssl0_9_8-hmac-0.9.8j-0.89.1
rpm -Uvh openssl-doc-0.9.8j-0.89.1lib
rpm -Uvh openssl0_9_8-hmac-32bit-0.9.8j-0.89.1

Cause

The openssl file versions of 0.9.8j-0.70.1 are incompatible with version 0.9.8j-0.89.

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented «AS IS» WITHOUT WARRANTY OF ANY KIND.

  • Document ID:7017949
  • Creation Date:
    12-Aug-2016
  • Modified Date:28-Sep-2022
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

  • Remove From My Forums
  • Вопрос

  • I have a number of FIPS compliant Oracle Linux servers that I am unable to monitor due to this. It seems like the agent install quits as soon as it discovers the machine is FIPS:

    «`

    Line 7047 — clone() invoked PID 7601.

    Line 7070 — PID 7601 execve() /opt/microsoft/scx/bin/omiserver

    Line 7080 — PID 7601 open() /opt/microsoft/scx/lib/libssl.so.1.0.0

    Line 7087 — PID 7601 open() /opt/microsoft/scx/lib/libcrypto.so.1.0.0

    Line 7231 — PID 7601 open() /lib64/libselinux.so.1 Line 7303 — PID 7601 open() /usr/lib64/libcrypto.so.1.0.1e

    Line 7309 — PID 7601 open() /proc/sys/crypto/fips_enabled Line 7310 — PID 7601 read() /proc/sys/crypto/fips_enabled (It’s 1/enabled.) Line 7311 — PID 7601 close()/proc/sys/crypto/fips_enabled

    Line 7312 — PID 7601 write() the fips.c error to STDERR.

    «`

    The next four lines process a SIGABRT that PID 7601 sends itself. The STDOUT/STDERR of the start attempt were

    «`

    [root@???????x ~]# service scx-cimd start Starting Microsoft SCX CIM Server: fips.c(143): OpenSSL internal error, assertion failed: FATAL FIPS SELFTEST FAILURE

    /bin/bash: line 1: 17626 Aborted                
    /opt/microsoft/scx/bin/omiserver -d

                                              
                    [FAILED] «`

    The error gets written as soon as the fips_enabled file gets read? Is this an automatic «can’t do FIPS» failure, maybe? I don’t see any indication that a read() of /usr/lib64/libssl.so.1.0.1e is even attempted. Are these libraries FIPS compliant?
    What’s happening here?

    • Изменено

      22 июня 2016 г. 22:09

Ответы

  • Well, this took us far too long to resolve.  We chased our tail for quite a while, but ultimately discovered what the real problem is.  The really good news is that problem has an easy fix, and can be easily worked around before Microsoft
    releases a fix.

    The failure is due to the OMI executables being unable to locate some auxiliary files that go with libssl.so and libcrypto.so.  These auxiliary files are needed only when operating in FIPS mode, so that’s why the problem only crops up when FIPS is enabled. 
    The solution is to create two additional symlinks so that the OMI executables can find these auxiliary files.

    For RHEL/CentOS/Oracle Linux version 6.x (64-bit version) running OpsMgr 2012 R2, the links for locating libssl.so and libcrypto.so are in /opt/microsoft/scx/lib.  To solve the problem, go to this directory as ‘root’, and run the following two
    shell command lines:

    # ln -s /usr/lib64/.libssl.so.10.hmac .libssl.so.1.0.0.hmac

    # ln -s /usr/lib64/.libcrypto.so.10.hmac .libcrypto.so.1.0.0.hmac

    These links will enable the OMI executable to find the hmac files that are needed in FIPS mode.  That’s all there is to it, and OMI should now work in FIPS mode.

    If you are running a different Linux distro or version, or OpsMgr 2016, the symlinks might be slightly different or in a different location, but the issue is the same — finding the hmac files. 

    Separately, we will work on updating the OpsMgr agent installer so that in a future Update Rollup, it will automatically create these symlinks in addition to the two main symlinks for libssl and libcrypto that it already creates.


    Michael Kelley, Lead Program Manager, Open Source Technology Center

    • Помечено в качестве ответа
      Michael Kelley [MSFT]
      2 декабря 2016 г. 18:09

  • My suggestion is to install our kit, and let the installation fail.  At this point, you should see something like:

    fips.c(143): OpenSSL internal error, assertion failed: FATAL FIPS SELFTEST FAILURE/var/tmp/rpm-tmp.kSP7C1:
    line 341: 24795 Aborted
                    /opt/microsoft/scx/bin/tools/scxsslconfig
    warning: %post(scx-1.5.1-184.x86_64) scriptlet failed, exit status 1

    At this point, two things have happened:

    1. We failed to generate a certificate because of the FIPS issue, and
    2. We failed to start the server.

    At this point, you should go to /opt/microsoft/scx/lib and set up the links. Here’s a log of what I did:

    [root@os64-ora67-01 ~]# rpm —install scx-1.5.1-184.universalr.1.x64.rpm 
    Checking existence of /lib64/libssl.so.1.0.1e-fips and /lib64/libcrypto.so.1.0.1e-fips …
    Checking existence of /lib64/libssl.so.1.0.1- and /lib64/libcrypto.so.1.0.1- …
    Checking existence of /lib64/libssl.so.1.0.1e and /lib64/libcrypto.so.1.0.1e …
    Checking existence of /lib64/libssl.so.1.0.1 and /lib64/libcrypto.so.1.0.1 …
    Checking existence of /lib64/libssl.so.1.0.0 and /lib64/libcrypto.so.1.0.0 …
    Checking existence of /usr/lib64/libssl.so.1.0.1e-fips and /usr/lib64/libcrypto.so.1.0.1e-fips …
    Checking existence of /usr/lib64/libssl.so.1.0.1- and /usr/lib64/libcrypto.so.1.0.1- …
    Checking existence of /usr/lib64/libssl.so.1.0.1e and /usr/lib64/libcrypto.so.1.0.1e …
      Found /usr/lib64/libssl.so.1.0.1e and /usr/lib64/libcrypto.so.1.0.1e …
    fips.c(143): OpenSSL internal error, assertion failed: FATAL FIPS SELFTEST FAILURE
    /var/tmp/rpm-tmp.SxPhxm: line 341:  2736 Aborted                 (core dumped) /opt/microsoft/scx/bin/tools/scxsslconfig
    warning: %post(scx-1.5.1-184.x86_64) scriptlet failed, exit status 1
    [root@os64-ora67-01 ~]# 
    [root@os64-ora67-01 ~]# pushd /opt/microsoft/scx/lib
    /opt/microsoft/scx/lib ~
    [root@os64-ora67-01 lib]# ln -s /usr/lib64/.libssl.so.10.hmac .libssl.so.1.0.0.hmac
    [root@os64-ora67-01 lib]# ln -s /usr/lib64/.libcrypto.so.10.hmac .libcrypto.so.1.0.0.hmac
    [root@os64-ora67-01 lib]# popd
    ~
    [root@os64-ora67-01 ~]# 
    [root@os64-ora67-01 ~]# /opt/microsoft/scx/bin/tools/scxsslconfig -f
    Generating certificate with hostname=»os64-ora67-01″, domainname=»scx.com»
    [root@os64-ora67-01 ~]# /etc/init.d/scx-cimd start
    Starting Microsoft SCX CIM Server:                         [  OK  ]
    [root@os64-ora67-01 ~]# ps -ef | grep omi
    root     22421     1  0 15:15 ?        00:00:00 /opt/microsoft/scx/bin/omiserver -d
    root     22423  2348  0 15:15 pts/0    00:00:00 grep omi
    [root@os64-ora67-01 ~]# 

    Let me know if you have further questions, and I’ll do my best to help you out.

    /Jeff

    • Помечено в качестве ответа
      Jeff CofflerMicrosoft employee
      13 декабря 2016 г. 16:53

pavandevaraj

Posts: 2
Joined: 2018/11/10 13:30:03

CentOS 7.5 — FIPS mode — sha512sum hashing fails with openssl error

Hi,

I am running CentOS 7.5.1804 in FIPS mode. When trying to hash a file using /usr/bin/sha512sum <FILE_NAME>, I get the following error:

sha512.c(81): OpenSSL internal error, assertion failed: Low level API call to digest SHA512 forbidden in FIPS mode!
Aborted

I also tried running openssl dgst command. It fails with error:

Error setting digest dgst
139795816437648:error:060A80A3:digital envelope routines:FIPS_DIGESTINIT:disabled for fips:fips_md.c:180:

Please advice.



pavandevaraj

Posts: 2
Joined: 2018/11/10 13:30:03

Re: CentOS 7.5 — FIPS mode — sha512sum hashing fails with openssl error

Post

by pavandevaraj » 2018/11/10 16:04:31

Thanks for the reply. The URL suggests to use EVP_Message_Digests. However, there’s nothing I have implemented here and am just using the sha512sum binary provided by coreutils package.

rpm -qf /usr/bin/sha512sum
coreutils-8.22-21.el7.x86_64

I am using openssl version: OpenSSL 1.0.2o-fips

The same call works on CentOS6.7 in FIPS mode. The openssl version is also same on centOS6.7. Not sure what is the problem here.


User avatar

TrevorH

Site Admin
Posts: 32529
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: CentOS 7.5 — FIPS mode — sha512sum hashing fails with openssl error

Post

by TrevorH » 2018/11/10 16:19:51

I am using openssl version: OpenSSL 1.0.2o-fips

We only support what we ship and we ship openssl 1.0.2k.


Понравилась статья? Поделить с друзьями:

Читайте также:

  • Openssl error messages error 1416f086 ssl
  • Openssl error c5065064 microsoft cryptoapi certfindcertificateinstore
  • Openssl error 140ab18e ssl routines ssl ctx use certificate ca md too weak
  • Openssl error 14090086
  • Opengl init error

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии