arXiv:2608.29773cs.CRAug 2026

Manuscript Offprint

arXiv:2608.29773

HSMLog: Small Language Model-Assisted Hardware Security Module Log Anomaly Detection with Behavioral Analysis

Chia-Hsuan Wu, Dar-Hsin Dustin Wu, Rui Fang, Yi-Ting Lee, Chia-Chih Lin, Ming-Syan Chen

Chia-Hsuan Wu*, Dar-Hsin Dustin Wu*, Rui Fang*, Yi-Ting Lee*, Chia-Chih Lin†, and Ming-Syan Chen*

*National Taiwan University, Taipei, Taiwan

†National Taiwan University of Science and Technology, Taipei, Taiwan

Email: {chwu, dustinwu, rfang, ytlee}@arbor.ee.ntu.edu.tw, cclin@mail.ntust.edu.tw, mschen@ntu.edu.tw

Abstract—Hardware Security Module (HSM) logs capture security-critical behavior, but anomalies emerge from relationships across event sequences, keys, object states, sessions, and temporal patterns rather than isolated events. Existing methods separate detection from HSM-specific evidence validation and reporting. In this paper, we present HSMLog, a two-stage framework for HSM log anomaly detection with retrieval-grounded behavioral analysis. In Stage 1, a small language model (SLM) identifies candidate alerts from sliding windows of structured HSM events and performs policy-guided assessment using HSM-specific operational rules. In Stage 2, retrieved policies and historical suspicious-key records strictly predating the alert window, together with candidate-related log context, support conservative candidate review and incident analysis. Evaluated on real industrial HSM background logs augmented with anomaly scenarios co-defined with industrial partners, HSMLog achieves 98.97% precision, 96.00% recall, 98.66% anomalous-event coverage, and a 97.46% F1 score, demonstrating effective anomaly alerting and incident triage in the studied setting.

Index Terms—hardware security module, log anomaly detection, small language model, behavioral analysis

I. INTRODUCTION

Hardware Security Modules (HSMs) protect cryptographic keys and execute security-critical operations, including signing, encryption, decryption, key generation, object management, and authentication. Failures, misuse, and behavior that departs from deployment expectations can affect security, service availability, auditability, and the reliability of dependent applications. Detecting such conditions is therefore important for maintaining dependable HSM-backed services.

Operational HSM logs differ from conventional system logs because each record describes a stateful cryptographic operation rather than only an event template or message. Its meaning depends on the target key or object, the session and role that issued the request, the object's lifecycle state, the cryptographic mechanism, returned handles, and the result code. For example, an invalid-handle result may be expected after a stale reference but may indicate object exploration when repeated across unrelated objects. Likewise, a successful operation may still require investigation when it violates a deployment-specific policy. Consequently, behavior that appears benign at the event level may become suspicious only when interpreted as part of a structured operational progression.

Existing log anomaly detection methods have achieved promising results on public datasets [1]–[3], but their application to operational HSM environments remains challenging. Sequence-only detectors can overlook organization-specific policies, whereas policy-guided SLM assessment alone cannot capture every contextual workflow deviation. Either alone may miss repeated operations involving the same protected asset, requester, or invalid state transition, all central to HSM interpretation. Industrial settings rarely provide exhaustive event-level labels, with supervision often limited to annotated cases or incident spans. Given sensitive HSM logs, HSMLog uses a compact SLM over local windows, avoiding full-history inference; Stage 2 retrieves broader evidence only for detected candidates.

This paper presents HSMLog, a two-stage framework for HSM log anomaly detection with retrieval-grounded behavioral analysis. Stage 1 uses an SLM to analyze structured event windows and assess organization-specific policies. Positive windows from contextual detection or policy-guided assessment are merged into candidate incidents. Stage 2 retrieves policies, suspicious-key records strictly predating the incident interval, and candidate-related log context, supporting conservative review and evidence-grounded behavioral analysis.

The contributions of this paper are as follows:

  • We propose HSMLog, a two-stage framework that combines SLM-based contextual anomaly detection and policy-guided SLM assessment of organization-specific operational policies with retrieval-grounded candidate review and evidence-grounded behavioral analysis.

  • We develop a structured representation of HSM events and a case-aware sliding-window training protocol that enable contextual SLM detection from annotated operational scenarios.

  • We evaluate HSMLog on real operational logs from an industrial HSM environment using five practitioner-informed anomaly categories: Cryptographic Failure Probing, Object Handle Probing, Lifecycle Violation, Policy Violation, and Low-and-Slow Metadata Probing. We compare HSMLog with representative baselines and analyze case detection, anomalous-event coverage, component contributions, retrieval-supported candidate review, and observation-window sensitivity.

© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works.