How to replace the calloc and free implementations in mbedtls library using MBEDTLS_MEMORY_BUFFER_ALLOC_C

Hello everyone,
I am new to mbedtls library and want to replace calloc and free using the MBEDTLS_MEMORY_BUFFER_ALLOC_C macro.
I replaced it in below function in mbedTLS library bignum.c file. Can anyone help me as how to do it?
int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs )
{
unsigned char memory_buf[100];
mbedtls_memory_buffer_alloc_init( memory_buf, sizeof(memory_buf) );

mbedtls_mpi_uint *p;

if( nblimbs > MBEDTLS_MPI_MAX_LIMBS )
    return( MBEDTLS_ERR_MPI_ALLOC_FAILED );

if( X->n < nblimbs )
{
   // if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( nblimbs * ciL ) ) == NULL ) 
   //     return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
   p =  &memory_buf[0];

    if( X->p != NULL )
    {
        memcpy( p, X->p, X->n * ciL );
        mbedtls_mpi_zeroize( X->p, X->n );
        mbedtls_free( X->p );
    }

    X->n = nblimbs;
    X->p = p;

    
}

return( 0 );

}