- Add OPTIONS OPENSSL_AES: use OpenSSL implementation of AES instead of bundled

one to speed up extraction of encrypted archives
- Bump PORTREVISION for package change

PR:		ports/166968 (based on)
Submitted by:	naddy
This commit is contained in:
Sunpoet Po-Chuan Hsieh 2012-04-24 16:31:16 +00:00
parent aa9bd333e8
commit 35c49f6c73
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=295411
4 changed files with 127 additions and 1 deletions

View File

@ -7,7 +7,7 @@
PORTNAME= unrar
PORTVERSION= 4.10
PORTREVISION= 1
PORTREVISION= 2
PORTEPOCH= 5
CATEGORIES+= archivers
MASTER_SITES= http://www.rarlab.com/rar/ \
@ -17,6 +17,8 @@ DISTNAME= unrarsrc-4.1.4
MAINTAINER?= sunpoet@FreeBSD.org
COMMENT= Extract, view & test RAR archives
OPTIONS= OPENSSL_AES "Use OpenSSL implementation of AES" on
CONFLICTS?= zh-unrar-[0-9].* unrar-iconv-[0-9].*
MAKEFILE= makefile.unix
@ -26,6 +28,14 @@ WRKSRC= ${WRKDIR}/${PORTNAME}
PLIST_FILES= bin/unrar
PORTDOCS= license.txt readme.txt
.include <bsd.port.options.mk>
.if !defined(WITHOUT_OPENSSL_AES)
CPPFLAGS+= -DOPENSSL_AES -I${OPENSSLINC}
LDFLAGS+= -L${OPENSSLLIB} -lcrypto
USE_OPENSSL= yes
.endif
post-patch:
@${REINPLACE_CMD} -e '/^CXX/ s|^|#|' ${WRKSRC}/${MAKEFILE}

View File

@ -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_AES
+#include <openssl/evp.h>
+#endif
+
#ifdef S_IFLNK
#define SAVE_LINKS
#endif

View File

@ -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_AES
+
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_AES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// API
@@ -61,13 +64,21 @@ inline void Copy128(byte *dest,const byt
Rijndael::Rijndael()
{
+#ifndef OPENSSL_AES
if (S[0]==0)
GenerateTables();
+#endif
}
void Rijndael::init(Direction dir,const byte * key,byte * initVector)
{
+#ifdef OPENSSL_AES
+ 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_AES
}
@@ -91,6 +103,11 @@ size_t Rijndael::blockDecrypt(const byte
if (input == 0 || inputLen <= 0)
return 0;
+#ifdef OPENSSL_AES
+ 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_AES
}
+#ifndef OPENSSL_AES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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_AES

View File

@ -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_AES
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_AES
+ 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);