Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
rsaperf.c File Reference
#include "seccomon.h"
#include "cert.h"
#include "secutil.h"
#include "nspr.h"
#include "nss.h"
#include "blapi.h"
#include "plgetopt.h"
#include "lowkeyi.h"
#include "pk11pub.h"

Go to the source code of this file.

Classes

struct  TimingContextStr
struct  PK11Keys
struct  ThreadRunDataStr

Defines

#define DEFAULT_ITERS   10
#define DEFAULT_DURATION   10
#define DEFAULT_KEY_BITS   1024
#define MIN_KEY_BITS   512
#define MAX_KEY_BITS   65536
#define BUFFER_BYTES   MAX_KEY_BITS / 8
#define DEFAULT_THREADS   1
#define DEFAULT_EXPONENT   0x10001
#define INT_ARG(arg, def)   atol(arg)>0?atol(arg):def

Typedefs

typedef struct TimingContextStr
typedef SECStatus(* RSAOp )(void *key, unsigned char *output, unsigned char *input)
typedef struct ThreadRunDataStr

Functions

NSSLOWKEYPrivateKey * getDefaultRSAPrivateKey (void)
NSSLOWKEYPublicKey * getDefaultRSAPublicKey (void)
TimingContext * CreateTimingContext (void)
void DestroyTimingContext (TimingContext *ctx)
void TimingBegin (TimingContext *ctx, PRTime begin)
static void timingUpdate (TimingContext *ctx)
void TimingEnd (TimingContext *ctx, PRTime end)
void TimingDivide (TimingContext *ctx, int divisor)
char * TimingGenerateString (TimingContext *ctx)
void Usage (char *progName)
static void dumpBytes (unsigned char *b, int l)
static void dumpItem (SECItem *item, const char *description)
void printPrivKey (NSSLOWKEYPrivateKey *privKey)
SECStatus PK11_PublicKeyOp (SECKEYPublicKey *key, unsigned char *output, unsigned char *input)
SECStatus PK11_PrivateKeyOp (PK11Keys *keys, unsigned char *output, unsigned char *input)
void ThreadExecFunction (void *data)
int main (int argc, char **argv)
 The Xalan testcases app.

Variables

secuPWData pwData = { PW_NONE, NULL }

Class Documentation

struct TimingContextStr

Definition at line 64 of file rsaperf.c.

Collaboration diagram for TimingContextStr:
Class Members
long days
PRTime end
timetype end
int hours
PRTime interval
timetype interval
int millisecs
int minutes
int seconds
PRTime start
timetype start
struct PK11Keys

Definition at line 238 of file rsaperf.c.

Class Members
SECKEYPrivateKey * privKey
SECKEYPublicKey * pubKey
struct ThreadRunDataStr

Definition at line 264 of file rsaperf.c.

Collaboration diagram for ThreadRunDataStr:
Class Members
const unsigned char * buf
const PRBool * doIters
PRErrorCode errNum
RSAOp fn
long iterRes
long iters
const void * rsaKey
int seconds
SECStatus status

Define Documentation

Definition at line 53 of file rsaperf.c.

Definition at line 49 of file rsaperf.c.

#define DEFAULT_EXPONENT   0x10001

Definition at line 55 of file rsaperf.c.

Definition at line 48 of file rsaperf.c.

Definition at line 50 of file rsaperf.c.

Definition at line 54 of file rsaperf.c.

#define INT_ARG (   arg,
  def 
)    atol(arg)>0?atol(arg):def

Definition at line 313 of file rsaperf.c.

#define MAX_KEY_BITS   65536

Definition at line 52 of file rsaperf.c.

#define MIN_KEY_BITS   512

Definition at line 51 of file rsaperf.c.


Typedef Documentation

typedef SECStatus(* RSAOp)(void *key, unsigned char *output, unsigned char *input)

Definition at line 234 of file rsaperf.c.

typedef struct ThreadRunDataStr

Definition at line 262 of file rsaperf.c.

typedef struct TimingContextStr

Definition at line 62 of file rsaperf.c.


Function Documentation

TimingContext* CreateTimingContext ( void  )

Definition at line 76 of file rsaperf.c.

                                         {
    return PORT_Alloc(sizeof(TimingContext));
}

Here is the call graph for this function:

void DestroyTimingContext ( TimingContext *  ctx)

Definition at line 80 of file rsaperf.c.

                                              {
    PORT_Free(ctx);
}

Here is the call graph for this function:

static void dumpBytes ( unsigned char *  b,
int  l 
) [static]

Definition at line 190 of file rsaperf.c.

{
    int i;
    if (l <= 0)
        return;
    for (i = 0; i < l; ++i) {
        if (i % 16 == 0)
            printf("\t");
        printf(" %02x", b[i]);
        if (i % 16 == 15)
            printf("\n");
    }
    if ((i % 16) != 0)
        printf("\n");
}

Here is the caller graph for this function:

static void dumpItem ( SECItem *  item,
const char *  description 
) [static]

Definition at line 207 of file rsaperf.c.

{
    if (item->len & 1 && item->data[0] == 0) {
       printf("%s: (%d bytes)\n", description, item->len - 1);
       dumpBytes(item->data + 1, item->len - 1);
    } else {
       printf("%s: (%d bytes)\n", description, item->len);
       dumpBytes(item->data, item->len);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSSLOWKEYPrivateKey* getDefaultRSAPrivateKey ( void  )

Definition at line 110 of file defkey.c.

{
    if (rsaPriv.keyType != NSSLOWKEYRSAKey) {

       /* leaving arena uninitialized. It isn't used in this test. */

       rsaPriv.keyType                     = NSSLOWKEYRSAKey;

       /* leaving arena   uninitialized. It isn't used. */
       /* leaving version uninitialized. It isn't used. */

       rsaPriv.u.rsa.modulus.data          =        default_n;
       rsaPriv.u.rsa.modulus.len           = sizeof default_n;
       rsaPriv.u.rsa.publicExponent.data   =        default_e;
       rsaPriv.u.rsa.publicExponent.len    = sizeof default_e;
       rsaPriv.u.rsa.privateExponent.data  =        default_d;
       rsaPriv.u.rsa.privateExponent.len   = sizeof default_d;
       rsaPriv.u.rsa.prime1.data           =        default_p;
       rsaPriv.u.rsa.prime1.len            = sizeof default_p;
       rsaPriv.u.rsa.prime2.data           =        default_q;
       rsaPriv.u.rsa.prime2.len            = sizeof default_q;
       rsaPriv.u.rsa.exponent1.data        =        default_dModP;
       rsaPriv.u.rsa.exponent1.len         = sizeof default_dModP;
       rsaPriv.u.rsa.exponent2.data        =        default_dModQ;
       rsaPriv.u.rsa.exponent2.len         = sizeof default_dModQ;
       rsaPriv.u.rsa.coefficient.data      =        default_qInvModP;
       rsaPriv.u.rsa.coefficient.len       = sizeof default_qInvModP;
    }
    return &rsaPriv;
}

Here is the caller graph for this function:

NSSLOWKEYPublicKey* getDefaultRSAPublicKey ( void  )

Definition at line 144 of file defkey.c.

{
    if (rsaPub.keyType != NSSLOWKEYRSAKey) {

       rsaPub.keyType                        = NSSLOWKEYRSAKey;

       rsaPub.u.rsa.modulus.data          =        default_n;
       rsaPub.u.rsa.modulus.len           = sizeof default_n;

       rsaPub.u.rsa.publicExponent.data   =        default_e;
       rsaPub.u.rsa.publicExponent.len    = sizeof default_e;
    }
    return &rsaPub;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 316 of file rsaperf.c.

{
    TimingContext *    timeCtx       = NULL;
    SECKEYPublicKey *         pubHighKey    = NULL;
    SECKEYPrivateKey *    privHighKey   = NULL;
    NSSLOWKEYPrivateKey * privKey       = NULL;
    NSSLOWKEYPublicKey *  pubKey        = NULL;
    CERTCertificate *         cert          = NULL;
    char *             progName      = NULL;
    char *             secDir      = NULL;
    char *             nickname    = NULL;
    char *                slotname      = NULL;
    char *                password      = NULL;
    long                  keybits     = 0;
    RSAOp                 fn;
    void *                rsaKey        = NULL;
    PLOptState *          optstate;
    PLOptStatus           optstatus;
    long               iters       = DEFAULT_ITERS;
    int                       i;
    PRBool             doPriv      = PR_FALSE;
    PRBool             doPub       = PR_FALSE;
    int                rv;
    unsigned char      buf[BUFFER_BYTES];
    unsigned char      buf2[BUFFER_BYTES];
    int                   seconds       = DEFAULT_DURATION;
    PRBool                doIters       = PR_FALSE;
    PRBool                doTime        = PR_FALSE;
    PRBool                useTokenKey   = PR_FALSE; /* use PKCS#11 token
                                                       object key */
    PRBool                useSessionKey = PR_FALSE; /* use PKCS#11 session
                                                       object key */
    PRBool                useBLKey = PR_FALSE;      /* use freebl */
    PK11SlotInfo*         slot          = NULL;     /* slot for session
                                                       object key operations */
    PRBool                doKeyGen      = PR_FALSE;
    int                   publicExponent  = DEFAULT_EXPONENT;
    PK11Keys keys;
    int peCount = 0;
    CK_BYTE pubEx[4];
    SECItem pe;
    RSAPublicKey          pubKeyStr;
    int                   threadNum     = DEFAULT_THREADS;
    ThreadRunData      ** runDataArr = NULL;
    PRThread           ** threadsArr = NULL;
    int                   calcThreads = 0;

    progName = strrchr(argv[0], '/');
    if (!progName)
       progName = strrchr(argv[0], '\\');
    progName = progName ? progName+1 : argv[0];

    optstate = PL_CreateOptState(argc, argv, "d:i:sen:p:t:h:k:w:gx:");
    while ((optstatus = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
       switch (optstate->option) {
       case '?':
           Usage(progName);
           break;
       case 'd':
           secDir = PORT_Strdup(optstate->value);
           break;
       case 'i':
           iters = INT_ARG(optstate->value, DEFAULT_ITERS);
           doIters = PR_TRUE;
           break;
       case 's':
           doPriv = PR_TRUE;
           break;
       case 'e':
           doPub = PR_TRUE;
           break;
       case 'g':
           doKeyGen = PR_TRUE;
           break;
       case 'n':
           nickname = PORT_Strdup(optstate->value);
            /* for compatibility, nickname of "none" means go to freebl */
            if (nickname && strcmp(nickname, "none")) {
               useTokenKey = PR_TRUE;
            } else {
                useBLKey = PR_TRUE;
            }
           break;
       case 'p':
           seconds = INT_ARG(optstate->value, DEFAULT_DURATION);
           doTime = PR_TRUE;
            break;
       case 'h':
           slotname = PORT_Strdup(optstate->value);
           useSessionKey = PR_TRUE;
           break;
       case 'k':
           keybits = INT_ARG(optstate->value, DEFAULT_KEY_BITS);
           break;
       case 'w':
           password = PORT_Strdup(optstate->value);
           pwData.data = password;
           pwData.source = PW_PLAINTEXT;
           break;
       case 'x':
           /*  -x public exponent (for RSA keygen)  */
           publicExponent = INT_ARG(optstate->value, DEFAULT_EXPONENT);
           break;
       case 't':
           threadNum = INT_ARG(optstate->value, DEFAULT_THREADS);
           break;
       }
    }
    if (optstatus == PL_OPT_BAD)
       Usage(progName);

    if ((doPriv && doPub) || (doIters && doTime) ||
        ((useTokenKey + useSessionKey + useBLKey) != PR_TRUE) ||
        (useTokenKey && keybits) || (useTokenKey && doKeyGen) ||
        (keybits && (keybits<MIN_KEY_BITS || keybits>MAX_KEY_BITS))) {
        Usage(progName);
    }

    if (!doPriv && !doPub) doPriv = PR_TRUE;

    if (doIters && doTime) Usage(progName);

    if (!doTime) {
        doIters = PR_TRUE;
    }

    PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);

    PK11_SetPasswordFunc(SECU_GetModulePassword);
    secDir = SECU_ConfigDirectory(secDir);

    if (useTokenKey || useSessionKey) {
       rv = NSS_Init(secDir);
       if (rv != SECSuccess) {
           fprintf(stderr, "NSS_Init failed.\n");
           exit(1);
       }
    } else {
       rv = NSS_NoDB_Init(NULL);
       if (rv != SECSuccess) {
           fprintf(stderr, "NSS_NoDB_Init failed.\n");
           exit(1);
       }
    }

    if (useTokenKey) {
        CK_OBJECT_HANDLE kh = CK_INVALID_HANDLE;
        CERTCertDBHandle* certdb = NULL;
       certdb = CERT_GetDefaultCertDB();
        
        cert = PK11_FindCertFromNickname(nickname, &pwData);
        if (cert == NULL) {
            fprintf(stderr,
                    "Can't find certificate by name \"%s\"\n", nickname);
            exit(1);
        }
        pubHighKey = CERT_ExtractPublicKey(cert);
        if (pubHighKey == NULL) {
            fprintf(stderr, "Can't extract public key from certificate");
            exit(1);
        }

        if (doPub) {
            /* do public key ops */
            fn = (RSAOp)PK11_PublicKeyOp;
            rsaKey = (void *) pubHighKey;
                
            kh = PK11_ImportPublicKey(cert->slot, pubHighKey, PR_FALSE);
            if (CK_INVALID_HANDLE == kh) {
                fprintf(stderr,
                        "Unable to import public key to certificate slot.");
                exit(1);
            }
            pubHighKey->pkcs11Slot = PK11_ReferenceSlot(cert->slot);
            pubHighKey->pkcs11ID = kh;
            printf("Using PKCS#11 for RSA encryption with token %s.\n",
                   PK11_GetTokenName(cert->slot));
        } else {
            /* do private key ops */
            privHighKey = PK11_FindKeyByAnyCert(cert, &pwData);
            if (privHighKey == NULL) {
                fprintf(stderr,
                        "Can't find private key by name \"%s\"\n", nickname);
                exit(1);
            }
    
            SECKEY_CacheStaticFlags(privHighKey);
            fn = (RSAOp)PK11_PrivateKeyOp;
            keys.privKey = privHighKey;
            keys.pubKey = pubHighKey;
            rsaKey = (void *) &keys;
            printf("Using PKCS#11 for RSA decryption with token %s.\n",
                   PK11_GetTokenName(privHighKey->pkcs11Slot));
        }        
    } else

    if (useSessionKey) {
        /* use PKCS#11 session key objects */
        PK11RSAGenParams   rsaparams;
        void             * params;

        slot = PK11_FindSlotByName(slotname); /* locate target slot */
        if (!slot) {
            fprintf(stderr, "Can't find slot \"%s\"\n", slotname);
            exit(1);
        }

        doKeyGen = PR_TRUE; /* Always do a keygen for session keys.
                               Import of hardcoded key is not supported */
        /* do a temporary keygen in selected slot */        
        if (!keybits) {
            keybits = DEFAULT_KEY_BITS;
        }

        printf("Using PKCS#11 with %ld bits session key in token %s.\n",
               keybits, PK11_GetTokenName(slot));

        rsaparams.keySizeInBits = keybits;
        rsaparams.pe = publicExponent;
        params = &rsaparams;

        fprintf(stderr,"\nGenerating RSA key. This may take a few moments.\n");

        privHighKey = PK11_GenerateKeyPair(slot, CKM_RSA_PKCS_KEY_PAIR_GEN,
                                           params, &pubHighKey, PR_FALSE,
                                           PR_FALSE, (void*)&pwData);
        if (!privHighKey) {
            fprintf(stderr,
                    "Key generation failed in token \"%s\"\n",
                    PK11_GetTokenName(slot));
            exit(1);
        }

        SECKEY_CacheStaticFlags(privHighKey);
        
        fprintf(stderr,"Keygen completed.\n");

        if (doPub) {
            /* do public key operations */
            fn = (RSAOp)PK11_PublicKeyOp;
            rsaKey = (void *) pubHighKey;
        } else {
            /* do private key operations */
            fn = (RSAOp)PK11_PrivateKeyOp;
            keys.privKey = privHighKey;
            keys.pubKey = pubHighKey;
            rsaKey = (void *) &keys;
        }        
    } else
        
    {
        /* use freebl directly */
        if (!keybits) {
            keybits = DEFAULT_KEY_BITS;
        }
        if (!doKeyGen) {
            if (keybits != DEFAULT_KEY_BITS) {
                doKeyGen = PR_TRUE;
            }
        }
        printf("Using freebl with %ld bits key.\n", keybits);
        if (doKeyGen) {
            fprintf(stderr,"\nGenerating RSA key. "
                    "This may take a few moments.\n");
            for (i=0; i < 4; i++) {
                if (peCount || (publicExponent & ((unsigned long)0xff000000L >>
                                                  (i*8)))) {
                    pubEx[peCount] =  (CK_BYTE)((publicExponent >>
                                                 (3-i)*8) & 0xff);
                    peCount++;
                }
            }
            pe.len = peCount;
            pe.data = &pubEx[0];
            pe.type = siBuffer;

            rsaKey = RSA_NewKey(keybits, &pe);
            fprintf(stderr,"Keygen completed.\n");
        } else {
            /* use a hardcoded key */
            printf("Using hardcoded %ld bits key.\n", keybits);
            if (doPub) {
                pubKey = getDefaultRSAPublicKey();
            } else {
                privKey = getDefaultRSAPrivateKey();
            }
        }

        if (doPub) {
            /* do public key operations */
            fn = (RSAOp)RSA_PublicKeyOp;
            if (rsaKey) {
                /* convert the RSAPrivateKey to RSAPublicKey */
                pubKeyStr.arena = NULL;
                pubKeyStr.modulus = ((RSAPrivateKey*)rsaKey)->modulus;
                pubKeyStr.publicExponent =
                    ((RSAPrivateKey*)rsaKey)->publicExponent;
                rsaKey = &pubKeyStr;
            } else {
                /* convert NSSLOWKeyPublicKey to RSAPublicKey */
                rsaKey = (void *)(&pubKey->u.rsa);
            }
            PORT_Assert(rsaKey);
        } else {
            /* do private key operations */
            fn = (RSAOp)RSA_PrivateKeyOp;
            if (privKey) {
                /* convert NSSLOWKeyPrivateKey to RSAPrivateKey */
                rsaKey = (void *)(&privKey->u.rsa);
            }
            PORT_Assert(rsaKey);
        }
    }

    memset(buf, 1, sizeof buf);
    rv = fn(rsaKey, buf2, buf);
    if (rv != SECSuccess) {
       PRErrorCode errNum;
       const char * errStr = NULL;

       errNum = PORT_GetError();
       if (errNum)
           errStr = SECU_Strerror(errNum);
       else
           errNum = rv;
       if (!errStr)
           errStr = "(null)";
       fprintf(stderr, "Error in RSA operation: %d : %s\n", errNum, errStr);
       exit(1);
    }

    threadsArr = (PRThread**)PORT_Alloc(threadNum*sizeof(PRThread*));
    runDataArr = (ThreadRunData**)PORT_Alloc(threadNum*sizeof(ThreadRunData*));
    timeCtx = CreateTimingContext();
    TimingBegin(timeCtx, PR_Now());
    for (i = 0;i < threadNum;i++) {
        runDataArr[i] = (ThreadRunData*)PORT_Alloc(sizeof(ThreadRunData));
        runDataArr[i]->fn = fn;
        runDataArr[i]->buf = buf;
        runDataArr[i]->doIters = &doIters;
        runDataArr[i]->rsaKey = rsaKey;
        runDataArr[i]->seconds = seconds;
        runDataArr[i]->iters = iters;
        threadsArr[i] = 
            PR_CreateThread(PR_USER_THREAD,
                 ThreadExecFunction,
                 (void*) runDataArr[i],
                 PR_PRIORITY_NORMAL,
                 PR_GLOBAL_THREAD,
                 PR_JOINABLE_THREAD,
                 0);
    }
    iters = 0;
    calcThreads = 0;
    for (i = 0;i < threadNum;i++, calcThreads++)
    {
        PR_JoinThread(threadsArr[i]);
        if (runDataArr[i]->status != SECSuccess) {
            const char * errStr = SECU_Strerror(runDataArr[i]->errNum);
            fprintf(stderr, "Thread %d: Error in RSA operation: %d : %s\n",
                    i, runDataArr[i]->errNum, errStr);
            calcThreads -= 1;
        } else {
            iters += runDataArr[i]->iterRes;
        }
        PORT_Free((void*)runDataArr[i]);
    }
    PORT_Free(runDataArr);
    PORT_Free(threadsArr);

    TimingEnd(timeCtx, PR_Now());
    
    printf("%ld iterations in %s\n",
          iters, TimingGenerateString(timeCtx));
    printf("%.2f operations/s .\n", ((double)(iters)*(double)1000000.0) /
           (double)timeCtx->interval );
    TimingDivide(timeCtx, iters);
    printf("one operation every %s\n", TimingGenerateString(timeCtx));

    if (pubHighKey) {
        SECKEY_DestroyPublicKey(pubHighKey);
    }

    if (privHighKey) {
         SECKEY_DestroyPrivateKey(privHighKey);
    }

    if (cert) {
        CERT_DestroyCertificate(cert);
    }

    if (NSS_Shutdown() != SECSuccess) {
        exit(1);
    }

    return 0;
}
SECStatus PK11_PrivateKeyOp ( PK11Keys keys,
unsigned char *  output,
unsigned char *  input 
)

Definition at line 252 of file rsaperf.c.

{
    unsigned outLen = 0;
    return PK11_PrivDecryptRaw(keys->privKey,
                               output, &outLen,
                               keys->pubKey->u.rsa.modulus.len, input,
                               keys->pubKey->u.rsa.modulus.len);
}
SECStatus PK11_PublicKeyOp ( SECKEYPublicKey *  key,
unsigned char *  output,
unsigned char *  input 
)

Definition at line 244 of file rsaperf.c.

{
    return PK11_PubEncryptRaw(key, output, input, key->u.rsa.modulus.len,
                              NULL);
}

Here is the call graph for this function:

void printPrivKey ( NSSLOWKEYPrivateKey *  privKey)

Definition at line 219 of file rsaperf.c.

{
    RSAPrivateKey *rsa = &privKey->u.rsa;

    dumpItem( &rsa->modulus,              "n");
    dumpItem( &rsa->publicExponent,       "e");
    dumpItem( &rsa->privateExponent,      "d");
    dumpItem( &rsa->prime1,               "P");
    dumpItem( &rsa->prime2,               "Q");
    dumpItem( &rsa->exponent1,             "d % (P-1)");
    dumpItem( &rsa->exponent2,             "d % (Q-1)");
    dumpItem( &rsa->coefficient,   "(Q ** -1) % P");
    puts("");
}

Here is the call graph for this function:

Definition at line 277 of file rsaperf.c.

{
    ThreadRunData *tdata = (ThreadRunData*)data;
    unsigned char buf2[BUFFER_BYTES];

    tdata->status = SECSuccess;
    if (*tdata->doIters) {
        long i = tdata->iters;
        tdata->iterRes = 0;
        while (i--) {
            SECStatus rv = tdata->fn((void*)tdata->rsaKey, buf2,
                                     (unsigned char*)tdata->buf);
            if (rv != SECSuccess) {
                tdata->errNum = PORT_GetError();
                tdata->status = rv;
                break;
            }
            tdata->iterRes++;
        }
    } else {
        PRIntervalTime total = PR_SecondsToInterval(tdata->seconds);
        PRIntervalTime start = PR_IntervalNow();
        tdata->iterRes = 0;
        while (PR_IntervalNow() - start < total) {
            SECStatus rv = tdata->fn((void*)tdata->rsaKey, buf2,
                                     (unsigned char*)tdata->buf);
            if (rv != SECSuccess) {
                tdata->errNum = PORT_GetError();
                tdata->status = rv;
                break;
            }
            tdata->iterRes++;
        }
    }
}

Here is the call graph for this function:

void TimingBegin ( TimingContext *  ctx,
PRTime  begin 
)

Definition at line 84 of file rsaperf.c.

                                                   {
    ctx->start = begin;
}
void TimingDivide ( TimingContext *  ctx,
int  divisor 
)

Definition at line 119 of file rsaperf.c.

                                                   {
    PRInt64 tmp;

    LL_I2L(tmp, divisor);
    LL_DIV(ctx->interval, ctx->interval, tmp);

    timingUpdate(ctx);
}

Here is the call graph for this function:

void TimingEnd ( TimingContext *  ctx,
PRTime  end 
)

Definition at line 112 of file rsaperf.c.

                                               {
    ctx->end = end;
    LL_SUB(ctx->interval, ctx->end, ctx->start);
    PORT_Assert(LL_GE_ZERO(ctx->interval));
    timingUpdate(ctx);
}

Here is the call graph for this function:

char* TimingGenerateString ( TimingContext *  ctx)

Definition at line 128 of file rsaperf.c.

                                               {
    char *buf = NULL;

    if (ctx->days != 0) {
       buf = PR_sprintf_append(buf, "%d days", ctx->days);
    }
    if (ctx->hours != 0) {
       if (buf != NULL) buf = PR_sprintf_append(buf, ", ");
       buf = PR_sprintf_append(buf, "%d hours", ctx->hours);
    }
    if (ctx->minutes != 0) {
       if (buf != NULL) buf = PR_sprintf_append(buf, ", ");
       buf = PR_sprintf_append(buf, "%d minutes", ctx->minutes);
    }
    if (buf != NULL) buf = PR_sprintf_append(buf, ", and ");
    if (!buf && ctx->seconds == 0) {
       int interval;
       LL_L2I(interval, ctx->interval);
       if (ctx->millisecs < 100) 
           buf = PR_sprintf_append(buf, "%d microseconds", interval);
       else
           buf = PR_sprintf_append(buf, "%d milliseconds", ctx->millisecs);
    } else if (ctx->millisecs == 0) {
       buf = PR_sprintf_append(buf, "%d seconds", ctx->seconds);
    } else {
       buf = PR_sprintf_append(buf, "%d.%03d seconds",
                            ctx->seconds, ctx->millisecs);
    }
    return buf;
}
static void timingUpdate ( TimingContext *  ctx) [static]

Definition at line 88 of file rsaperf.c.

                                             {
    PRInt64 tmp, remaining;
    PRInt64 L1000,L60,L24;

    LL_I2L(L1000,1000);
    LL_I2L(L60,60);
    LL_I2L(L24,24);

    LL_DIV(remaining, ctx->interval, L1000);
    LL_MOD(tmp, remaining, L1000);
    LL_L2I(ctx->millisecs, tmp);
    LL_DIV(remaining, remaining, L1000);
    LL_MOD(tmp, remaining, L60);
    LL_L2I(ctx->seconds, tmp);
    LL_DIV(remaining, remaining, L60);
    LL_MOD(tmp, remaining, L60);
    LL_L2I(ctx->minutes, tmp);
    LL_DIV(remaining, remaining, L60);
    LL_MOD(tmp, remaining, L24);
    LL_L2I(ctx->hours, tmp);
    LL_DIV(remaining, remaining, L24);
    LL_L2I(ctx->days, remaining);
}

Here is the caller graph for this function:

void Usage ( char *  progName)

Definition at line 160 of file rsaperf.c.

{
    fprintf(stderr, "Usage: %s [-s | -e] [-i iterations | -p period] "
            "[-t threads]\n[-n none [-k keylength] [ [-g] -x exponent] |\n"
            " -n token:nickname [-d certdir] [-w password] |\n"
            " -h token [-d certdir] [-w password] [-g] [-k keylength] "
            "[-x exponent] ]\n",
           progName);
    fprintf(stderr, "%-20s Cert database directory (default is ~/.netscape)\n",
           "-d certdir");
    fprintf(stderr, "%-20s How many operations to perform\n", "-i iterations");
    fprintf(stderr, "%-20s How many seconds to run\n", "-p period");
    fprintf(stderr, "%-20s Perform signing (private key) operations\n", "-s");
    fprintf(stderr, "%-20s Perform encryption (public key) operations\n","-e");
    fprintf(stderr, "%-20s Nickname of certificate or key, prefixed "
            "by optional token name\n", "-n nickname");
    fprintf(stderr, "%-20s PKCS#11 token to perform operation with.\n",
            "-h token");
    fprintf(stderr, "%-20s key size in bits, from %d to %d\n", "-k keylength",
            MIN_KEY_BITS, MAX_KEY_BITS);
    fprintf(stderr, "%-20s token password\n", "-w password");
    fprintf(stderr, "%-20s temporary key generation. Not for token keys.\n",
            "-g");
    fprintf(stderr, "%-20s set public exponent for keygen\n", "-x");
    fprintf(stderr, "%-20s Number of execution threads (default 1)\n",
            "-t threads");
    exit(-1);
}

Here is the call graph for this function:


Variable Documentation

secuPWData pwData = { PW_NONE, NULL }

Definition at line 60 of file rsaperf.c.