- Integrated `zupt_mac_verify_ct` in `zupt_decrypt_buffer()` to replace C XOR loop for HMAC-SHA256 - Integrated `zupt_ct_select_32` in `zupt_mlkem768_decaps()` to replace C `cmov()` for FO transformation - Added `include/zupt_jasmin.h` with extern declarations and ABI docs - Added `#ifdef ZUPT_USE_JASMIN` guards with clean C fallbacks in `zupt_crypto.c` and `zupt_mlkem.c` - Makefile now auto-detects `jasmin/*.s`, assembles and links with `-DZUPT_USE_JASMIN` Closes #3
28 lines
638 B
Text
28 lines
638 B
Text
/* Zupt — Constant-Time MAC Comparison (Jasmin)
|
||
* Copyright (c) 2026 Cristian Cezar Moisés — MIT License
|
||
*
|
||
* CT-REQUIRED: Timing independent of input byte values.
|
||
* Compare 32 bytes as 4 × u64 — no byte-level access needed.
|
||
*/
|
||
|
||
export fn zupt_mac_verify_ct(
|
||
reg u64 expected_ptr,
|
||
reg u64 actual_ptr)
|
||
-> reg u64
|
||
{
|
||
reg u64 diff a b tmp;
|
||
inline int i;
|
||
|
||
diff = 0;
|
||
|
||
/* 4 × 8 bytes = 32 bytes. u64 loads — no size mismatch. */
|
||
for i = 0 to 4 {
|
||
a = [expected_ptr + 8 * i];
|
||
b = [actual_ptr + 8 * i];
|
||
tmp = a;
|
||
tmp ^= b;
|
||
diff |= tmp;
|
||
}
|
||
|
||
return diff;
|
||
}
|