1 (edited by DAZHOU0424wupan 2020-01-13 22:07:34)

Topic: [SOLVED] wolfSSL_new return 0

  I'm trying work with Wolfssl using FreeRTOS+TCP on mpc5748g board.
   ret = wolfSSL_Init();
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  socket_saddr.sin_family = AF_INET;
  socket_saddr.sin_addr.s_addr = PP_HTONL(INADDR_ANY);
  socket_saddr.sin_port = lwip_htons(PORT); /* echo server port */

  ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  LWIP_ASSERT("wolfSSL_CTX_new() failed", ctx != NULL);

  /* Limit to AES128 - hardware-accelerated */
  ret = wolfSSL_CTX_set_cipher_list(ctx, "AES128-SHA");

  /* Load CA certificates */
  ret = wolfSSL_CTX_load_verify_buffer(ctx, CA_CERT, CA_CERT_SIZE, SSL_FILETYPE_ASN1);

  /* Load server certificate */
  ret = wolfSSL_CTX_use_certificate_buffer(ctx, SERVER_CERT, SERVER_CERT_SIZE, SSL_FILETYPE_ASN1);

  /* Load keys */
  ret = wolfSSL_CTX_use_PrivateKey_buffer(ctx, SERVER_KEY, SERVER_KEY_SIZE, SSL_FILETYPE_ASN1);

   if (bind(listenfd, (struct sockaddr *) &socket_saddr, sizeof(socket_saddr)) == -1) {
    LWIP_ASSERT("socket_server_thread(): Socket bind failed.", 0);

  /* Put socket into listening mode */
  if (listen(listenfd, MAX_SERV) == -1) {
    LWIP_ASSERT("socket_server_thread(): Listen failed.", 0);
for (;;) {
        p_clientcb->socket = accept(listenfd,
                (struct sockaddr *) &p_clientcb->cliaddr,
        if (p_clientcb->socket < 0) {

        } else {
          /* Keep this tecb in our list */
          p_clientcb->ssl = wolfSSL_new(ctx);
          LWIP_ASSERT("wolfSSL_new() failed.", p_clientcb->ssl != NULL);
          wolfSSL_set_fd(p_clientcb->ssl, p_clientcb->socket);
          p_clientcb->next = clientcb_list;
          clientcb_list = p_clientcb;


Re: [SOLVED] wolfSSL_new return 0


Can you tell us a bit about what is driving this project, what the end product will be and what it will do? Looking forward to hearing more!

When wolfSSL_new(ctx); returns a NULL this means there was not sufficient HEAP to allocate an SSL object. Check the (in FreeRTOS) configTOTAL_HEAP_SIZE setting in FreeRTOSConfig.h is set sufficiently high enough to support whatever task stack size you are setting (task stacks are allocated from the top level configTOTAL_HEAP_SIZE).

Next check what stack size was set in your call to "xTaskCreate" (usually in your main.c or application main etc). Try increasing the stack size set. Here is an example I use:

// modify desired_stack_size as needed, never touch actual_size
int desired_stack_size = 30; // I want my stack to be 30k

int actual_size = (desired_stack_size * 1024) / 4; // Note FreeRTOS stack is declared in 4-byte words so 30kb == (30*1024) / 4;

xTaskCreate(main_thread, "Main Thread", actual_size, NULL, 5, &main_thread_h) ;



Re: [SOLVED] wolfSSL_new return 0

Thanks for the help! The problem was solved by creating a custom random seed generator, now everything is running fine


Re: [SOLVED] wolfSSL_new return 0


Thanks so much for the update, happy to hear you were able to resolve by setting up an entropy source!