Skip to content

Commit b197319

Browse files
committed
bump deps
1 parent f9f7442 commit b197319

File tree

11 files changed

+415
-271
lines changed

11 files changed

+415
-271
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ paste = "1.0.15"
5858
peekmore = "1.3.0"
5959
pest = "2.8.1"
6060
pest_derive = "2.8.1"
61+
rand = "0.9.1"
6162
regex = "1.11.1"
6263
rustversion = "1.0.21"
6364
serde = { version = "1.0.219", features = ["derive"] }
@@ -68,10 +69,10 @@ supports-hyperlinks = "3.1.0"
6869
tabled = "0.20.0"
6970
terminal-link = "0.1.0"
7071
thiserror = "2.0.12"
71-
toml = "0.8.23"
72+
toml = "0.9.2"
7273
tower-lsp = "0.20.0"
7374
tracing = { version = "0.1.41", features = ["attributes"] }
7475
tracing-test = "0.2.5"
75-
vfs = "0.12.1"
76+
vfs = "0.12.2"
7677
walkdir = "2.5.0"
77-
zip = "4.2.0"
78+
zip = "4.3.0"

bin/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ fs_extra = "1.3.0"
4040
git2 = { workspace = true }
4141
glob = "0.3.2"
4242
image = "0.25.6"
43-
indicatif = "0.17.11"
43+
indicatif = "0.18.0"
4444
interprocess = { workspace = true }
4545
num_cpus = "1.17.0"
4646
paste = { workspace = true }
4747
rayon = "1.10.0"
4848
regex = { workspace = true }
49-
reqwest = { version = "0.12.20", features = ["blocking", "json"] }
49+
reqwest = { version = "0.12.22", features = ["blocking", "json"] }
5050
rhai = "1.22.2"
5151
rust-embed = "8.7.2"
5252
semver = "1.0.26"

hls/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ regex = { workspace = true }
2121
ropey = "1.6.1"
2222
serde = { workspace = true }
2323
serde_json = { workspace = true }
24-
tokio = { version = "1.44.1", features = ["full"] }
24+
tokio = { version = "1.46.1", features = ["full"] }
2525
tower-lsp = { workspace = true, features = ["proposed"]}
2626
tracing = { workspace = true }
2727
tracing-subscriber = { version = "0.3.19", features = ["json"] }

libs/lzo/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ license = "GPL-2.0"
99
workspace = true
1010

1111
[dependencies]
12-
libc = "0.2.172"
12+
libc = "0.2.174"
1313
thiserror = { workspace = true }
1414

1515
[dev-dependencies]
16-
rand = "0.8.5"
16+
rand = { workspace = true }
1717

1818
[features]
1919
default = ["compress", "decompress"]

libs/signing/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ hemtt-common = { path = "../common" }
1717
hemtt-pbo = { path = "../pbo" }
1818

1919
byteorder = { workspace = true }
20-
rand = "0.8.5"
21-
rsa = "0.9.8"
20+
crypto-bigint = { version = "0.7.0-pre.6", features = ["alloc"] }
21+
rand = { workspace = true }
22+
rsa = "0.10.0-rc.3"
2223
sha-1 = { workspace = true }
2324
thiserror = { workspace = true }

libs/signing/src/lib.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99

1010
use std::io::{Read, Seek, Write};
1111

12+
use crypto_bigint::{
13+
Odd, Resize,
14+
modular::{BoxedMontyForm, BoxedMontyParams},
15+
};
1216
use hemtt_common::BISignVersion;
1317
use hemtt_pbo::ReadablePbo;
14-
use rsa::BigUint;
18+
use rsa::BoxedUint;
1519
use sha1::{Digest, Sha1};
1620

1721
mod error;
@@ -24,19 +28,19 @@ pub use private::BIPrivateKey;
2428
pub use public::BIPublicKey;
2529
pub use signature::BISign;
2630

27-
/// Writes a [`BigUint`] to the given output.
31+
/// Writes a [`BoxedUint`] to the given output.
2832
///
2933
/// # Errors
3034
/// If the output fails to write.
31-
pub fn write_biguint<O: Write>(output: &mut O, bn: &BigUint, size: usize) -> Result<(), Error> {
32-
let mut vec: Vec<u8> = bn.to_bytes_le();
35+
pub fn write_boxeduint<O: Write>(output: &mut O, bn: &BoxedUint, size: usize) -> Result<(), Error> {
36+
let mut vec: Vec<u8> = bn.to_le_bytes().to_vec();
3337
vec.resize(size, 0);
3438
output.write_all(&vec).map_err(std::convert::Into::into)
3539
}
3640

37-
fn display_hashes(a: &BigUint, b: &BigUint) -> (String, String) {
38-
let hex_a = a.to_str_radix(16).to_lowercase();
39-
let hex_b = b.to_str_radix(16).to_lowercase();
41+
fn display_hashes(a: &BoxedUint, b: &BoxedUint) -> (String, String) {
42+
let hex_a = a.to_string_radix_vartime(16).to_lowercase();
43+
let hex_b = b.to_string_radix_vartime(16).to_lowercase();
4044

4145
if hex_a.len() != hex_b.len() || hex_a.len() <= 40 {
4246
return (hex_a, hex_b);
@@ -60,7 +64,7 @@ pub fn generate_hashes<I: Seek + Read>(
6064
pbo: &mut ReadablePbo<I>,
6165
version: BISignVersion,
6266
length: u32,
63-
) -> Result<(BigUint, BigUint, BigUint), Error> {
67+
) -> Result<(BoxedUint, BoxedUint, BoxedUint), Error> {
6468
let mut hasher = Sha1::new();
6569
let hash1 = pbo.gen_checksum()?;
6670

@@ -94,23 +98,40 @@ pub fn generate_hashes<I: Seek + Read>(
9498

9599
#[must_use]
96100
/// Pad a hash to the given size
97-
pub fn pad_hash(hash: &[u8], size: usize) -> BigUint {
101+
pub fn pad_hash(hash: &[u8], size: usize) -> BoxedUint {
98102
let mut vec: Vec<u8> = vec![0, 1];
99103
vec.resize(size - 36, 255);
100104
vec.extend(b"\x00\x30\x21\x30\x09\x06\x05\x2b");
101105
vec.extend(b"\x0e\x03\x02\x1a\x05\x00\x04\x14");
102106
vec.extend(hash);
103107

104-
BigUint::from_bytes_be(&vec)
108+
BoxedUint::from_be_slice_vartime(&vec)
109+
}
110+
111+
#[must_use]
112+
pub fn modpow(base: &BoxedUint, exponent: &BoxedUint, modulus: &BoxedUint) -> BoxedUint {
113+
let n_params = BoxedMontyParams::new(Odd::new(modulus.clone()).unwrap());
114+
pow_mod_params(base, exponent, &n_params)
115+
}
116+
117+
fn pow_mod_params(base: &BoxedUint, exp: &BoxedUint, n_params: &BoxedMontyParams) -> BoxedUint {
118+
let base = reduce_vartime(base, n_params);
119+
base.pow(exp).retrieve()
120+
}
121+
122+
fn reduce_vartime(n: &BoxedUint, p: &BoxedMontyParams) -> BoxedMontyForm {
123+
let modulus = p.modulus().as_nz_ref().clone();
124+
let n_reduced = n.rem_vartime(&modulus).resize_unchecked(p.bits_precision());
125+
BoxedMontyForm::new(n_reduced, p.clone())
105126
}
106127

107128
#[cfg(test)]
108129
mod tests {
109-
use rsa::BigUint;
130+
use rsa::BoxedUint;
110131

111132
#[test]
112133
fn display_hashes() {
113-
let bu = &BigUint::from_slice_native(&[
134+
let bu = &BoxedUint::from_words([
114135
3_383_022_893_987_068_657,
115136
211_522_787_039_626_673,
116137
12_924_607_435_213_790_771,

libs/signing/src/private.rs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
44
use hemtt_common::io::{ReadExt, WriteExt};
55
use hemtt_pbo::{BISignVersion, ReadablePbo};
66
use rsa::{
7-
BigUint, RsaPrivateKey,
7+
BoxedUint, RsaPrivateKey,
88
traits::{PrivateKeyParts, PublicKeyParts},
99
};
1010

11-
use crate::{error::Error, generate_hashes, public::BIPublicKey, signature::BISign};
11+
use crate::{error::Error, generate_hashes, modpow, public::BIPublicKey, signature::BISign};
1212

1313
#[allow(clippy::module_name_repetitions)]
1414
#[derive(Debug, Clone)]
1515
/// A private key for signing PBOs
1616
pub struct BIPrivateKey {
1717
authority: String,
1818
length: u32,
19-
exponent: BigUint,
20-
n: BigUint,
21-
p: BigUint,
22-
q: BigUint,
23-
dp: BigUint,
24-
dq: BigUint,
25-
qinv: BigUint,
26-
d: BigUint,
19+
exponent: BoxedUint,
20+
n: BoxedUint,
21+
p: BoxedUint,
22+
q: BoxedUint,
23+
dp: BoxedUint,
24+
dq: BoxedUint,
25+
qinv: BoxedUint,
26+
d: BoxedUint,
2727
}
2828

2929
impl BIPrivateKey {
@@ -35,20 +35,18 @@ impl BIPrivateKey {
3535
/// # Errors
3636
/// If RSA generation fails.
3737
pub fn generate(length: u32, authority: &str) -> Result<Self, Error> {
38-
let mut rng = rand::thread_rng();
38+
let mut rng = rand::rng();
3939
let mut rsa = RsaPrivateKey::new(&mut rng, length as usize)?;
4040
rsa.precompute()?;
4141
let primes = rsa.primes();
42-
let Some(qinv) = rsa.qinv().expect(
42+
let qinv = rsa.qinv().expect(
4343
"qinv should be precomputed, if it's not, the precompute failed and we should return",
44-
).to_biguint() else {
45-
return Err(Error::Rsa(rsa::errors::Error::Internal));
46-
};
44+
).to_montgomery();
4745
Ok(Self {
4846
authority: authority.to_string(),
4947
length,
5048
exponent: rsa.e().clone(),
51-
n: rsa.n().clone(),
49+
n: rsa.n().clone().get(),
5250
p: primes[0].clone(),
5351
q: primes[1].clone(),
5452
dp: rsa.dp().expect(
@@ -92,49 +90,49 @@ impl BIPrivateKey {
9290
let exponent = {
9391
let mut buffer = vec![0; 4];
9492
input.read_exact(&mut buffer)?;
95-
BigUint::from_bytes_le(&buffer)
93+
BoxedUint::from_le_slice_vartime(&buffer)
9694
};
9795

9896
let n = {
9997
let mut buffer = vec![0; (length / 8) as usize];
10098
input.read_exact(&mut buffer)?;
101-
BigUint::from_bytes_le(&buffer)
99+
BoxedUint::from_le_slice_vartime(&buffer)
102100
};
103101

104102
let p = {
105103
let mut buffer = vec![0; (length / 16) as usize];
106104
input.read_exact(&mut buffer)?;
107-
BigUint::from_bytes_le(&buffer)
105+
BoxedUint::from_le_slice_vartime(&buffer)
108106
};
109107

110108
let q = {
111109
let mut buffer = vec![0; (length / 16) as usize];
112110
input.read_exact(&mut buffer)?;
113-
BigUint::from_bytes_le(&buffer)
111+
BoxedUint::from_le_slice_vartime(&buffer)
114112
};
115113

116114
let dp = {
117115
let mut buffer = vec![0; (length / 16) as usize];
118116
input.read_exact(&mut buffer)?;
119-
BigUint::from_bytes_le(&buffer)
117+
BoxedUint::from_le_slice_vartime(&buffer)
120118
};
121119

122120
let dq = {
123121
let mut buffer = vec![0; (length / 16) as usize];
124122
input.read_exact(&mut buffer)?;
125-
BigUint::from_bytes_le(&buffer)
123+
BoxedUint::from_le_slice_vartime(&buffer)
126124
};
127125

128126
let qinv = {
129127
let mut buffer = vec![0; (length / 16) as usize];
130128
input.read_exact(&mut buffer)?;
131-
BigUint::from_bytes_le(&buffer)
129+
BoxedUint::from_le_slice_vartime(&buffer)
132130
};
133131

134132
let d = {
135133
let mut buffer = vec![0; (length / 8) as usize];
136134
input.read_exact(&mut buffer)?;
137-
BigUint::from_bytes_le(&buffer)
135+
BoxedUint::from_le_slice_vartime(&buffer)
138136
};
139137

140138
Ok(Self {
@@ -162,9 +160,9 @@ impl BIPrivateKey {
162160
) -> Result<BISign, Error> {
163161
let (hash1, hash2, hash3) = generate_hashes(pbo, version, self.length)?;
164162

165-
let sig1 = hash1.modpow(&self.d, &self.n);
166-
let sig2 = hash2.modpow(&self.d, &self.n);
167-
let sig3 = hash3.modpow(&self.d, &self.n);
163+
let sig1 = modpow(&hash1, &self.d, &self.n);
164+
let sig2 = modpow(&hash2, &self.d, &self.n);
165+
let sig3 = modpow(&hash3, &self.d, &self.n);
168166

169167
Ok(BISign {
170168
version,
@@ -191,21 +189,21 @@ impl BIPrivateKey {
191189
output.write_all(b"\x07\x02\x00\x00\x00\x24\x00\x00")?;
192190
output.write_all(b"RSA2")?;
193191
output.write_u32::<LittleEndian>(self.length)?;
194-
super::write_biguint(output, &self.exponent, 4)?;
192+
super::write_boxeduint(output, &self.exponent, 4)?;
195193
// output.write_all(&self.exponent.to_bytes_le())?;
196-
super::write_biguint(output, &self.n, (self.length / 8) as usize)?;
194+
super::write_boxeduint(output, &self.n, (self.length / 8) as usize)?;
197195
// output.write_all(&self.n.to_bytes_le())?;
198-
super::write_biguint(output, &self.p, (self.length / 16) as usize)?;
196+
super::write_boxeduint(output, &self.p, (self.length / 16) as usize)?;
199197
// output.write_all(&self.p.to_bytes_le())?;
200-
super::write_biguint(output, &self.q, (self.length / 16) as usize)?;
198+
super::write_boxeduint(output, &self.q, (self.length / 16) as usize)?;
201199
// output.write_all(&self.q.to_bytes_le())?;
202-
super::write_biguint(output, &self.dp, (self.length / 16) as usize)?;
200+
super::write_boxeduint(output, &self.dp, (self.length / 16) as usize)?;
203201
// output.write_all(&self.dp.to_bytes_le())?;
204-
super::write_biguint(output, &self.dq, (self.length / 16) as usize)?;
202+
super::write_boxeduint(output, &self.dq, (self.length / 16) as usize)?;
205203
// output.write_all(&self.dq.to_bytes_le())?;
206-
super::write_biguint(output, &self.qinv, (self.length / 16) as usize)?;
204+
super::write_boxeduint(output, &self.qinv, (self.length / 16) as usize)?;
207205
// output.write_all(&self.qinv.to_bytes_le())?;
208-
super::write_biguint(output, &self.d, (self.length / 8) as usize)?;
206+
super::write_boxeduint(output, &self.d, (self.length / 8) as usize)?;
209207
// output.write_all(&self.d.to_bytes_le())?;
210208
Ok(())
211209
}

0 commit comments

Comments
 (0)