Back to index

lightning-sunbird  0.9+nobinonly
debug_module.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 #include "prlog.h"
00037 #include <stdio.h>
00038 
00039 static PRLogModuleInfo *modlog = NULL;
00040 
00041 static CK_FUNCTION_LIST_PTR module_functions;
00042 
00043 static CK_FUNCTION_LIST debug_functions;
00044 
00045 static void print_final_statistics(void);
00046 
00047 /* The AIX 64-bit compiler chokes on large switch statements (see
00048  * bug #63815).  I tried the trick recommended there, using -O2 in
00049  * debug builds, and it didn't work.  Instead, I'll suppress some of
00050  * the verbose output and just dump values.
00051  */
00052 
00053 static void get_attr_type_str(CK_ATTRIBUTE_TYPE atype, char *str, int len)
00054 {
00055 #define SETA(attr) \
00056     PR_snprintf(str, len, "%s", attr); break;
00057     switch (atype) {
00058 #ifndef AIX_64BIT
00059     case CKA_CLASS: SETA("CKA_CLASS");
00060     case CKA_TOKEN: SETA("CKA_TOKEN");
00061     case CKA_PRIVATE: SETA("CKA_PRIVATE");
00062     case CKA_LABEL: SETA("CKA_LABEL");
00063     case CKA_APPLICATION: SETA("CKA_APPLICATION");
00064     case CKA_VALUE: SETA("CKA_VALUE");
00065     case CKA_OBJECT_ID: SETA("CKA_OBJECT_ID");
00066     case CKA_CERTIFICATE_TYPE: SETA("CKA_CERTIFICATE_TYPE");
00067     case CKA_ISSUER: SETA("CKA_ISSUER");
00068     case CKA_SERIAL_NUMBER: SETA("CKA_SERIAL_NUMBER");
00069     case CKA_AC_ISSUER: SETA("CKA_AC_ISSUER");
00070     case CKA_OWNER: SETA("CKA_OWNER");
00071     case CKA_ATTR_TYPES: SETA("CKA_ATTR_TYPES");
00072     case CKA_TRUSTED: SETA("CKA_TRUSTED");
00073     case CKA_KEY_TYPE: SETA("CKA_KEY_TYPE");
00074     case CKA_SUBJECT: SETA("CKA_SUBJECT");
00075     case CKA_ID: SETA("CKA_ID");
00076     case CKA_SENSITIVE: SETA("CKA_SENSITIVE");
00077     case CKA_ENCRYPT: SETA("CKA_ENCRYPT");
00078     case CKA_DECRYPT: SETA("CKA_DECRYPT");
00079     case CKA_WRAP: SETA("CKA_WRAP");
00080     case CKA_UNWRAP: SETA("CKA_UNWRAP");
00081     case CKA_SIGN: SETA("CKA_SIGN");
00082     case CKA_SIGN_RECOVER: SETA("CKA_SIGN_RECOVER");
00083     case CKA_VERIFY: SETA("CKA_VERIFY");
00084     case CKA_VERIFY_RECOVER: SETA("CKA_VERIFY_RECOVER");
00085     case CKA_DERIVE: SETA("CKA_DERIVE");
00086     case CKA_START_DATE: SETA("CKA_START_DATE");
00087     case CKA_END_DATE: SETA("CKA_END_DATE");
00088     case CKA_MODULUS: SETA("CKA_MODULUS");
00089     case CKA_MODULUS_BITS: SETA("CKA_MODULUS_BITS");
00090     case CKA_PUBLIC_EXPONENT: SETA("CKA_PUBLIC_EXPONENT");
00091     case CKA_PRIVATE_EXPONENT: SETA("CKA_PRIVATE_EXPONENT");
00092     case CKA_PRIME_1: SETA("CKA_PRIME_1");
00093     case CKA_PRIME_2: SETA("CKA_PRIME_2");
00094     case CKA_EXPONENT_1: SETA("CKA_EXPONENT_1");
00095     case CKA_EXPONENT_2: SETA("CKA_EXPONENT_2");
00096     case CKA_COEFFICIENT: SETA("CKA_COEFFICIENT");
00097     case CKA_PRIME: SETA("CKA_PRIME");
00098     case CKA_SUBPRIME: SETA("CKA_SUBPRIME");
00099     case CKA_BASE: SETA("CKA_BASE");
00100     case CKA_PRIME_BITS: SETA("CKA_PRIME_BITS");
00101     case CKA_SUB_PRIME_BITS: SETA("CKA_SUB_PRIME_BITS");
00102     case CKA_VALUE_BITS: SETA("CKA_VALUE_BITS");
00103     case CKA_VALUE_LEN: SETA("CKA_VALUE_LEN");
00104     case CKA_EXTRACTABLE: SETA("CKA_EXTRACTABLE");
00105     case CKA_LOCAL: SETA("CKA_LOCAL");
00106     case CKA_NEVER_EXTRACTABLE: SETA("CKA_NEVER_EXTRACTABLE");
00107     case CKA_ALWAYS_SENSITIVE: SETA("CKA_ALWAYS_SENSITIVE");
00108     case CKA_KEY_GEN_MECHANISM: SETA("CKA_KEY_GEN_MECHANISM");
00109     case CKA_MODIFIABLE: SETA("CKA_MODIFIABLE");
00110     case CKA_ECDSA_PARAMS: SETA("CKA_ECDSA_PARAMS");
00111     case CKA_EC_POINT: SETA("CKA_EC_POINT");
00112     case CKA_SECONDARY_AUTH: SETA("CKA_SECONDARY_AUTH");
00113     case CKA_AUTH_PIN_FLAGS: SETA("CKA_AUTH_PIN_FLAGS");
00114     case CKA_HW_FEATURE_TYPE: SETA("CKA_HW_FEATURE_TYPE");
00115     case CKA_RESET_ON_INIT: SETA("CKA_RESET_ON_INIT");
00116     case CKA_HAS_RESET: SETA("CKA_HAS_RESET");
00117     case CKA_VENDOR_DEFINED: SETA("CKA_VENDOR_DEFINED");
00118     case CKA_NETSCAPE_URL: SETA("CKA_NETSCAPE_URL");
00119     case CKA_NETSCAPE_EMAIL: SETA("CKA_NETSCAPE_EMAIL");
00120     case CKA_NETSCAPE_SMIME_INFO: SETA("CKA_NETSCAPE_SMIME_INFO");
00121     case CKA_NETSCAPE_SMIME_TIMESTAMP: SETA("CKA_NETSCAPE_SMIME_TIMESTAMP");
00122     case CKA_NETSCAPE_PKCS8_SALT: SETA("CKA_NETSCAPE_PKCS8_SALT");
00123     case CKA_NETSCAPE_PASSWORD_CHECK: SETA("CKA_NETSCAPE_PASSWORD_CHECK");
00124     case CKA_NETSCAPE_EXPIRES: SETA("CKA_NETSCAPE_EXPIRES");
00125     case CKA_NETSCAPE_KRL: SETA("CKA_NETSCAPE_KRL");
00126     case CKA_NETSCAPE_PQG_COUNTER: SETA("CKA_NETSCAPE_PQG_COUNTER");
00127     case CKA_NETSCAPE_PQG_SEED: SETA("CKA_NETSCAPE_PQG_SEED");
00128     case CKA_NETSCAPE_PQG_H: SETA("CKA_NETSCAPE_PQG_H");
00129     case CKA_NETSCAPE_PQG_SEED_BITS: SETA("CKA_NETSCAPE_PQG_SEED_BITS");
00130     case CKA_TRUST: SETA("CKA_TRUST");
00131     case CKA_TRUST_DIGITAL_SIGNATURE: SETA("CKA_TRUST_DIGITAL_SIGNATURE");
00132     case CKA_TRUST_NON_REPUDIATION: SETA("CKA_TRUST_NON_REPUDIATION");
00133     case CKA_TRUST_KEY_ENCIPHERMENT: SETA("CKA_TRUST_KEY_ENCIPHERMENT");
00134     case CKA_TRUST_DATA_ENCIPHERMENT: SETA("CKA_TRUST_DATA_ENCIPHERMENT");
00135     case CKA_TRUST_KEY_AGREEMENT: SETA("CKA_TRUST_KEY_AGREEMENT");
00136     case CKA_TRUST_KEY_CERT_SIGN: SETA("CKA_TRUST_KEY_CERT_SIGN");
00137     case CKA_TRUST_CRL_SIGN: SETA("CKA_TRUST_CRL_SIGN");
00138     case CKA_TRUST_SERVER_AUTH: SETA("CKA_TRUST_SERVER_AUTH");
00139     case CKA_TRUST_CLIENT_AUTH: SETA("CKA_TRUST_CLIENT_AUTH");
00140     case CKA_TRUST_CODE_SIGNING: SETA("CKA_TRUST_CODE_SIGNING");
00141     case CKA_TRUST_EMAIL_PROTECTION: SETA("CKA_TRUST_EMAIL_PROTECTION");
00142     case CKA_TRUST_IPSEC_END_SYSTEM: SETA("CKA_TRUST_IPSEC_END_SYSTEM");
00143     case CKA_TRUST_IPSEC_TUNNEL: SETA("CKA_TRUST_IPSEC_TUNNEL");
00144     case CKA_TRUST_IPSEC_USER: SETA("CKA_TRUST_IPSEC_USER");
00145     case CKA_TRUST_TIME_STAMPING: SETA("CKA_TRUST_TIME_STAMPING");
00146     case CKA_CERT_SHA1_HASH: SETA("CKA_CERT_SHA1_HASH");
00147     case CKA_CERT_MD5_HASH: SETA("CKA_CERT_MD5_HASH");
00148     case CKA_NETSCAPE_DB: SETA("CKA_NETSCAPE_DB");
00149     case CKA_NETSCAPE_TRUST: SETA("CKA_NETSCAPE_TRUST");
00150 #endif
00151     default: PR_snprintf(str, len, "0x%p", atype); break;
00152     }
00153 }
00154 
00155 static void get_obj_class(CK_OBJECT_CLASS objClass, char *str, int len)
00156 {
00157 #define SETO(objc) \
00158     PR_snprintf(str, len, "%s", objc); break;
00159     switch (objClass) {
00160 #ifndef AIX_64BIT
00161     case CKO_DATA: SETO("CKO_DATA");
00162     case CKO_CERTIFICATE: SETO("CKO_CERTIFICATE");
00163     case CKO_PUBLIC_KEY: SETO("CKO_PUBLIC_KEY");
00164     case CKO_PRIVATE_KEY: SETO("CKO_PRIVATE_KEY");
00165     case CKO_SECRET_KEY: SETO("CKO_SECRET_KEY");
00166     case CKO_HW_FEATURE: SETO("CKO_HW_FEATURE");
00167     case CKO_DOMAIN_PARAMETERS: SETO("CKO_DOMAIN_PARAMETERS");
00168     case CKO_NETSCAPE_CRL: SETO("CKO_NETSCAPE_CRL");
00169     case CKO_NETSCAPE_SMIME: SETO("CKO_NETSCAPE_SMIME");
00170     case CKO_NETSCAPE_TRUST: SETO("CKO_NETSCAPE_TRUST");
00171     case CKO_NETSCAPE_BUILTIN_ROOT_LIST: SETO("CKO_NETSCAPE_BUILTIN_ROOT_LIST");
00172 #endif
00173     default: PR_snprintf(str, len, "0x%p", objClass); break;
00174     }
00175 }
00176 
00177 static void get_trust_val(CK_TRUST trust, char *str, int len)
00178 {
00179 #define SETT(objc) \
00180     PR_snprintf(str, len, "%s", objc); break;
00181     switch (trust) {
00182 #ifndef AIX_64BIT
00183     case CKT_NETSCAPE_TRUSTED: SETT("CKT_NETSCAPE_TRUSTED");
00184     case CKT_NETSCAPE_TRUSTED_DELEGATOR: SETT("CKT_NETSCAPE_TRUSTED_DELEGATOR");
00185     case CKT_NETSCAPE_UNTRUSTED: SETT("CKT_NETSCAPE_UNTRUSTED");
00186     case CKT_NETSCAPE_MUST_VERIFY: SETT("CKT_NETSCAPE_MUST_VERIFY");
00187     case CKT_NETSCAPE_TRUST_UNKNOWN: SETT("CKT_NETSCAPE_TRUST_UNKNOWN");
00188     case CKT_NETSCAPE_VALID: SETT("CKT_NETSCAPE_VALID");
00189     case CKT_NETSCAPE_VALID_DELEGATOR: SETT("CKT_NETSCAPE_VALID_DELEGATOR");
00190 #endif
00191     default: PR_snprintf(str, len, "0x%p", trust); break;
00192     }
00193 }
00194 
00195 static void print_attr_value(CK_ATTRIBUTE_PTR attr)
00196 {
00197     char atype[48];
00198     char valstr[48];
00199     int len;
00200     get_attr_type_str(attr->type, atype, sizeof atype);
00201     switch (attr->type) {
00202     case CKA_TOKEN:
00203     case CKA_PRIVATE:
00204     case CKA_SENSITIVE:
00205     case CKA_ENCRYPT:
00206     case CKA_DECRYPT:
00207     case CKA_WRAP:
00208     case CKA_UNWRAP:
00209     case CKA_SIGN:
00210     case CKA_SIGN_RECOVER:
00211     case CKA_VERIFY:
00212     case CKA_VERIFY_RECOVER:
00213     case CKA_DERIVE:
00214     case CKA_EXTRACTABLE:
00215     case CKA_LOCAL:
00216     case CKA_NEVER_EXTRACTABLE:
00217     case CKA_ALWAYS_SENSITIVE:
00218     case CKA_MODIFIABLE:
00219        if (attr->ulValueLen > 0 && attr->pValue) {
00220            CK_BBOOL tf = *((CK_BBOOL *)attr->pValue);
00221            len = sizeof(valstr);
00222            PR_snprintf(valstr, len, "%s", tf ? "CK_TRUE" : "CK_FALSE");
00223            PR_LOG(modlog, 4, ("    %s = %s [%d]", 
00224                   atype, valstr, attr->ulValueLen));
00225            break;
00226        }
00227     case CKA_CLASS:
00228        if (attr->ulValueLen > 0 && attr->pValue) {
00229            CK_OBJECT_CLASS objClass = *((CK_OBJECT_CLASS *)attr->pValue);
00230            get_obj_class(objClass, valstr, sizeof valstr);
00231            PR_LOG(modlog, 4, ("    %s = %s [%d]", 
00232                   atype, valstr, attr->ulValueLen));
00233            break;
00234        }
00235     case CKA_TRUST_SERVER_AUTH:
00236     case CKA_TRUST_CLIENT_AUTH:
00237     case CKA_TRUST_CODE_SIGNING:
00238     case CKA_TRUST_EMAIL_PROTECTION:
00239        if (attr->ulValueLen > 0 && attr->pValue) {
00240            CK_TRUST trust = *((CK_TRUST *)attr->pValue);
00241            get_trust_val(trust, valstr, sizeof valstr);
00242            PR_LOG(modlog, 4, ("    %s = %s [%d]", 
00243                   atype, valstr, attr->ulValueLen));
00244            break;
00245        }
00246     case CKA_LABEL:
00247     case CKA_NETSCAPE_EMAIL:
00248     case CKA_NETSCAPE_URL:
00249        if (attr->ulValueLen > 0 && attr->pValue) {
00250            len = PR_MIN(attr->ulValueLen + 1, sizeof valstr);
00251            PR_snprintf(valstr, len, "%s", attr->pValue);
00252            PR_LOG(modlog, 4, ("    %s = %s [%d]", 
00253                   atype, valstr, attr->ulValueLen));
00254            break;
00255        }
00256     default:
00257        PR_LOG(modlog, 4, ("    %s = 0x%p [%d]", 
00258               atype, attr->pValue, attr->ulValueLen));
00259        break;
00260     }
00261 }
00262 
00263 static void print_template(CK_ATTRIBUTE_PTR templ, CK_ULONG tlen)
00264 {
00265     CK_ULONG i;
00266     for (i=0; i<tlen; i++) {
00267        print_attr_value(&templ[i]);
00268     }
00269 }
00270 
00271 static void print_mechanism(CK_MECHANISM_PTR m)
00272 {
00273     PR_LOG(modlog, 4, ("      mechanism = 0x%p", m->mechanism));
00274 }
00275 
00276 struct nssdbg_prof_str {
00277     PRUint32 time;
00278     PRUint32 calls;
00279     char *function;
00280 };
00281 
00282 #define NSSDBG_DEFINE(func) { 0, 0, #func }
00283 
00284 struct nssdbg_prof_str nssdbg_prof_data[] = {
00285 #define FUNC_C_INITIALIZE 0
00286     NSSDBG_DEFINE(C_Initialize),
00287 #define FUNC_C_FINALIZE 1
00288     NSSDBG_DEFINE(C_Finalize),
00289 #define FUNC_C_GETINFO 2
00290     NSSDBG_DEFINE(C_GetInfo),
00291 #define FUNC_C_GETFUNCITONLIST 3
00292     NSSDBG_DEFINE(C_GetFunctionList),
00293 #define FUNC_C_GETSLOTLIST 4
00294     NSSDBG_DEFINE(C_GetSlotList),
00295 #define FUNC_C_GETSLOTINFO 5
00296     NSSDBG_DEFINE(C_GetSlotInfo),
00297 #define FUNC_C_GETTOKENINFO 6
00298     NSSDBG_DEFINE(C_GetTokenInfo),
00299 #define FUNC_C_GETMECHANISMLIST 7
00300     NSSDBG_DEFINE(C_GetMechanismList),
00301 #define FUNC_C_GETMECHANISMINFO 8
00302     NSSDBG_DEFINE(C_GetMechanismInfo),
00303 #define FUNC_C_INITTOKEN 9
00304     NSSDBG_DEFINE(C_InitToken),
00305 #define FUNC_C_INITPIN 10
00306     NSSDBG_DEFINE(C_InitPIN),
00307 #define FUNC_C_SETPIN 11
00308     NSSDBG_DEFINE(C_SetPIN),
00309 #define FUNC_C_OPENSESSION 12
00310     NSSDBG_DEFINE(C_OpenSession),
00311 #define FUNC_C_CLOSESESSION 13
00312     NSSDBG_DEFINE(C_CloseSession),
00313 #define FUNC_C_CLOSEALLSESSIONS 14
00314     NSSDBG_DEFINE(C_CloseAllSessions),
00315 #define FUNC_C_GETSESSIONINFO 15
00316     NSSDBG_DEFINE(C_GetSessionInfo),
00317 #define FUNC_C_GETOPERATIONSTATE 16
00318     NSSDBG_DEFINE(C_GetOperationState),
00319 #define FUNC_C_SETOPERATIONSTATE 17
00320     NSSDBG_DEFINE(C_SetOperationState),
00321 #define FUNC_C_LOGIN 18
00322     NSSDBG_DEFINE(C_Login),
00323 #define FUNC_C_LOGOUT 19
00324     NSSDBG_DEFINE(C_Logout),
00325 #define FUNC_C_CREATEOBJECT 20
00326     NSSDBG_DEFINE(C_CreateObject),
00327 #define FUNC_C_COPYOBJECT 21
00328     NSSDBG_DEFINE(C_CopyObject),
00329 #define FUNC_C_DESTROYOBJECT 22
00330     NSSDBG_DEFINE(C_DestroyObject),
00331 #define FUNC_C_GETOBJECTSIZE  23
00332     NSSDBG_DEFINE(C_GetObjectSize),
00333 #define FUNC_C_GETATTRIBUTEVALUE 24
00334     NSSDBG_DEFINE(C_GetAttributeValue),
00335 #define FUNC_C_SETATTRIBUTEVALUE 25
00336     NSSDBG_DEFINE(C_SetAttributeValue),
00337 #define FUNC_C_FINDOBJECTSINIT 26
00338     NSSDBG_DEFINE(C_FindObjectsInit),
00339 #define FUNC_C_FINDOBJECTS 27
00340     NSSDBG_DEFINE(C_FindObjects),
00341 #define FUNC_C_FINDOBJECTSFINAL 28
00342     NSSDBG_DEFINE(C_FindObjectsFinal),
00343 #define FUNC_C_ENCRYPTINIT 29
00344     NSSDBG_DEFINE(C_EncryptInit),
00345 #define FUNC_C_ENCRYPT 30
00346     NSSDBG_DEFINE(C_Encrypt),
00347 #define FUNC_C_ENCRYPTUPDATE 31
00348     NSSDBG_DEFINE(C_EncryptUpdate),
00349 #define FUNC_C_ENCRYPTFINAL 32
00350     NSSDBG_DEFINE(C_EncryptFinal),
00351 #define FUNC_C_DECRYPTINIT 33
00352     NSSDBG_DEFINE(C_DecryptInit),
00353 #define FUNC_C_DECRYPT 34
00354     NSSDBG_DEFINE(C_Decrypt),
00355 #define FUNC_C_DECRYPTUPDATE 35
00356     NSSDBG_DEFINE(C_DecryptUpdate),
00357 #define FUNC_C_DECRYPTFINAL 36
00358     NSSDBG_DEFINE(C_DecryptFinal),
00359 #define FUNC_C_DIGESTINIT 37
00360     NSSDBG_DEFINE(C_DigestInit),
00361 #define FUNC_C_DIGEST 38
00362     NSSDBG_DEFINE(C_Digest),
00363 #define FUNC_C_DIGESTUPDATE 39
00364     NSSDBG_DEFINE(C_DigestUpdate),
00365 #define FUNC_C_DIGESTKEY 40
00366     NSSDBG_DEFINE(C_DigestKey),
00367 #define FUNC_C_DIGESTFINAL 41
00368     NSSDBG_DEFINE(C_DigestFinal),
00369 #define FUNC_C_SIGNINIT 42
00370     NSSDBG_DEFINE(C_SignInit),
00371 #define FUNC_C_SIGN 43
00372     NSSDBG_DEFINE(C_Sign),
00373 #define FUNC_C_SIGNUPDATE 44
00374     NSSDBG_DEFINE(C_SignUpdate),
00375 #define FUNC_C_SIGNFINAL 45
00376     NSSDBG_DEFINE(C_SignFinal),
00377 #define FUNC_C_SIGNRECOVERINIT 46
00378     NSSDBG_DEFINE(C_SignRecoverInit),
00379 #define FUNC_C_SIGNRECOVER 47
00380     NSSDBG_DEFINE(C_SignRecover),
00381 #define FUNC_C_VERIFYINIT 48
00382     NSSDBG_DEFINE(C_VerifyInit),
00383 #define FUNC_C_VERIFY 49
00384     NSSDBG_DEFINE(C_Verify),
00385 #define FUNC_C_VERIFYUPDATE 50
00386     NSSDBG_DEFINE(C_VerifyUpdate),
00387 #define FUNC_C_VERIFYFINAL 51
00388     NSSDBG_DEFINE(C_VerifyFinal),
00389 #define FUNC_C_VERIFYRECOVERINIT 52
00390     NSSDBG_DEFINE(C_VerifyRecoverInit),
00391 #define FUNC_C_VERIFYRECOVER 53
00392     NSSDBG_DEFINE(C_VerifyRecover),
00393 #define FUNC_C_DIGESTENCRYPTUPDATE 54
00394     NSSDBG_DEFINE(C_DigestEncryptUpdate),
00395 #define FUNC_C_DECRYPTDIGESTUPDATE 55
00396     NSSDBG_DEFINE(C_DecryptDigestUpdate),
00397 #define FUNC_C_SIGNENCRYPTUPDATE 56
00398     NSSDBG_DEFINE(C_SignEncryptUpdate),
00399 #define FUNC_C_DECRYPTVERIFYUPDATE 57
00400     NSSDBG_DEFINE(C_DecryptVerifyUpdate),
00401 #define FUNC_C_GENERATEKEY 58
00402     NSSDBG_DEFINE(C_GenerateKey),
00403 #define FUNC_C_GENERATEKEYPAIR 59
00404     NSSDBG_DEFINE(C_GenerateKeyPair),
00405 #define FUNC_C_WRAPKEY 60
00406     NSSDBG_DEFINE(C_WrapKey),
00407 #define FUNC_C_UNWRAPKEY 61
00408     NSSDBG_DEFINE(C_UnWrapKey),
00409 #define FUNC_C_DERIVEKEY 62 
00410     NSSDBG_DEFINE(C_DeriveKey),
00411 #define FUNC_C_SEEDRANDOM 63
00412     NSSDBG_DEFINE(C_SeedRandom),
00413 #define FUNC_C_GENERATERANDOM 64
00414     NSSDBG_DEFINE(C_GenerateRandom),
00415 #define FUNC_C_GETFUNCTIONSTATUS 65
00416     NSSDBG_DEFINE(C_GetFunctionStatus),
00417 #define FUNC_C_CANCELFUNCTION 66
00418     NSSDBG_DEFINE(C_CancelFunction),
00419 #define FUNC_C_WAITFORSLOTEVENT 67
00420     NSSDBG_DEFINE(C_WaitForSlotEvent)
00421 };
00422 
00423 int nssdbg_prof_size = sizeof(nssdbg_prof_data)/sizeof(nssdbg_prof_data[0]);
00424     
00425 
00426 static void nssdbg_finish_time(PRInt32 fun_number, PRIntervalTime start)
00427 {
00428     PRIntervalTime ival;
00429     PRIntervalTime end = PR_IntervalNow();
00430 
00431     ival = end-start;
00432     /* sigh, lie to PRAtomic add and say we are using signed values */
00433     PR_AtomicAdd((PRInt32 *)&nssdbg_prof_data[fun_number].time, (PRInt32)ival);
00434 }
00435 
00436 static void nssdbg_start_time(PRInt32 fun_number, PRIntervalTime *start)
00437 {
00438     PR_AtomicIncrement((PRInt32 *)&nssdbg_prof_data[fun_number].calls);
00439     *start = PR_IntervalNow();
00440 }
00441 
00442 CK_RV NSSDBGC_Initialize(
00443   CK_VOID_PTR pInitArgs
00444 )
00445 {
00446     CK_RV rv;
00447     PRIntervalTime start;
00448     PR_LOG(modlog, 1, ("C_Initialize"));
00449     PR_LOG(modlog, 3, ("  pInitArgs = 0x%p", pInitArgs));
00450     nssdbg_start_time(FUNC_C_INITIALIZE,&start);
00451     rv = module_functions->C_Initialize(pInitArgs);
00452     nssdbg_finish_time(FUNC_C_INITIALIZE,start);
00453     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00454     return rv;
00455 }
00456 
00457 CK_RV NSSDBGC_Finalize(
00458   CK_VOID_PTR pReserved
00459 )
00460 {
00461     CK_RV rv;
00462     PRIntervalTime start;
00463     PR_LOG(modlog, 1, ("C_Finalize"));
00464     PR_LOG(modlog, 3, ("  pReserved = 0x%p", pReserved));
00465     nssdbg_start_time(FUNC_C_FINALIZE,&start);
00466     rv = module_functions->C_Finalize(pReserved);
00467     nssdbg_finish_time(FUNC_C_FINALIZE,start);
00468     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00469     return rv;
00470 }
00471 
00472 CK_RV NSSDBGC_GetInfo(
00473   CK_INFO_PTR pInfo
00474 )
00475 {
00476     CK_RV rv;
00477     PRIntervalTime start;
00478     PR_LOG(modlog, 1, ("C_GetInfo"));
00479     PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
00480     nssdbg_start_time(FUNC_C_GETINFO,&start);
00481     rv = module_functions->C_GetInfo(pInfo);
00482     nssdbg_finish_time(FUNC_C_GETINFO,start);
00483     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00484     return rv;
00485 }
00486 
00487 CK_RV NSSDBGC_GetFunctionList(
00488   CK_FUNCTION_LIST_PTR_PTR ppFunctionList
00489 )
00490 {
00491     CK_RV rv;
00492     PRIntervalTime start;
00493     PR_LOG(modlog, 1, ("C_GetFunctionList"));
00494     PR_LOG(modlog, 3, ("  ppFunctionList = 0x%p", ppFunctionList));
00495     nssdbg_start_time(FUNC_C_GETFUNCITONLIST,&start);
00496     rv = module_functions->C_GetFunctionList(ppFunctionList);
00497     nssdbg_finish_time(FUNC_C_GETFUNCITONLIST,start);
00498     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00499     return rv;
00500 }
00501 
00502 CK_RV NSSDBGC_GetSlotList(
00503   CK_BBOOL       tokenPresent,
00504   CK_SLOT_ID_PTR pSlotList,
00505   CK_ULONG_PTR   pulCount
00506 )
00507 {
00508     CK_RV rv;
00509     PRIntervalTime start;
00510     CK_ULONG i;
00511     PR_LOG(modlog, 1, ("C_GetSlotList"));
00512     PR_LOG(modlog, 3, ("  tokenPresent = 0x%x", tokenPresent));
00513     PR_LOG(modlog, 3, ("  pSlotList = 0x%p", pSlotList));
00514     PR_LOG(modlog, 3, ("  pulCount = 0x%p", pulCount));
00515     nssdbg_start_time(FUNC_C_GETSLOTLIST,&start);
00516     rv = module_functions->C_GetSlotList(tokenPresent,
00517                                  pSlotList,
00518                                  pulCount);
00519     nssdbg_finish_time(FUNC_C_GETSLOTLIST,start);
00520     PR_LOG(modlog, 4, ("  *pulCount = 0x%x", *pulCount));
00521     if (pSlotList) {
00522        for (i=0; i<*pulCount; i++) {
00523            PR_LOG(modlog, 4, ("  slotID[%d] = %x", i, pSlotList[i]));
00524        }
00525     }
00526     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00527     return rv;
00528 }
00529 
00530 CK_RV NSSDBGC_GetSlotInfo(
00531   CK_SLOT_ID       slotID,
00532   CK_SLOT_INFO_PTR pInfo
00533 )
00534 {
00535     CK_RV rv;
00536     PRIntervalTime start;
00537     PR_LOG(modlog, 1, ("C_GetSlotInfo"));
00538     PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
00539     PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
00540     nssdbg_start_time(FUNC_C_GETSLOTINFO,&start);
00541     rv = module_functions->C_GetSlotInfo(slotID,
00542                                  pInfo);
00543     nssdbg_finish_time(FUNC_C_GETSLOTINFO,start);
00544     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00545     return rv;
00546 }
00547 
00548 CK_RV NSSDBGC_GetTokenInfo(
00549   CK_SLOT_ID        slotID,
00550   CK_TOKEN_INFO_PTR pInfo
00551 )
00552 {
00553     CK_RV rv;
00554     PRIntervalTime start;
00555     PR_LOG(modlog, 1, ("C_GetTokenInfo"));
00556     PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
00557     PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
00558     nssdbg_start_time(FUNC_C_GETTOKENINFO,&start);
00559     rv = module_functions->C_GetTokenInfo(slotID,
00560                                  pInfo);
00561     nssdbg_finish_time(FUNC_C_GETTOKENINFO,start);
00562     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00563     return rv;
00564 }
00565 
00566 CK_RV NSSDBGC_GetMechanismList(
00567   CK_SLOT_ID            slotID,
00568   CK_MECHANISM_TYPE_PTR pMechanismList,
00569   CK_ULONG_PTR          pulCount
00570 )
00571 {
00572     CK_RV rv;
00573     PRIntervalTime start;
00574     PR_LOG(modlog, 1, ("C_GetMechanismList"));
00575     PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
00576     PR_LOG(modlog, 3, ("  pMechanismList = 0x%p", pMechanismList));
00577     PR_LOG(modlog, 3, ("  pulCount = 0x%p", pulCount));
00578     nssdbg_start_time(FUNC_C_GETMECHANISMLIST,&start);
00579     rv = module_functions->C_GetMechanismList(slotID,
00580                                  pMechanismList,
00581                                  pulCount);
00582     nssdbg_finish_time(FUNC_C_GETMECHANISMLIST,start);
00583     PR_LOG(modlog, 4, ("  *pulCount = 0x%x", *pulCount));
00584     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00585     return rv;
00586 }
00587 
00588 CK_RV NSSDBGC_GetMechanismInfo(
00589   CK_SLOT_ID            slotID,
00590   CK_MECHANISM_TYPE     type,
00591   CK_MECHANISM_INFO_PTR pInfo
00592 )
00593 {
00594     CK_RV rv;
00595     PRIntervalTime start;
00596     PR_LOG(modlog, 1, ("C_GetMechanismInfo"));
00597     PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
00598     PR_LOG(modlog, 3, ("  type = 0x%x", type));
00599     PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
00600     nssdbg_start_time(FUNC_C_GETMECHANISMINFO,&start);
00601     rv = module_functions->C_GetMechanismInfo(slotID,
00602                                  type,
00603                                  pInfo);
00604     nssdbg_finish_time(FUNC_C_GETMECHANISMINFO,start);
00605     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00606     return rv;
00607 }
00608 
00609 CK_RV NSSDBGC_InitToken(
00610   CK_SLOT_ID  slotID,
00611   CK_CHAR_PTR pPin,
00612   CK_ULONG    ulPinLen,
00613   CK_CHAR_PTR pLabel
00614 )
00615 {
00616     CK_RV rv;
00617     PRIntervalTime start;
00618     PR_LOG(modlog, 1, ("C_InitToken"));
00619     PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
00620     PR_LOG(modlog, 3, ("  pPin = 0x%p", pPin));
00621     PR_LOG(modlog, 3, ("  ulPinLen = %d", ulPinLen));
00622     PR_LOG(modlog, 3, ("  pLabel = 0x%p", pLabel));
00623     nssdbg_start_time(FUNC_C_INITTOKEN,&start);
00624     rv = module_functions->C_InitToken(slotID,
00625                                  pPin,
00626                                  ulPinLen,
00627                                  pLabel);
00628     nssdbg_finish_time(FUNC_C_INITTOKEN,start);
00629     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00630     return rv;
00631 }
00632 
00633 CK_RV NSSDBGC_InitPIN(
00634   CK_SESSION_HANDLE hSession,
00635   CK_CHAR_PTR       pPin,
00636   CK_ULONG          ulPinLen
00637 )
00638 {
00639     CK_RV rv;
00640     PRIntervalTime start;
00641     PR_LOG(modlog, 1, ("C_InitPIN"));
00642     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00643     PR_LOG(modlog, 3, ("  pPin = 0x%p", pPin));
00644     PR_LOG(modlog, 3, ("  ulPinLen = %d", ulPinLen));
00645     nssdbg_start_time(FUNC_C_INITPIN,&start);
00646     rv = module_functions->C_InitPIN(hSession,
00647                                  pPin,
00648                                  ulPinLen);
00649     nssdbg_finish_time(FUNC_C_INITPIN,start);
00650     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00651     return rv;
00652 }
00653 
00654 CK_RV NSSDBGC_SetPIN(
00655   CK_SESSION_HANDLE hSession,
00656   CK_CHAR_PTR       pOldPin,
00657   CK_ULONG          ulOldLen,
00658   CK_CHAR_PTR       pNewPin,
00659   CK_ULONG          ulNewLen
00660 )
00661 {
00662     CK_RV rv;
00663     PRIntervalTime start;
00664     PR_LOG(modlog, 1, ("C_SetPIN"));
00665     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00666     PR_LOG(modlog, 3, ("  pOldPin = 0x%p", pOldPin));
00667     PR_LOG(modlog, 3, ("  ulOldLen = %d", ulOldLen));
00668     PR_LOG(modlog, 3, ("  pNewPin = 0x%p", pNewPin));
00669     PR_LOG(modlog, 3, ("  ulNewLen = %d", ulNewLen));
00670     nssdbg_start_time(FUNC_C_SETPIN,&start);
00671     rv = module_functions->C_SetPIN(hSession,
00672                                  pOldPin,
00673                                  ulOldLen,
00674                                  pNewPin,
00675                                  ulNewLen);
00676     nssdbg_finish_time(FUNC_C_SETPIN,start);
00677     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00678     return rv;
00679 }
00680 
00681 static PRUint32 numOpenSessions = 0;
00682 static PRUint32 maxOpenSessions = 0;
00683 CK_RV NSSDBGC_OpenSession(
00684   CK_SLOT_ID            slotID,
00685   CK_FLAGS              flags,
00686   CK_VOID_PTR           pApplication,
00687   CK_NOTIFY             Notify,
00688   CK_SESSION_HANDLE_PTR phSession
00689 )
00690 {
00691     CK_RV rv;
00692     PRIntervalTime start;
00693     PR_AtomicIncrement((PRInt32 *)&numOpenSessions);
00694     maxOpenSessions = PR_MAX(numOpenSessions, maxOpenSessions);
00695     PR_LOG(modlog, 1, ("C_OpenSession"));
00696     PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
00697     PR_LOG(modlog, 3, ("  flags = 0x%x", flags));
00698     PR_LOG(modlog, 3, ("  pApplication = 0x%p", pApplication));
00699     PR_LOG(modlog, 3, ("  Notify = 0x%x", Notify));
00700     PR_LOG(modlog, 3, ("  phSession = 0x%p", phSession));
00701     nssdbg_start_time(FUNC_C_OPENSESSION,&start);
00702     rv = module_functions->C_OpenSession(slotID,
00703                                  flags,
00704                                  pApplication,
00705                                  Notify,
00706                                  phSession);
00707     nssdbg_finish_time(FUNC_C_OPENSESSION,start);
00708     PR_LOG(modlog, 4, ("  *phSession = 0x%x", *phSession));
00709     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00710     return rv;
00711 }
00712 
00713 CK_RV NSSDBGC_CloseSession(
00714   CK_SESSION_HANDLE hSession
00715 )
00716 {
00717     CK_RV rv;
00718     PRIntervalTime start;
00719     PR_AtomicDecrement((PRInt32 *)&numOpenSessions);
00720     PR_LOG(modlog, 1, ("C_CloseSession"));
00721     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00722     nssdbg_start_time(FUNC_C_CLOSESESSION,&start);
00723     rv = module_functions->C_CloseSession(hSession);
00724     nssdbg_finish_time(FUNC_C_CLOSESESSION,start);
00725     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00726     return rv;
00727 }
00728 
00729 CK_RV NSSDBGC_CloseAllSessions(
00730   CK_SLOT_ID slotID
00731 )
00732 {
00733     CK_RV rv;
00734     PRIntervalTime start;
00735     PR_LOG(modlog, 1, ("C_CloseAllSessions"));
00736     PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
00737     nssdbg_start_time(FUNC_C_CLOSEALLSESSIONS,&start);
00738     rv = module_functions->C_CloseAllSessions(slotID);
00739     nssdbg_finish_time(FUNC_C_CLOSEALLSESSIONS,start);
00740     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00741     return rv;
00742 }
00743 
00744 CK_RV NSSDBGC_GetSessionInfo(
00745   CK_SESSION_HANDLE   hSession,
00746   CK_SESSION_INFO_PTR pInfo
00747 )
00748 {
00749     CK_RV rv;
00750     PRIntervalTime start;
00751     PR_LOG(modlog, 1, ("C_GetSessionInfo"));
00752     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00753     PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
00754     nssdbg_start_time(FUNC_C_GETSESSIONINFO,&start);
00755     rv = module_functions->C_GetSessionInfo(hSession,
00756                                  pInfo);
00757     nssdbg_finish_time(FUNC_C_GETSESSIONINFO,start);
00758     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00759     return rv;
00760 }
00761 
00762 CK_RV NSSDBGC_GetOperationState(
00763   CK_SESSION_HANDLE hSession,
00764   CK_BYTE_PTR       pOperationState,
00765   CK_ULONG_PTR      pulOperationStateLen
00766 )
00767 {
00768     CK_RV rv;
00769     PRIntervalTime start;
00770     PR_LOG(modlog, 1, ("C_GetOperationState"));
00771     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00772     PR_LOG(modlog, 3, ("  pOperationState = 0x%p", pOperationState));
00773     PR_LOG(modlog, 3, ("  pulOperationStateLen = 0x%p", pulOperationStateLen));
00774     nssdbg_start_time(FUNC_C_GETOPERATIONSTATE,&start);
00775     rv = module_functions->C_GetOperationState(hSession,
00776                                  pOperationState,
00777                                  pulOperationStateLen);
00778     nssdbg_finish_time(FUNC_C_GETOPERATIONSTATE,start);
00779     PR_LOG(modlog, 4, ("  *pulOperationStateLen = 0x%x", *pulOperationStateLen));
00780     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00781     return rv;
00782 }
00783 
00784 CK_RV NSSDBGC_SetOperationState(
00785   CK_SESSION_HANDLE hSession,
00786   CK_BYTE_PTR      pOperationState,
00787   CK_ULONG         ulOperationStateLen,
00788   CK_OBJECT_HANDLE hEncryptionKey,
00789   CK_OBJECT_HANDLE hAuthenticationKey
00790 )
00791 {
00792     CK_RV rv;
00793     PRIntervalTime start;
00794     PR_LOG(modlog, 1, ("C_SetOperationState"));
00795     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00796     PR_LOG(modlog, 3, ("  pOperationState = 0x%p", pOperationState));
00797     PR_LOG(modlog, 3, ("  ulOperationStateLen = %d", ulOperationStateLen));
00798     PR_LOG(modlog, 3, ("  hEncryptionKey = 0x%x", hEncryptionKey));
00799     PR_LOG(modlog, 3, ("  hAuthenticationKey = 0x%x", hAuthenticationKey));
00800     nssdbg_start_time(FUNC_C_SETOPERATIONSTATE,&start);
00801     rv = module_functions->C_SetOperationState(hSession,
00802                                  pOperationState,
00803                                  ulOperationStateLen,
00804                                  hEncryptionKey,
00805                                  hAuthenticationKey);
00806     nssdbg_finish_time(FUNC_C_SETOPERATIONSTATE,start);
00807     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00808     return rv;
00809 }
00810 
00811 CK_RV NSSDBGC_Login(
00812   CK_SESSION_HANDLE hSession,
00813   CK_USER_TYPE      userType,
00814   CK_CHAR_PTR       pPin,
00815   CK_ULONG          ulPinLen
00816 )
00817 {
00818     CK_RV rv;
00819     PRIntervalTime start;
00820     PR_LOG(modlog, 1, ("C_Login"));
00821     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00822     PR_LOG(modlog, 3, ("  userType = 0x%x", userType));
00823     PR_LOG(modlog, 3, ("  pPin = 0x%p", pPin));
00824     PR_LOG(modlog, 3, ("  ulPinLen = %d", ulPinLen));
00825     nssdbg_start_time(FUNC_C_LOGIN,&start);
00826     rv = module_functions->C_Login(hSession,
00827                                  userType,
00828                                  pPin,
00829                                  ulPinLen);
00830     nssdbg_finish_time(FUNC_C_LOGIN,start);
00831     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00832     return rv;
00833 }
00834 
00835 CK_RV NSSDBGC_Logout(
00836   CK_SESSION_HANDLE hSession
00837 )
00838 {
00839     CK_RV rv;
00840     PRIntervalTime start;
00841     PR_LOG(modlog, 1, ("C_Logout"));
00842     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00843     nssdbg_start_time(FUNC_C_LOGOUT,&start);
00844     rv = module_functions->C_Logout(hSession);
00845     nssdbg_finish_time(FUNC_C_LOGOUT,start);
00846     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00847     return rv;
00848 }
00849 
00850 CK_RV NSSDBGC_CreateObject(
00851   CK_SESSION_HANDLE    hSession,
00852   CK_ATTRIBUTE_PTR     pTemplate,
00853   CK_ULONG             ulCount,
00854   CK_OBJECT_HANDLE_PTR phObject
00855 )
00856 {
00857     CK_RV rv;
00858     PRIntervalTime start;
00859     PR_LOG(modlog, 1, ("C_CreateObject"));
00860     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00861     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
00862     PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
00863     PR_LOG(modlog, 3, ("  phObject = 0x%p", phObject));
00864     print_template(pTemplate, ulCount);
00865     nssdbg_start_time(FUNC_C_CREATEOBJECT,&start);
00866     rv = module_functions->C_CreateObject(hSession,
00867                                  pTemplate,
00868                                  ulCount,
00869                                  phObject);
00870     nssdbg_finish_time(FUNC_C_CREATEOBJECT,start);
00871     PR_LOG(modlog, 4, ("  *phObject = 0x%x", *phObject));
00872     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00873     return rv;
00874 }
00875 
00876 CK_RV NSSDBGC_CopyObject(
00877   CK_SESSION_HANDLE    hSession,
00878   CK_OBJECT_HANDLE     hObject,
00879   CK_ATTRIBUTE_PTR     pTemplate,
00880   CK_ULONG             ulCount,
00881   CK_OBJECT_HANDLE_PTR phNewObject
00882 )
00883 {
00884     CK_RV rv;
00885     PRIntervalTime start;
00886     PR_LOG(modlog, 1, ("C_CopyObject"));
00887     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00888     PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
00889     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
00890     PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
00891     PR_LOG(modlog, 3, ("  phNewObject = 0x%p", phNewObject));
00892     print_template(pTemplate, ulCount);
00893     nssdbg_start_time(FUNC_C_COPYOBJECT,&start);
00894     rv = module_functions->C_CopyObject(hSession,
00895                                  hObject,
00896                                  pTemplate,
00897                                  ulCount,
00898                                  phNewObject);
00899     nssdbg_finish_time(FUNC_C_COPYOBJECT,start);
00900     PR_LOG(modlog, 4, ("  *phNewObject = 0x%x", *phNewObject));
00901     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00902     return rv;
00903 }
00904 
00905 CK_RV NSSDBGC_DestroyObject(
00906   CK_SESSION_HANDLE hSession,
00907   CK_OBJECT_HANDLE  hObject
00908 )
00909 {
00910     CK_RV rv;
00911     PRIntervalTime start;
00912     PR_LOG(modlog, 1, ("C_DestroyObject"));
00913     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00914     PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
00915     nssdbg_start_time(FUNC_C_DESTROYOBJECT,&start);
00916     rv = module_functions->C_DestroyObject(hSession,
00917                                  hObject);
00918     nssdbg_finish_time(FUNC_C_DESTROYOBJECT,start);
00919     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00920     return rv;
00921 }
00922 
00923 CK_RV NSSDBGC_GetObjectSize(
00924   CK_SESSION_HANDLE hSession,
00925   CK_OBJECT_HANDLE  hObject,
00926   CK_ULONG_PTR      pulSize
00927 )
00928 {
00929     CK_RV rv;
00930     PRIntervalTime start;
00931     PR_LOG(modlog, 1, ("C_GetObjectSize"));
00932     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00933     PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
00934     PR_LOG(modlog, 3, ("  pulSize = 0x%p", pulSize));
00935     nssdbg_start_time(FUNC_C_GETOBJECTSIZE,&start);
00936     rv = module_functions->C_GetObjectSize(hSession,
00937                                  hObject,
00938                                  pulSize);
00939     nssdbg_finish_time(FUNC_C_GETOBJECTSIZE,start);
00940     PR_LOG(modlog, 4, ("  *pulSize = 0x%x", *pulSize));
00941     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00942     return rv;
00943 }
00944 
00945 CK_RV NSSDBGC_GetAttributeValue(
00946   CK_SESSION_HANDLE hSession,
00947   CK_OBJECT_HANDLE  hObject,
00948   CK_ATTRIBUTE_PTR  pTemplate,
00949   CK_ULONG          ulCount
00950 )
00951 {
00952     CK_RV rv;
00953     PRIntervalTime start;
00954     PR_LOG(modlog, 1, ("C_GetAttributeValue"));
00955     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00956     PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
00957     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
00958     PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
00959     nssdbg_start_time(FUNC_C_GETATTRIBUTEVALUE,&start);
00960     rv = module_functions->C_GetAttributeValue(hSession,
00961                                  hObject,
00962                                  pTemplate,
00963                                  ulCount);
00964     nssdbg_finish_time(FUNC_C_GETATTRIBUTEVALUE,start);
00965     print_template(pTemplate, ulCount);
00966     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00967     return rv;
00968 }
00969 
00970 CK_RV NSSDBGC_SetAttributeValue(
00971   CK_SESSION_HANDLE hSession,
00972   CK_OBJECT_HANDLE  hObject,
00973   CK_ATTRIBUTE_PTR  pTemplate,
00974   CK_ULONG          ulCount
00975 )
00976 {
00977     CK_RV rv;
00978     PRIntervalTime start;
00979     PR_LOG(modlog, 1, ("C_SetAttributeValue"));
00980     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
00981     PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
00982     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
00983     PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
00984     print_template(pTemplate, ulCount);
00985     nssdbg_start_time(FUNC_C_SETATTRIBUTEVALUE,&start);
00986     rv = module_functions->C_SetAttributeValue(hSession,
00987                                  hObject,
00988                                  pTemplate,
00989                                  ulCount);
00990     nssdbg_finish_time(FUNC_C_SETATTRIBUTEVALUE,start);
00991     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
00992     return rv;
00993 }
00994 
00995 CK_RV NSSDBGC_FindObjectsInit(
00996   CK_SESSION_HANDLE hSession,
00997   CK_ATTRIBUTE_PTR  pTemplate,
00998   CK_ULONG          ulCount
00999 )
01000 {
01001     CK_RV rv;
01002     PRIntervalTime start;
01003     PR_LOG(modlog, 1, ("C_FindObjectsInit"));
01004     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01005     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
01006     PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
01007     print_template(pTemplate, ulCount);
01008     nssdbg_start_time(FUNC_C_FINDOBJECTSINIT,&start);
01009     rv = module_functions->C_FindObjectsInit(hSession,
01010                                  pTemplate,
01011                                  ulCount);
01012     nssdbg_finish_time(FUNC_C_FINDOBJECTSINIT,start);
01013     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01014     return rv;
01015 }
01016 
01017 CK_RV NSSDBGC_FindObjects(
01018   CK_SESSION_HANDLE    hSession,
01019   CK_OBJECT_HANDLE_PTR phObject,
01020   CK_ULONG             ulMaxObjectCount,
01021   CK_ULONG_PTR         pulObjectCount
01022 )
01023 {
01024     CK_RV rv;
01025     CK_ULONG i;
01026     PRIntervalTime start;
01027     PR_LOG(modlog, 1, ("C_FindObjects"));
01028     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01029     PR_LOG(modlog, 3, ("  phObject = 0x%p", phObject));
01030     PR_LOG(modlog, 3, ("  ulMaxObjectCount = %d", ulMaxObjectCount));
01031     PR_LOG(modlog, 3, ("  pulObjectCount = 0x%p", pulObjectCount));
01032     nssdbg_start_time(FUNC_C_FINDOBJECTS,&start);
01033     rv = module_functions->C_FindObjects(hSession,
01034                                  phObject,
01035                                  ulMaxObjectCount,
01036                                  pulObjectCount);
01037     nssdbg_finish_time(FUNC_C_FINDOBJECTS,start);
01038     PR_LOG(modlog, 4, ("  *pulObjectCount = 0x%x", *pulObjectCount));
01039     for (i=0; i<*pulObjectCount; i++) {
01040        PR_LOG(modlog, 4, ("  phObject[%d] = 0x%x", i, phObject[i]));
01041     }
01042     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01043     return rv;
01044 }
01045 
01046 CK_RV NSSDBGC_FindObjectsFinal(
01047   CK_SESSION_HANDLE hSession
01048 )
01049 {
01050     CK_RV rv;
01051     PRIntervalTime start;
01052     PR_LOG(modlog, 1, ("C_FindObjectsFinal"));
01053     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01054     nssdbg_start_time(FUNC_C_FINDOBJECTSFINAL,&start);
01055     rv = module_functions->C_FindObjectsFinal(hSession);
01056     nssdbg_finish_time(FUNC_C_FINDOBJECTSFINAL,start);
01057     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01058     return rv;
01059 }
01060 
01061 CK_RV NSSDBGC_EncryptInit(
01062   CK_SESSION_HANDLE hSession,
01063   CK_MECHANISM_PTR  pMechanism,
01064   CK_OBJECT_HANDLE  hKey
01065 )
01066 {
01067     CK_RV rv;
01068     PRIntervalTime start;
01069     PR_LOG(modlog, 1, ("C_EncryptInit"));
01070     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01071     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01072     PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
01073     print_mechanism(pMechanism);
01074     nssdbg_start_time(FUNC_C_ENCRYPTINIT,&start);
01075     rv = module_functions->C_EncryptInit(hSession,
01076                                  pMechanism,
01077                                  hKey);
01078     nssdbg_finish_time(FUNC_C_ENCRYPTINIT,start);
01079     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01080     return rv;
01081 }
01082 
01083 CK_RV NSSDBGC_Encrypt(
01084   CK_SESSION_HANDLE hSession,
01085   CK_BYTE_PTR       pData,
01086   CK_ULONG          ulDataLen,
01087   CK_BYTE_PTR       pEncryptedData,
01088   CK_ULONG_PTR      pulEncryptedDataLen
01089 )
01090 {
01091     CK_RV rv;
01092     PRIntervalTime start;
01093     PR_LOG(modlog, 1, ("C_Encrypt"));
01094     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01095     PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
01096     PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
01097     PR_LOG(modlog, 3, ("  pEncryptedData = 0x%p", pEncryptedData));
01098     PR_LOG(modlog, 3, ("  pulEncryptedDataLen = 0x%p", pulEncryptedDataLen));
01099     nssdbg_start_time(FUNC_C_ENCRYPT,&start);
01100     rv = module_functions->C_Encrypt(hSession,
01101                                  pData,
01102                                  ulDataLen,
01103                                  pEncryptedData,
01104                                  pulEncryptedDataLen);
01105     nssdbg_finish_time(FUNC_C_ENCRYPT,start);
01106     PR_LOG(modlog, 4, ("  *pulEncryptedDataLen = 0x%x", *pulEncryptedDataLen));
01107     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01108     return rv;
01109 }
01110 
01111 CK_RV NSSDBGC_EncryptUpdate(
01112   CK_SESSION_HANDLE hSession,
01113   CK_BYTE_PTR       pPart,
01114   CK_ULONG          ulPartLen,
01115   CK_BYTE_PTR       pEncryptedPart,
01116   CK_ULONG_PTR      pulEncryptedPartLen
01117 )
01118 {
01119     CK_RV rv;
01120     PRIntervalTime start;
01121     PR_LOG(modlog, 1, ("C_EncryptUpdate"));
01122     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01123     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01124     PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
01125     PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
01126     PR_LOG(modlog, 3, ("  pulEncryptedPartLen = 0x%p", pulEncryptedPartLen));
01127     nssdbg_start_time(FUNC_C_ENCRYPTUPDATE,&start);
01128     rv = module_functions->C_EncryptUpdate(hSession,
01129                                  pPart,
01130                                  ulPartLen,
01131                                  pEncryptedPart,
01132                                  pulEncryptedPartLen);
01133     nssdbg_finish_time(FUNC_C_ENCRYPTUPDATE,start);
01134     PR_LOG(modlog, 4, ("  *pulEncryptedPartLen = 0x%x", *pulEncryptedPartLen));
01135     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01136     return rv;
01137 }
01138 
01139 CK_RV NSSDBGC_EncryptFinal(
01140   CK_SESSION_HANDLE hSession,
01141   CK_BYTE_PTR       pLastEncryptedPart,
01142   CK_ULONG_PTR      pulLastEncryptedPartLen
01143 )
01144 {
01145     CK_RV rv;
01146     PRIntervalTime start;
01147     PR_LOG(modlog, 1, ("C_EncryptFinal"));
01148     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01149     PR_LOG(modlog, 3, ("  pLastEncryptedPart = 0x%p", pLastEncryptedPart));
01150     PR_LOG(modlog, 3, ("  pulLastEncryptedPartLen = 0x%p", pulLastEncryptedPartLen));
01151     nssdbg_start_time(FUNC_C_ENCRYPTFINAL,&start);
01152     rv = module_functions->C_EncryptFinal(hSession,
01153                                  pLastEncryptedPart,
01154                                  pulLastEncryptedPartLen);
01155     nssdbg_finish_time(FUNC_C_ENCRYPTFINAL,start);
01156     PR_LOG(modlog, 4, ("  *pulLastEncryptedPartLen = 0x%x", *pulLastEncryptedPartLen));
01157     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01158     return rv;
01159 }
01160 
01161 CK_RV NSSDBGC_DecryptInit(
01162   CK_SESSION_HANDLE hSession,
01163   CK_MECHANISM_PTR  pMechanism,
01164   CK_OBJECT_HANDLE  hKey
01165 )
01166 {
01167     CK_RV rv;
01168     PRIntervalTime start;
01169     PR_LOG(modlog, 1, ("C_DecryptInit"));
01170     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01171     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01172     PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
01173     print_mechanism(pMechanism);
01174     nssdbg_start_time(FUNC_C_DECRYPTINIT,&start);
01175     rv = module_functions->C_DecryptInit(hSession,
01176                                  pMechanism,
01177                                  hKey);
01178     nssdbg_finish_time(FUNC_C_DECRYPTINIT,start);
01179     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01180     return rv;
01181 }
01182 
01183 CK_RV NSSDBGC_Decrypt(
01184   CK_SESSION_HANDLE hSession,
01185   CK_BYTE_PTR       pEncryptedData,
01186   CK_ULONG          ulEncryptedDataLen,
01187   CK_BYTE_PTR       pData,
01188   CK_ULONG_PTR      pulDataLen
01189 )
01190 {
01191     CK_RV rv;
01192     PRIntervalTime start;
01193     PR_LOG(modlog, 1, ("C_Decrypt"));
01194     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01195     PR_LOG(modlog, 3, ("  pEncryptedData = 0x%p", pEncryptedData));
01196     PR_LOG(modlog, 3, ("  ulEncryptedDataLen = %d", ulEncryptedDataLen));
01197     PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
01198     PR_LOG(modlog, 3, ("  pulDataLen = 0x%p", pulDataLen));
01199     nssdbg_start_time(FUNC_C_DECRYPT,&start);
01200     rv = module_functions->C_Decrypt(hSession,
01201                                  pEncryptedData,
01202                                  ulEncryptedDataLen,
01203                                  pData,
01204                                  pulDataLen);
01205     nssdbg_finish_time(FUNC_C_DECRYPT,start);
01206     PR_LOG(modlog, 4, ("  *pulDataLen = 0x%x", *pulDataLen));
01207     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01208     return rv;
01209 }
01210 
01211 CK_RV NSSDBGC_DecryptUpdate(
01212   CK_SESSION_HANDLE hSession,
01213   CK_BYTE_PTR       pEncryptedPart,
01214   CK_ULONG          ulEncryptedPartLen,
01215   CK_BYTE_PTR       pPart,
01216   CK_ULONG_PTR      pulPartLen
01217 )
01218 {
01219     CK_RV rv;
01220     PRIntervalTime start;
01221     PR_LOG(modlog, 1, ("C_DecryptUpdate"));
01222     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01223     PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
01224     PR_LOG(modlog, 3, ("  ulEncryptedPartLen = %d", ulEncryptedPartLen));
01225     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01226     PR_LOG(modlog, 3, ("  pulPartLen = 0x%p", pulPartLen));
01227     nssdbg_start_time(FUNC_C_DECRYPTUPDATE,&start);
01228     rv = module_functions->C_DecryptUpdate(hSession,
01229                                  pEncryptedPart,
01230                                  ulEncryptedPartLen,
01231                                  pPart,
01232                                  pulPartLen);
01233     nssdbg_finish_time(FUNC_C_DECRYPTUPDATE,start);
01234     PR_LOG(modlog, 4, ("  *pulPartLen = 0x%x", *pulPartLen));
01235     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01236     return rv;
01237 }
01238 
01239 CK_RV NSSDBGC_DecryptFinal(
01240   CK_SESSION_HANDLE hSession,
01241   CK_BYTE_PTR       pLastPart,
01242   CK_ULONG_PTR      pulLastPartLen
01243 )
01244 {
01245     CK_RV rv;
01246     PRIntervalTime start;
01247     PR_LOG(modlog, 1, ("C_DecryptFinal"));
01248     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01249     PR_LOG(modlog, 3, ("  pLastPart = 0x%p", pLastPart));
01250     PR_LOG(modlog, 3, ("  pulLastPartLen = 0x%p", pulLastPartLen));
01251     nssdbg_start_time(FUNC_C_DECRYPTFINAL,&start);
01252     rv = module_functions->C_DecryptFinal(hSession,
01253                                  pLastPart,
01254                                  pulLastPartLen);
01255     nssdbg_finish_time(FUNC_C_DECRYPTFINAL,start);
01256     PR_LOG(modlog, 4, ("  *pulLastPartLen = 0x%x", *pulLastPartLen));
01257     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01258     return rv;
01259 }
01260 
01261 CK_RV NSSDBGC_DigestInit(
01262   CK_SESSION_HANDLE hSession,
01263   CK_MECHANISM_PTR  pMechanism
01264 )
01265 {
01266     CK_RV rv;
01267     PRIntervalTime start;
01268     PR_LOG(modlog, 1, ("C_DigestInit"));
01269     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01270     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01271     print_mechanism(pMechanism);
01272     nssdbg_start_time(FUNC_C_DIGESTINIT,&start);
01273     rv = module_functions->C_DigestInit(hSession,
01274                                  pMechanism);
01275     nssdbg_finish_time(FUNC_C_DIGESTINIT,start);
01276     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01277     return rv;
01278 }
01279 
01280 CK_RV NSSDBGC_Digest(
01281   CK_SESSION_HANDLE hSession,
01282   CK_BYTE_PTR       pData,
01283   CK_ULONG          ulDataLen,
01284   CK_BYTE_PTR       pDigest,
01285   CK_ULONG_PTR      pulDigestLen
01286 )
01287 {
01288     CK_RV rv;
01289     PRIntervalTime start;
01290     PR_LOG(modlog, 1, ("C_Digest"));
01291     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01292     PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
01293     PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
01294     PR_LOG(modlog, 3, ("  pDigest = 0x%p", pDigest));
01295     PR_LOG(modlog, 3, ("  pulDigestLen = 0x%p", pulDigestLen));
01296     nssdbg_start_time(FUNC_C_DIGEST,&start);
01297     rv = module_functions->C_Digest(hSession,
01298                                  pData,
01299                                  ulDataLen,
01300                                  pDigest,
01301                                  pulDigestLen);
01302     nssdbg_finish_time(FUNC_C_DIGEST,start);
01303     PR_LOG(modlog, 4, ("  *pulDigestLen = 0x%x", *pulDigestLen));
01304     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01305     return rv;
01306 }
01307 
01308 CK_RV NSSDBGC_DigestUpdate(
01309   CK_SESSION_HANDLE hSession,
01310   CK_BYTE_PTR       pPart,
01311   CK_ULONG          ulPartLen
01312 )
01313 {
01314     CK_RV rv;
01315     PRIntervalTime start;
01316     PR_LOG(modlog, 1, ("C_DigestUpdate"));
01317     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01318     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01319     PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
01320     nssdbg_start_time(FUNC_C_DIGESTUPDATE,&start);
01321     rv = module_functions->C_DigestUpdate(hSession,
01322                                  pPart,
01323                                  ulPartLen);
01324     nssdbg_finish_time(FUNC_C_DIGESTUPDATE,start);
01325     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01326     return rv;
01327 }
01328 
01329 CK_RV NSSDBGC_DigestKey(
01330   CK_SESSION_HANDLE hSession,
01331   CK_OBJECT_HANDLE  hKey
01332 )
01333 {
01334     CK_RV rv;
01335     PRIntervalTime start;
01336     PR_LOG(modlog, 1, ("C_DigestKey"));
01337     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01338     nssdbg_start_time(FUNC_C_DIGESTKEY,&start);
01339     rv = module_functions->C_DigestKey(hSession,
01340                                  hKey);
01341     nssdbg_finish_time(FUNC_C_DIGESTKEY,start);
01342     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01343     return rv;
01344 }
01345 
01346 CK_RV NSSDBGC_DigestFinal(
01347   CK_SESSION_HANDLE hSession,
01348   CK_BYTE_PTR       pDigest,
01349   CK_ULONG_PTR      pulDigestLen
01350 )
01351 {
01352     CK_RV rv;
01353     PRIntervalTime start;
01354     PR_LOG(modlog, 1, ("C_DigestFinal"));
01355     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01356     PR_LOG(modlog, 3, ("  pDigest = 0x%p", pDigest));
01357     PR_LOG(modlog, 3, ("  pulDigestLen = 0x%p", pulDigestLen));
01358     nssdbg_start_time(FUNC_C_DIGESTFINAL,&start);
01359     rv = module_functions->C_DigestFinal(hSession,
01360                                  pDigest,
01361                                  pulDigestLen);
01362     nssdbg_finish_time(FUNC_C_DIGESTFINAL,start);
01363     PR_LOG(modlog, 4, ("  *pulDigestLen = 0x%x", *pulDigestLen));
01364     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01365     return rv;
01366 }
01367 
01368 CK_RV NSSDBGC_SignInit(
01369   CK_SESSION_HANDLE hSession,
01370   CK_MECHANISM_PTR  pMechanism,
01371   CK_OBJECT_HANDLE  hKey
01372 )
01373 {
01374     CK_RV rv;
01375     PRIntervalTime start;
01376     PR_LOG(modlog, 1, ("C_SignInit"));
01377     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01378     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01379     PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
01380     print_mechanism(pMechanism);
01381     nssdbg_start_time(FUNC_C_SIGNINIT,&start);
01382     rv = module_functions->C_SignInit(hSession,
01383                                  pMechanism,
01384                                  hKey);
01385     nssdbg_finish_time(FUNC_C_SIGNINIT,start);
01386     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01387     return rv;
01388 }
01389 
01390 CK_RV NSSDBGC_Sign(
01391   CK_SESSION_HANDLE hSession,
01392   CK_BYTE_PTR       pData,
01393   CK_ULONG          ulDataLen,
01394   CK_BYTE_PTR       pSignature,
01395   CK_ULONG_PTR      pulSignatureLen
01396 )
01397 {
01398     CK_RV rv;
01399     PRIntervalTime start;
01400     PR_LOG(modlog, 1, ("C_Sign"));
01401     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01402     PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
01403     PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
01404     PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
01405     PR_LOG(modlog, 3, ("  pulSignatureLen = 0x%p", pulSignatureLen));
01406     nssdbg_start_time(FUNC_C_SIGN,&start);
01407     rv = module_functions->C_Sign(hSession,
01408                                  pData,
01409                                  ulDataLen,
01410                                  pSignature,
01411                                  pulSignatureLen);
01412     nssdbg_finish_time(FUNC_C_SIGN,start);
01413     PR_LOG(modlog, 4, ("  *pulSignatureLen = 0x%x", *pulSignatureLen));
01414     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01415     return rv;
01416 }
01417 
01418 CK_RV NSSDBGC_SignUpdate(
01419   CK_SESSION_HANDLE hSession,
01420   CK_BYTE_PTR       pPart,
01421   CK_ULONG          ulPartLen
01422 )
01423 {
01424     CK_RV rv;
01425     PRIntervalTime start;
01426     PR_LOG(modlog, 1, ("C_SignUpdate"));
01427     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01428     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01429     PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
01430     nssdbg_start_time(FUNC_C_SIGNUPDATE,&start);
01431     rv = module_functions->C_SignUpdate(hSession,
01432                                  pPart,
01433                                  ulPartLen);
01434     nssdbg_finish_time(FUNC_C_SIGNUPDATE,start);
01435     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01436     return rv;
01437 }
01438 
01439 CK_RV NSSDBGC_SignFinal(
01440   CK_SESSION_HANDLE hSession,
01441   CK_BYTE_PTR       pSignature,
01442   CK_ULONG_PTR      pulSignatureLen
01443 )
01444 {
01445     CK_RV rv;
01446     PRIntervalTime start;
01447     PR_LOG(modlog, 1, ("C_SignFinal"));
01448     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01449     PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
01450     PR_LOG(modlog, 3, ("  pulSignatureLen = 0x%p", pulSignatureLen));
01451     nssdbg_start_time(FUNC_C_SIGNFINAL,&start);
01452     rv = module_functions->C_SignFinal(hSession,
01453                                  pSignature,
01454                                  pulSignatureLen);
01455     nssdbg_finish_time(FUNC_C_SIGNFINAL,start);
01456     PR_LOG(modlog, 4, ("  *pulSignatureLen = 0x%x", *pulSignatureLen));
01457     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01458     return rv;
01459 }
01460 
01461 CK_RV NSSDBGC_SignRecoverInit(
01462   CK_SESSION_HANDLE hSession,
01463   CK_MECHANISM_PTR  pMechanism,
01464   CK_OBJECT_HANDLE  hKey
01465 )
01466 {
01467     CK_RV rv;
01468     PRIntervalTime start;
01469     PR_LOG(modlog, 1, ("C_SignRecoverInit"));
01470     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01471     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01472     PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
01473     print_mechanism(pMechanism);
01474     nssdbg_start_time(FUNC_C_SIGNRECOVERINIT,&start);
01475     rv = module_functions->C_SignRecoverInit(hSession,
01476                                  pMechanism,
01477                                  hKey);
01478     nssdbg_finish_time(FUNC_C_SIGNRECOVERINIT,start);
01479     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01480     return rv;
01481 }
01482 
01483 CK_RV NSSDBGC_SignRecover(
01484   CK_SESSION_HANDLE hSession,
01485   CK_BYTE_PTR       pData,
01486   CK_ULONG          ulDataLen,
01487   CK_BYTE_PTR       pSignature,
01488   CK_ULONG_PTR      pulSignatureLen
01489 )
01490 {
01491     CK_RV rv;
01492     PRIntervalTime start;
01493     PR_LOG(modlog, 1, ("C_SignRecover"));
01494     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01495     PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
01496     PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
01497     PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
01498     PR_LOG(modlog, 3, ("  pulSignatureLen = 0x%p", pulSignatureLen));
01499     nssdbg_start_time(FUNC_C_SIGNRECOVER,&start);
01500     rv = module_functions->C_SignRecover(hSession,
01501                                  pData,
01502                                  ulDataLen,
01503                                  pSignature,
01504                                  pulSignatureLen);
01505     nssdbg_finish_time(FUNC_C_SIGNRECOVER,start);
01506     PR_LOG(modlog, 4, ("  *pulSignatureLen = 0x%x", *pulSignatureLen));
01507     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01508     return rv;
01509 }
01510 
01511 CK_RV NSSDBGC_VerifyInit(
01512   CK_SESSION_HANDLE hSession,
01513   CK_MECHANISM_PTR  pMechanism,
01514   CK_OBJECT_HANDLE  hKey
01515 )
01516 {
01517     CK_RV rv;
01518     PRIntervalTime start;
01519     PR_LOG(modlog, 1, ("C_VerifyInit"));
01520     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01521     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01522     PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
01523     print_mechanism(pMechanism);
01524     nssdbg_start_time(FUNC_C_VERIFYINIT,&start);
01525     rv = module_functions->C_VerifyInit(hSession,
01526                                  pMechanism,
01527                                  hKey);
01528     nssdbg_finish_time(FUNC_C_VERIFYINIT,start);
01529     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01530     return rv;
01531 }
01532 
01533 CK_RV NSSDBGC_Verify(
01534   CK_SESSION_HANDLE hSession,
01535   CK_BYTE_PTR       pData,
01536   CK_ULONG          ulDataLen,
01537   CK_BYTE_PTR       pSignature,
01538   CK_ULONG          ulSignatureLen
01539 )
01540 {
01541     CK_RV rv;
01542     PRIntervalTime start;
01543     PR_LOG(modlog, 1, ("C_Verify"));
01544     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01545     PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
01546     PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
01547     PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
01548     PR_LOG(modlog, 3, ("  ulSignatureLen = %d", ulSignatureLen));
01549     nssdbg_start_time(FUNC_C_VERIFY,&start);
01550     rv = module_functions->C_Verify(hSession,
01551                                  pData,
01552                                  ulDataLen,
01553                                  pSignature,
01554                                  ulSignatureLen);
01555     nssdbg_finish_time(FUNC_C_VERIFY,start);
01556     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01557     return rv;
01558 }
01559 
01560 CK_RV NSSDBGC_VerifyUpdate(
01561   CK_SESSION_HANDLE hSession,
01562   CK_BYTE_PTR       pPart,
01563   CK_ULONG          ulPartLen
01564 )
01565 {
01566     CK_RV rv;
01567     PRIntervalTime start;
01568     PR_LOG(modlog, 1, ("C_VerifyUpdate"));
01569     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01570     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01571     PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
01572     nssdbg_start_time(FUNC_C_VERIFYUPDATE,&start);
01573     rv = module_functions->C_VerifyUpdate(hSession,
01574                                  pPart,
01575                                  ulPartLen);
01576     nssdbg_finish_time(FUNC_C_VERIFYUPDATE,start);
01577     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01578     return rv;
01579 }
01580 
01581 CK_RV NSSDBGC_VerifyFinal(
01582   CK_SESSION_HANDLE hSession,
01583   CK_BYTE_PTR       pSignature,
01584   CK_ULONG          ulSignatureLen
01585 )
01586 {
01587     CK_RV rv;
01588     PRIntervalTime start;
01589     PR_LOG(modlog, 1, ("C_VerifyFinal"));
01590     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01591     PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
01592     PR_LOG(modlog, 3, ("  ulSignatureLen = %d", ulSignatureLen));
01593     nssdbg_start_time(FUNC_C_VERIFYFINAL,&start);
01594     rv = module_functions->C_VerifyFinal(hSession,
01595                                  pSignature,
01596                                  ulSignatureLen);
01597     nssdbg_finish_time(FUNC_C_VERIFYFINAL,start);
01598     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01599     return rv;
01600 }
01601 
01602 CK_RV NSSDBGC_VerifyRecoverInit(
01603   CK_SESSION_HANDLE hSession,
01604   CK_MECHANISM_PTR  pMechanism,
01605   CK_OBJECT_HANDLE  hKey
01606 )
01607 {
01608     CK_RV rv;
01609     PRIntervalTime start;
01610     PR_LOG(modlog, 1, ("C_VerifyRecoverInit"));
01611     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01612     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01613     PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
01614     print_mechanism(pMechanism);
01615     nssdbg_start_time(FUNC_C_VERIFYRECOVERINIT,&start);
01616     rv = module_functions->C_VerifyRecoverInit(hSession,
01617                                  pMechanism,
01618                                  hKey);
01619     nssdbg_finish_time(FUNC_C_VERIFYRECOVERINIT,start);
01620     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01621     return rv;
01622 }
01623 
01624 CK_RV NSSDBGC_VerifyRecover(
01625   CK_SESSION_HANDLE hSession,
01626   CK_BYTE_PTR       pSignature,
01627   CK_ULONG          ulSignatureLen,
01628   CK_BYTE_PTR       pData,
01629   CK_ULONG_PTR      pulDataLen
01630 )
01631 {
01632     CK_RV rv;
01633     PRIntervalTime start;
01634     PR_LOG(modlog, 1, ("C_VerifyRecover"));
01635     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01636     PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
01637     PR_LOG(modlog, 3, ("  ulSignatureLen = %d", ulSignatureLen));
01638     PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
01639     PR_LOG(modlog, 3, ("  pulDataLen = 0x%p", pulDataLen));
01640     nssdbg_start_time(FUNC_C_VERIFYRECOVER,&start);
01641     rv = module_functions->C_VerifyRecover(hSession,
01642                                  pSignature,
01643                                  ulSignatureLen,
01644                                  pData,
01645                                  pulDataLen);
01646     nssdbg_finish_time(FUNC_C_VERIFYRECOVER,start);
01647     PR_LOG(modlog, 4, ("  *pulDataLen = 0x%x", *pulDataLen));
01648     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01649     return rv;
01650 }
01651 
01652 CK_RV NSSDBGC_DigestEncryptUpdate(
01653   CK_SESSION_HANDLE hSession,
01654   CK_BYTE_PTR       pPart,
01655   CK_ULONG          ulPartLen,
01656   CK_BYTE_PTR       pEncryptedPart,
01657   CK_ULONG_PTR      pulEncryptedPartLen
01658 )
01659 {
01660     CK_RV rv;
01661     PRIntervalTime start;
01662     PR_LOG(modlog, 1, ("C_DigestEncryptUpdate"));
01663     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01664     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01665     PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
01666     PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
01667     PR_LOG(modlog, 3, ("  pulEncryptedPartLen = 0x%p", pulEncryptedPartLen));
01668     nssdbg_start_time(FUNC_C_DIGESTENCRYPTUPDATE,&start);
01669     rv = module_functions->C_DigestEncryptUpdate(hSession,
01670                                  pPart,
01671                                  ulPartLen,
01672                                  pEncryptedPart,
01673                                  pulEncryptedPartLen);
01674     nssdbg_finish_time(FUNC_C_DIGESTENCRYPTUPDATE,start);
01675     PR_LOG(modlog, 4, ("  *pulEncryptedPartLen = 0x%x", *pulEncryptedPartLen));
01676     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01677     return rv;
01678 }
01679 
01680 CK_RV NSSDBGC_DecryptDigestUpdate(
01681   CK_SESSION_HANDLE hSession,
01682   CK_BYTE_PTR       pEncryptedPart,
01683   CK_ULONG          ulEncryptedPartLen,
01684   CK_BYTE_PTR       pPart,
01685   CK_ULONG_PTR      pulPartLen
01686 )
01687 {
01688     CK_RV rv;
01689     PRIntervalTime start;
01690     PR_LOG(modlog, 1, ("C_DecryptDigestUpdate"));
01691     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01692     PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
01693     PR_LOG(modlog, 3, ("  ulEncryptedPartLen = %d", ulEncryptedPartLen));
01694     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01695     PR_LOG(modlog, 3, ("  pulPartLen = 0x%p", pulPartLen));
01696     nssdbg_start_time(FUNC_C_DECRYPTDIGESTUPDATE,&start);
01697     rv = module_functions->C_DecryptDigestUpdate(hSession,
01698                                  pEncryptedPart,
01699                                  ulEncryptedPartLen,
01700                                  pPart,
01701                                  pulPartLen);
01702     nssdbg_finish_time(FUNC_C_DECRYPTDIGESTUPDATE,start);
01703     PR_LOG(modlog, 4, ("  *pulPartLen = 0x%x", *pulPartLen));
01704     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01705     return rv;
01706 }
01707 
01708 CK_RV NSSDBGC_SignEncryptUpdate(
01709   CK_SESSION_HANDLE hSession,
01710   CK_BYTE_PTR       pPart,
01711   CK_ULONG          ulPartLen,
01712   CK_BYTE_PTR       pEncryptedPart,
01713   CK_ULONG_PTR      pulEncryptedPartLen
01714 )
01715 {
01716     CK_RV rv;
01717     PRIntervalTime start;
01718     PR_LOG(modlog, 1, ("C_SignEncryptUpdate"));
01719     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01720     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01721     PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
01722     PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
01723     PR_LOG(modlog, 3, ("  pulEncryptedPartLen = 0x%p", pulEncryptedPartLen));
01724     nssdbg_start_time(FUNC_C_SIGNENCRYPTUPDATE,&start);
01725     rv = module_functions->C_SignEncryptUpdate(hSession,
01726                                  pPart,
01727                                  ulPartLen,
01728                                  pEncryptedPart,
01729                                  pulEncryptedPartLen);
01730     nssdbg_finish_time(FUNC_C_SIGNENCRYPTUPDATE,start);
01731     PR_LOG(modlog, 4, ("  *pulEncryptedPartLen = 0x%x", *pulEncryptedPartLen));
01732     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01733     return rv;
01734 }
01735 
01736 CK_RV NSSDBGC_DecryptVerifyUpdate(
01737   CK_SESSION_HANDLE hSession,
01738   CK_BYTE_PTR       pEncryptedPart,
01739   CK_ULONG          ulEncryptedPartLen,
01740   CK_BYTE_PTR       pPart,
01741   CK_ULONG_PTR      pulPartLen
01742 )
01743 {
01744     CK_RV rv;
01745     PRIntervalTime start;
01746     PR_LOG(modlog, 1, ("C_DecryptVerifyUpdate"));
01747     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01748     PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
01749     PR_LOG(modlog, 3, ("  ulEncryptedPartLen = %d", ulEncryptedPartLen));
01750     PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
01751     PR_LOG(modlog, 3, ("  pulPartLen = 0x%p", pulPartLen));
01752     nssdbg_start_time(FUNC_C_DECRYPTVERIFYUPDATE,&start);
01753     rv = module_functions->C_DecryptVerifyUpdate(hSession,
01754                                  pEncryptedPart,
01755                                  ulEncryptedPartLen,
01756                                  pPart,
01757                                  pulPartLen);
01758     nssdbg_finish_time(FUNC_C_DECRYPTVERIFYUPDATE,start);
01759     PR_LOG(modlog, 4, ("  *pulPartLen = 0x%x", *pulPartLen));
01760     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01761     return rv;
01762 }
01763 
01764 CK_RV NSSDBGC_GenerateKey(
01765   CK_SESSION_HANDLE    hSession,
01766   CK_MECHANISM_PTR     pMechanism,
01767   CK_ATTRIBUTE_PTR     pTemplate,
01768   CK_ULONG             ulCount,
01769   CK_OBJECT_HANDLE_PTR phKey
01770 )
01771 {
01772     CK_RV rv;
01773     PRIntervalTime start;
01774     PR_LOG(modlog, 1, ("C_GenerateKey"));
01775     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01776     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01777     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
01778     PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
01779     PR_LOG(modlog, 3, ("  phKey = 0x%p", phKey));
01780     print_template(pTemplate, ulCount);
01781     print_mechanism(pMechanism);
01782     nssdbg_start_time(FUNC_C_GENERATEKEY,&start);
01783     rv = module_functions->C_GenerateKey(hSession,
01784                                  pMechanism,
01785                                  pTemplate,
01786                                  ulCount,
01787                                  phKey);
01788     nssdbg_finish_time(FUNC_C_GENERATEKEY,start);
01789     PR_LOG(modlog, 4, ("  *phKey = 0x%x", *phKey));
01790     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01791     return rv;
01792 }
01793 
01794 CK_RV NSSDBGC_GenerateKeyPair(
01795   CK_SESSION_HANDLE    hSession,
01796   CK_MECHANISM_PTR     pMechanism,
01797   CK_ATTRIBUTE_PTR     pPublicKeyTemplate,
01798   CK_ULONG             ulPublicKeyAttributeCount,
01799   CK_ATTRIBUTE_PTR     pPrivateKeyTemplate,
01800   CK_ULONG             ulPrivateKeyAttributeCount,
01801   CK_OBJECT_HANDLE_PTR phPublicKey,
01802   CK_OBJECT_HANDLE_PTR phPrivateKey
01803 )
01804 {
01805     CK_RV rv;
01806     PRIntervalTime start;
01807     PR_LOG(modlog, 1, ("C_GenerateKeyPair"));
01808     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01809     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01810     PR_LOG(modlog, 3, ("  pPublicKeyTemplate = 0x%p", pPublicKeyTemplate));
01811     PR_LOG(modlog, 3, ("  ulPublicKeyAttributeCount = %d", ulPublicKeyAttributeCount));
01812     PR_LOG(modlog, 3, ("  pPrivateKeyTemplate = 0x%p", pPrivateKeyTemplate));
01813     PR_LOG(modlog, 3, ("  ulPrivateKeyAttributeCount = %d", ulPrivateKeyAttributeCount));
01814     PR_LOG(modlog, 3, ("  phPublicKey = 0x%p", phPublicKey));
01815     PR_LOG(modlog, 3, ("  phPrivateKey = 0x%p", phPrivateKey));
01816     print_template(pPublicKeyTemplate, ulPublicKeyAttributeCount);
01817     print_template(pPrivateKeyTemplate, ulPrivateKeyAttributeCount);
01818     print_mechanism(pMechanism);
01819     nssdbg_start_time(FUNC_C_GENERATEKEYPAIR,&start);
01820     rv = module_functions->C_GenerateKeyPair(hSession,
01821                                  pMechanism,
01822                                  pPublicKeyTemplate,
01823                                  ulPublicKeyAttributeCount,
01824                                  pPrivateKeyTemplate,
01825                                  ulPrivateKeyAttributeCount,
01826                                  phPublicKey,
01827                                  phPrivateKey);
01828     nssdbg_finish_time(FUNC_C_GENERATEKEYPAIR,start);
01829     PR_LOG(modlog, 4, ("  *phPublicKey = 0x%x", *phPublicKey));
01830     PR_LOG(modlog, 4, ("  *phPrivateKey = 0x%x", *phPrivateKey));
01831     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01832     return rv;
01833 }
01834 
01835 CK_RV NSSDBGC_WrapKey(
01836   CK_SESSION_HANDLE hSession,
01837   CK_MECHANISM_PTR  pMechanism,
01838   CK_OBJECT_HANDLE  hWrappingKey,
01839   CK_OBJECT_HANDLE  hKey,
01840   CK_BYTE_PTR       pWrappedKey,
01841   CK_ULONG_PTR      pulWrappedKeyLen
01842 )
01843 {
01844     CK_RV rv;
01845     PRIntervalTime start;
01846     PR_LOG(modlog, 1, ("C_WrapKey"));
01847     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01848     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01849     PR_LOG(modlog, 3, ("  hWrappingKey = 0x%x", hWrappingKey));
01850     PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
01851     PR_LOG(modlog, 3, ("  pWrappedKey = 0x%p", pWrappedKey));
01852     PR_LOG(modlog, 3, ("  pulWrappedKeyLen = 0x%p", pulWrappedKeyLen));
01853     print_mechanism(pMechanism);
01854     nssdbg_start_time(FUNC_C_WRAPKEY,&start);
01855     rv = module_functions->C_WrapKey(hSession,
01856                                  pMechanism,
01857                                  hWrappingKey,
01858                                  hKey,
01859                                  pWrappedKey,
01860                                  pulWrappedKeyLen);
01861     nssdbg_finish_time(FUNC_C_WRAPKEY,start);
01862     PR_LOG(modlog, 4, ("  *pulWrappedKeyLen = 0x%x", *pulWrappedKeyLen));
01863     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01864     return rv;
01865 }
01866 
01867 CK_RV NSSDBGC_UnwrapKey(
01868   CK_SESSION_HANDLE    hSession,
01869   CK_MECHANISM_PTR     pMechanism,
01870   CK_OBJECT_HANDLE     hUnwrappingKey,
01871   CK_BYTE_PTR          pWrappedKey,
01872   CK_ULONG             ulWrappedKeyLen,
01873   CK_ATTRIBUTE_PTR     pTemplate,
01874   CK_ULONG             ulAttributeCount,
01875   CK_OBJECT_HANDLE_PTR phKey
01876 )
01877 {
01878     CK_RV rv;
01879     PRIntervalTime start;
01880     PR_LOG(modlog, 1, ("C_UnwrapKey"));
01881     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01882     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01883     PR_LOG(modlog, 3, ("  hUnwrappingKey = 0x%x", hUnwrappingKey));
01884     PR_LOG(modlog, 3, ("  pWrappedKey = 0x%p", pWrappedKey));
01885     PR_LOG(modlog, 3, ("  ulWrappedKeyLen = %d", ulWrappedKeyLen));
01886     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
01887     PR_LOG(modlog, 3, ("  ulAttributeCount = %d", ulAttributeCount));
01888     PR_LOG(modlog, 3, ("  phKey = 0x%p", phKey));
01889     print_template(pTemplate, ulAttributeCount);
01890     print_mechanism(pMechanism);
01891     nssdbg_start_time(FUNC_C_UNWRAPKEY,&start);
01892     rv = module_functions->C_UnwrapKey(hSession,
01893                                  pMechanism,
01894                                  hUnwrappingKey,
01895                                  pWrappedKey,
01896                                  ulWrappedKeyLen,
01897                                  pTemplate,
01898                                  ulAttributeCount,
01899                                  phKey);
01900     nssdbg_finish_time(FUNC_C_UNWRAPKEY,start);
01901     PR_LOG(modlog, 4, ("  *phKey = 0x%x", *phKey));
01902     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01903     return rv;
01904 }
01905 
01906 CK_RV NSSDBGC_DeriveKey(
01907   CK_SESSION_HANDLE    hSession,
01908   CK_MECHANISM_PTR     pMechanism,
01909   CK_OBJECT_HANDLE     hBaseKey,
01910   CK_ATTRIBUTE_PTR     pTemplate,
01911   CK_ULONG             ulAttributeCount,
01912   CK_OBJECT_HANDLE_PTR phKey
01913 )
01914 {
01915     CK_RV rv;
01916     PRIntervalTime start;
01917     PR_LOG(modlog, 1, ("C_DeriveKey"));
01918     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01919     PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
01920     PR_LOG(modlog, 3, ("  hBaseKey = 0x%x", hBaseKey));
01921     PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
01922     PR_LOG(modlog, 3, ("  ulAttributeCount = %d", ulAttributeCount));
01923     PR_LOG(modlog, 3, ("  phKey = 0x%p", phKey));
01924     print_template(pTemplate, ulAttributeCount);
01925     print_mechanism(pMechanism);
01926     nssdbg_start_time(FUNC_C_DERIVEKEY,&start);
01927     rv = module_functions->C_DeriveKey(hSession,
01928                                  pMechanism,
01929                                  hBaseKey,
01930                                  pTemplate,
01931                                  ulAttributeCount,
01932                                  phKey);
01933     nssdbg_finish_time(FUNC_C_DERIVEKEY,start);
01934     PR_LOG(modlog, 4, ("  *phKey = 0x%x", *phKey));
01935     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01936     return rv;
01937 }
01938 
01939 CK_RV NSSDBGC_SeedRandom(
01940   CK_SESSION_HANDLE hSession,
01941   CK_BYTE_PTR       pSeed,
01942   CK_ULONG          ulSeedLen
01943 )
01944 {
01945     CK_RV rv;
01946     PRIntervalTime start;
01947     PR_LOG(modlog, 1, ("C_SeedRandom"));
01948     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01949     PR_LOG(modlog, 3, ("  pSeed = 0x%p", pSeed));
01950     PR_LOG(modlog, 3, ("  ulSeedLen = %d", ulSeedLen));
01951     nssdbg_start_time(FUNC_C_SEEDRANDOM,&start);
01952     rv = module_functions->C_SeedRandom(hSession,
01953                                  pSeed,
01954                                  ulSeedLen);
01955     nssdbg_finish_time(FUNC_C_SEEDRANDOM,start);
01956     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01957     return rv;
01958 }
01959 
01960 CK_RV NSSDBGC_GenerateRandom(
01961   CK_SESSION_HANDLE hSession,
01962   CK_BYTE_PTR       RandomData,
01963   CK_ULONG          ulRandomLen
01964 )
01965 {
01966     CK_RV rv;
01967     PRIntervalTime start;
01968     PR_LOG(modlog, 1, ("C_GenerateRandom"));
01969     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01970     PR_LOG(modlog, 3, ("  RandomData = 0x%p", RandomData));
01971     PR_LOG(modlog, 3, ("  ulRandomLen = %d", ulRandomLen));
01972     nssdbg_start_time(FUNC_C_GENERATERANDOM,&start);
01973     rv = module_functions->C_GenerateRandom(hSession,
01974                                  RandomData,
01975                                  ulRandomLen);
01976     nssdbg_finish_time(FUNC_C_GENERATERANDOM,start);
01977     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01978     return rv;
01979 }
01980 
01981 CK_RV NSSDBGC_GetFunctionStatus(
01982   CK_SESSION_HANDLE hSession
01983 )
01984 {
01985     CK_RV rv;
01986     PRIntervalTime start;
01987     PR_LOG(modlog, 1, ("C_GetFunctionStatus"));
01988     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
01989     nssdbg_start_time(FUNC_C_GETFUNCTIONSTATUS,&start);
01990     rv = module_functions->C_GetFunctionStatus(hSession);
01991     nssdbg_finish_time(FUNC_C_GETFUNCTIONSTATUS,start);
01992     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
01993     return rv;
01994 }
01995 
01996 CK_RV NSSDBGC_CancelFunction(
01997   CK_SESSION_HANDLE hSession
01998 )
01999 {
02000     CK_RV rv;
02001     PRIntervalTime start;
02002     PR_LOG(modlog, 1, ("C_CancelFunction"));
02003     PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
02004     nssdbg_start_time(FUNC_C_CANCELFUNCTION,&start);
02005     rv = module_functions->C_CancelFunction(hSession);
02006     nssdbg_finish_time(FUNC_C_CANCELFUNCTION,start);
02007     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
02008     return rv;
02009 }
02010 
02011 CK_RV NSSDBGC_WaitForSlotEvent(
02012   CK_FLAGS       flags,
02013   CK_SLOT_ID_PTR pSlot,
02014   CK_VOID_PTR    pRserved
02015 )
02016 {
02017     CK_RV rv;
02018     PRIntervalTime start;
02019     PR_LOG(modlog, 1, ("C_WaitForSlotEvent"));
02020     PR_LOG(modlog, 3, ("  flags = 0x%x", flags));
02021     PR_LOG(modlog, 3, ("  pSlot = 0x%p", pSlot));
02022     PR_LOG(modlog, 3, ("  pRserved = 0x%p", pRserved));
02023     nssdbg_start_time(FUNC_C_WAITFORSLOTEVENT,&start);
02024     rv = module_functions->C_WaitForSlotEvent(flags,
02025                                  pSlot,
02026                                  pRserved);
02027     nssdbg_finish_time(FUNC_C_WAITFORSLOTEVENT,start);
02028     PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
02029     return rv;
02030 }
02031 
02032 CK_FUNCTION_LIST_PTR nss_InsertDeviceLog(
02033   CK_FUNCTION_LIST_PTR devEPV
02034 )
02035 {
02036     module_functions = devEPV;
02037     modlog = PR_NewLogModule("nss_mod_log");
02038     debug_functions.C_Initialize = NSSDBGC_Initialize;
02039     debug_functions.C_Finalize = NSSDBGC_Finalize;
02040     debug_functions.C_GetInfo = NSSDBGC_GetInfo;
02041     debug_functions.C_GetFunctionList = NSSDBGC_GetFunctionList;
02042     debug_functions.C_GetSlotList = NSSDBGC_GetSlotList;
02043     debug_functions.C_GetSlotInfo = NSSDBGC_GetSlotInfo;
02044     debug_functions.C_GetTokenInfo = NSSDBGC_GetTokenInfo;
02045     debug_functions.C_GetMechanismList = NSSDBGC_GetMechanismList;
02046     debug_functions.C_GetMechanismInfo = NSSDBGC_GetMechanismInfo;
02047     debug_functions.C_InitToken = NSSDBGC_InitToken;
02048     debug_functions.C_InitPIN = NSSDBGC_InitPIN;
02049     debug_functions.C_SetPIN = NSSDBGC_SetPIN;
02050     debug_functions.C_OpenSession = NSSDBGC_OpenSession;
02051     debug_functions.C_CloseSession = NSSDBGC_CloseSession;
02052     debug_functions.C_CloseAllSessions = NSSDBGC_CloseAllSessions;
02053     debug_functions.C_GetSessionInfo = NSSDBGC_GetSessionInfo;
02054     debug_functions.C_GetOperationState = NSSDBGC_GetOperationState;
02055     debug_functions.C_SetOperationState = NSSDBGC_SetOperationState;
02056     debug_functions.C_Login = NSSDBGC_Login;
02057     debug_functions.C_Logout = NSSDBGC_Logout;
02058     debug_functions.C_CreateObject = NSSDBGC_CreateObject;
02059     debug_functions.C_CopyObject = NSSDBGC_CopyObject;
02060     debug_functions.C_DestroyObject = NSSDBGC_DestroyObject;
02061     debug_functions.C_GetObjectSize = NSSDBGC_GetObjectSize;
02062     debug_functions.C_GetAttributeValue = NSSDBGC_GetAttributeValue;
02063     debug_functions.C_SetAttributeValue = NSSDBGC_SetAttributeValue;
02064     debug_functions.C_FindObjectsInit = NSSDBGC_FindObjectsInit;
02065     debug_functions.C_FindObjects = NSSDBGC_FindObjects;
02066     debug_functions.C_FindObjectsFinal = NSSDBGC_FindObjectsFinal;
02067     debug_functions.C_EncryptInit = NSSDBGC_EncryptInit;
02068     debug_functions.C_Encrypt = NSSDBGC_Encrypt;
02069     debug_functions.C_EncryptUpdate = NSSDBGC_EncryptUpdate;
02070     debug_functions.C_EncryptFinal = NSSDBGC_EncryptFinal;
02071     debug_functions.C_DecryptInit = NSSDBGC_DecryptInit;
02072     debug_functions.C_Decrypt = NSSDBGC_Decrypt;
02073     debug_functions.C_DecryptUpdate = NSSDBGC_DecryptUpdate;
02074     debug_functions.C_DecryptFinal = NSSDBGC_DecryptFinal;
02075     debug_functions.C_DigestInit = NSSDBGC_DigestInit;
02076     debug_functions.C_Digest = NSSDBGC_Digest;
02077     debug_functions.C_DigestUpdate = NSSDBGC_DigestUpdate;
02078     debug_functions.C_DigestKey = NSSDBGC_DigestKey;
02079     debug_functions.C_DigestFinal = NSSDBGC_DigestFinal;
02080     debug_functions.C_SignInit = NSSDBGC_SignInit;
02081     debug_functions.C_Sign = NSSDBGC_Sign;
02082     debug_functions.C_SignUpdate = NSSDBGC_SignUpdate;
02083     debug_functions.C_SignFinal = NSSDBGC_SignFinal;
02084     debug_functions.C_SignRecoverInit = NSSDBGC_SignRecoverInit;
02085     debug_functions.C_SignRecover = NSSDBGC_SignRecover;
02086     debug_functions.C_VerifyInit = NSSDBGC_VerifyInit;
02087     debug_functions.C_Verify = NSSDBGC_Verify;
02088     debug_functions.C_VerifyUpdate = NSSDBGC_VerifyUpdate;
02089     debug_functions.C_VerifyFinal = NSSDBGC_VerifyFinal;
02090     debug_functions.C_VerifyRecoverInit = NSSDBGC_VerifyRecoverInit;
02091     debug_functions.C_VerifyRecover = NSSDBGC_VerifyRecover;
02092     debug_functions.C_DigestEncryptUpdate = NSSDBGC_DigestEncryptUpdate;
02093     debug_functions.C_DecryptDigestUpdate = NSSDBGC_DecryptDigestUpdate;
02094     debug_functions.C_SignEncryptUpdate = NSSDBGC_SignEncryptUpdate;
02095     debug_functions.C_DecryptVerifyUpdate = NSSDBGC_DecryptVerifyUpdate;
02096     debug_functions.C_GenerateKey = NSSDBGC_GenerateKey;
02097     debug_functions.C_GenerateKeyPair = NSSDBGC_GenerateKeyPair;
02098     debug_functions.C_WrapKey = NSSDBGC_WrapKey;
02099     debug_functions.C_UnwrapKey = NSSDBGC_UnwrapKey;
02100     debug_functions.C_DeriveKey = NSSDBGC_DeriveKey;
02101     debug_functions.C_SeedRandom = NSSDBGC_SeedRandom;
02102     debug_functions.C_GenerateRandom = NSSDBGC_GenerateRandom;
02103     debug_functions.C_GetFunctionStatus = NSSDBGC_GetFunctionStatus;
02104     debug_functions.C_CancelFunction = NSSDBGC_CancelFunction;
02105     debug_functions.C_WaitForSlotEvent = NSSDBGC_WaitForSlotEvent;
02106     return &debug_functions;
02107 }
02108 
02109 /*
02110  * scale the time factor up accordingly.
02111  * This routine tries to keep at least 2 significant figures on output.
02112  *    If the time is 0, then indicate that with a 'z' for units.
02113  *    If the time is greater than 10 minutes, output the time in minutes.
02114  *    If the time is less than 10 minutes but greater than 10 seconds output 
02115  * the time in second.
02116  *    If the time is less than 10 seconds but greater than 10 milliseconds 
02117  * output * the time in millisecond.
02118  *    If the time is less than 10 milliseconds but greater than 0 ticks output 
02119  * the time in microsecond.
02120  *
02121  */
02122 static PRUint32 getPrintTime(PRIntervalTime time ,char **type)
02123 {
02124        PRUint32 prTime;
02125 
02126         /* detect a programming error by outputting 'bu' to the output stream
02127         * rather than crashing */
02128        *type = "bug";
02129        if (time == 0) {
02130            *type = "z";
02131            return 0;
02132        }
02133 
02134        prTime = PR_IntervalToSeconds(time);
02135 
02136        if (prTime >= 600) {
02137            *type="m";
02138            return prTime/60;
02139        }
02140         if (prTime >= 10) {
02141            *type="s";
02142            return prTime;
02143        } 
02144        prTime = PR_IntervalToMilliseconds(time);
02145         if (prTime >= 10) {
02146            *type="ms";
02147            return prTime;
02148        } 
02149        *type = "us";
02150        return PR_IntervalToMicroseconds(time);
02151 }
02152 
02153 static void print_final_statistics(void)
02154 {
02155     int total_calls = 0;
02156     PRIntervalTime total_time = 0;
02157     PRUint32 pr_total_time;
02158     char *type;
02159     char *fname;
02160     FILE *outfile = NULL;
02161     int i;
02162 
02163     fname = PR_GetEnv("NSS_OUTPUT_FILE");
02164     if (fname) {
02165        /* need to add an optional process id to the filename */
02166        outfile = fopen(fname,"w+");
02167     }
02168     if (!outfile) {
02169        outfile = stdout;
02170     }
02171        
02172 
02173     fprintf(outfile,"%-25s %10s %12s %12s %10s\n", "Function", "# Calls", 
02174                             "Time", "Avg.", "% Time");
02175     fprintf(outfile,"\n");
02176     for (i=0; i < nssdbg_prof_size; i++) {
02177        total_calls += nssdbg_prof_data[i].calls;
02178        total_time += nssdbg_prof_data[i].time;
02179     }
02180     for (i=0; i < nssdbg_prof_size; i++) {
02181        PRIntervalTime time = nssdbg_prof_data[i].time;
02182        PRUint32 usTime = PR_IntervalToMicroseconds(time);
02183        PRUint32 prTime = 0;
02184        PRUint32 calls = nssdbg_prof_data[i].calls;
02185        /* don't print out functions that weren't even called */
02186        if (calls == 0) {
02187            continue;
02188        }
02189 
02190        prTime = getPrintTime(time,&type);
02191 
02192        fprintf(outfile,"%-25s %10d %10d%2s ", nssdbg_prof_data[i].function, 
02193                                           calls, prTime, type);
02194        /* for now always output the average in microseconds */
02195        fprintf(outfile,"%10.2f%2s", (float)usTime / (float)calls, "us" );
02196        fprintf(outfile,"%10.2f%%", ((float)time / (float)total_time) * 100);
02197        fprintf(outfile,"\n");
02198     }
02199     fprintf(outfile,"\n");
02200 
02201     pr_total_time = getPrintTime(total_time,&type);
02202 
02203     fprintf(outfile,"%25s %10d %10d%2s\n", "Totals", total_calls, 
02204                                                  pr_total_time, type);
02205     fprintf(outfile,"\n\nMaximum number of concurrent open sessions: %d\n\n",
02206                                                   maxOpenSessions);
02207     fflush (outfile);
02208     if (outfile != stdout) {
02209        fclose(outfile);
02210     }
02211 }
02212