From be4e3df01b6eac7947912762af31fcaeda335b0d Mon Sep 17 00:00:00 2001 From: philsmd Date: Tue, 8 Sep 2020 10:39:21 +0200 Subject: [PATCH] UnRAR: Allow using key and IV instead of password --- deps/unrar/crypt.cpp | 5 +++++ deps/unrar/crypt.hpp | 1 + deps/unrar/rdwrfn.cpp | 7 +++++++ deps/unrar/rdwrfn.hpp | 1 + 4 files changed, 14 insertions(+) diff --git a/deps/unrar/crypt.cpp b/deps/unrar/crypt.cpp index fc2126d46..378ffff6b 100644 --- a/deps/unrar/crypt.cpp +++ b/deps/unrar/crypt.cpp @@ -91,6 +91,11 @@ bool CryptData::SetCryptKeys(bool Encrypt,CRYPT_METHOD Method, return true; } +void CryptData::SetRijndalDecryptKey(byte *Key,byte *InitV) +{ + CryptData::Method=CRYPT_RAR30; + rin.Init(false,Key,128,InitV); +} // Use the current system time to additionally randomize data. static void TimeRandomize(byte *RndBuf,size_t BufSize) diff --git a/deps/unrar/crypt.hpp b/deps/unrar/crypt.hpp index f6382ef50..ebbad96ed 100644 --- a/deps/unrar/crypt.hpp +++ b/deps/unrar/crypt.hpp @@ -81,6 +81,7 @@ class CryptData bool SetCryptKeys(bool Encrypt,CRYPT_METHOD Method,SecPassword *Password, const byte *Salt,const byte *InitV,uint Lg2Cnt, byte *HashKey,byte *PswCheck); + void SetRijndalDecryptKey(byte *Key,byte *InitV); void SetAV15Encryption(); void SetCmt13Encryption(); void EncryptBlock(byte *Buf,size_t Size); diff --git a/deps/unrar/rdwrfn.cpp b/deps/unrar/rdwrfn.cpp index 66a68fc74..a1e9d832c 100644 --- a/deps/unrar/rdwrfn.cpp +++ b/deps/unrar/rdwrfn.cpp @@ -292,6 +292,13 @@ void ComprDataIO::SetEncryption(bool Encrypt,CRYPT_METHOD Method, #endif } +void ComprDataIO::InitRijindal(byte *Key,byte *InitV) +{ +#ifndef RAR_NOCRYPT + Decryption=true; + Decrypt->SetRijndalDecryptKey(Key,InitV); +#endif +} #if !defined(SFX_MODULE) && !defined(RAR_NOCRYPT) void ComprDataIO::SetAV15Encryption() diff --git a/deps/unrar/rdwrfn.hpp b/deps/unrar/rdwrfn.hpp index fc38fd309..7355d3b92 100644 --- a/deps/unrar/rdwrfn.hpp +++ b/deps/unrar/rdwrfn.hpp @@ -70,6 +70,7 @@ class ComprDataIO void SetSubHeader(FileHeader *hd,int64 *Pos) {SubHead=hd;SubHeadPos=Pos;} void SetEncryption(bool Encrypt,CRYPT_METHOD Method,SecPassword *Password, const byte *Salt,const byte *InitV,uint Lg2Cnt,byte *HashKey,byte *PswCheck); + void InitRijindal(byte *Key,byte *InitV); void SetAV15Encryption(); void SetCmt13Encryption(); void SetUnpackToMemory(byte *Addr,uint Size);