{"id":27147362,"url":"https://github.com/uncallable/ct_memcmp","last_synced_at":"2025-07-22T04:35:11.034Z","repository":{"id":286030776,"uuid":"959988265","full_name":"uncallable/ct_memcmp","owner":"uncallable","description":"ct memcmp() w/ sidechannel resistance via data oblivious access patterns","archived":false,"fork":false,"pushed_at":"2025-04-03T23:28:13.000Z","size":4755,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T01:15:15.174Z","etag":null,"topics":["bitwise","logic","pattern","rust","x86"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uncallable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-03T17:16:12.000Z","updated_at":"2025-04-03T23:48:15.000Z","dependencies_parsed_at":"2025-04-04T01:01:27.049Z","dependency_job_id":null,"html_url":"https://github.com/uncallable/ct_memcmp","commit_stats":null,"previous_names":["r3tima/ct_memcmp","uncallable/ct_memcmp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uncallable/ct_memcmp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncallable%2Fct_memcmp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncallable%2Fct_memcmp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncallable%2Fct_memcmp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncallable%2Fct_memcmp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uncallable","download_url":"https://codeload.github.com/uncallable/ct_memcmp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uncallable%2Fct_memcmp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266428439,"owners_count":23926994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitwise","logic","pattern","rust","x86"],"created_at":"2025-04-08T11:25:53.157Z","updated_at":"2025-07-22T04:35:11.005Z","avatar_url":"https://github.com/uncallable.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ct_memcmp\n\nct_memcmp is a minimal, FFI-safe, cryptographically hygienic constant time comparator implemented in pure rust with optional inline x86_64 assembly and speculative execution mitigations. the core design enforces deterministic, branchless execution across arbitrarily aligned memory regions using bitwise accumulator folding to eliminate data-dependent control flow. all logic is encoded within a strictly monotonic instruction stream free of conditional branches or short-circuiting logic, ensuring uniform cacheline traversal and mitigating classic microarchitectural timing disclosure vectors.\n\ninternally, the comparator emits a data-oblivious diff stream by computing the bitwise xor delta per byte and collapsing the result via an OR-reduction accumulator. each memory dereference is wrapped in volatile semantics to prevent the optimizer from reordering, merging, or short-circuiting accesses based on static equivalence heuristics. inputs may be optionally aligned to 64-byte boundaries to enforce L1d cacheline uniformity and simulate cache probe scenarios under adversarial buffer layout.\n\nit includes optional architectural hardening for speculative execution leaks. under the sse2 feature gate, execution emits an lfence barrier post-load to serialize dispatch and inhibit speculative branching past load gates. the implementation supports rdtscp delta measurement as an instrumentation hook to detect cycle-based variance under kvm, qemu, or bare metal perf event contexts. performance deltas are extracted via a dedicated probe binary that invokes ct_memcmp() across thermally isolated hot and cold buffers, then dumps the timing histogram alongside perf_event_open counters for raw branch misses, dTLB lookups, and LLC ref/miss telemetry.\n\nintegration is possible via the exported #[no_mangle] C ABI function signature which accepts raw u8 pointers and buffer length. all public interfaces are marked #[inline(never)] and compiled under opt-level=z with lto and frame pointers enabled to preserve instruction shape and enforce maximal observability under dynamic analysis. the build config pins target-cpu=native and enforces -z now via linker args to eliminate lazy plt resolution and reduce variance in cold start execution flows.\n\nfuzz instrumentation is provided via a harness that randomizes buffer values, length fields, and allocation patterns across page boundaries to surface timing skew under afl or honggfuzz. cache footprint and branch consistency are validated across thousands of trials and diffed against randomized patterns. delta amplification is optionally induced via rdtscp tightloop profiling to exaggerate per-byte access deltas in the presence of speculative predictors.\n\n### constant time primitives\n\nthe core implementation provides constant time memory comparison through carefully crafted assembly sequences:\n\n```rust\npub fn ct_memcmp(a: *const u8, b: *const u8, len: usize) -\u003e i32\n```\n\n### performance probing\n\nincludes a probe binary for analysing memory access patterns:\n\n```rust\nfn measure_memcmp_delta(hot: *const u8, cold: *const u8) -\u003e (u64, PerfCounters)\n```\n\n## usage\n\n### basic memory operations\n\n```rust\nuse memcopy::ct_memcmp;\n\nlet result = ct_memcmp(buf1.as_ptr(), buf2.as_ptr(), 64);\n```\n\n### performance analysis\n\n```bash\ncargo run --bin probe\n# or  \nsudo cargo run --bin probe\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funcallable%2Fct_memcmp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funcallable%2Fct_memcmp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funcallable%2Fct_memcmp/lists"}