Skip to content

Commit 6bd7075

Browse files
committed
kernel: update aes-kw crate and enable zeroize feature
The current version of aes-kw that the SVSM uses does not have a zeroizing feature that will wipe secrets from memory on drop. Update the crate to version 0.3.1, which does have this feature. This brings in a number of API changes, so update the attestation code making use of the crate accordingly. Further, aes-kw depends on a newer version of the aes crate than aes-gcm, or that aes-kw itself did with the previous version. The newer version of the aes crate renamed the `aes_force_soft` cfg to a generic `aes_backend="soft"` cfg, so update config.toml as well. Keep the older `aes_force_soft` cfg, since aes-gcm still depends on the older aes crate. Signed-off-by: Carlos López <clopez@suse.de>
1 parent dd7ac8e commit 6bd7075

5 files changed

Lines changed: 98 additions & 32 deletions

File tree

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
rustflags = [
55
"-C", "force-frame-pointers",
66
"--cfg", "aes_force_soft",
7+
"--cfg", 'aes_backend="soft"',
78
"--cfg", "polyval_force_soft",
89
]
910

Cargo.lock

Lines changed: 90 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ virtio-drivers = { git = "https://github.com/coconut-svsm/virtio-drivers.git", r
6969

7070
# crates.io
7171
aes-gcm = { version = "0.10.3", default-features = false }
72-
aes-kw = { version = "0.2.1", default-features = false }
72+
aes-kw = { version = "0.3.1", default-features = false }
7373
arbitrary = "1.3.0"
7474
base64 = { version = "0.22.1", default-features = false }
7575
bindgen = {version = "0.71.0", default-features = false }

kernel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ elf.workspace = true
2121
syscall.workspace = true
2222

2323
aes-gcm = { workspace = true, features = ["aes", "alloc", "zeroize"] }
24-
aes-kw = { workspace = true, optional = true }
24+
aes-kw = { workspace = true, features = ["zeroize"], optional = true }
2525
bitfield-struct.workspace = true
2626
bitflags.workspace = true
2727
cocoon-tpm-crypto = { workspace = true, features = [

kernel/src/attest.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
#[cfg(feature = "vsock")]
1919
use crate::{vsock::VMADDR_CID_HOST, vsock::stream::VsockStream};
2020
use aes_gcm::{AeadInPlace, Aes256Gcm, KeyInit, Nonce, aead::generic_array::GenericArray};
21-
use aes_kw::{Kek, KekAes256};
21+
use aes_kw::{KeyInit as _, KwAes256};
2222
use alloc::{string::ToString, vec::Vec};
2323
use cocoon_tpm_crypto::{
2424
CryptoError, EmptyCryptoIoSlices,
@@ -215,20 +215,20 @@ impl AttestationDriver<'_> {
215215
kdm.extend_from_slice(&(0_u32).to_be_bytes());
216216
kdm.extend_from_slice(&(256_u32).to_be_bytes());
217217

218-
let wrapping_key: KekAes256 = {
218+
let wrapping_key: KwAes256 = {
219219
let mut buf = SecretSlice::new_sized(32).or(Err(AttestationError::VecAlloc))?;
220220

221221
concat_kdf::derive_key_into::<sha2::Sha256>(&z, &kdm, &mut buf)
222222
.map_err(AttestationError::KeyDerivation)?;
223223

224-
Kek::new(GenericArray::from_slice(&buf))
225-
};
224+
KwAes256::new_from_slice(&buf).or(Err(AttestationError::WrapKeyArrayConvert))
225+
}?;
226226

227227
let mut cek = SecretSlice::new_sized(&decryption.wrapped_cek.len() - 8)
228228
.or(Err(AttestationError::VecAlloc))?;
229229

230230
wrapping_key
231-
.unwrap(&decryption.wrapped_cek, &mut cek)
231+
.unwrap_key(&decryption.wrapped_cek, &mut cek)
232232
.or(Err(AttestationError::CekUnwrap))?;
233233

234234
let cipher = Aes256Gcm::new(GenericArray::from_slice(&cek));

0 commit comments

Comments
 (0)