Mbed TLS is now part of TrustedFirmware.org.

mbedtls_ctr_drbg_seed - memory allocation issue


Oct 1, 2017 23:55
john

Hi,

I am trying to set up a random number generator, and I am experiencing an issue in which a SIGABRT is raised sometimes. The issue is intermittent, although the program itself is single-threaded and very short.

The basics look like this:

const char *pers = "generate random data";
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_context entropy;

int initialize() {
    int ret;
    mbedtls_entropy_init(&entropy);
    mbedtls_ctr_drbg_init(&ctr_drbg);
    ret = mbedtls_ctr_drbg_seed(    &ctr_drbg,
                                    mbedtls_entropy_func,
                                    &entropy,
                                    (const unsigned char *) pers,
                                    strlen(pers));
    return ret;
}

int main(void) {
    if (initialize() != 0) {
        printf("Couldn't initialize\n");
        return 1;
    }
    return 0;
}

It is at the call to "mbedtls_ctr_drbg_seed" that I get this (sometimes):

malloc: *** error for object 0x7f8379002408: incorrect checksum for freed object - object was probably modified after being freed. *** set a breakpoint in malloc_error_break to debug Abort trap: 6

I only perform the initialization once at the beginning of the program, but some of the time, I get the error, and other times I do not.

Any help in resolving this issue will be greatly appreciated!

 
Oct 2, 2017 05:41
john

Issue resolved! Just another PEBKAC.

 
Jan 18, 2018 07:01
Amit Shirbhate

Hi John,

For a similar, single threaded simple program, I am experiencing

MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED error.

Can you please suggest, what must be going wrong ?

May be in this case too PEBKAC however, not able to locate it. :)

Thanks, Amit