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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
"""
FIPS 140-3 Compliant Cryptographic Module
This module provides FIPS 140-3 compliant encryption/decryption for model storage.
Uses AES-256-GCM with PBKDF2 key derivation.
.. warning:: Crypto Compatibility
This Python module uses **PBKDF2-HMAC-SHA256** for key derivation.
The Rust implementation (``src/crypto/mod.rs``) uses **Argon2id**.
Vaults created by the Rust ``aim`` CLI **cannot** be decrypted by this
Python module and vice-versa. For interop, use the Rust binary via
``aimodelvault.core.vault.Vault`` (subprocess wrapper) or wait for
PyO3 bindings (planned for v0.3.0).
Security Controls:
- NIST SP 800-38D (GCM mode)
- NIST SP 800-132 (PBKDF2)
- FIPS 197 (AES)
"""
"""
FIPS 140-3 compliant cryptographic operations.
Compliance Mappings:
- CMMC 2.0: SC.3.177 (Employ FIPS-validated cryptography)
- MITRE ATT&CK: T1486 mitigation (Data Encrypted for Impact)
"""
# FIPS 140-3 approved parameters
= 32 # 256 bits for AES-256
= 32 # 256 bits
= 12 # 96 bits (recommended for GCM)
= 16 # 128 bits authentication tag
= 600000 # OWASP recommendation for PBKDF2-HMAC-SHA256
"""Initialize FIPS crypto module."""
=
"""
Derive encryption key from passphrase using PBKDF2-HMAC-SHA256.
Args:
passphrase: User passphrase
salt: Optional salt (generated if not provided)
Returns:
Tuple of (encryption_key, salt)
Compliance:
- FIPS 140-3: Approved key derivation
- NIST SP 800-132: Password-based key derivation
"""
=
=
=
return ,
"""
Encrypt data using AES-256-GCM.
Args:
data: Plaintext data to encrypt
key: 256-bit encryption key
Returns:
Encrypted data with format: nonce || ciphertext || tag
Compliance:
- FIPS 197: AES encryption
- NIST SP 800-38D: GCM mode
- CMMC SC.3.191: Protection of CUI at rest
"""
# Generate cryptographically secure random nonce
=
# Create AESGCM cipher
=
# Encrypt and authenticate
=
# Format: nonce || ciphertext (includes auth tag)
return +
"""
Decrypt data using AES-256-GCM.
Args:
encrypted_data: Encrypted data (nonce || ciphertext || tag)
key: 256-bit encryption key
Returns:
Decrypted plaintext data
Raises:
InvalidTag: If authentication fails (tampering detected)
"""
# Extract nonce and ciphertext
=
=
# Create AESGCM cipher
=
# Decrypt and verify authentication tag
=
return
"""
Generate cryptographically secure random passphrase.
Args:
length: Length of passphrase in bytes
Returns:
Hex-encoded passphrase
Compliance:
- FIPS 140-3: Approved random number generation
"""
return
"""
Constant-time comparison to prevent timing attacks.
Args:
a: First value
b: Second value
Returns:
True if equal, False otherwise
Compliance:
- MITRE ATT&CK: T1552.004 mitigation (timing attacks)
"""
return
"""
Secure key management system.
Compliance:
- CMMC AC.3.018: Control connection of mobile devices
- CMMC IA.3.080: Protect authenticators
"""
"""
Initialize key manager.
Args:
key_storage_path: Optional path for encrypted key storage
"""
=
=
"""
Store encryption key securely using key encryption key (KEK).
Args:
key: Key to store
filename: Storage filename
master_passphrase: Master passphrase for KEK
"""
# Generate KEK from master passphrase
, =
# Encrypt the key
=
# Store salt || encrypted_key
=
# Set restrictive permissions (owner read/write only)
"""
Load and decrypt stored encryption key.
Args:
filename: Storage filename
master_passphrase: Master passphrase for KEK
Returns:
Decrypted key
"""
=
=
# Extract salt and encrypted key
=
=
# Derive KEK from master passphrase
, =
# Decrypt the key
=
return