More confid cleanup

This commit is contained in:
Alex Page 2023-06-22 02:18:09 -04:00
parent ce9442e9b8
commit 78b45cf929

View file

@ -1,5 +1,3 @@
#![allow(clippy::too_many_arguments)]
use std::{ffi::c_void, ptr}; use std::{ffi::c_void, ptr};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -15,31 +13,31 @@ struct C2RustUnnamed {
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
union C2RustUnnamed_0 { union C2RustUnnamed0 {
c2rust_unnamed: C2RustUnnamed_1, c2rust_unnamed: C2RustUnnamed1,
c2rust_unnamed_0: C2RustUnnamed, c2rust_unnamed_0: C2RustUnnamed,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
struct C2RustUnnamed_1 { struct C2RustUnnamed1 {
encoded_lo: u64, encoded_lo: u64,
encoded_hi: u64, encoded_hi: u64,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
struct C2RustUnnamed_2 { struct C2RustUnnamed2 {
lo: u64, lo: u64,
hi: u64, hi: u64,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
union C2RustUnnamed_3 { union C2RustUnnamed3 {
buffer: [u8; 14], buffer: [u8; 14],
c2rust_unnamed: C2RustUnnamed_2, c2rust_unnamed: C2RustUnnamed2,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C, packed)] #[repr(C, packed)]
struct C2RustUnnamed_4 { struct C2RustUnnamed4 {
hardware_id: u64, hardware_id: u64,
product_id_low: u64, product_id_low: u64,
product_id_high: u8, product_id_high: u8,
@ -75,7 +73,6 @@ fn residue_sub(x: u64, y: u64) -> u64 {
z z
} }
/// Confirmed working
fn umul128(a: u64, b: u64, hi: &mut u64) -> u64 { fn umul128(a: u64, b: u64, hi: &mut u64) -> u64 {
let r: u128 = a as u128 * b as u128; let r: u128 = a as u128 * b as u128;
*hi = (r >> 64) as u64; *hi = (r >> 64) as u64;
@ -83,8 +80,6 @@ fn umul128(a: u64, b: u64, hi: &mut u64) -> u64 {
} }
/// `hi:lo * ceil(2**170/MOD) >> (64 + 64 + 42)` /// `hi:lo * ceil(2**170/MOD) >> (64 + 64 + 42)`
///
/// Confirmed working
fn ui128_quotient_mod(lo: u64, hi: u64) -> u64 { fn ui128_quotient_mod(lo: u64, hi: u64) -> u64 {
let mut prod1: u64 = 0; let mut prod1: u64 = 0;
umul128(lo, 0x604fa6a1c6346a87_i64 as u64, &mut prod1); umul128(lo, 0x604fa6a1c6346a87_i64 as u64, &mut prod1);
@ -358,6 +353,7 @@ unsafe fn polynomial_div_monic(
i i
} }
#[allow(clippy::too_many_arguments)]
unsafe fn polynomial_xgcd( unsafe fn polynomial_xgcd(
adeg: i32, adeg: i32,
a: *const u64, a: *const u64,
@ -1074,7 +1070,7 @@ pub unsafe fn generate(installation_id_str: *const i8, confirmation_id: *mut i8)
if installation_id[18_i32 as usize] as i32 >= 0x10_i32 { if installation_id[18_i32 as usize] as i32 >= 0x10_i32 {
return 5_i32; return 5_i32;
} }
let mut parsed: C2RustUnnamed_4 = C2RustUnnamed_4 { let mut parsed: C2RustUnnamed4 = C2RustUnnamed4 {
hardware_id: 0, hardware_id: 0,
product_id_low: 0, product_id_low: 0,
product_id_high: 0, product_id_high: 0,
@ -1082,8 +1078,8 @@ pub unsafe fn generate(installation_id_str: *const i8, confirmation_id: *mut i8)
}; };
ptr::copy_nonoverlapping( ptr::copy_nonoverlapping(
installation_id.as_mut_ptr() as *const c_void, installation_id.as_mut_ptr() as *const c_void,
&mut parsed as *mut C2RustUnnamed_4 as *mut c_void, &mut parsed as *mut C2RustUnnamed4 as *mut c_void,
std::mem::size_of::<C2RustUnnamed_4>(), std::mem::size_of::<C2RustUnnamed4>(),
); );
let product_id_1: u32 = (parsed.product_id_low & ((1_i32 << 17_i32) - 1_i32) as u64) as u32; let product_id_1: u32 = (parsed.product_id_low & ((1_i32 << 17_i32) - 1_i32) as u64) as u32;
let product_id_2: u32 = let product_id_2: u32 =
@ -1118,7 +1114,7 @@ pub unsafe fn generate(installation_id_str: *const i8, confirmation_id: *mut i8)
}; };
let mut attempt = 0_i32 as u8; let mut attempt = 0_i32 as u8;
while attempt as i32 <= 0x80_i32 { while attempt as i32 <= 0x80_i32 {
let mut u: C2RustUnnamed_3 = C2RustUnnamed_3 { buffer: [0; 14] }; let mut u: C2RustUnnamed3 = C2RustUnnamed3 { buffer: [0; 14] };
u.c2rust_unnamed.lo = 0_i32 as u64; u.c2rust_unnamed.lo = 0_i32 as u64;
u.c2rust_unnamed.hi = 0_i32 as u64; u.c2rust_unnamed.hi = 0_i32 as u64;
u.buffer[7_i32 as usize] = attempt; u.buffer[7_i32 as usize] = attempt;
@ -1150,8 +1146,8 @@ pub unsafe fn generate(installation_id_str: *const i8, confirmation_id: *mut i8)
0x40da7c36d44c_i64 as u64, 0x40da7c36d44c_i64 as u64,
&mut d_0, &mut d_0,
); );
let mut e: C2RustUnnamed_0 = C2RustUnnamed_0 { let mut e: C2RustUnnamed0 = C2RustUnnamed0 {
c2rust_unnamed: C2RustUnnamed_1 { c2rust_unnamed: C2RustUnnamed1 {
encoded_lo: 0, encoded_lo: 0,
encoded_hi: 0, encoded_hi: 0,
}, },