feat(kgm): move slot_key logic out
All checks were successful
Build and Publish / build (push) Successful in 52s
All checks were successful
Build and Publish / build (push) Successful in 52s
This commit is contained in:
parent
6706eb85e5
commit
ba422e3cce
@ -1,5 +1,6 @@
|
|||||||
pub mod header;
|
pub mod header;
|
||||||
mod pc_db_decrypt;
|
mod pc_db_decrypt;
|
||||||
|
mod slot_keys;
|
||||||
pub mod v2;
|
pub mod v2;
|
||||||
pub mod v3;
|
pub mod v3;
|
||||||
mod v5;
|
mod v5;
|
||||||
@ -68,15 +69,9 @@ impl Decipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_v5(header: &Header, ekey: Option<String>) -> Result<Self, KugouError> {
|
pub fn new_v5(header: &Header, ekey: Option<String>) -> Result<Self, KugouError> {
|
||||||
let slot_key: &[u8] = match header.key_slot {
|
|
||||||
1 => b"l,/'",
|
|
||||||
-1 => b"", // unused, kgm v5 (kgg)
|
|
||||||
slot => Err(KugouError::UnsupportedKeySlot(slot))?,
|
|
||||||
};
|
|
||||||
|
|
||||||
let decipher = match header.crypto_version {
|
let decipher = match header.crypto_version {
|
||||||
2 => Decipher::V2(DecipherV2::new(header, slot_key)?),
|
2 => Decipher::V2(DecipherV2::new(header)?),
|
||||||
3 => Decipher::V3(DecipherV3::new(header, slot_key)?),
|
3 => Decipher::V3(DecipherV3::new(header)?),
|
||||||
5 => match ekey {
|
5 => match ekey {
|
||||||
Some(ekey) => Decipher::V5(DecipherV5::new(&ekey)?),
|
Some(ekey) => Decipher::V5(DecipherV5::new(&ekey)?),
|
||||||
_ => Err(KugouError::V5EKeyRequired)?,
|
_ => Err(KugouError::V5EKeyRequired)?,
|
||||||
|
9
um_crypto/kgm/src/slot_keys.rs
Normal file
9
um_crypto/kgm/src/slot_keys.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use crate::header::Header;
|
||||||
|
use crate::KugouError;
|
||||||
|
|
||||||
|
pub fn get_slot_key(header: &Header) -> Result<&'static [u8], KugouError> {
|
||||||
|
match header.key_slot {
|
||||||
|
1 => Ok(b"l,/'"),
|
||||||
|
slot => Err(KugouError::UnsupportedKeySlot(slot)),
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
use crate::header::Header;
|
use crate::header::Header;
|
||||||
|
use crate::slot_keys::get_slot_key;
|
||||||
use crate::KugouError;
|
use crate::KugouError;
|
||||||
|
|
||||||
pub struct DecipherV2 {
|
pub struct DecipherV2 {
|
||||||
@ -6,9 +7,9 @@ pub struct DecipherV2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DecipherV2 {
|
impl DecipherV2 {
|
||||||
pub fn new(_header: &Header, slot_key: &[u8]) -> Result<Self, KugouError> {
|
pub fn new(header: &Header) -> Result<Self, KugouError> {
|
||||||
let mut key = [0u8; 4];
|
let mut key = [0u8; 4];
|
||||||
key.copy_from_slice(slot_key);
|
key.copy_from_slice(get_slot_key(&header)?);
|
||||||
Ok(Self { key })
|
Ok(Self { key })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ impl DecipherV2 {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_v2_init() -> Result<(), KugouError> {
|
fn test_v2_init() -> Result<(), KugouError> {
|
||||||
let hdr = Header::from_buffer(include_bytes!("__fixtures__/kgm_v2_hdr.bin"))?;
|
let hdr = Header::from_buffer(include_bytes!("__fixtures__/kgm_v2_hdr.bin"))?;
|
||||||
DecipherV2::new(&hdr, b"1234")?;
|
DecipherV2::new(&hdr)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::header::Header;
|
use crate::header::Header;
|
||||||
|
use crate::slot_keys::get_slot_key;
|
||||||
use crate::KugouError;
|
use crate::KugouError;
|
||||||
|
|
||||||
pub struct DecipherV3 {
|
pub struct DecipherV3 {
|
||||||
@ -17,8 +18,8 @@ impl DecipherV3 {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(header: &Header, slot_key: &[u8]) -> Result<Self, KugouError> {
|
pub fn new(header: &Header) -> Result<Self, KugouError> {
|
||||||
let slot_key = Self::hash_key(slot_key);
|
let slot_key = Self::hash_key(get_slot_key(header)?);
|
||||||
|
|
||||||
let mut file_key = [0x6b; 17];
|
let mut file_key = [0x6b; 17];
|
||||||
file_key[..16].copy_from_slice(&Self::hash_key(header.file_key));
|
file_key[..16].copy_from_slice(&Self::hash_key(header.file_key));
|
||||||
|
Loading…
Reference in New Issue
Block a user