Use OpenSSL instead of the included AES code to speed up extraction

of encrypted archives.
This commit is contained in:
naddy 2012-04-08 16:36:12 +00:00
parent f74f7f564c
commit 5b8d075767
5 changed files with 142 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.54 2012/04/08 11:30:25 naddy Exp $
# $OpenBSD: Makefile,v 1.55 2012/04/08 16:36:12 naddy Exp $
COMMENT= extract, list, and test RAR archives
@ -11,7 +11,7 @@ COMMENT= extract, list, and test RAR archives
PKGNAME= unrar-4.00
EPOCH= 1
REVISION= 0
REVISION= 1
DISTNAME= unrarsrc-4.0.7
CATEGORIES= archivers
@ -25,7 +25,7 @@ PERMIT_PACKAGE_FTP= Yes
PERMIT_DISTFILES_CDROM= Yes
PERMIT_DISTFILES_FTP= Yes
WANTLIB= c m stdc++
WANTLIB= c crypto m stdc++
MASTER_SITES= ${HOMEPAGE}rar/

View File

@ -1,12 +1,24 @@
$OpenBSD: patch-makefile_unix,v 1.13 2011/03/18 20:14:58 naddy Exp $
--- makefile.unix.orig Wed Mar 9 17:40:47 2011
+++ makefile.unix Wed Mar 9 17:41:01 2011
@@ -107,6 +107,8 @@ OBJECTS=rar.o strlist.o strfn.o pathfn.o savepos.o sma
$OpenBSD: patch-makefile_unix,v 1.14 2012/04/08 16:36:12 naddy Exp $
--- makefile.unix.orig Tue Mar 30 17:26:26 2010
+++ makefile.unix Fri Apr 6 00:30:46 2012
@@ -8,9 +8,10 @@
# Linux using GCC
#CXX=g++
#CXXFLAGS=-O2
-DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
+DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DOPENSSL
STRIP=strip
DESTDIR=/usr
+LIBS=-lcrypto
# Linux using LCC
#CXX=lcc
@@ -106,6 +107,8 @@ OBJECTS=rar.o strlist.o strfn.o pathfn.o savepos.o sma
archive.o arcread.o unicode.o system.o isnt.o crypt.o crc.o rawread.o encname.o \
resource.o match.o timefn.o rdwrfn.o consio.o options.o ulinks.o errhnd.o rarvm.o \
rijndael.o getbits.o sha1.o extinfo.o extract.o volume.o list.o find.o unpack.o cmddata.o
+.SUFFIXES: .cpp
+
+.SUFFIXES: .cpp
.cpp.o:
$(COMPILE) -D$(WHAT) -c $<

View File

@ -1,7 +1,18 @@
$OpenBSD: patch-os_hpp,v 1.6 2010/12/30 07:51:31 benoit Exp $
--- os.hpp.orig Fri Nov 26 08:20:01 2010
+++ os.hpp Mon Dec 6 07:49:22 2010
@@ -262,12 +262,12 @@
$OpenBSD: patch-os_hpp,v 1.7 2012/04/08 16:36:12 naddy Exp $
--- os.hpp.orig Wed Mar 2 08:43:12 2011
+++ os.hpp Fri Apr 6 00:30:19 2012
@@ -192,6 +192,10 @@
#include <utime.h>
#include <locale.h>
+#ifdef OPENSSL
+#include <openssl/evp.h>
+#endif
+
#ifdef S_IFLNK
#define SAVE_LINKS
#endif
@@ -262,12 +266,12 @@
#endif
#endif

View File

@ -0,0 +1,80 @@
$OpenBSD: patch-rijndael_cpp,v 1.1 2012/04/08 16:36:12 naddy Exp $
--- rijndael.cpp.orig Wed Mar 2 08:43:12 2011
+++ rijndael.cpp Fri Apr 6 00:32:04 2012
@@ -7,6 +7,8 @@
**************************************************************************/
#include "rar.hpp"
+#ifndef OPENSSL
+
const int uKeyLenInBytes=16, m_uRounds=10;
static byte S[256],S5[256],rcon[30];
@@ -54,6 +56,7 @@ inline void Copy128(byte *dest,const byte *src)
#endif
}
+#endif // OPENSSL
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// API
@@ -61,13 +64,21 @@ inline void Copy128(byte *dest,const byte *src)
Rijndael::Rijndael()
{
+#ifndef OPENSSL
if (S[0]==0)
GenerateTables();
+#endif
}
void Rijndael::init(Direction dir,const byte * key,byte * initVector)
{
+#ifdef OPENSSL
+ EVP_CIPHER_CTX_init(&ctx);
+ EVP_CipherInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key, initVector,
+ dir == Decrypt ? 0 : 1);
+ EVP_CIPHER_CTX_set_padding(&ctx, 0);
+#else
m_direction = dir;
byte keyMatrix[_MAX_KEY_COLUMNS][4];
@@ -82,6 +93,7 @@ void Rijndael::init(Direction dir,const byte * key,byt
if(m_direction == Decrypt)
keyEncToDec();
+#endif // OPENSSL
}
@@ -91,6 +103,11 @@ size_t Rijndael::blockDecrypt(const byte *input, size_
if (input == 0 || inputLen <= 0)
return 0;
+#ifdef OPENSSL
+ int outLen;
+ EVP_CipherUpdate(&ctx, outBuffer, &outLen, input, inputLen);
+ return outLen;
+#else
byte block[16], iv[4][4];
memcpy(iv,m_initVector,16);
@@ -113,9 +130,11 @@ size_t Rijndael::blockDecrypt(const byte *input, size_
memcpy(m_initVector,iv,16);
return 16*numBlocks;
+#endif // OPENSSL
}
+#ifndef OPENSSL
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ALGORITHM
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -296,3 +315,5 @@ void Rijndael::GenerateTables()
U1[b][0]=U2[b][1]=U3[b][2]=U4[b][3]=T5[i][0]=T6[i][1]=T7[i][2]=T8[i][3]=FFmul0e(b);
}
}
+
+#endif // OPENSSL

View File

@ -0,0 +1,25 @@
$OpenBSD: patch-rijndael_hpp,v 1.1 2012/04/08 16:36:12 naddy Exp $
--- rijndael.hpp.orig Wed Mar 2 08:43:13 2011
+++ rijndael.hpp Fri Apr 6 00:32:04 2012
@@ -18,15 +18,21 @@ class Rijndael
public:
enum Direction { Encrypt , Decrypt };
private:
+#ifndef OPENSSL
void keySched(byte key[_MAX_KEY_COLUMNS][4]);
void keyEncToDec();
void encrypt(const byte a[16], byte b[16]);
void decrypt(const byte a[16], byte b[16]);
void GenerateTables();
+#endif
+#ifdef OPENSSL
+ EVP_CIPHER_CTX ctx;
+#else
Direction m_direction;
byte m_initVector[MAX_IV_SIZE];
byte m_expandedKey[_MAX_ROUNDS+1][4][4];
+#endif
public:
Rijndael();
void init(Direction dir,const byte *key,byte *initVector);