Implement working unpack for bink1998

This commit is contained in:
Alex Page 2023-06-19 02:18:58 -04:00
parent 0208c863aa
commit 3993cafa35
7 changed files with 273 additions and 44 deletions

View file

@ -8,6 +8,8 @@ use openssl::{
};
use serde_json::from_reader;
use crate::crypto::initialize_elliptic_curve;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
Bink1998,
@ -111,8 +113,7 @@ impl Cli {
println!();
}
let (e_curve, gen_point, pub_point) =
Cli::initialize_elliptic_curve(p, a, b, gx, gy, kx, ky);
let (e_curve, gen_point, pub_point) = initialize_elliptic_curve(p, a, b, gx, gy, kx, ky);
Ok(Self {
options,
@ -127,14 +128,6 @@ impl Cli {
})
}
pub fn run(&mut self) -> Result<()> {
match self.options.application_mode {
Mode::Bink1998 => todo!(),
Mode::Bink2002 => todo!(),
Mode::ConfirmationId => todo!(),
}
}
fn parse_command_line() -> Options {
let mut args = Options::parse();
if args.instid.is_some() {
@ -188,44 +181,39 @@ impl Cli {
Ok(json)
}
fn initialize_elliptic_curve(
p_sel: &str,
a_sel: &str,
b_sel: &str,
generator_x_sel: &str,
generator_y_sel: &str,
public_key_x_sel: &str,
public_key_y_sel: &str,
) -> (EcGroup, EcPoint, EcPoint) {
let mut context = openssl::bn::BigNumContext::new().unwrap();
pub fn run(&mut self) -> Result<()> {
match self.options.application_mode {
Mode::Bink1998 => self.bink1998(),
Mode::Bink2002 => self.bink2002(),
Mode::ConfirmationId => self.confirmation_id(),
}
}
let p = BigNum::from_dec_str(p_sel).unwrap();
let a = BigNum::from_dec_str(a_sel).unwrap();
let b = BigNum::from_dec_str(b_sel).unwrap();
let generator_x = BigNum::from_dec_str(generator_x_sel).unwrap();
let generator_y = BigNum::from_dec_str(generator_y_sel).unwrap();
fn bink1998(&mut self) -> Result<()> {
Ok(())
}
let public_key_x = BigNum::from_dec_str(public_key_x_sel).unwrap();
let public_key_y = BigNum::from_dec_str(public_key_y_sel).unwrap();
fn bink2002(&mut self) -> Result<()> {
todo!()
}
let c_curve = EcGroup::from_components(p, a, b, &mut context).unwrap();
fn confirmation_id(&mut self) -> Result<()> {
todo!()
}
let mut gen_point = EcPoint::new(&c_curve).unwrap();
let _ = gen_point.set_affine_coordinates_gfp(
&c_curve,
&generator_x,
&generator_y,
&mut context,
fn print_key(pk: &str) {
assert_eq!(pk.len(), 25);
println!(
"{}",
pk.chars()
.enumerate()
.fold(String::new(), |mut acc: String, (i, c)| {
if i > 0 && i % 5 == 0 {
acc.push('-');
}
acc.push(c);
acc
})
);
let mut pub_point = EcPoint::new(&c_curve).unwrap();
let _ = pub_point.set_affine_coordinates_gfp(
&c_curve,
&public_key_x,
&public_key_y,
&mut context,
);
(c_curve, gen_point, pub_point)
}
}