Contact Details
alex@minres.com
Version
5.9.1 (commit 6a3eb6f)
Description
RISC-V systems may, but do not need to support unaligned loads and stores. Concretely, there are systems that expect sw / lw and sd / ld to be 4 and 8 byte aligned, respectively. Misaligned loads and stores can then raise an exception.
I ran into a few occasions where alignment was not given.
The first issue I ran into was that there are no alignment requirements for the secret and masterSecret byte Arrays in the Arrays struct. These happened to lay at 1 byte alignment for me and were propagated to some RISC-V assembly, which expected 4 or 8 byte alignment.
I managed to work around this locally by enabling WOLFSSL_USE_ALIGN and prepending the corresponding define:
<internal.h>
typedef struct Arrays {
...
#ifdef WOLFSSL_TLS13
ALIGN8 byte secret[SECRET_LEN];
#endif
#ifdef HAVE_KEYING_MATERIAL
byte exporterSecret[WC_MAX_DIGEST_SIZE];
#endif
ALIGN8 byte masterSecret[SECRET_LEN];
...
} Arrays;
The one I cannot solve on my own is from the following call stack (breakpoint on the faulting instruction):
In this very case createSigData propagates an address in ret = GetMsgHash(ssl, &sigData[idx]); with idx equal to 92. sigData is 4 byte aligned, an offset of 92 is then only 2 byte aligned. This then faults when it propagates the call stack down to this store instruction.
I have tested the standalone wolfcrypt API for RISC-V assembly successfully, but I encounter these issues in the TLS1.3 application I am trying to run. My application runs fine when not enabling the RISC-V assembly.
This is not an exhaustive list but shows what I encountered so far, basically stepping through the build-up of the TLS connection. I encountered the first error when keys were generated, the second one when validating certificates.
Let me know what more I can provide to help you get this resolved.
-Alex
Contact Details
alex@minres.com
Version
5.9.1 (commit 6a3eb6f)
Description
RISC-V systems may, but do not need to support unaligned loads and stores. Concretely, there are systems that expect
sw / lwandsd / ldto be 4 and 8 byte aligned, respectively. Misaligned loads and stores can then raise an exception.I ran into a few occasions where alignment was not given.
The first issue I ran into was that there are no alignment requirements for the
secretandmasterSecretbyte Arrays in theArraysstruct. These happened to lay at 1 byte alignment for me and were propagated to some RISC-V assembly, which expected 4 or 8 byte alignment.I managed to work around this locally by enabling
WOLFSSL_USE_ALIGNand prepending the corresponding define:The one I cannot solve on my own is from the following call stack (breakpoint on the faulting instruction):
In this very case
createSigDatapropagates an address inret = GetMsgHash(ssl, &sigData[idx]);with idx equal to 92.sigDatais 4 byte aligned, an offset of 92 is then only 2 byte aligned. This then faults when it propagates the call stack down to this store instruction.I have tested the standalone wolfcrypt API for RISC-V assembly successfully, but I encounter these issues in the TLS1.3 application I am trying to run. My application runs fine when not enabling the RISC-V assembly.
This is not an exhaustive list but shows what I encountered so far, basically stepping through the build-up of the TLS connection. I encountered the first error when keys were generated, the second one when validating certificates.
Let me know what more I can provide to help you get this resolved.
-Alex