Files
Hanzo AI 201f3db6b3 p3q: import CT harness from precompile — crypto owns CT testing
Adds p3q/ct/dudect/ (constant-time test harness for P3Q precompile),
parallel to the existing mlkem/ct/dudect/. Moved from
~/work/lux/precompile/p3q/ct/dudect/ as part of the "keep precompile
light, import crypto" cleanup.

Files: dudect_compat.h, dudect_verify.c, verify_ct.go, Makefile,
fetch.sh, run-submission.sh, README.md.

The verify_ct.go cgo bridge is build-tag-gated (p3q_verify_ct) and has
no public Go imports, so moving the file path is safe.
2026-05-21 13:57:17 -07:00

50 lines
1.5 KiB
C

/*
* dudect_compat.h — AArch64 compatibility shim for dudect.h.
*
* dudect.h unconditionally includes <emmintrin.h> and <x86intrin.h>;
* on ARM64 those headers are absent. This shim provides equivalents
* for the only two intrinsics dudect actually uses:
*
* - _mm_mfence() — memory fence
* - __rdtsc() — read time-stamp counter
*
* Accuracy disclaimer
* -------------------
* The ARM equivalent of TSC is the CNTVCT_EL0 virtual counter. It has
* sub-nanosecond resolution on modern Cortex / Apple cores; for
* dudect's purposes (relative cycle distribution comparison via
* Welch's t-test) this is adequate. We do not normalise the counter
* frequency — dudect compares within a single run so absolute units
* do not matter, only that the counter is monotonic and reasonably
* granular.
*
* The shim defines the x86 intrinsics as static-inline equivalents
* and blocks the x86 header includes via #define.
*/
#ifndef P3Q_DUDECT_COMPAT_H
#define P3Q_DUDECT_COMPAT_H
#if defined(__aarch64__) || defined(__arm64__)
/* Block the x86 includes — provide our own intrinsics below. */
#define _EMMINTRIN_H_INCLUDED 1
#define _X86INTRIN_H_INCLUDED 1
#define _MM_MALLOC_H_INCLUDED 1
#include <stdint.h>
static inline void _mm_mfence(void) {
__asm__ __volatile__("dmb sy" ::: "memory");
}
static inline uint64_t __rdtsc(void) {
uint64_t v;
__asm__ __volatile__("mrs %0, cntvct_el0" : "=r"(v));
return v;
}
#endif /* __aarch64__ */
#endif /* P3Q_DUDECT_COMPAT_H */