Skip to content

Commit 186f1e2

Browse files
committed
Repo: Update rust-crypto crates (#3330)
This resolves component governance warnings.
1 parent bcad144 commit 186f1e2

8 files changed

Lines changed: 148 additions & 176 deletions

File tree

Cargo.lock

Lines changed: 108 additions & 141 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ crc32fast = { version = "1.3.2", default-features = false }
459459
criterion = { version = "0.7", default-features = false }
460460
crossterm = { version = "0.29.0", default-features = false }
461461
ctrlc = "3.4.0"
462-
der = "0.7"
462+
der = "0.8"
463463
dhat = "0.3.3"
464464
dirs = "6.0"
465465
elfcore = "2.0.1"
@@ -540,15 +540,15 @@ range_map_vec = "0.2.0"
540540
resolv-conf = "0.7"
541541
rlimit = "0.10.1"
542542
roxmltree = "0.20.0"
543-
rsa = "0.9.10"
543+
rsa = { version = "0.10.0-rc.17", default-features = false }
544544
rusqlite = "0.37"
545545
rustc-hash = "2.1.1"
546546
rustyline = "17"
547547
seccompiler = "0.5"
548548
serde = { version = "1.0.185", default-features = false }
549549
serde_json = { version = "1.0", default-features = false }
550550
serde_yaml = "0.9"
551-
sha2 = { version = "0.10.8", default-features = false }
551+
sha2 = { version = "0.11.0", default-features = false }
552552
shell-words = "1.1"
553553
signal-hook = { version = "0.3", default-features = false }
554554
slab = "0.4"

openhcl/minimal_rt/x86_64-config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ target = "x86_64-unknown-none"
88

99
[env]
1010
MINIMAL_RT_BUILD = "1"
11+
12+
# By default the sha2 crate uses CPU feature detection which on x86_64 uses the
13+
# cpuid instruction. Executing cpuid in an SNP CVM would require implementing an
14+
# exception handler, so force sha2's software backend instead. These cfgs are
15+
# read by the sha2 crate itself, so they must be set via rustflags (which apply
16+
# to all crates in the build, including dependencies) rather than via a
17+
# downstream build.rs (whose `cargo:rustc-cfg` only affects that one crate).
18+
# The `sha2_backend_soft = "compact"` cfg additionally disables loop unrolling
19+
# in the soft backend, trading performance for a smaller code size.
20+
[target.x86_64-unknown-none]
21+
rustflags = [
22+
"--cfg", 'sha2_backend="soft"',
23+
"--cfg", 'sha2_backend_soft="compact"',
24+
]

openhcl/openhcl_boot/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ zerocopy.workspace = true
3030
[target.'cfg(target_arch = "x86_64")'.dependencies]
3131
page_table.workspace = true
3232
safe_intrinsics.workspace = true
33-
# By default the sha2 crate uses cpu feature detection which on x86_64 uses the
34-
# cpuid instruction. Executing cpuid in an SNP CVM would require implementing an
35-
# exception handler. Using the force-soft feature flag enables a software
36-
# implementation of the hashing algorithms that does not use cpuid.
37-
sha2 = { workspace = true, features = ["force-soft"] }
33+
sha2.workspace = true
3834
static_assertions.workspace = true
3935
tdcall.workspace = true
4036
x86defs.workspace = true

vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/auth_var_crypto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mod pkcs7_details {
153153
let content_info = ContentInfo {
154154
content_type: PKCS_7_SIGNED_DATA_OID,
155155
content: ContextSpecific {
156-
tag_number: TagNumber::new(0),
156+
tag_number: TagNumber(0),
157157
value: AnyRef::try_from(content)?,
158158
tag_mode: TagMode::Explicit,
159159
},

vm/devices/get/test_igvm_agent_lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ base64.workspace = true
1111
get_resources.workspace = true
1212
inspect = { workspace = true, features = ["derive"] }
1313
openhcl_attestation_protocol.workspace = true
14-
rsa.workspace = true
14+
rsa = { workspace = true, features = ["std", "encoding"] }
1515
serde_json.workspace = true
1616
sha2.workspace = true
1717
thiserror.workspace = true

vm/devices/get/test_igvm_agent_lib/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ use rsa::Oaep;
3333
use rsa::RsaPrivateKey;
3434
use rsa::RsaPublicKey;
3535
use rsa::pkcs8::EncodePrivateKey;
36-
use rsa::rand_core::OsRng;
37-
use rsa::rand_core::RngCore;
36+
use rsa::rand_core::Rng;
3837
use rsa::rand_core::SeedableRng;
3938
use sha2::Sha256;
4039
use std::collections::HashMap;
@@ -469,7 +468,7 @@ impl TestIgvmAgent {
469468

470469
self.secret_key = Some(private_key);
471470

472-
RngCore::fill_bytes(&mut rng, &mut des_key);
471+
Rng::fill_bytes(&mut rng, &mut des_key);
473472
self.des_key = Some(des_key);
474473

475474
Ok(())
@@ -491,8 +490,8 @@ impl TestIgvmAgent {
491490
.ok_or(WrappedKeyError::SecretKeyNotInitialized)?;
492491

493492
// Encrypt the DES key using RSA-OAEP
494-
let mut rng = OsRng;
495-
let padding = Oaep::new::<Sha256>();
493+
let mut rng = DummyRng::from_seed(0xabcdu64.to_le_bytes());
494+
let padding = Oaep::<Sha256>::new();
496495
let rsa_public = RsaPublicKey::from(secret_key);
497496
let encrypted_des = rsa_public
498497
.encrypt(&mut rng, padding, &des_key)
@@ -567,8 +566,8 @@ impl TestIgvmAgent {
567566

568567
// Convert the JWK RSA key to a usable RSA public key
569568
let rsa_public_key = RsaPublicKey::new(
570-
rsa::BigUint::from_bytes_be(&transfer_key.n),
571-
rsa::BigUint::from_bytes_be(&transfer_key.e),
569+
rsa::BoxedUint::from_be_slice(&transfer_key.n, 4096 * 8).unwrap(),
570+
rsa::BoxedUint::from_be_slice(&transfer_key.e, 4096 * 8).unwrap(),
572571
)
573572
.map_err(KeyReleaseError::ConvertJwkRsaFailed)?;
574573

@@ -587,18 +586,18 @@ impl TestIgvmAgent {
587586
.secret_key
588587
.as_ref()
589588
.ok_or(KeyReleaseError::SecretKeyNotInitialized)?;
590-
let mut rng = OsRng;
589+
let mut rng = DummyRng::from_seed(0xabcdu64.to_le_bytes());
591590

592591
// Generate the KEK (32 bytes) and wrap the private key using internal wrapper
593592
let mut kek_bytes = [0u8; 32];
594-
RngCore::fill_bytes(&mut rng, &mut kek_bytes);
593+
Rng::fill_bytes(&mut rng, &mut kek_bytes);
595594
let priv_key_der = secret_key
596595
.to_pkcs8_der()
597596
.map_err(KeyReleaseError::RsaToPkcs8Error)?;
598597
let wrapped_key = aes_key_wrap_with_padding(&kek_bytes, priv_key_der.as_bytes());
599598

600599
// Encrypt the KEK using RSA-OAEP
601-
let padding = Oaep::new::<TestSha1>();
600+
let padding = Oaep::<TestSha1>::new();
602601
let encrypted_kek = public_key
603602
.encrypt(&mut rng, padding, &kek_bytes)
604603
.map_err(KeyReleaseError::RsaEncryptionError)?;

vm/devices/get/test_igvm_agent_lib/src/test_crypto.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
//! are not vetted for production use and are *exclusively* for this test module on the
99
//! Windows platform.
1010
11-
use rsa::rand_core::CryptoRng;
12-
use rsa::rand_core::RngCore;
11+
use rsa::rand_core::Rng;
1312
use rsa::rand_core::SeedableRng;
1413
use sha2::digest;
1514
use sha2::digest::consts::U20;
1615
use sha2::digest::consts::U64;
17-
use sha2::digest::core_api::BlockSizeUser;
1816

1917
/// Minimal, non-constant-time SHA-1 implementation sufficient to satisfy the
2018
/// `digest::Digest` trait required by `rsa::Oaep`. Do NOT use in production.
@@ -122,7 +120,7 @@ impl digest::OutputSizeUser for TestSha1 {
122120
type OutputSize = U20;
123121
}
124122

125-
impl BlockSizeUser for TestSha1 {
123+
impl digest::common::BlockSizeUser for TestSha1 {
126124
type BlockSize = U64;
127125
}
128126

@@ -415,32 +413,30 @@ impl SeedableRng for DummyRng {
415413
}
416414
}
417415

418-
impl RngCore for DummyRng {
419-
fn next_u32(&mut self) -> u32 {
416+
impl rsa::rand_core::TryRng for DummyRng {
417+
type Error = std::convert::Infallible;
418+
419+
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
420420
self.state = self.state.wrapping_mul(6364136223846793005).wrapping_add(1);
421-
(self.state >> 32) as u32
421+
Ok((self.state >> 32) as u32)
422422
}
423423

424-
fn next_u64(&mut self) -> u64 {
424+
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
425425
self.state = self.state.wrapping_mul(6364136223846793005).wrapping_add(1);
426-
self.state
426+
Ok(self.state)
427427
}
428428

429-
fn fill_bytes(&mut self, dest: &mut [u8]) {
429+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
430430
for chunk in dest.chunks_mut(8) {
431431
let n = self.next_u64().to_le_bytes();
432432
chunk.copy_from_slice(&n[..chunk.len()]);
433433
}
434-
}
435-
436-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rsa::rand_core::Error> {
437-
self.fill_bytes(dest);
438434
Ok(())
439435
}
440436
}
441437

442438
/// Marker trait to satisfy `rsa::RsaPrivateKey::new`.
443-
impl CryptoRng for DummyRng {}
439+
impl rsa::rand_core::TryCryptoRng for DummyRng {}
444440

445441
#[cfg(test)]
446442
mod tests {

0 commit comments

Comments
 (0)