Merge pull request #10272 from The-Capable-Hub/wbeasley/meta-cheri-fixes

Fix support on CHERI RISC-V architecture
This commit is contained in:
David Garske
2026-05-13 09:33:53 -07:00
committed by GitHub
8 changed files with 106 additions and 9 deletions
+8 -8
View File
@@ -2158,14 +2158,14 @@ static void XorTable_Multi(const word32* t, word32* t0, byte o0,
word32 e1 = 0;
word32 e2 = 0;
word32 e3 = 0;
byte hi0 = o0 & 0xf0;
byte lo0 = o0 & 0x0f;
byte hi1 = o1 & 0xf0;
byte lo1 = o1 & 0x0f;
byte hi2 = o2 & 0xf0;
byte lo2 = o2 & 0x0f;
byte hi3 = o3 & 0xf0;
byte lo3 = o3 & 0x0f;
byte hi0 = o0 & WC_CACHE_LINE_MASK_HI;
byte lo0 = o0 & WC_CACHE_LINE_MASK_LO;
byte hi1 = o1 & WC_CACHE_LINE_MASK_HI;
byte lo1 = o1 & WC_CACHE_LINE_MASK_LO;
byte hi2 = o2 & WC_CACHE_LINE_MASK_HI;
byte lo2 = o2 & WC_CACHE_LINE_MASK_LO;
byte hi3 = o3 & WC_CACHE_LINE_MASK_HI;
byte lo3 = o3 & WC_CACHE_LINE_MASK_LO;
int i;
for (i = 0; i < 256; i += (1 << WC_CACHE_LINE_BITS)) {
+7
View File
@@ -2649,12 +2649,19 @@ static int sakke_modexp_loop(SakkeKey* key, mp_int* b, mp_int* e, mp_proj* r,
err = sakke_proj_mul_qx1(c[0], by, prime, mp, c[j^1], t1, t2);
#else
err = sakke_proj_mul_qx1(c[0], by, prime, mp, c[2], t1, t2);
#ifdef WC_NO_PTR_INT_CAST
err = mp_cond_copy(c[2]->x, j, c[0]->x);
err = mp_cond_copy(c[2]->x, j^1, c[1]->x);
err = mp_cond_copy(c[2]->y, j, c[0]->y);
err = mp_cond_copy(c[2]->y, j^1, c[1]->y);
#else
mp_copy(c[2]->x,
(mp_int*) ( ((wc_ptr_t)c[0]->x & wc_off_on_addr[j]) +
((wc_ptr_t)c[1]->x & wc_off_on_addr[j^1]) ) );
mp_copy(c[2]->y,
(mp_int*) ( ((wc_ptr_t)c[0]->y & wc_off_on_addr[j]) +
((wc_ptr_t)c[1]->y & wc_off_on_addr[j^1]) ) );
#endif
#endif
}
}
+66
View File
@@ -5115,6 +5115,21 @@ static WC_INLINE sp_int_digit sp_div_word(sp_int_digit hi, sp_int_digit lo,
(defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA) || \
(defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
#ifndef WC_NO_CACHE_RESISTANT
#ifdef WC_NO_PTR_INT_CAST
static void _sp_cond_copy(const sp_int* a, int copy, sp_int* r, sp_size_t used)
{
sp_int_digit mask = (sp_int_digit)0 - (sp_int_digit)copy;
unsigned int i;
for (i = 0; i < (unsigned int)used; i++) {
r->dp[i] ^= (r->dp[i] ^ a->dp[i]) & mask;
}
r->used ^= (r->used ^ a->used) & (sp_size_t)mask;
#ifdef WOLFSSL_SP_INT_NEGATIVE
r->sign ^= (r->sign ^ a->sign) & (sp_sign_t)mask;
#endif
}
#else
/* Mask of address for constant time operations. */
const size_t sp_off_on_addr[2] =
{
@@ -5123,6 +5138,7 @@ static WC_INLINE sp_int_digit sp_div_word(sp_int_digit hi, sp_int_digit lo,
};
#endif
#endif
#endif
#if defined(WOLFSSL_HAVE_SP_DH) || defined(WOLFSSL_HAVE_SP_RSA)
@@ -13166,13 +13182,23 @@ static int _sp_exptmod_ex(const sp_int* b, const sp_int* e, int bits,
}
#else
/* 4.1. t[s] = t[s] ^ 2 */
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[0], s^1, t[2], m->used);
_sp_cond_copy(t[1], s, t[2], m->used);
#else
_sp_copy((sp_int*)(((size_t)t[0] & sp_off_on_addr[s^1]) +
((size_t)t[1] & sp_off_on_addr[s ])),
t[2]);
#endif
err = sp_sqrmod(t[2], m, t[2]);
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[2], s^1, t[0], m->used);
_sp_cond_copy(t[2], s, t[1], m->used);
#else
_sp_copy(t[2],
(sp_int*)(((size_t)t[0] & sp_off_on_addr[s^1]) +
((size_t)t[1] & sp_off_on_addr[s ])));
#endif
if (err == MP_OKAY) {
/* 4.2. y = e[i] */
@@ -13183,13 +13209,23 @@ static int _sp_exptmod_ex(const sp_int* b, const sp_int* e, int bits,
/* 4.4 s = s | y */
s |= y;
/* 4.5. t[j] = t[j] * b */
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[0], j^1, t[2], m->used);
_sp_cond_copy(t[1], j, t[2], m->used);
#else
_sp_copy((sp_int*)(((size_t)t[0] & sp_off_on_addr[j^1]) +
((size_t)t[1] & sp_off_on_addr[j ])),
t[2]);
#endif
err = _sp_mulmod(t[2], b, m, t[2]);
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[2], j^1, t[0], m->used);
_sp_cond_copy(t[2], j, t[1], m->used);
#else
_sp_copy(t[2],
(sp_int*)(((size_t)t[0] & sp_off_on_addr[j^1]) +
((size_t)t[1] & sp_off_on_addr[j ])));
#endif
}
#endif
}
@@ -13279,9 +13315,14 @@ static int _sp_exptmod_ex(const sp_int* b, const sp_int* e, int bits,
err = sp_mulmod(t[0], t[1], m, t[2]);
/* 3.3. t[3] = t[y] ^ 2 */
if (err == MP_OKAY) {
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[0], y^1, t[3], m->used);
_sp_cond_copy(t[1], y, t[3], m->used);
#else
_sp_copy((sp_int*)(((size_t)t[0] & sp_off_on_addr[y^1]) +
((size_t)t[1] & sp_off_on_addr[y ])),
t[3]);
#endif
err = sp_sqrmod(t[3], m, t[3]);
}
/* 3.4. t[y] = t[3], t[y^1] = t[2] */
@@ -13403,16 +13444,26 @@ static int _sp_exptmod_mont_ex(const sp_int* b, const sp_int* e, int bits,
/* 6. For i in (bits-1)...0 */
for (i = bits - 1; (err == MP_OKAY) && (i >= 0); i--) {
/* 6.1. t[s] = t[s] ^ 2 */
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[0], s^1, t[3], m->used);
_sp_cond_copy(t[1], s, t[3], m->used);
#else
_sp_copy((sp_int*)(((size_t)t[0] & sp_off_on_addr[s^1]) +
((size_t)t[1] & sp_off_on_addr[s ])),
t[3]);
#endif
err = sp_sqr(t[3], t[3]);
if (err == MP_OKAY) {
err = _sp_mont_red(t[3], m, mp, 0);
}
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[3], s^1, t[0], m->used);
_sp_cond_copy(t[3], s, t[1], m->used);
#else
_sp_copy(t[3],
(sp_int*)(((size_t)t[0] & sp_off_on_addr[s^1]) +
((size_t)t[1] & sp_off_on_addr[s ])));
#endif
if (err == MP_OKAY) {
/* 6.2. y = e[i] */
@@ -13424,16 +13475,26 @@ static int _sp_exptmod_mont_ex(const sp_int* b, const sp_int* e, int bits,
s |= y;
/* 6.5. t[j] = t[j] * bm */
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[0], j^1, t[3], m->used);
_sp_cond_copy(t[1], j, t[3], m->used);
#else
_sp_copy((sp_int*)(((size_t)t[0] & sp_off_on_addr[j^1]) +
((size_t)t[1] & sp_off_on_addr[j ])),
t[3]);
#endif
err = sp_mul(t[3], t[2], t[3]);
if (err == MP_OKAY) {
err = _sp_mont_red(t[3], m, mp, 0);
}
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[3], j^1, t[0], m->used);
_sp_cond_copy(t[3], j, t[1], m->used);
#else
_sp_copy(t[3],
(sp_int*)(((size_t)t[0] & sp_off_on_addr[j^1]) +
((size_t)t[1] & sp_off_on_addr[j ])));
#endif
}
}
if (err == MP_OKAY) {
@@ -13543,9 +13604,14 @@ static int _sp_exptmod_mont_ex(const sp_int* b, const sp_int* e, int bits,
}
/* 4.3. t[3] = t[y] ^ 2 */
if (err == MP_OKAY) {
#ifdef WC_NO_PTR_INT_CAST
_sp_cond_copy(t[0], y^1, t[3], m->used);
_sp_cond_copy(t[1], y, t[3], m->used);
#else
_sp_copy((sp_int*)(((size_t)t[0] & sp_off_on_addr[y^1]) +
((size_t)t[1] & sp_off_on_addr[y ])),
t[3]);
#endif
err = sp_sqr(t[3], t[3]);
}
if (err == MP_OKAY) {
+5 -1
View File
@@ -5831,7 +5831,7 @@ typedef struct BuildMsgArgs {
#endif
#ifdef WOLFSSL_ASYNC_IO
#define MAX_ASYNC_ARGS 18
#define MAX_ASYNC_ARGS 24
typedef void (*FreeArgsCb)(struct WOLFSSL* ssl, void* pArgs);
struct WOLFSSL_ASYNC {
@@ -5839,7 +5839,11 @@ typedef struct BuildMsgArgs {
BuildMsgArgs buildArgs; /* holder for current BuildMessage args */
#endif
FreeArgsCb freeArgs; /* function pointer to cleanup args */
#ifdef WC_NO_PTR_INT_CAST
max_align_t args[MAX_ASYNC_ARGS * sizeof(word32) / sizeof(max_align_t)]; /* holder for current args */
#else
word32 args[MAX_ASYNC_ARGS]; /* holder for current args */
#endif
};
#endif
+8
View File
@@ -43,9 +43,17 @@
typedef struct WOLFSSL_MD5_CTX {
/* big enough to hold wolfcrypt md5, but check on init */
#ifdef STM32_HASH
# ifdef WC_NO_PTR_INT_CAST
void* holder[(128 + WC_ASYNC_DEV_SIZE + sizeof(STM32_HASH_Context)) / sizeof(void*)];
# else
void* holder[(112 + WC_ASYNC_DEV_SIZE + sizeof(STM32_HASH_Context)) / sizeof(void*)];
# endif
#else
# ifdef WC_NO_PTR_INT_CAST
void* holder[(128 + WC_ASYNC_DEV_SIZE) / sizeof(void*)];
# else
void* holder[(112 + WC_ASYNC_DEV_SIZE) / sizeof(void*)];
# endif
#endif
} WOLFSSL_MD5_CTX;
+4
View File
@@ -39,7 +39,11 @@
* the size of RC4_KEY structures. */
typedef struct WOLFSSL_RC4_KEY {
/* big enough for Arc4 from wolfssl/wolfcrypt/arc4.h */
#ifdef WC_NO_PTR_INT_CAST
void* holder[(288 + WC_ASYNC_DEV_SIZE) / sizeof(void*)];
#else
void* holder[(272 + WC_ASYNC_DEV_SIZE) / sizeof(void*)];
#endif
} WOLFSSL_RC4_KEY;
WOLFSSL_API void wolfSSL_RC4_set_key(WOLFSSL_RC4_KEY* key, int len,
+4
View File
@@ -52,7 +52,11 @@
#ifndef NO_SHA
typedef struct WOLFSSL_SHA_CTX {
/* big enough to hold wolfcrypt Sha, but check on init */
#ifdef WC_NO_PTR_INT_CAST
void* holder[(160 + WC_ASYNC_DEV_SIZE + CTX_SHA_HW_ADDER) / sizeof(void*)];
#else
void* holder[(112 + WC_ASYNC_DEV_SIZE + CTX_SHA_HW_ADDER) / sizeof(void*)];
#endif
#if defined(WOLFSSL_DEVCRYPTO_HASH) || defined(WOLFSSL_HASH_KEEP)
void* keephash_holder[sizeof(void*) + (2 * sizeof(unsigned int))];
#endif
+4
View File
@@ -5178,6 +5178,10 @@ extern void uITRON4_free(void *p) ;
#endif
#endif
#ifdef __CHERI_PURE_CAPABILITY__
#define WC_NO_PTR_INT_CAST
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif