Skip to main content

ws63_hal/
spacc.rs

1//! SPACC (Security Accelerator) driver for WS63.
2//!
3//! The SPACC peripheral provides hardware acceleration for:
4//! - AES (128/192/256)
5//! - SM4 (Chinese national standard)
6//! - LEA (Lightweight Encryption Algorithm)
7//! - TDES (Triple DES)
8//! - HASH (SHA-256, SM3)
9//! - HMAC
10
11use crate::peripherals::Spacc;
12
13/// SPACC driver.
14pub struct SpaccDriver<'d> {
15    _spacc: Spacc<'d>,
16}
17
18/// Cipher algorithm selection.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum CipherAlg {
21    Aes128,
22    Aes192,
23    Aes256,
24    Sm4,
25    Lea,
26    Tdes,
27}
28
29/// Cipher operation mode.
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
31pub enum CipherMode {
32    Ecb,
33    Cbc,
34    Ctr,
35    Ccm,
36    Gcm,
37}
38
39/// Cipher direction.
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum CipherDir {
42    Encrypt,
43    Decrypt,
44}
45
46/// Hash algorithm selection.
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum HashAlg {
49    Sha256,
50    Sm3,
51}
52
53impl<'d> SpaccDriver<'d> {
54    /// Create a new SPACC driver.
55    pub fn new(spacc: Spacc<'d>) -> Self {
56        Self { _spacc: spacc }
57    }
58
59    #[allow(dead_code)]
60    fn regs(&self) -> &'static ws63_pac::spacc::RegisterBlock {
61        // SAFETY: PAC peripheral pointer is a static physical MMIO address, always valid
62        unsafe { &*Spacc::ptr() }
63    }
64
65    /// Enable the SPACC peripheral.
66    pub fn enable(&mut self) {
67        // Enable clock via the security clock gate
68        // Hardware-specific initialization
69    }
70
71    /// Disable the SPACC peripheral.
72    pub fn disable(&mut self) {
73        // Disable clock
74    }
75
76    /// Check if the accelerator is busy.
77    pub fn is_busy(&self) -> bool {
78        false // Hardware-specific status check
79    }
80}