Topic: Problem with wolfssl on riscv with static memory feature
Hi,
I am trying to create an encrypted connection between two riscv processors. These are basic units without support for dynamic memory allocation. The library is compiled using the following command:
./configure\
--prefix=/home/david/wolfbare\
--host=riscv32-unknown-elf\
CC=/opt/riscv_gcc10.1/bin/riscv32-unknown-elf-gcc\
AR=/opt/riscv_gcc10.1/bin/riscv32-unknown-elf-ar\
AS=/opt/riscv_gcc10.1/bin/riscv32-unknown-elf-a\
RANLIB=/opt/riscv_gcc10.1/bin/riscv32-unknown-elf-gcc-ranlib\
LD=/opt/riscv_gcc10.1/bin/riscv32-unknown-elf-ld\
CXX=/opt/riscv_gcc10.1/bin/riscv32-unknown-elf-g++\
--disable-examples\
--enable-static\
--disable-dh\
--disable-shared\
--disable-crypttests\
--disable-asm\
--disable-rsa\
--enable-tls13\
--disable-tlsv12\
--disable-filesystem\
--enable-singlethreaded\
--enable-debug\
--enable-staticmemory\
--enable-fastmath\
--enable-sp=nomalloc\
CFLAGS="-march=rv32i -mabi=ilp32 -mcmodel=medany -ffunction-sections -fdata-sections -D WOLFSSL_USER_IO -D NO_WRITEV"
I then try to initialise the library using the following functions:
WOLFSSL_CTX* ctx = NULL; /* pass NULL to generate WOLFSSL_CTX */
#define MAX_CONCURRENT_TLS 0
#define MAX_CONCURRENT_IO 0
#define GEN_MEM_SIZE 200000
#define IO_MEM_SIZE 100000
unsigned char GEN_MEM[GEN_MEM_SIZE];
unsigned char IO_MEM[IO_MEM_SIZE ];
int ret;
if (wolfSSL_Debugging_ON() != 0) {
uart.write("debugin FAIL.\n");
}
ret = wolfSSL_CTX_load_static_memory(
&ctx, /* set NULL to ctx */
wolfTLSv1_3_client_method_ex, /* use function with "_ex" */
GEN_MEM, GEN_MEM_SIZE, /* buffer and its size */
WOLFMEM_GENERAL, /* general purpose */
MAX_CONCURRENT_TLS); /* max concurrent objects */
if (ret != SSL_SUCCESS)
uart.write("wolfSSL_CTX_load_static_memory FAIL.\n");
else
uart.write("wolfSSL_CTX_load_static_memory PASS.\n");
/* set up a I/O-purpose buffer on the second call. */
wolfSSL_CTX_load_static_memory(
&ctx, /* make sure ctx is holding the object */
NULL, /* pass it to NULL this time */
IO_MEM, IO_MEM_SIZE, /* buffer and its size */
WOLFMEM_IO_POOL_FIXED, /* I/O purpose */
MAX_CONCURRENT_IO); /* max concurrent objects */
if (ret != SSL_SUCCESS)
uart.write("wolfSSL_CTX_load_static_memory FAIL.\n");
else
uart.write("wolfSSL_CTX_load_static_memory PASS.\n");
/* Load CA certificates into WOLFSSL_CTX */
ret = wolfSSL_CTX_load_verify_buffer(ctx, certBuf, certBufSz, SSL_FILETYPE_PEM);
if (ret != SSL_SUCCESS)
uart.write("wolfSSL_CTX_load_verify_buffer FAIL.\n");
else
uart.write("wolfSSL_CTX_load_verify_buffer PASS.\n");
And I get this:
wolfSSL Entering wolfSSL_load_static_memory
wolfSSL Entering TLSv1_3_client_method_ex
wolfSSL Entering TLSv1_3_client_method_ex
wolfSSL Entering wolfSSL_CTX_new_ex
wolfSSL Entering wolfCrypt_Init
wolfSSL Entering wolfSSL_CertManagerNew
wolfSSL Leaving wolfSSL_CTX_new_ex, return 0
wolfSSL_CTX_load_static_memory PASS.
wolfSSL Entering wolfSSL_load_static_memory
wolfSSL_CTX_load_static_memory PASS.
wolfSSL Entering wolfSSL_CTX_load_verify_buffer_ex
Processing CA PEM file
wolfSSL Entering PemToDer
Adding a CA
Getting Cert Name
Getting Cert Name
wolfSSL Entering GetAlgoId
Unknown or not compiled in key OID
Parsed new CA
No key size check done on CA
Freeing Parsed CA
Freeing der CA
OK Freeing der CA
wolfSSL Leaving AddCA, return -148
wolfSSL error occurred, error = -148
CA Parse failed, with progress in file.
Search for other certs in file
wolfSSL Leaving wolfSSL_CTX_load_verify_buffer_ex, return -148
I do not know what to do with this?
[Edit]
I managed to solve this problem and it turned out that I had the RSA algorithm turned off during the compilation. So it is worth looking into asn.c and checking that the code that GetAlgoId returns is defined.
But I still have a question to function:
ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method())
should I use it before function:
wolfSSL_CTX_load_verify_buffer()
Beacues when I will use it i will recive error -125 in AllocDer() function ? And I am testing this setup on linux between two terminals and when I try to setup echoclient without this function I am unable to connect to server