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