Impelement generation for bink1998

This commit is contained in:
Alex Page 2023-06-19 16:42:50 -04:00
parent e9e7b1506f
commit bd51609f05
3 changed files with 119 additions and 11 deletions

View file

@ -3,12 +3,12 @@ use std::{fs::File, io::BufReader, path::Path};
use anyhow::{anyhow, Result};
use clap::Parser;
use openssl::{
bn::BigNum,
bn::{BigNum, MsbOption},
ec::{EcGroup, EcPoint},
};
use serde_json::from_reader;
use crate::crypto::initialize_elliptic_curve;
use crate::{bink1998, crypto::initialize_elliptic_curve};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
@ -52,7 +52,7 @@ pub struct Options {
/// Specify which Channel Identifier to use
#[arg(short = 'c', long = "channel", default_value = "640")]
channel_id: i32,
channel_id: u32,
#[clap(skip)]
application_mode: Mode,
@ -190,6 +190,39 @@ impl Cli {
}
fn bink1998(&mut self) -> Result<()> {
let mut n_raw = self.options.channel_id * 1_000_000; // <- change
let mut bn_rand = BigNum::new()?;
bn_rand.rand(19, MsbOption::MAYBE_ZERO, false)?;
let o_raw: u32 = u32::from_be_bytes(bn_rand.to_vec_padded(4)?.try_into().unwrap());
n_raw += o_raw % 999999;
if self.options.verbose {
println!("> PID: {n_raw:09}");
}
let private_key = &self.gen_order - &self.private_key;
let upgrade = false;
for _ in 0..self.options.num_keys {
let p_key = bink1998::generate(
&self.e_curve,
&self.gen_point,
&self.gen_order,
&private_key,
n_raw,
upgrade,
)?;
Cli::print_key(&p_key);
if bink1998::verify(&self.e_curve, &self.gen_point, &self.pub_point, &p_key)? {
self.count += 1;
}
}
println!("Success count: {}/{}", self.count, self.options.num_keys);
Ok(())
}