Date: Sun, 15 Apr 2012 17:47:54 +0200 (CEST) From: Christian Weisgerber <naddy@FreeBSD.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: ports/166968: archivers/unrar: speed up decryption Message-ID: <201204151547.q3FFlsoq049151@lorvorc.mips.inka.de> Resent-Message-ID: <201204151630.q3FGUBSo036090@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 166968 >Category: ports >Synopsis: archivers/unrar: speed up decryption >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Apr 15 16:30:11 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Christian Weisgerber >Release: FreeBSD 7.4-STABLE amd64 >Organization: >Environment: System: FreeBSD lorvorc.mips.inka.de 7.4-STABLE FreeBSD 7.4-STABLE #0: Sat Apr 14 12:42:37 CEST 2012 naddy@lorvorc.mips.inka.de:/usr/obj/usr/src/sys/GENERIC amd64 >Description: Use OpenSSL instead of the included AES code to speed up extraction of encrypted archives. >How-To-Repeat: >Fix: Index: Makefile =================================================================== RCS file: /home/pcvs/ports/archivers/unrar/Makefile,v retrieving revision 1.74 diff -u -r1.74 Makefile --- Makefile 19 Feb 2012 06:05:10 -0000 1.74 +++ Makefile 15 Apr 2012 15:45:41 -0000 @@ -7,7 +7,7 @@ PORTNAME= unrar PORTVERSION= 4.10 -PORTREVISION= 1 +PORTREVISION= 2 PORTEPOCH= 5 CATEGORIES+= archivers MASTER_SITES= http://www.rarlab.com/rar/ \ Index: files/patch-makefile.unix =================================================================== RCS file: files/patch-makefile.unix diff -N files/patch-makefile.unix --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ files/patch-makefile.unix 15 Apr 2012 15:45:41 -0000 @@ -0,0 +1,14 @@ +--- makefile.unix.orig 2012-04-05 23:34:11.000000000 +0200 ++++ makefile.unix 2012-04-05 23:34:26.000000000 +0200 +@@ -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 Index: files/patch-os.hpp =================================================================== RCS file: files/patch-os.hpp diff -N files/patch-os.hpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ files/patch-os.hpp 15 Apr 2012 15:45:41 -0000 @@ -0,0 +1,13 @@ +--- os.hpp.orig 2012-04-05 22:20:56.000000000 +0200 ++++ os.hpp 2012-04-05 22:21:36.000000000 +0200 +@@ -193,6 +193,10 @@ + #include <utime.h> + #include <locale.h> + ++#ifdef OPENSSL ++#include <openssl/evp.h> ++#endif ++ + #ifdef S_IFLNK + #define SAVE_LINKS + #endif Index: files/patch-rijndael.cpp =================================================================== RCS file: files/patch-rijndael.cpp diff -N files/patch-rijndael.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ files/patch-rijndael.cpp 15 Apr 2012 15:45:41 -0000 @@ -0,0 +1,79 @@ +--- rijndael.cpp.orig 2012-01-09 14:46:08.000000000 +0100 ++++ rijndael.cpp 2012-04-05 23:36:23.000000000 +0200 +@@ -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 byt + #endif + } + ++#endif // OPENSSL + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // API +@@ -61,13 +64,21 @@ inline void Copy128(byte *dest,const byt + + 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 + + if(m_direction == Decrypt) + keyEncToDec(); ++#endif // OPENSSL + } + + +@@ -91,6 +103,11 @@ size_t Rijndael::blockDecrypt(const byte + 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 + 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 Index: files/patch-rijndael.hpp =================================================================== RCS file: files/patch-rijndael.hpp diff -N files/patch-rijndael.hpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ files/patch-rijndael.hpp 15 Apr 2012 15:45:41 -0000 @@ -0,0 +1,24 @@ +--- rijndael.hpp.orig 2012-01-09 14:46:08.000000000 +0100 ++++ rijndael.hpp 2012-04-05 22:42:56.000000000 +0200 +@@ -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); >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204151547.q3FFlsoq049151>