Use correct channel_id for bink2002
This commit is contained in:
parent
b73401cefb
commit
49ce9a47f3
4 changed files with 76 additions and 85 deletions
|
@ -241,7 +241,6 @@ impl Cli {
|
||||||
self.options.channel_id,
|
self.options.channel_id,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)?;
|
)?;
|
||||||
println!("{product_key}");
|
println!("{product_key}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,10 +72,10 @@ impl ProductKey {
|
||||||
|
|
||||||
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
||||||
let key = strip_key(key)?;
|
let key = strip_key(key)?;
|
||||||
let Ok(p_raw) = base24_decode(&key) else {
|
let Ok(packed_key) = base24_decode(&key) else {
|
||||||
bail!("Product key is in an incorrect format!")
|
bail!("Product key is in an incorrect format!")
|
||||||
};
|
};
|
||||||
let product_key = Self::from_packed(&p_raw)?;
|
let product_key = Self::from_packed(&packed_key)?;
|
||||||
product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
||||||
Ok(product_key)
|
Ok(product_key)
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,8 @@ impl ProductKey {
|
||||||
base_point: &EcPoint,
|
base_point: &EcPoint,
|
||||||
gen_order: &BigNum,
|
gen_order: &BigNum,
|
||||||
private_key: &BigNum,
|
private_key: &BigNum,
|
||||||
p_serial: u32,
|
serial: u32,
|
||||||
p_upgrade: bool,
|
upgrade: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut num_context = BigNumContext::new().unwrap();
|
let mut num_context = BigNumContext::new().unwrap();
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ impl ProductKey {
|
||||||
|
|
||||||
let mut ek: BigNum;
|
let mut ek: BigNum;
|
||||||
|
|
||||||
let p_data = p_serial << 1 | p_upgrade as u32;
|
let data = serial << 1 | upgrade as u32;
|
||||||
|
|
||||||
let product_key = loop {
|
let product_key = loop {
|
||||||
let mut r = EcPoint::new(e_curve)?;
|
let mut r = EcPoint::new(e_curve)?;
|
||||||
|
@ -120,28 +120,28 @@ impl ProductKey {
|
||||||
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
||||||
y_bin.reverse();
|
y_bin.reverse();
|
||||||
|
|
||||||
msg_buffer[0..4].copy_from_slice(&p_data.to_le_bytes());
|
msg_buffer[0..4].copy_from_slice(&data.to_le_bytes());
|
||||||
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer);
|
let msg_digest = sha1(&msg_buffer);
|
||||||
|
|
||||||
let p_hash: u32 =
|
let hash: u32 =
|
||||||
u32::from_le_bytes(msg_digest[0..4].try_into().unwrap()) >> 4 & bitmask(28) as u32;
|
u32::from_le_bytes(msg_digest[0..4].try_into().unwrap()) >> 4 & bitmask(28) as u32;
|
||||||
|
|
||||||
ek = (*private_key).to_owned()?;
|
ek = (*private_key).to_owned()?;
|
||||||
ek.mul_word(p_hash)?;
|
ek.mul_word(hash)?;
|
||||||
|
|
||||||
s.mod_add(&ek, &c, gen_order, &mut num_context)?;
|
s.mod_add(&ek, &c, gen_order, &mut num_context)?;
|
||||||
|
|
||||||
let p_signature = u64::from_be_bytes(s.to_vec_padded(8)?.try_into().unwrap());
|
let signature = u64::from_be_bytes(s.to_vec_padded(8)?.try_into().unwrap());
|
||||||
|
|
||||||
if p_signature <= bitmask(55) {
|
if signature <= bitmask(55) {
|
||||||
break Self {
|
break Self {
|
||||||
upgrade: p_upgrade,
|
upgrade,
|
||||||
serial: p_serial,
|
serial,
|
||||||
hash: p_hash,
|
hash,
|
||||||
signature: p_signature,
|
signature,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -182,9 +182,9 @@ impl ProductKey {
|
||||||
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
let mut y_bin = y.to_vec_padded(FIELD_BYTES as i32)?;
|
||||||
y_bin.reverse();
|
y_bin.reverse();
|
||||||
|
|
||||||
let p_data = self.serial << 1 | self.upgrade as u32;
|
let data = self.serial << 1 | self.upgrade as u32;
|
||||||
|
|
||||||
msg_buffer[0..4].copy_from_slice(&p_data.to_le_bytes());
|
msg_buffer[0..4].copy_from_slice(&data.to_le_bytes());
|
||||||
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[4..4 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[4 + FIELD_BYTES..4 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
|
||||||
|
@ -215,14 +215,14 @@ impl ProductKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pack(&self) -> Vec<u8> {
|
fn pack(&self) -> Vec<u8> {
|
||||||
let mut p_raw: u128 = 0;
|
let mut packed_key: u128 = 0;
|
||||||
|
|
||||||
p_raw |= (self.signature as u128) << EVERYTHING_ELSE;
|
packed_key |= (self.signature as u128) << EVERYTHING_ELSE;
|
||||||
p_raw |= (self.hash as u128) << (SERIAL_LENGTH_BITS + UPGRADE_LENGTH_BITS);
|
packed_key |= (self.hash as u128) << (SERIAL_LENGTH_BITS + UPGRADE_LENGTH_BITS);
|
||||||
p_raw |= (self.serial as u128) << UPGRADE_LENGTH_BITS;
|
packed_key |= (self.serial as u128) << UPGRADE_LENGTH_BITS;
|
||||||
p_raw |= self.upgrade as u128;
|
packed_key |= self.upgrade as u128;
|
||||||
|
|
||||||
p_raw
|
packed_key
|
||||||
.to_be_bytes()
|
.to_be_bytes()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.skip_while(|&x| x == 0)
|
.skip_while(|&x| x == 0)
|
||||||
|
|
100
src/bink2002.rs
100
src/bink2002.rs
|
@ -40,28 +40,16 @@ impl ProductKey {
|
||||||
curve: &EllipticCurve,
|
curve: &EllipticCurve,
|
||||||
private_key: &PrivateKey,
|
private_key: &PrivateKey,
|
||||||
channel_id: u32,
|
channel_id: u32,
|
||||||
sequence: Option<u32>,
|
|
||||||
auth_info: Option<u32>,
|
auth_info: Option<u32>,
|
||||||
upgrade: Option<bool>,
|
upgrade: Option<bool>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
// Generate random sequence if none supplied
|
|
||||||
let sequence = match sequence {
|
|
||||||
Some(serial) => serial,
|
|
||||||
None => {
|
|
||||||
let mut bn_rand = BigNum::new()?;
|
|
||||||
bn_rand.rand(19, MsbOption::MAYBE_ZERO, false)?;
|
|
||||||
let o_raw = u32::from_be_bytes(bn_rand.to_vec_padded(4)?.try_into().unwrap());
|
|
||||||
o_raw % 999999
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Generate random auth info if none supplied
|
// Generate random auth info if none supplied
|
||||||
let auth_info = match auth_info {
|
let auth_info = match auth_info {
|
||||||
Some(auth_info) => auth_info,
|
Some(auth_info) => auth_info,
|
||||||
None => {
|
None => {
|
||||||
let mut p_auth_info_bytes = [0_u8; 4];
|
let mut auth_info_bytes = [0_u8; 4];
|
||||||
rand_bytes(&mut p_auth_info_bytes)?;
|
rand_bytes(&mut auth_info_bytes)?;
|
||||||
u32::from_ne_bytes(p_auth_info_bytes) & ((1 << 10) - 1)
|
u32::from_ne_bytes(auth_info_bytes) & ((1 << 10) - 1)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -74,7 +62,7 @@ impl ProductKey {
|
||||||
&curve.gen_point,
|
&curve.gen_point,
|
||||||
&private_key.gen_order,
|
&private_key.gen_order,
|
||||||
&private_key.private_key,
|
&private_key.private_key,
|
||||||
channel_id * 1_000_000 + sequence,
|
channel_id,
|
||||||
auth_info,
|
auth_info,
|
||||||
upgrade,
|
upgrade,
|
||||||
)?;
|
)?;
|
||||||
|
@ -88,10 +76,10 @@ impl ProductKey {
|
||||||
|
|
||||||
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
pub fn from_key(curve: &EllipticCurve, key: &str) -> Result<Self> {
|
||||||
let key = strip_key(key)?;
|
let key = strip_key(key)?;
|
||||||
let Ok(p_raw) = base24_decode(&key) else {
|
let Ok(packed_key) = base24_decode(&key) else {
|
||||||
bail!("Product key is in an incorrect format!")
|
bail!("Product key is in an incorrect format!")
|
||||||
};
|
};
|
||||||
let product_key = Self::from_packed(&p_raw)?;
|
let product_key = Self::from_packed(&packed_key)?;
|
||||||
let verified = product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
let verified = product_key.verify(&curve.curve, &curve.gen_point, &curve.pub_point)?;
|
||||||
if !verified {
|
if !verified {
|
||||||
bail!("Product key is invalid! Wrong BINK ID?");
|
bail!("Product key is invalid! Wrong BINK ID?");
|
||||||
|
@ -104,9 +92,9 @@ impl ProductKey {
|
||||||
base_point: &EcPoint,
|
base_point: &EcPoint,
|
||||||
gen_order: &BigNum,
|
gen_order: &BigNum,
|
||||||
private_key: &BigNum,
|
private_key: &BigNum,
|
||||||
p_channel_id: u32,
|
channel_id: u32,
|
||||||
p_auth_info: u32,
|
auth_info: u32,
|
||||||
p_upgrade: bool,
|
upgrade: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut num_context = BigNumContext::new().unwrap();
|
let mut num_context = BigNumContext::new().unwrap();
|
||||||
|
|
||||||
|
@ -114,7 +102,7 @@ impl ProductKey {
|
||||||
let mut x = BigNum::new()?;
|
let mut x = BigNum::new()?;
|
||||||
let mut y = BigNum::new()?;
|
let mut y = BigNum::new()?;
|
||||||
|
|
||||||
let p_data = p_channel_id << 1 | p_upgrade as u32;
|
let data = channel_id << 1 | upgrade as u32;
|
||||||
|
|
||||||
let mut no_square = false;
|
let mut no_square = false;
|
||||||
let key = loop {
|
let key = loop {
|
||||||
|
@ -134,25 +122,25 @@ impl ProductKey {
|
||||||
y_bin.reverse();
|
y_bin.reverse();
|
||||||
|
|
||||||
msg_buffer[0x00] = 0x79;
|
msg_buffer[0x00] = 0x79;
|
||||||
msg_buffer[0x01] = (p_data & 0x00FF) as u8;
|
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
||||||
msg_buffer[0x02] = ((p_data & 0xFF00) >> 8) as u8;
|
msg_buffer[0x02] = ((data & 0xFF00) >> 8) as u8;
|
||||||
|
|
||||||
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
|
||||||
let msg_digest = sha1(&msg_buffer);
|
let msg_digest = sha1(&msg_buffer);
|
||||||
|
|
||||||
let p_hash: u32 = by_dword(&msg_digest[0..4]) & bitmask(31) as u32;
|
let hash: u32 = by_dword(&msg_digest[0..4]) & bitmask(31) as u32;
|
||||||
|
|
||||||
msg_buffer[0x00] = 0x5D;
|
msg_buffer[0x00] = 0x5D;
|
||||||
msg_buffer[0x01] = (p_data & 0x00FF) as u8;
|
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
||||||
msg_buffer[0x02] = ((p_data & 0xFF00) >> 8) as u8;
|
msg_buffer[0x02] = ((data & 0xFF00) >> 8) as u8;
|
||||||
msg_buffer[0x03] = (p_hash & 0x000000FF) as u8;
|
msg_buffer[0x03] = (hash & 0x000000FF) as u8;
|
||||||
msg_buffer[0x04] = ((p_hash & 0x0000FF00) >> 8) as u8;
|
msg_buffer[0x04] = ((hash & 0x0000FF00) >> 8) as u8;
|
||||||
msg_buffer[0x05] = ((p_hash & 0x00FF0000) >> 16) as u8;
|
msg_buffer[0x05] = ((hash & 0x00FF0000) >> 16) as u8;
|
||||||
msg_buffer[0x06] = ((p_hash & 0xFF000000) >> 24) as u8;
|
msg_buffer[0x06] = ((hash & 0xFF000000) >> 24) as u8;
|
||||||
msg_buffer[0x07] = (p_auth_info & 0x00FF) as u8;
|
msg_buffer[0x07] = (auth_info & 0x00FF) as u8;
|
||||||
msg_buffer[0x08] = ((p_auth_info & 0xFF00) >> 8) as u8;
|
msg_buffer[0x08] = ((auth_info & 0xFF00) >> 8) as u8;
|
||||||
msg_buffer[0x09] = 0x00;
|
msg_buffer[0x09] = 0x00;
|
||||||
msg_buffer[0x0A] = 0x00;
|
msg_buffer[0x0A] = 0x00;
|
||||||
|
|
||||||
|
@ -191,17 +179,17 @@ impl ProductKey {
|
||||||
let s_2 = s.to_owned()?;
|
let s_2 = s.to_owned()?;
|
||||||
s.rshift1(&s_2)?;
|
s.rshift1(&s_2)?;
|
||||||
|
|
||||||
let p_signature = u64::from_be_bytes(s.to_vec_padded(8)?.try_into().unwrap());
|
let signature = u64::from_be_bytes(s.to_vec_padded(8)?.try_into().unwrap());
|
||||||
|
|
||||||
let product_key = Self {
|
let product_key = Self {
|
||||||
upgrade: p_upgrade,
|
upgrade,
|
||||||
channel_id: p_channel_id,
|
channel_id,
|
||||||
hash: p_hash,
|
hash,
|
||||||
signature: p_signature,
|
signature,
|
||||||
auth_info: p_auth_info,
|
auth_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
if p_signature <= bitmask(62) && !no_square {
|
if signature <= bitmask(62) && !no_square {
|
||||||
break product_key;
|
break product_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,13 +207,13 @@ impl ProductKey {
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut num_context = BigNumContext::new()?;
|
let mut num_context = BigNumContext::new()?;
|
||||||
|
|
||||||
let p_data = self.channel_id << 1 | self.upgrade as u32;
|
let data = self.channel_id << 1 | self.upgrade as u32;
|
||||||
|
|
||||||
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
let mut msg_buffer: [u8; SHA_MSG_LENGTH] = [0; SHA_MSG_LENGTH];
|
||||||
|
|
||||||
msg_buffer[0x00] = 0x5D;
|
msg_buffer[0x00] = 0x5D;
|
||||||
msg_buffer[0x01] = (p_data & 0x00FF) as u8;
|
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
||||||
msg_buffer[0x02] = ((p_data & 0xFF00) >> 8) as u8;
|
msg_buffer[0x02] = ((data & 0xFF00) >> 8) as u8;
|
||||||
msg_buffer[0x03] = (self.hash & 0x000000FF) as u8;
|
msg_buffer[0x03] = (self.hash & 0x000000FF) as u8;
|
||||||
msg_buffer[0x04] = ((self.hash & 0x0000FF00) >> 8) as u8;
|
msg_buffer[0x04] = ((self.hash & 0x0000FF00) >> 8) as u8;
|
||||||
msg_buffer[0x05] = ((self.hash & 0x00FF0000) >> 16) as u8;
|
msg_buffer[0x05] = ((self.hash & 0x00FF0000) >> 16) as u8;
|
||||||
|
@ -251,12 +239,16 @@ impl ProductKey {
|
||||||
|
|
||||||
t.mul(e_curve, base_point, &s, &num_context)?;
|
t.mul(e_curve, base_point, &s, &num_context)?;
|
||||||
p.mul(e_curve, public_key, &e, &num_context)?;
|
p.mul(e_curve, public_key, &e, &num_context)?;
|
||||||
let p_2 = p.to_owned(e_curve)?;
|
|
||||||
|
|
||||||
|
{
|
||||||
|
let p_2 = p.to_owned(e_curve)?;
|
||||||
p.add(e_curve, &t, &p_2, &mut num_context)?;
|
p.add(e_curve, &t, &p_2, &mut num_context)?;
|
||||||
let p_2 = p.to_owned(e_curve)?;
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let p_2 = p.to_owned(e_curve)?;
|
||||||
p.mul(e_curve, &p_2, &s, &num_context)?;
|
p.mul(e_curve, &p_2, &s, &num_context)?;
|
||||||
|
}
|
||||||
|
|
||||||
p.affine_coordinates(e_curve, &mut x, &mut y, &mut num_context)?;
|
p.affine_coordinates(e_curve, &mut x, &mut y, &mut num_context)?;
|
||||||
|
|
||||||
|
@ -266,8 +258,8 @@ impl ProductKey {
|
||||||
y_bin.reverse();
|
y_bin.reverse();
|
||||||
|
|
||||||
msg_buffer[0x00] = 0x79;
|
msg_buffer[0x00] = 0x79;
|
||||||
msg_buffer[0x01] = (p_data & 0x00FF) as u8;
|
msg_buffer[0x01] = (data & 0x00FF) as u8;
|
||||||
msg_buffer[0x02] = ((p_data & 0xFF00) >> 8) as u8;
|
msg_buffer[0x02] = ((data & 0xFF00) >> 8) as u8;
|
||||||
|
|
||||||
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
msg_buffer[3..3 + FIELD_BYTES].copy_from_slice(&x_bin);
|
||||||
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
msg_buffer[3 + FIELD_BYTES..3 + FIELD_BYTES * 2].copy_from_slice(&y_bin);
|
||||||
|
@ -300,20 +292,20 @@ impl ProductKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pack(&self) -> Vec<u8> {
|
fn pack(&self) -> Vec<u8> {
|
||||||
let mut p_raw: u128 = 0;
|
let mut packed_key: u128 = 0;
|
||||||
|
|
||||||
p_raw |= (self.auth_info as u128)
|
packed_key |= (self.auth_info as u128)
|
||||||
<< (SIGNATURE_LENGTH_BITS
|
<< (SIGNATURE_LENGTH_BITS
|
||||||
+ HASH_LENGTH_BITS
|
+ HASH_LENGTH_BITS
|
||||||
+ CHANNEL_ID_LENGTH_BITS
|
+ CHANNEL_ID_LENGTH_BITS
|
||||||
+ UPGRADE_LENGTH_BITS);
|
+ UPGRADE_LENGTH_BITS);
|
||||||
p_raw |= (self.signature as u128)
|
packed_key |= (self.signature as u128)
|
||||||
<< (HASH_LENGTH_BITS + CHANNEL_ID_LENGTH_BITS + UPGRADE_LENGTH_BITS);
|
<< (HASH_LENGTH_BITS + CHANNEL_ID_LENGTH_BITS + UPGRADE_LENGTH_BITS);
|
||||||
p_raw |= (self.hash as u128) << (CHANNEL_ID_LENGTH_BITS + UPGRADE_LENGTH_BITS);
|
packed_key |= (self.hash as u128) << (CHANNEL_ID_LENGTH_BITS + UPGRADE_LENGTH_BITS);
|
||||||
p_raw |= (self.channel_id as u128) << UPGRADE_LENGTH_BITS;
|
packed_key |= (self.channel_id as u128) << UPGRADE_LENGTH_BITS;
|
||||||
p_raw |= self.upgrade as u128;
|
packed_key |= self.upgrade as u128;
|
||||||
|
|
||||||
p_raw
|
packed_key
|
||||||
.to_be_bytes()
|
.to_be_bytes()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.skip_while(|&x| x == 0)
|
.skip_while(|&x| x == 0)
|
||||||
|
|
12
src/key.rs
12
src/key.rs
|
@ -6,20 +6,20 @@ use openssl::bn::BigNum;
|
||||||
const PK_LENGTH: usize = 25;
|
const PK_LENGTH: usize = 25;
|
||||||
|
|
||||||
/// The allowed character set in a product key.
|
/// The allowed character set in a product key.
|
||||||
pub const P_KEY_CHARSET: [char; 24] = [
|
pub const KEY_CHARSET: [char; 24] = [
|
||||||
'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y', '2', '3',
|
'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y', '2', '3',
|
||||||
'4', '6', '7', '8', '9',
|
'4', '6', '7', '8', '9',
|
||||||
];
|
];
|
||||||
|
|
||||||
pub(crate) fn base24_decode(cd_key: &str) -> Result<Vec<u8>> {
|
pub(crate) fn base24_decode(cd_key: &str) -> Result<Vec<u8>> {
|
||||||
let p_decoded_key: Vec<u8> = cd_key
|
let decoded_key: Vec<u8> = cd_key
|
||||||
.chars()
|
.chars()
|
||||||
.filter_map(|c| P_KEY_CHARSET.iter().position(|&x| x == c).map(|i| i as u8))
|
.filter_map(|c| KEY_CHARSET.iter().position(|&x| x == c).map(|i| i as u8))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut y = BigNum::from_u32(0).unwrap();
|
let mut y = BigNum::from_u32(0).unwrap();
|
||||||
|
|
||||||
for i in p_decoded_key {
|
for i in decoded_key {
|
||||||
y.mul_word((PK_LENGTH - 1) as u32).unwrap();
|
y.mul_word((PK_LENGTH - 1) as u32).unwrap();
|
||||||
y.add_word(i.into()).unwrap();
|
y.add_word(i.into()).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ pub(crate) fn base24_decode(cd_key: &str) -> Result<Vec<u8>> {
|
||||||
pub(crate) fn base24_encode(byte_seq: &[u8]) -> Result<String> {
|
pub(crate) fn base24_encode(byte_seq: &[u8]) -> Result<String> {
|
||||||
let mut z = BigNum::from_slice(byte_seq).unwrap();
|
let mut z = BigNum::from_slice(byte_seq).unwrap();
|
||||||
let mut out: VecDeque<char> = VecDeque::new();
|
let mut out: VecDeque<char> = VecDeque::new();
|
||||||
(0..=24).for_each(|_| out.push_front(P_KEY_CHARSET[z.div_word(24).unwrap() as usize]));
|
(0..=24).for_each(|_| out.push_front(KEY_CHARSET[z.div_word(24).unwrap() as usize]));
|
||||||
Ok(out.iter().collect())
|
Ok(out.iter().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ pub(crate) fn strip_key(in_key: &str) -> Result<String> {
|
||||||
.chars()
|
.chars()
|
||||||
.filter_map(|c| {
|
.filter_map(|c| {
|
||||||
let c = c.to_ascii_uppercase();
|
let c = c.to_ascii_uppercase();
|
||||||
if P_KEY_CHARSET.into_iter().any(|x| x == c) {
|
if KEY_CHARSET.into_iter().any(|x| x == c) {
|
||||||
Some(c)
|
Some(c)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Reference in a new issue