Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-14 19:55:56 +02:00
parent 6957d74742
commit 0acd686720
2 changed files with 22 additions and 6 deletions
+9 -2
View File
@@ -172,7 +172,11 @@ pub fn java_hex_digest(digest: &[u8]) -> String {
let hex: String = magnitude.iter().map(|b| format!("{b:02x}")).collect();
let hex = hex.trim_start_matches('0');
let hex = if hex.is_empty() { "0" } else { hex };
if negative { format!("-{hex}") } else { hex.to_owned() }
if negative {
format!("-{hex}")
} else {
hex.to_owned()
}
}
/// The server id sent to the session service when joining an online-mode
@@ -181,7 +185,10 @@ pub fn java_hex_digest(digest: &[u8]) -> String {
pub fn server_hash(server_id: &str, secret: &[u8], public_key: &[u8]) -> String {
let mut sha = Sha1::new();
// ISO-8859-1: characters above U+00FF become '?' like String.getBytes.
let latin1: Vec<u8> = server_id.chars().map(|c| u8::try_from(u32::from(c)).unwrap_or(b'?')).collect();
let latin1: Vec<u8> = server_id
.chars()
.map(|c| u8::try_from(u32::from(c)).unwrap_or(b'?'))
.collect();
sha.update(&latin1);
sha.update(secret);
sha.update(public_key);
+13 -4
View File
@@ -150,7 +150,9 @@ fn der(input: &[u8]) -> Result<(u8, &[u8], &[u8])> {
if n == 0 || n > 4 || rest.len() < n {
return Err(bad());
}
let len = rest[..n].iter().fold(0usize, |l, b| l << 8 | usize::from(*b));
let len = rest[..n]
.iter()
.fold(0usize, |l, b| l << 8 | usize::from(*b));
rest = &rest[n..];
len
};
@@ -219,8 +221,11 @@ impl RsaPublicKey {
let limbs = self.size().div_ceil(4);
let mont = Mont::new(Big::from_be_bytes(&self.modulus, limbs));
let m = Big::from_be_bytes(block, limbs);
mont.pow(&m, &Big::from_be_bytes(exponent, limbs.max(exponent.len().div_ceil(4))))
.to_be_bytes(self.size())
mont.pow(
&m,
&Big::from_be_bytes(exponent, limbs.max(exponent.len().div_ceil(4))),
)
.to_be_bytes(self.size())
}
/// RSAES-PKCS1-v1_5 (RFC 8017 7.2.1) with random non-zero padding.
pub fn encrypt(&self, message: &[u8]) -> Result<Vec<u8>> {
@@ -249,7 +254,11 @@ pub(crate) mod tests {
use super::*;
pub fn hex(s: &str) -> Vec<u8> {
let s = if s.len() % 2 == 1 { format!("0{s}") } else { s.to_owned() };
let s = if s.len() % 2 == 1 {
format!("0{s}")
} else {
s.to_owned()
};
(0..s.len())
.step_by(2)
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap())