I'm testing Triple DES encryption speeds with the OpenSSL library on Linux
on my machine.

With dynamic linking, I get about 16 Mbytes per second whereas with static
linking, I get only about 5 Mbytes per second. For compiling, I used:

DYNAMIC: gcc testdes.c -o testdes-dyn -lcrypto
STATIC:  gcc testdes.c -o testdes-sta -lcrypto -static

GCC is version 2.96 on Redhat 7.3. I have also tried gcc 3.2.2 on Redhat 9
with the same results.

Why is this so? Please find below the code I used for the test (testdes.c).

Regards,
Ujval Lodha

========= testdes.c =========

#include <openssl/des.h>
#include <sys/time.h>
#include <stdio.h>

#define BUF_SIZE (1<<20)
int main(int c, char *v[])
{
  des_cblock pass1, pass2;
  des_key_schedule ks1, ks2;
  int i = 0;

  char buffer[BUF_SIZE], outBuffer[BUF_SIZE];

  int chunksProcessed =  0;
  struct timeval tv1, tv2;
  struct timezone tz;
  int timesRun = 100;
  long long bytesDone;
  long long msTaken;
  long long bytesPerSecond;

  memcpy((char*)pass1,"12345678", 8);
  memcpy((char*)pass2,"87654321", 8);
  des_set_key ((des_cblock *) (&pass1), ks1);
  des_set_key ((des_cblock *) (&pass2), ks2);

  gettimeofday(&tv1, &tz);

  for (i=0; i<timesRun; i++)
  {
    int pos = 0;
    while(pos+8<=BUF_SIZE)
    {
      des_ecb2_encrypt((des_cblock*)&buffer[pos],
(des_cblock*)&outBuffer[pos], ks1, ks2, DES_ENCRYPT);
      pos += 8;
      chunksProcessed++;
    }
  }

  gettimeofday(&tv2, &tz);

  bytesDone = BUF_SIZE;
  bytesDone *= timesRun;
  msTaken = (tv2.tv_usec - tv1.tv_usec)/1000 + (tv2.tv_sec * 1000 -
tv1.tv_sec * 1000);
  bytesPerSecond = (bytesDone * 1000)/ msTaken;
  printf("%lld MB done in %lld ms\n", (bytesDone >> 20), msTaken);
  printf("%lld MB per second\n", (bytesPerSecond>>20));
  printf("%d chunks were processed\n", chunksProcessed);
}
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to