Skip to content

Commit a0fe4ae

Browse files
cheri: Use conditional copy over bitmask arithmetic in sakke_modexp_loop
On CHERI casting mp_int pointers to wc_ptr_t for the bitmask arithmetic strips the hardware capability tag. The reconstructed pointer won't have a valid tag and will cause a tag violation when it is dereferenced. Under __CHERI_PURE_CAPABILITY__, replace the pointer arithmetic with four mp_cond_copy calls that operate on the digit data directly. This preserves the capability tags and accesses both accumulators unconditionally. Non-CHERI builds retain the original wc_off_on_addr path unchanged. Signed-off-by: William Beasley (The Capable Hub) <wbeasley@thegoodpenguin.co.uk>
1 parent aee7f40 commit a0fe4ae

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

wolfcrypt/src/sakke.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,12 +2649,19 @@ static int sakke_modexp_loop(SakkeKey* key, mp_int* b, mp_int* e, mp_proj* r,
26492649
err = sakke_proj_mul_qx1(c[0], by, prime, mp, c[j^1], t1, t2);
26502650
#else
26512651
err = sakke_proj_mul_qx1(c[0], by, prime, mp, c[2], t1, t2);
2652+
#ifdef __CHERI_PURE_CAPABILITY__
2653+
err = mp_cond_copy(c[2]->x, j, c[0]->x);
2654+
err = mp_cond_copy(c[2]->x, j^1, c[1]->x);
2655+
err = mp_cond_copy(c[2]->y, j, c[0]->y);
2656+
err = mp_cond_copy(c[2]->y, j^1, c[1]->y);
2657+
#else
26522658
mp_copy(c[2]->x,
26532659
(mp_int*) ( ((wc_ptr_t)c[0]->x & wc_off_on_addr[j]) +
26542660
((wc_ptr_t)c[1]->x & wc_off_on_addr[j^1]) ) );
26552661
mp_copy(c[2]->y,
26562662
(mp_int*) ( ((wc_ptr_t)c[0]->y & wc_off_on_addr[j]) +
26572663
((wc_ptr_t)c[1]->y & wc_off_on_addr[j^1]) ) );
2664+
#endif
26582665
#endif
26592666
}
26602667
}

0 commit comments

Comments
 (0)