Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : QYVORA8 * File : security/tests/Sources/CAuditDIT/dit.c9 * Module : Tests10 * Repository : https://git.spboucher.ai/qyvora11 * Project Website : Not specified12 * Created : 2026-12-0413 * Last Modified : 2026-12-0414 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// QYVORA security audit — access to the ARM "data independent timing" (DIT) processor flag.44// With PSTATE.DIT set, the processor guarantees that the duration of a defined set of instructions does45// not depend on their operands. Test environment only; not part of the engine.46#include "qydit.h"4748#include <stddef.h>49#include <sys/sysctl.h>5051int qy_audit_dit_supported(void) {52#if defined(__aarch64__)53 int value = 0;54 size_t size = sizeof value;55 if (sysctlbyname("hw.optional.arm.FEAT_DIT", &value, &size, NULL, 0) != 0) return 0;56 return value != 0;57#else58 return 0;59#endif60}6162void qy_audit_dit_enable(void) {63#if defined(__aarch64__)64 if (qy_audit_dit_supported()) __asm__ volatile(".inst 0xd503415f"); // msr dit, #165#endif66}6768int qy_audit_dit_enabled(void) {69#if defined(__aarch64__)70 if (!qy_audit_dit_supported()) return 0;71 unsigned long value = 0;72 __asm__ volatile("mrs %0, s3_3_c4_c2_5" : "=r"(value)); // DIT system register, bit 2473 return (int)((value >> 24) & 1);74#else75 return 0;76#endif77}7879void qy_audit_serialize(void) {80#if defined(__aarch64__)81 __asm__ volatile("dsb sy\n\tisb");82#endif83}84