Back to index

opendkim  2.6.4
Defines | Functions | Variables
t-verifyperf.c File Reference
#include "build-config.h"
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sysexits.h>
#include "../dkim.h"
#include "../dkim-tables.h"
#include "t-testdata.h"

Go to the source code of this file.

Defines

#define DEFMSGSIZE   1024
#define DEFTESTINT   5
#define BODYBUFRSZ   8192
#define MAXHEADER   4096
#define MIN(x, y)   ((x) < (y) ? (x) : (y))

Functions

dkim_canon_t canon_code (char *name)
char * canon_name (dkim_canon_t code)
dkim_alg_t alg_code (char *name)
char * alg_name (dkim_alg_t code)
int usage (void)
int main (int argc, char **argv)

Variables

static char t_verifyperf_c_id [] = "@(#)$Id: t-verifyperf.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $"
char * progname

Define Documentation

#define BODYBUFRSZ   8192

Definition at line 34 of file t-verifyperf.c.

#define DEFMSGSIZE   1024

Definition at line 32 of file t-verifyperf.c.

#define DEFTESTINT   5

Definition at line 33 of file t-verifyperf.c.

#define MAXHEADER   4096

Definition at line 35 of file t-verifyperf.c.

#define MIN (   x,
 
)    ((x) < (y) ? (x) : (y))

Definition at line 38 of file t-verifyperf.c.


Function Documentation

dkim_alg_t alg_code ( char *  name)

Definition at line 104 of file t-verifyperf.c.

{
       if (name == NULL)
              return (dkim_alg_t) DKIM_SIGN_UNKNOWN;
       else if (strcasecmp(name, "rsa-sha1") == 0)
              return (dkim_alg_t) DKIM_SIGN_RSASHA1;
       else if (strcasecmp(name, "rsa-sha256") == 0)
              return (dkim_alg_t) DKIM_SIGN_RSASHA256;
       else
              return (dkim_alg_t) DKIM_SIGN_UNKNOWN;
}
char* alg_name ( dkim_alg_t  code)

Definition at line 127 of file t-verifyperf.c.

{
       switch (code)
       {
         case DKIM_SIGN_DEFAULT:
              return "default";

         case DKIM_SIGN_RSASHA1:
              return "rsa-sha1";

         case DKIM_SIGN_RSASHA256:
              return "rsa-sha256";

         case DKIM_SIGN_UNKNOWN:
         default:
              return "unknown";
       }
}
dkim_canon_t canon_code ( char *  name)

Definition at line 54 of file t-verifyperf.c.

{
       if (name == NULL)
              return (dkim_canon_t) DKIM_CANON_UNKNOWN;
       else if (strcasecmp(name, "simple") == 0)
              return (dkim_canon_t) DKIM_CANON_SIMPLE;
       else if (strcasecmp(name, "relaxed") == 0)
              return (dkim_canon_t) DKIM_CANON_RELAXED;
       else
              return (dkim_canon_t) DKIM_CANON_UNKNOWN;
}
char* canon_name ( dkim_canon_t  code)

Definition at line 77 of file t-verifyperf.c.

{
       switch (code)
       {
         case DKIM_CANON_SIMPLE:
              return "simple";

         case DKIM_CANON_RELAXED:
              return "relaxed";

         case DKIM_CANON_UNKNOWN:
         default:
              return "unknown";
       }
}
int main ( int  argc,
char **  argv 
)

Definition at line 181 of file t-verifyperf.c.

{
       DKIM_STAT status;
       u_int verifycnt = 0;
       int c;
       int w;
       int rate;
       size_t msgsize = DEFMSGSIZE;
       size_t msgrem;
       size_t wsz;
       time_t start = DEFTESTINT;
       time_t testint = DEFTESTINT;
       dkim_canon_t hcanon = DKIM_CANON_RELAXED;
       dkim_canon_t bcanon = DKIM_CANON_SIMPLE;
       dkim_alg_t signalg = DKIM_SIGN_UNKNOWN;
       dkim_query_t qtype = DKIM_QUERY_FILE;
       char *p;
       DKIM *dkim;
       DKIM_LIB *lib;
       dkim_sigkey_t key;
       unsigned char hdr[MAXHEADER + 1];
       unsigned char body[BODYBUFRSZ];

       progname = (p = strrchr(argv[0], '/')) == NULL ? argv[0] : p + 1;

       while ((c = getopt(argc, argv, "b:h:m:s:t:")) != -1)
       {
              switch (c)
              {
                case 'b':
                     bcanon = canon_code(optarg);
                     if (bcanon == (dkim_canon_t) -1)
                     {
                            fprintf(stderr,
                                    "%s: unknown canonicalization '%s'\n",
                                    progname, optarg);
                            return EX_USAGE;
                     }
                     break;

                case 'h':
                     hcanon = canon_code(optarg);
                     if (hcanon == (dkim_canon_t) -1)
                     {
                            fprintf(stderr,
                                    "%s: unknown canonicalization '%s'\n",
                                    progname, optarg);
                            return EX_USAGE;
                     }
                     break;

                case 'm':
                     msgsize = strtoul(optarg, &p, 10);
                     if (*p != '\0')
                     {
                            fprintf(stderr, "%s: invalid size '%s'\n",
                                    progname, optarg);
                            return EX_USAGE;
                     }
                     break;

                case 's':
                     signalg = alg_code(optarg);
                     if (signalg == (dkim_alg_t) -1)
                     {
                            fprintf(stderr,
                                    "%s: unknown signing algorithm '%s'\n",
                                    progname, optarg);
                            return EX_USAGE;
                     }
                     break;

                case 't':
                     testint = strtoul(optarg, &p, 10);
                     if (*p != '\0')
                     {
                            fprintf(stderr, "%s: invalid seconds '%s'\n",
                                    progname, optarg);
                            return EX_USAGE;
                     }
                     break;

                default:
                     return usage();
              }
       }

#ifdef USE_GNUTLS
       (void) gnutls_global_init();
#endif /* USE_GNUTLS */

       /* instantiate the library */
       lib = dkim_init(NULL, NULL);

       if (signalg == DKIM_SIGN_UNKNOWN)
       {
              if (dkim_libfeature(lib, DKIM_FEATURE_SHA256))
                     signalg = DKIM_SIGN_RSASHA256;
              else
                     signalg = DKIM_SIGN_RSASHA1;
       }
       else if (signalg == DKIM_SIGN_RSASHA256 &&
                !dkim_libfeature(lib, DKIM_FEATURE_SHA256))
       {
              fprintf(stdout,
                      "### requested signing algorithm not available\n");
              dkim_close(lib);
              return 1;
       }

       fprintf(stdout,
               "*** VERIFYING SPEED TEST: %s/%s with %s, size %u for %lds\n",
               canon_name(hcanon), canon_name(bcanon), alg_name(signalg),
               msgsize, (long) testint);

       key = KEY;

       (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
                           &qtype, sizeof qtype);
       (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
                           KEYFILE, strlen(KEYFILE));

       srandom(time(NULL));

       /* prepare a random body buffer */
       for (c = 0, w = 0; c < sizeof body; c++)
       {
              if (w >= 75 && c < sizeof body - 2)
              {
                     body[c++] = '\r';
                     body[c++] = '\n';
                     w = 0;
              }

              body[c++] = (random() + 32) % 127;
              w++;
       }

       /* generate the signature */
       dkim = dkim_sign(lib, JOBID, NULL, key, SELECTOR, DOMAIN,
                        hcanon, bcanon, signalg, -1L, &status);

       status = dkim_header(dkim, HEADER02, strlen(HEADER02));

       status = dkim_header(dkim, HEADER03, strlen(HEADER03));

       status = dkim_header(dkim, HEADER04, strlen(HEADER04));

       status = dkim_header(dkim, HEADER05, strlen(HEADER05));

       status = dkim_header(dkim, HEADER06, strlen(HEADER06));

       status = dkim_header(dkim, HEADER07, strlen(HEADER07));

       status = dkim_header(dkim, HEADER08, strlen(HEADER08));

       status = dkim_header(dkim, HEADER09, strlen(HEADER09));

       status = dkim_eoh(dkim);

       msgrem = msgsize;

       while (msgrem > 0)
       {
              wsz = MIN(msgrem, sizeof body);

              status = dkim_body(dkim, body, wsz);

              msgrem -= wsz;
       }

       status = dkim_eom(dkim, NULL);

       memset(hdr, '\0', sizeof hdr);
       snprintf(hdr, sizeof hdr, "%s: ", DKIM_SIGNHEADER);
       status = dkim_getsighdr(dkim, hdr + strlen(hdr),
                               sizeof hdr - strlen(hdr),
                               strlen(hdr) + 1);

       status = dkim_free(dkim);

       (void) time(&start);

       /* begin the verify loop */
       while (time(NULL) < start + testint)
       {
              dkim = dkim_verify(lib, JOBID, NULL, &status);

              status = dkim_header(dkim, hdr, strlen(hdr));

              status = dkim_header(dkim, HEADER02, strlen(HEADER02));

              status = dkim_header(dkim, HEADER03, strlen(HEADER03));

              status = dkim_header(dkim, HEADER04, strlen(HEADER04));

              status = dkim_header(dkim, HEADER05, strlen(HEADER05));

              status = dkim_header(dkim, HEADER06, strlen(HEADER06));

              status = dkim_header(dkim, HEADER07, strlen(HEADER07));

              status = dkim_header(dkim, HEADER08, strlen(HEADER08));

              status = dkim_header(dkim, HEADER09, strlen(HEADER09));

              status = dkim_eoh(dkim);

              msgrem = DEFMSGSIZE;

              while (msgrem > 0)
              {
                     wsz = MIN(msgrem, sizeof body);

                     status = dkim_body(dkim, body, wsz);

                     msgrem -= wsz;
              }

              status = dkim_eom(dkim, NULL);

              status = dkim_free(dkim);

              verifycnt++;
       }

       dkim_close(lib);

       rate = verifycnt / testint;

       fprintf(stdout, "*** %u messages verified (%d msgs/sec)\n",
               verifycnt, rate);

       return 0;
}

Here is the call graph for this function:

int usage ( void  )

Definition at line 157 of file t-verifyperf.c.

{
       fprintf(stderr, "%s: usage: %s [options]\n"
               "\t-b bodycanon\tbody canonicalization to use\n"
               "\t-h hdrcanon \theader canonicalization to use\n"
               "\t-m bytes    \tmessage size in bytes\n"
               "\t-s signalg  \tsigning algorithm to use\n"
               "\t-t seconds  \ttest time in seconds\n",
               progname, progname);

       return EX_USAGE;
}

Variable Documentation

char* progname

Definition at line 41 of file t-verifyperf.c.

char t_verifyperf_c_id[] = "@(#)$Id: t-verifyperf.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $" [static]

Definition at line 9 of file t-verifyperf.c.