PageRenderTime 108ms CodeModel.GetById 13ms app.highlight 83ms RepoModel.GetById 1ms app.codeStats 1ms

/security/nss/lib/pk11wrap/debug_module.c

http://github.com/zpao/v8monkey
C | 2765 lines | 2515 code | 191 blank | 59 comment | 69 complexity | 63f8023c3ca2eeba4114bd52dbfae15b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/* ***** BEGIN LICENSE BLOCK *****
   2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
   3 *
   4 * The contents of this file are subject to the Mozilla Public License Version
   5 * 1.1 (the "License"); you may not use this file except in compliance with
   6 * the License. You may obtain a copy of the License at
   7 * http://www.mozilla.org/MPL/
   8 *
   9 * Software distributed under the License is distributed on an "AS IS" basis,
  10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11 * for the specific language governing rights and limitations under the
  12 * License.
  13 *
  14 * The Original Code is the Netscape security libraries.
  15 *
  16 * The Initial Developer of the Original Code is
  17 * Netscape Communications Corporation.
  18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
  19 * the Initial Developer. All Rights Reserved.
  20 *
  21 * Contributor(s):
  22 *
  23 * Alternatively, the contents of this file may be used under the terms of
  24 * either the GNU General Public License Version 2 or later (the "GPL"), or
  25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26 * in which case the provisions of the GPL or the LGPL are applicable instead
  27 * of those above. If you wish to allow use of your version of this file only
  28 * under the terms of either the GPL or the LGPL, and not to allow others to
  29 * use your version of this file under the terms of the MPL, indicate your
  30 * decision by deleting the provisions above and replace them with the notice
  31 * and other provisions required by the GPL or the LGPL. If you do not delete
  32 * the provisions above, a recipient may use your version of this file under
  33 * the terms of any one of the MPL, the GPL or the LGPL.
  34 *
  35 * ***** END LICENSE BLOCK ***** */
  36#include "prlog.h"
  37#include <stdio.h>
  38#include "cert.h"  /* for CERT_DerNameToAscii & CERT_Hexify */
  39
  40static PRLogModuleInfo *modlog = NULL;
  41
  42static CK_FUNCTION_LIST_PTR module_functions;
  43
  44static CK_FUNCTION_LIST debug_functions;
  45
  46static void print_final_statistics(void);
  47
  48#define STRING static const char 
  49
  50STRING fmt_flags[]                = "  flags = 0x%x";
  51STRING fmt_hKey[]                 = "  hKey = 0x%x";
  52STRING fmt_hObject[]              = "  hObject = 0x%x";
  53STRING fmt_hSession[]             = "  hSession = 0x%x";
  54STRING fmt_manufacturerID[]       = "  manufacturerID = \"%.32s\"";
  55STRING fmt_pData[]                = "  pData = 0x%p";
  56STRING fmt_pDigest[]              = "  pDigest = 0x%p";
  57STRING fmt_pEncryptedData[]       = "  pEncryptedData = 0x%p";
  58STRING fmt_pEncryptedPart[]       = "  pEncryptedPart = 0x%p";
  59STRING fmt_pInfo[]                = "  pInfo = 0x%p";
  60STRING fmt_pMechanism[]           = "  pMechanism = 0x%p";
  61STRING fmt_pOperationState[]      = "  pOperationState = 0x%p";
  62STRING fmt_pPart[]                = "  pPart = 0x%p";
  63STRING fmt_pPin[]                 = "  pPin = 0x%p";
  64STRING fmt_pSignature[]           = "  pSignature = 0x%p";
  65STRING fmt_pTemplate[]            = "  pTemplate = 0x%p";
  66STRING fmt_pWrappedKey[]          = "  pWrappedKey = 0x%p";
  67STRING fmt_phKey[]                = "  phKey = 0x%p";
  68STRING fmt_phObject[]             = "  phObject = 0x%p";
  69STRING fmt_pulCount[]             = "  pulCount = 0x%p";
  70STRING fmt_pulDataLen[]           = "  pulDataLen = 0x%p";
  71STRING fmt_pulDigestLen[]         = "  pulDigestLen = 0x%p";
  72STRING fmt_pulEncryptedPartLen[]  = "  pulEncryptedPartLen = 0x%p";
  73STRING fmt_pulPartLen[]           = "  pulPartLen = 0x%p";
  74STRING fmt_pulSignatureLen[]      = "  pulSignatureLen = 0x%p";
  75STRING fmt_slotID[]               = "  slotID = 0x%x";
  76STRING fmt_sphKey[]               = "  *phKey = 0x%x";
  77STRING fmt_spulCount[]            = "  *pulCount = 0x%x";
  78STRING fmt_spulDataLen[]          = "  *pulDataLen = 0x%x";
  79STRING fmt_spulDigestLen[]        = "  *pulDigestLen = 0x%x";
  80STRING fmt_spulEncryptedPartLen[] = "  *pulEncryptedPartLen = 0x%x";
  81STRING fmt_spulPartLen[]          = "  *pulPartLen = 0x%x";
  82STRING fmt_spulSignatureLen[]     = "  *pulSignatureLen = 0x%x";
  83STRING fmt_ulAttributeCount[]     = "  ulAttributeCount = %d";
  84STRING fmt_ulCount[]              = "  ulCount = %d";
  85STRING fmt_ulDataLen[]            = "  ulDataLen = %d";
  86STRING fmt_ulEncryptedPartLen[]   = "  ulEncryptedPartLen = %d";
  87STRING fmt_ulPartLen[]            = "  ulPartLen = %d";
  88STRING fmt_ulPinLen[]             = "  ulPinLen = %d";
  89STRING fmt_ulSignatureLen[]       = "  ulSignatureLen = %d";
  90
  91STRING fmt_fwVersion[]            = "  firmware version: %d.%d";
  92STRING fmt_hwVersion[]            = "  hardware version: %d.%d";
  93STRING fmt_s_qsq_d[]              = "    %s = \"%s\" [%d]";
  94STRING fmt_s_s_d[]                = "    %s = %s [%d]";
  95STRING fmt_s_lu[]                 = "    %s = %lu";
  96STRING fmt_invalid_handle[]       = " (CK_INVALID_HANDLE)";
  97
  98
  99static void get_attr_type_str(CK_ATTRIBUTE_TYPE atype, char *str, int len)
 100{
 101#define CASE(attr) case attr: a = #attr ; break
 102
 103    const char * a = NULL;
 104
 105    switch (atype) {
 106    CASE(CKA_CLASS);
 107    CASE(CKA_TOKEN);
 108    CASE(CKA_PRIVATE);
 109    CASE(CKA_LABEL);
 110    CASE(CKA_APPLICATION);
 111    CASE(CKA_VALUE);
 112    CASE(CKA_OBJECT_ID);
 113    CASE(CKA_CERTIFICATE_TYPE);
 114    CASE(CKA_CERTIFICATE_CATEGORY);
 115    CASE(CKA_ISSUER);
 116    CASE(CKA_SERIAL_NUMBER);
 117    CASE(CKA_AC_ISSUER);
 118    CASE(CKA_OWNER);
 119    CASE(CKA_ATTR_TYPES);
 120    CASE(CKA_TRUSTED);
 121    CASE(CKA_KEY_TYPE);
 122    CASE(CKA_SUBJECT);
 123    CASE(CKA_ID);
 124    CASE(CKA_SENSITIVE);
 125    CASE(CKA_ENCRYPT);
 126    CASE(CKA_DECRYPT);
 127    CASE(CKA_WRAP);
 128    CASE(CKA_UNWRAP);
 129    CASE(CKA_SIGN);
 130    CASE(CKA_SIGN_RECOVER);
 131    CASE(CKA_VERIFY);
 132    CASE(CKA_VERIFY_RECOVER);
 133    CASE(CKA_DERIVE);
 134    CASE(CKA_START_DATE);
 135    CASE(CKA_END_DATE);
 136    CASE(CKA_MODULUS);
 137    CASE(CKA_MODULUS_BITS);
 138    CASE(CKA_PUBLIC_EXPONENT);
 139    CASE(CKA_PRIVATE_EXPONENT);
 140    CASE(CKA_PRIME_1);
 141    CASE(CKA_PRIME_2);
 142    CASE(CKA_EXPONENT_1);
 143    CASE(CKA_EXPONENT_2);
 144    CASE(CKA_COEFFICIENT);
 145    CASE(CKA_PRIME);
 146    CASE(CKA_SUBPRIME);
 147    CASE(CKA_BASE);
 148    CASE(CKA_PRIME_BITS);
 149    CASE(CKA_SUBPRIME_BITS);
 150    CASE(CKA_VALUE_BITS);
 151    CASE(CKA_VALUE_LEN);
 152    CASE(CKA_EXTRACTABLE);
 153    CASE(CKA_LOCAL);
 154    CASE(CKA_NEVER_EXTRACTABLE);
 155    CASE(CKA_ALWAYS_SENSITIVE);
 156    CASE(CKA_KEY_GEN_MECHANISM);
 157    CASE(CKA_MODIFIABLE);
 158    CASE(CKA_ECDSA_PARAMS);
 159    CASE(CKA_EC_POINT);
 160    CASE(CKA_SECONDARY_AUTH);
 161    CASE(CKA_AUTH_PIN_FLAGS);
 162    CASE(CKA_HW_FEATURE_TYPE);
 163    CASE(CKA_RESET_ON_INIT);
 164    CASE(CKA_HAS_RESET);
 165    CASE(CKA_VENDOR_DEFINED);
 166    CASE(CKA_NSS_URL);
 167    CASE(CKA_NSS_EMAIL);
 168    CASE(CKA_NSS_SMIME_INFO);
 169    CASE(CKA_NSS_SMIME_TIMESTAMP);
 170    CASE(CKA_NSS_PKCS8_SALT);
 171    CASE(CKA_NSS_PASSWORD_CHECK);
 172    CASE(CKA_NSS_EXPIRES);
 173    CASE(CKA_NSS_KRL);
 174    CASE(CKA_NSS_PQG_COUNTER);
 175    CASE(CKA_NSS_PQG_SEED);
 176    CASE(CKA_NSS_PQG_H);
 177    CASE(CKA_NSS_PQG_SEED_BITS);
 178    CASE(CKA_TRUST);
 179    CASE(CKA_TRUST_DIGITAL_SIGNATURE);
 180    CASE(CKA_TRUST_NON_REPUDIATION);
 181    CASE(CKA_TRUST_KEY_ENCIPHERMENT);
 182    CASE(CKA_TRUST_DATA_ENCIPHERMENT);
 183    CASE(CKA_TRUST_KEY_AGREEMENT);
 184    CASE(CKA_TRUST_KEY_CERT_SIGN);
 185    CASE(CKA_TRUST_CRL_SIGN);
 186    CASE(CKA_TRUST_SERVER_AUTH);
 187    CASE(CKA_TRUST_CLIENT_AUTH);
 188    CASE(CKA_TRUST_CODE_SIGNING);
 189    CASE(CKA_TRUST_EMAIL_PROTECTION);
 190    CASE(CKA_TRUST_IPSEC_END_SYSTEM);
 191    CASE(CKA_TRUST_IPSEC_TUNNEL);
 192    CASE(CKA_TRUST_IPSEC_USER);
 193    CASE(CKA_TRUST_TIME_STAMPING);
 194    CASE(CKA_CERT_SHA1_HASH);
 195    CASE(CKA_CERT_MD5_HASH);
 196    CASE(CKA_NETSCAPE_DB);
 197    CASE(CKA_NETSCAPE_TRUST);
 198    default: break;
 199    }
 200    if (a)
 201	PR_snprintf(str, len, "%s", a);
 202    else
 203	PR_snprintf(str, len, "0x%p", atype);
 204}
 205
 206static void get_obj_class(CK_OBJECT_CLASS objClass, char *str, int len)
 207{
 208
 209    const char * a = NULL;
 210
 211    switch (objClass) {
 212    CASE(CKO_DATA);
 213    CASE(CKO_CERTIFICATE);
 214    CASE(CKO_PUBLIC_KEY);
 215    CASE(CKO_PRIVATE_KEY);
 216    CASE(CKO_SECRET_KEY);
 217    CASE(CKO_HW_FEATURE);
 218    CASE(CKO_DOMAIN_PARAMETERS);
 219    CASE(CKO_NSS_CRL);
 220    CASE(CKO_NSS_SMIME);
 221    CASE(CKO_NSS_TRUST);
 222    CASE(CKO_NSS_BUILTIN_ROOT_LIST);
 223    default: break;
 224    }
 225    if (a)
 226	PR_snprintf(str, len, "%s", a);
 227    else
 228	PR_snprintf(str, len, "0x%p", objClass);
 229}
 230
 231static void get_trust_val(CK_TRUST trust, char *str, int len)
 232{
 233    const char * a = NULL;
 234
 235    switch (trust) {
 236    CASE(CKT_NSS_TRUSTED);
 237    CASE(CKT_NSS_TRUSTED_DELEGATOR);
 238    CASE(CKT_NSS_NOT_TRUSTED);
 239    CASE(CKT_NSS_MUST_VERIFY_TRUST);
 240    CASE(CKT_NSS_TRUST_UNKNOWN);
 241    CASE(CKT_NSS_VALID_DELEGATOR);
 242    default: break;
 243    }
 244    if (a)
 245	PR_snprintf(str, len, "%s", a);
 246    else
 247	PR_snprintf(str, len, "0x%p", trust);
 248}
 249
 250static void log_rv(CK_RV rv)
 251{
 252    const char * a = NULL;
 253
 254    switch (rv) {
 255    CASE(CKR_OK);
 256    CASE(CKR_CANCEL);
 257    CASE(CKR_HOST_MEMORY);
 258    CASE(CKR_SLOT_ID_INVALID);
 259    CASE(CKR_GENERAL_ERROR);
 260    CASE(CKR_FUNCTION_FAILED);
 261    CASE(CKR_ARGUMENTS_BAD);
 262    CASE(CKR_NO_EVENT);
 263    CASE(CKR_NEED_TO_CREATE_THREADS);
 264    CASE(CKR_CANT_LOCK);
 265    CASE(CKR_ATTRIBUTE_READ_ONLY);
 266    CASE(CKR_ATTRIBUTE_SENSITIVE);
 267    CASE(CKR_ATTRIBUTE_TYPE_INVALID);
 268    CASE(CKR_ATTRIBUTE_VALUE_INVALID);
 269    CASE(CKR_DATA_INVALID);
 270    CASE(CKR_DATA_LEN_RANGE);
 271    CASE(CKR_DEVICE_ERROR);
 272    CASE(CKR_DEVICE_MEMORY);
 273    CASE(CKR_DEVICE_REMOVED);
 274    CASE(CKR_ENCRYPTED_DATA_INVALID);
 275    CASE(CKR_ENCRYPTED_DATA_LEN_RANGE);
 276    CASE(CKR_FUNCTION_CANCELED);
 277    CASE(CKR_FUNCTION_NOT_PARALLEL);
 278    CASE(CKR_FUNCTION_NOT_SUPPORTED);
 279    CASE(CKR_KEY_HANDLE_INVALID);
 280    CASE(CKR_KEY_SIZE_RANGE);
 281    CASE(CKR_KEY_TYPE_INCONSISTENT);
 282    CASE(CKR_KEY_NOT_NEEDED);
 283    CASE(CKR_KEY_CHANGED);
 284    CASE(CKR_KEY_NEEDED);
 285    CASE(CKR_KEY_INDIGESTIBLE);
 286    CASE(CKR_KEY_FUNCTION_NOT_PERMITTED);
 287    CASE(CKR_KEY_NOT_WRAPPABLE);
 288    CASE(CKR_KEY_UNEXTRACTABLE);
 289    CASE(CKR_MECHANISM_INVALID);
 290    CASE(CKR_MECHANISM_PARAM_INVALID);
 291    CASE(CKR_OBJECT_HANDLE_INVALID);
 292    CASE(CKR_OPERATION_ACTIVE);
 293    CASE(CKR_OPERATION_NOT_INITIALIZED);
 294    CASE(CKR_PIN_INCORRECT);
 295    CASE(CKR_PIN_INVALID);
 296    CASE(CKR_PIN_LEN_RANGE);
 297    CASE(CKR_PIN_EXPIRED);
 298    CASE(CKR_PIN_LOCKED);
 299    CASE(CKR_SESSION_CLOSED);
 300    CASE(CKR_SESSION_COUNT);
 301    CASE(CKR_SESSION_HANDLE_INVALID);
 302    CASE(CKR_SESSION_PARALLEL_NOT_SUPPORTED);
 303    CASE(CKR_SESSION_READ_ONLY);
 304    CASE(CKR_SESSION_EXISTS);
 305    CASE(CKR_SESSION_READ_ONLY_EXISTS);
 306    CASE(CKR_SESSION_READ_WRITE_SO_EXISTS);
 307    CASE(CKR_SIGNATURE_INVALID);
 308    CASE(CKR_SIGNATURE_LEN_RANGE);
 309    CASE(CKR_TEMPLATE_INCOMPLETE);
 310    CASE(CKR_TEMPLATE_INCONSISTENT);
 311    CASE(CKR_TOKEN_NOT_PRESENT);
 312    CASE(CKR_TOKEN_NOT_RECOGNIZED);
 313    CASE(CKR_TOKEN_WRITE_PROTECTED);
 314    CASE(CKR_UNWRAPPING_KEY_HANDLE_INVALID);
 315    CASE(CKR_UNWRAPPING_KEY_SIZE_RANGE);
 316    CASE(CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT);
 317    CASE(CKR_USER_ALREADY_LOGGED_IN);
 318    CASE(CKR_USER_NOT_LOGGED_IN);
 319    CASE(CKR_USER_PIN_NOT_INITIALIZED);
 320    CASE(CKR_USER_TYPE_INVALID);
 321    CASE(CKR_USER_ANOTHER_ALREADY_LOGGED_IN);
 322    CASE(CKR_USER_TOO_MANY_TYPES);
 323    CASE(CKR_WRAPPED_KEY_INVALID);
 324    CASE(CKR_WRAPPED_KEY_LEN_RANGE);
 325    CASE(CKR_WRAPPING_KEY_HANDLE_INVALID);
 326    CASE(CKR_WRAPPING_KEY_SIZE_RANGE);
 327    CASE(CKR_WRAPPING_KEY_TYPE_INCONSISTENT);
 328    CASE(CKR_RANDOM_SEED_NOT_SUPPORTED);
 329    CASE(CKR_RANDOM_NO_RNG);
 330    CASE(CKR_DOMAIN_PARAMS_INVALID);
 331    CASE(CKR_BUFFER_TOO_SMALL);
 332    CASE(CKR_SAVED_STATE_INVALID);
 333    CASE(CKR_INFORMATION_SENSITIVE);
 334    CASE(CKR_STATE_UNSAVEABLE);
 335    CASE(CKR_CRYPTOKI_NOT_INITIALIZED);
 336    CASE(CKR_CRYPTOKI_ALREADY_INITIALIZED);
 337    CASE(CKR_MUTEX_BAD);
 338    CASE(CKR_MUTEX_NOT_LOCKED);
 339    CASE(CKR_FUNCTION_REJECTED);
 340    CASE(CKR_KEY_PARAMS_INVALID);
 341    default: break;
 342    }
 343    if (a)
 344	PR_LOG(modlog, 1, ("  rv = %s\n", a));
 345    else
 346	PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
 347}
 348
 349static void log_state(CK_STATE state)
 350{
 351    const char * a = NULL;
 352
 353    switch (state) {
 354    CASE(CKS_RO_PUBLIC_SESSION);
 355    CASE(CKS_RO_USER_FUNCTIONS);
 356    CASE(CKS_RW_PUBLIC_SESSION);
 357    CASE(CKS_RW_USER_FUNCTIONS);
 358    CASE(CKS_RW_SO_FUNCTIONS);
 359    default: break;
 360    }
 361    if (a)
 362	PR_LOG(modlog, 1, ("  state = %s\n", a));
 363    else
 364	PR_LOG(modlog, 1, ("  state = 0x%x\n", state));
 365}
 366
 367static void log_handle(int level, const char * format, CK_ULONG handle)
 368{
 369    char fmtBuf[80];
 370    if (handle)
 371	PR_LOG(modlog, level, (format, handle));
 372    else {
 373	PL_strncpyz(fmtBuf, format, sizeof fmtBuf);
 374	PL_strcatn(fmtBuf, sizeof fmtBuf, fmt_invalid_handle);
 375	PR_LOG(modlog, level, (fmtBuf, handle));
 376    }
 377}
 378
 379static void print_mechanism(CK_MECHANISM_PTR m)
 380{
 381
 382    const char * a = NULL;
 383
 384    switch (m->mechanism) {
 385    CASE(CKM_AES_CBC);
 386    CASE(CKM_AES_CBC_ENCRYPT_DATA);
 387    CASE(CKM_AES_CBC_PAD);
 388    CASE(CKM_AES_ECB);
 389    CASE(CKM_AES_ECB_ENCRYPT_DATA);
 390    CASE(CKM_AES_KEY_GEN);
 391    CASE(CKM_AES_MAC);
 392    CASE(CKM_AES_MAC_GENERAL);
 393    CASE(CKM_CAMELLIA_CBC);
 394    CASE(CKM_CAMELLIA_CBC_ENCRYPT_DATA);
 395    CASE(CKM_CAMELLIA_CBC_PAD);
 396    CASE(CKM_CAMELLIA_ECB);
 397    CASE(CKM_CAMELLIA_ECB_ENCRYPT_DATA);
 398    CASE(CKM_CAMELLIA_KEY_GEN);
 399    CASE(CKM_CAMELLIA_MAC);
 400    CASE(CKM_CAMELLIA_MAC_GENERAL);
 401    CASE(CKM_CDMF_CBC);
 402    CASE(CKM_CDMF_CBC_PAD);
 403    CASE(CKM_CDMF_ECB);
 404    CASE(CKM_CDMF_KEY_GEN);
 405    CASE(CKM_CDMF_MAC);
 406    CASE(CKM_CDMF_MAC_GENERAL);
 407    CASE(CKM_CMS_SIG);
 408    CASE(CKM_CONCATENATE_BASE_AND_DATA);
 409    CASE(CKM_CONCATENATE_BASE_AND_KEY);
 410    CASE(CKM_CONCATENATE_DATA_AND_BASE);
 411    CASE(CKM_DES2_KEY_GEN);
 412    CASE(CKM_DES3_CBC);
 413    CASE(CKM_DES3_CBC_ENCRYPT_DATA);
 414    CASE(CKM_DES3_CBC_PAD);
 415    CASE(CKM_DES3_ECB);
 416    CASE(CKM_DES3_ECB_ENCRYPT_DATA);
 417    CASE(CKM_DES3_KEY_GEN);
 418    CASE(CKM_DES3_MAC);
 419    CASE(CKM_DES3_MAC_GENERAL);
 420    CASE(CKM_DES_CBC);
 421    CASE(CKM_DES_CBC_ENCRYPT_DATA);
 422    CASE(CKM_DES_CBC_PAD);
 423    CASE(CKM_DES_CFB64);
 424    CASE(CKM_DES_CFB8);
 425    CASE(CKM_DES_ECB);
 426    CASE(CKM_DES_ECB_ENCRYPT_DATA);
 427    CASE(CKM_DES_KEY_GEN);
 428    CASE(CKM_DES_MAC);
 429    CASE(CKM_DES_MAC_GENERAL);
 430    CASE(CKM_DES_OFB64);
 431    CASE(CKM_DES_OFB8);
 432    CASE(CKM_DH_PKCS_DERIVE);
 433    CASE(CKM_DH_PKCS_KEY_PAIR_GEN);
 434    CASE(CKM_DH_PKCS_PARAMETER_GEN);
 435    CASE(CKM_DSA);
 436    CASE(CKM_DSA_KEY_PAIR_GEN);
 437    CASE(CKM_DSA_PARAMETER_GEN);
 438    CASE(CKM_DSA_SHA1);
 439    CASE(CKM_ECDH1_COFACTOR_DERIVE);
 440    CASE(CKM_ECDH1_DERIVE);
 441    CASE(CKM_ECDSA);
 442    CASE(CKM_ECDSA_SHA1);
 443    CASE(CKM_ECMQV_DERIVE);
 444    CASE(CKM_EC_KEY_PAIR_GEN);	     /* also CASE(CKM_ECDSA_KEY_PAIR_GEN); */
 445    CASE(CKM_EXTRACT_KEY_FROM_KEY);
 446    CASE(CKM_FASTHASH);
 447    CASE(CKM_FORTEZZA_TIMESTAMP);
 448    CASE(CKM_GENERIC_SECRET_KEY_GEN);
 449    CASE(CKM_IDEA_CBC);
 450    CASE(CKM_IDEA_CBC_PAD);
 451    CASE(CKM_IDEA_ECB);
 452    CASE(CKM_IDEA_KEY_GEN);
 453    CASE(CKM_IDEA_MAC);
 454    CASE(CKM_IDEA_MAC_GENERAL);
 455    CASE(CKM_KEA_KEY_DERIVE);
 456    CASE(CKM_KEA_KEY_PAIR_GEN);
 457    CASE(CKM_KEY_WRAP_LYNKS);
 458    CASE(CKM_KEY_WRAP_SET_OAEP);
 459    CASE(CKM_MD2);
 460    CASE(CKM_MD2_HMAC);
 461    CASE(CKM_MD2_HMAC_GENERAL);
 462    CASE(CKM_MD2_KEY_DERIVATION);
 463    CASE(CKM_MD2_RSA_PKCS);
 464    CASE(CKM_MD5);
 465    CASE(CKM_MD5_HMAC);
 466    CASE(CKM_MD5_HMAC_GENERAL);
 467    CASE(CKM_MD5_KEY_DERIVATION);
 468    CASE(CKM_MD5_RSA_PKCS);
 469    CASE(CKM_PBA_SHA1_WITH_SHA1_HMAC);
 470    CASE(CKM_PBE_MD2_DES_CBC);
 471    CASE(CKM_PBE_MD5_DES_CBC);
 472    CASE(CKM_PBE_SHA1_DES2_EDE_CBC);
 473    CASE(CKM_PBE_SHA1_DES3_EDE_CBC);
 474    CASE(CKM_PBE_SHA1_RC2_128_CBC);
 475    CASE(CKM_PBE_SHA1_RC2_40_CBC);
 476    CASE(CKM_PBE_SHA1_RC4_128);
 477    CASE(CKM_PBE_SHA1_RC4_40);
 478    CASE(CKM_PKCS5_PBKD2);
 479    CASE(CKM_RC2_CBC);
 480    CASE(CKM_RC2_CBC_PAD);
 481    CASE(CKM_RC2_ECB);
 482    CASE(CKM_RC2_KEY_GEN);
 483    CASE(CKM_RC2_MAC);
 484    CASE(CKM_RC2_MAC_GENERAL);
 485    CASE(CKM_RC4);
 486    CASE(CKM_RC4_KEY_GEN);
 487    CASE(CKM_RC5_CBC);
 488    CASE(CKM_RC5_CBC_PAD);
 489    CASE(CKM_RC5_ECB);
 490    CASE(CKM_RC5_KEY_GEN);
 491    CASE(CKM_RC5_MAC);
 492    CASE(CKM_RC5_MAC_GENERAL);
 493    CASE(CKM_RIPEMD128);
 494    CASE(CKM_RIPEMD128_HMAC);
 495    CASE(CKM_RIPEMD128_HMAC_GENERAL);
 496    CASE(CKM_RIPEMD128_RSA_PKCS);
 497    CASE(CKM_RIPEMD160);
 498    CASE(CKM_RIPEMD160_HMAC);
 499    CASE(CKM_RIPEMD160_HMAC_GENERAL);
 500    CASE(CKM_RIPEMD160_RSA_PKCS);
 501    CASE(CKM_RSA_9796);
 502    CASE(CKM_RSA_PKCS);
 503    CASE(CKM_RSA_PKCS_KEY_PAIR_GEN);
 504    CASE(CKM_RSA_PKCS_OAEP);
 505    CASE(CKM_RSA_PKCS_PSS);
 506    CASE(CKM_RSA_X9_31);
 507    CASE(CKM_RSA_X9_31_KEY_PAIR_GEN);
 508    CASE(CKM_RSA_X_509);
 509    CASE(CKM_SHA1_KEY_DERIVATION);
 510    CASE(CKM_SHA1_RSA_PKCS);
 511    CASE(CKM_SHA1_RSA_PKCS_PSS);
 512    CASE(CKM_SHA1_RSA_X9_31);
 513    CASE(CKM_SHA224);
 514    CASE(CKM_SHA224_HMAC);
 515    CASE(CKM_SHA224_HMAC_GENERAL);
 516    CASE(CKM_SHA224_KEY_DERIVATION);
 517    CASE(CKM_SHA224_RSA_PKCS);
 518    CASE(CKM_SHA224_RSA_PKCS_PSS);
 519    CASE(CKM_SHA256);
 520    CASE(CKM_SHA256_HMAC);
 521    CASE(CKM_SHA256_HMAC_GENERAL);
 522    CASE(CKM_SHA256_KEY_DERIVATION);
 523    CASE(CKM_SHA256_RSA_PKCS);
 524    CASE(CKM_SHA256_RSA_PKCS_PSS);
 525    CASE(CKM_SHA384);
 526    CASE(CKM_SHA384_HMAC);
 527    CASE(CKM_SHA384_HMAC_GENERAL);
 528    CASE(CKM_SHA384_KEY_DERIVATION);
 529    CASE(CKM_SHA384_RSA_PKCS);
 530    CASE(CKM_SHA384_RSA_PKCS_PSS);
 531    CASE(CKM_SHA512);
 532    CASE(CKM_SHA512_HMAC);
 533    CASE(CKM_SHA512_HMAC_GENERAL);
 534    CASE(CKM_SHA512_KEY_DERIVATION);
 535    CASE(CKM_SHA512_RSA_PKCS);
 536    CASE(CKM_SHA512_RSA_PKCS_PSS);
 537    CASE(CKM_SHA_1);
 538    CASE(CKM_SHA_1_HMAC);
 539    CASE(CKM_SHA_1_HMAC_GENERAL);
 540    CASE(CKM_SKIPJACK_CBC64);
 541    CASE(CKM_SKIPJACK_CFB16);
 542    CASE(CKM_SKIPJACK_CFB32);
 543    CASE(CKM_SKIPJACK_CFB64);
 544    CASE(CKM_SKIPJACK_CFB8);
 545    CASE(CKM_SKIPJACK_ECB64);
 546    CASE(CKM_SKIPJACK_KEY_GEN);
 547    CASE(CKM_SKIPJACK_OFB64);
 548    CASE(CKM_SKIPJACK_PRIVATE_WRAP);
 549    CASE(CKM_SKIPJACK_RELAYX);
 550    CASE(CKM_SKIPJACK_WRAP);
 551    CASE(CKM_SSL3_KEY_AND_MAC_DERIVE);
 552    CASE(CKM_SSL3_MASTER_KEY_DERIVE);
 553    CASE(CKM_SSL3_MASTER_KEY_DERIVE_DH);
 554    CASE(CKM_SSL3_MD5_MAC);
 555    CASE(CKM_SSL3_PRE_MASTER_KEY_GEN);
 556    CASE(CKM_SSL3_SHA1_MAC);
 557    CASE(CKM_TLS_KEY_AND_MAC_DERIVE);
 558    CASE(CKM_TLS_MASTER_KEY_DERIVE);
 559    CASE(CKM_TLS_MASTER_KEY_DERIVE_DH);
 560    CASE(CKM_TLS_PRE_MASTER_KEY_GEN);
 561    CASE(CKM_TLS_PRF);
 562    CASE(CKM_TWOFISH_CBC);
 563    CASE(CKM_TWOFISH_KEY_GEN);
 564    CASE(CKM_X9_42_DH_DERIVE);
 565    CASE(CKM_X9_42_DH_HYBRID_DERIVE);
 566    CASE(CKM_X9_42_DH_KEY_PAIR_GEN);
 567    CASE(CKM_X9_42_DH_PARAMETER_GEN);
 568    CASE(CKM_X9_42_MQV_DERIVE);
 569    CASE(CKM_XOR_BASE_AND_DATA);
 570    default: break;
 571    }
 572    if (a)
 573	PR_LOG(modlog, 4, ("      mechanism = %s", a));
 574    else
 575	PR_LOG(modlog, 4, ("      mechanism = 0x%p", m->mechanism));
 576}
 577
 578static void get_key_type(CK_KEY_TYPE keyType, char *str, int len)
 579{
 580
 581    const char * a = NULL;
 582
 583    switch (keyType) {
 584    CASE(CKK_AES);
 585    CASE(CKK_CAMELLIA);
 586    CASE(CKK_CDMF);
 587    CASE(CKK_DES);
 588    CASE(CKK_DES2);
 589    CASE(CKK_DES3);
 590    CASE(CKK_DH);
 591    CASE(CKK_DSA);
 592    CASE(CKK_EC);		/* also CASE(CKK_ECDSA); */
 593    CASE(CKK_GENERIC_SECRET);
 594    CASE(CKK_IDEA);
 595    CASE(CKK_INVALID_KEY_TYPE);
 596    CASE(CKK_KEA);
 597    CASE(CKK_RC2);
 598    CASE(CKK_RC4);
 599    CASE(CKK_RC5);
 600    CASE(CKK_RSA);
 601    CASE(CKK_SKIPJACK);
 602    CASE(CKK_TWOFISH);
 603    CASE(CKK_X9_42_DH);
 604    default: break;
 605    }
 606    if (a)
 607	PR_snprintf(str, len, "%s", a);
 608    else
 609	PR_snprintf(str, len, "0x%p", keyType);
 610}
 611
 612static void print_attr_value(CK_ATTRIBUTE_PTR attr)
 613{
 614    char atype[48];
 615    char valstr[49];
 616    int len;
 617
 618    get_attr_type_str(attr->type, atype, sizeof atype);
 619    switch (attr->type) {
 620    case CKA_ALWAYS_SENSITIVE:
 621    case CKA_DECRYPT:
 622    case CKA_DERIVE:
 623    case CKA_ENCRYPT:
 624    case CKA_EXTRACTABLE:
 625    case CKA_LOCAL:
 626    case CKA_MODIFIABLE:
 627    case CKA_NEVER_EXTRACTABLE:
 628    case CKA_PRIVATE:
 629    case CKA_SENSITIVE:
 630    case CKA_SIGN:
 631    case CKA_SIGN_RECOVER:
 632    case CKA_TOKEN:
 633    case CKA_UNWRAP:
 634    case CKA_VERIFY:
 635    case CKA_VERIFY_RECOVER:
 636    case CKA_WRAP:
 637	if (attr->ulValueLen > 0 && attr->pValue) {
 638	    CK_BBOOL tf = *((CK_BBOOL *)attr->pValue);
 639	    PR_LOG(modlog, 4, (fmt_s_s_d, 
 640	           atype, tf ? "CK_TRUE" : "CK_FALSE", attr->ulValueLen));
 641	    break;
 642	}
 643    case CKA_CLASS:
 644	if (attr->ulValueLen > 0 && attr->pValue) {
 645	    CK_OBJECT_CLASS objClass = *((CK_OBJECT_CLASS *)attr->pValue);
 646	    get_obj_class(objClass, valstr, sizeof valstr);
 647	    PR_LOG(modlog, 4, (fmt_s_s_d, 
 648	           atype, valstr, attr->ulValueLen));
 649	    break;
 650	}
 651    case CKA_TRUST_CLIENT_AUTH:
 652    case CKA_TRUST_CODE_SIGNING:
 653    case CKA_TRUST_EMAIL_PROTECTION:
 654    case CKA_TRUST_SERVER_AUTH:
 655	if (attr->ulValueLen > 0 && attr->pValue) {
 656	    CK_TRUST trust = *((CK_TRUST *)attr->pValue);
 657	    get_trust_val(trust, valstr, sizeof valstr);
 658	    PR_LOG(modlog, 4, (fmt_s_s_d, 
 659	           atype, valstr, attr->ulValueLen));
 660	    break;
 661	}
 662    case CKA_KEY_TYPE:
 663	if (attr->ulValueLen > 0 && attr->pValue) {
 664	    CK_KEY_TYPE keyType = *((CK_KEY_TYPE *)attr->pValue);
 665	    get_key_type(keyType, valstr, sizeof valstr);
 666	    PR_LOG(modlog, 4, (fmt_s_s_d, 
 667	           atype, valstr, attr->ulValueLen));
 668	    break;
 669	}
 670    case CKA_PIXEL_X:
 671    case CKA_PIXEL_Y:
 672    case CKA_RESOLUTION:
 673    case CKA_CHAR_ROWS:
 674    case CKA_CHAR_COLUMNS:
 675    case CKA_BITS_PER_PIXEL:
 676    case CKA_CERTIFICATE_CATEGORY:  /* should print as enum/string */
 677    case CKA_JAVA_MIDP_SECURITY_DOMAIN:  /* should print as enum/string */
 678    case CKA_MODULUS_BITS:
 679    case CKA_PRIME_BITS:
 680    case CKA_SUBPRIME_BITS:
 681    case CKA_VALUE_BITS:
 682    case CKA_VALUE_LEN:
 683	if (attr->ulValueLen > 0 && attr->pValue) {
 684	    CK_ULONG valueLen = *((CK_ULONG *)attr->pValue);
 685	    /* XXX check for the special value CK_UNAVAILABLE_INFORMATION */
 686	    PR_LOG(modlog, 4, (fmt_s_lu, atype, (PRUint32)valueLen));
 687	    break;
 688	}
 689    case CKA_LABEL:
 690    case CKA_NSS_EMAIL:
 691    case CKA_NSS_URL:
 692	if (attr->ulValueLen > 0 && attr->pValue) {
 693	    len = PR_MIN(attr->ulValueLen + 1, sizeof valstr);
 694	    PR_snprintf(valstr, len, "%s", attr->pValue);
 695	    PR_LOG(modlog, 4, (fmt_s_qsq_d, 
 696	           atype, valstr, attr->ulValueLen));
 697	    break;
 698	}
 699    case CKA_ISSUER:
 700    case CKA_SUBJECT:
 701	if (attr->ulValueLen > 0 && attr->pValue) {
 702	    char * asciiName;
 703	    SECItem derName;
 704	    derName.type = siDERNameBuffer;
 705	    derName.data = attr->pValue;
 706	    derName.len  = attr->ulValueLen;
 707	    asciiName = CERT_DerNameToAscii(&derName);
 708	    if (asciiName) {
 709		PR_LOG(modlog, 4, (fmt_s_s_d, 
 710		       atype, asciiName, attr->ulValueLen));
 711	    	PORT_Free(asciiName);
 712		break;
 713	    }
 714	    /* else treat like a binary buffer */
 715	    goto binary_buffer;
 716	}
 717    case CKA_ID:
 718	if (attr->ulValueLen > 0 && attr->pValue) {
 719	    unsigned char * pV = attr->pValue;
 720	    for (len = (int)attr->ulValueLen; len > 0; --len) {
 721		unsigned int ch = *pV++;
 722		if (ch >= 0x20 && ch < 0x7f) 
 723		    continue;
 724		if (!ch && len == 1)  /* will ignore NUL if last character */
 725		    continue;
 726		break;
 727	    }
 728	    if (!len) {	/* entire string is printable */
 729		len = PR_MIN(attr->ulValueLen + 1, sizeof valstr);
 730		PR_snprintf(valstr, len, "%s", attr->pValue);
 731		PR_LOG(modlog, 4, (fmt_s_qsq_d, 
 732		       atype, valstr, attr->ulValueLen));
 733		break;
 734	    }
 735	    /* else fall through and treat like a binary buffer */
 736	}
 737binary_buffer:
 738    case CKA_SERIAL_NUMBER:
 739    default:
 740	if (attr->ulValueLen > 0 && attr->pValue) {
 741	    char * hexBuf;
 742	    SECItem attrBuf;
 743	    attrBuf.type = siDERNameBuffer;
 744	    attrBuf.data = attr->pValue;
 745	    attrBuf.len  = PR_MIN(attr->ulValueLen, (sizeof valstr)/2);
 746
 747	    hexBuf = CERT_Hexify(&attrBuf, PR_FALSE);
 748	    if (hexBuf) {
 749		PR_LOG(modlog, 4, (fmt_s_s_d, 
 750		       atype, hexBuf, attr->ulValueLen));
 751	    	PORT_Free(hexBuf);
 752		break;
 753	    }
 754	    /* else fall through and show only the address. :( */
 755	}
 756	PR_LOG(modlog, 4, ("    %s = [0x%p] [%d]", 
 757	       atype, attr->pValue, attr->ulValueLen));
 758	break;
 759    }
 760}
 761
 762static void print_template(CK_ATTRIBUTE_PTR templ, CK_ULONG tlen)
 763{
 764    CK_ULONG i;
 765    for (i=0; i<tlen; i++) {
 766	print_attr_value(&templ[i]);
 767    }
 768}
 769
 770struct nssdbg_prof_str {
 771    PRUint32 time;
 772    PRUint32 calls;
 773    char *function;
 774};
 775
 776#define NSSDBG_DEFINE(func) { 0, 0, #func }
 777
 778struct nssdbg_prof_str nssdbg_prof_data[] = {
 779#define FUNC_C_INITIALIZE 0
 780    NSSDBG_DEFINE(C_Initialize),
 781#define FUNC_C_FINALIZE 1
 782    NSSDBG_DEFINE(C_Finalize),
 783#define FUNC_C_GETINFO 2
 784    NSSDBG_DEFINE(C_GetInfo),
 785#define FUNC_C_GETFUNCITONLIST 3
 786    NSSDBG_DEFINE(C_GetFunctionList),
 787#define FUNC_C_GETSLOTLIST 4
 788    NSSDBG_DEFINE(C_GetSlotList),
 789#define FUNC_C_GETSLOTINFO 5
 790    NSSDBG_DEFINE(C_GetSlotInfo),
 791#define FUNC_C_GETTOKENINFO 6
 792    NSSDBG_DEFINE(C_GetTokenInfo),
 793#define FUNC_C_GETMECHANISMLIST 7
 794    NSSDBG_DEFINE(C_GetMechanismList),
 795#define FUNC_C_GETMECHANISMINFO 8
 796    NSSDBG_DEFINE(C_GetMechanismInfo),
 797#define FUNC_C_INITTOKEN 9
 798    NSSDBG_DEFINE(C_InitToken),
 799#define FUNC_C_INITPIN 10
 800    NSSDBG_DEFINE(C_InitPIN),
 801#define FUNC_C_SETPIN 11
 802    NSSDBG_DEFINE(C_SetPIN),
 803#define FUNC_C_OPENSESSION 12
 804    NSSDBG_DEFINE(C_OpenSession),
 805#define FUNC_C_CLOSESESSION 13
 806    NSSDBG_DEFINE(C_CloseSession),
 807#define FUNC_C_CLOSEALLSESSIONS 14
 808    NSSDBG_DEFINE(C_CloseAllSessions),
 809#define FUNC_C_GETSESSIONINFO 15
 810    NSSDBG_DEFINE(C_GetSessionInfo),
 811#define FUNC_C_GETOPERATIONSTATE 16
 812    NSSDBG_DEFINE(C_GetOperationState),
 813#define FUNC_C_SETOPERATIONSTATE 17
 814    NSSDBG_DEFINE(C_SetOperationState),
 815#define FUNC_C_LOGIN 18
 816    NSSDBG_DEFINE(C_Login),
 817#define FUNC_C_LOGOUT 19
 818    NSSDBG_DEFINE(C_Logout),
 819#define FUNC_C_CREATEOBJECT 20
 820    NSSDBG_DEFINE(C_CreateObject),
 821#define FUNC_C_COPYOBJECT 21
 822    NSSDBG_DEFINE(C_CopyObject),
 823#define FUNC_C_DESTROYOBJECT 22
 824    NSSDBG_DEFINE(C_DestroyObject),
 825#define FUNC_C_GETOBJECTSIZE  23
 826    NSSDBG_DEFINE(C_GetObjectSize),
 827#define FUNC_C_GETATTRIBUTEVALUE 24
 828    NSSDBG_DEFINE(C_GetAttributeValue),
 829#define FUNC_C_SETATTRIBUTEVALUE 25
 830    NSSDBG_DEFINE(C_SetAttributeValue),
 831#define FUNC_C_FINDOBJECTSINIT 26
 832    NSSDBG_DEFINE(C_FindObjectsInit),
 833#define FUNC_C_FINDOBJECTS 27
 834    NSSDBG_DEFINE(C_FindObjects),
 835#define FUNC_C_FINDOBJECTSFINAL 28
 836    NSSDBG_DEFINE(C_FindObjectsFinal),
 837#define FUNC_C_ENCRYPTINIT 29
 838    NSSDBG_DEFINE(C_EncryptInit),
 839#define FUNC_C_ENCRYPT 30
 840    NSSDBG_DEFINE(C_Encrypt),
 841#define FUNC_C_ENCRYPTUPDATE 31
 842    NSSDBG_DEFINE(C_EncryptUpdate),
 843#define FUNC_C_ENCRYPTFINAL 32
 844    NSSDBG_DEFINE(C_EncryptFinal),
 845#define FUNC_C_DECRYPTINIT 33
 846    NSSDBG_DEFINE(C_DecryptInit),
 847#define FUNC_C_DECRYPT 34
 848    NSSDBG_DEFINE(C_Decrypt),
 849#define FUNC_C_DECRYPTUPDATE 35
 850    NSSDBG_DEFINE(C_DecryptUpdate),
 851#define FUNC_C_DECRYPTFINAL 36
 852    NSSDBG_DEFINE(C_DecryptFinal),
 853#define FUNC_C_DIGESTINIT 37
 854    NSSDBG_DEFINE(C_DigestInit),
 855#define FUNC_C_DIGEST 38
 856    NSSDBG_DEFINE(C_Digest),
 857#define FUNC_C_DIGESTUPDATE 39
 858    NSSDBG_DEFINE(C_DigestUpdate),
 859#define FUNC_C_DIGESTKEY 40
 860    NSSDBG_DEFINE(C_DigestKey),
 861#define FUNC_C_DIGESTFINAL 41
 862    NSSDBG_DEFINE(C_DigestFinal),
 863#define FUNC_C_SIGNINIT 42
 864    NSSDBG_DEFINE(C_SignInit),
 865#define FUNC_C_SIGN 43
 866    NSSDBG_DEFINE(C_Sign),
 867#define FUNC_C_SIGNUPDATE 44
 868    NSSDBG_DEFINE(C_SignUpdate),
 869#define FUNC_C_SIGNFINAL 45
 870    NSSDBG_DEFINE(C_SignFinal),
 871#define FUNC_C_SIGNRECOVERINIT 46
 872    NSSDBG_DEFINE(C_SignRecoverInit),
 873#define FUNC_C_SIGNRECOVER 47
 874    NSSDBG_DEFINE(C_SignRecover),
 875#define FUNC_C_VERIFYINIT 48
 876    NSSDBG_DEFINE(C_VerifyInit),
 877#define FUNC_C_VERIFY 49
 878    NSSDBG_DEFINE(C_Verify),
 879#define FUNC_C_VERIFYUPDATE 50
 880    NSSDBG_DEFINE(C_VerifyUpdate),
 881#define FUNC_C_VERIFYFINAL 51
 882    NSSDBG_DEFINE(C_VerifyFinal),
 883#define FUNC_C_VERIFYRECOVERINIT 52
 884    NSSDBG_DEFINE(C_VerifyRecoverInit),
 885#define FUNC_C_VERIFYRECOVER 53
 886    NSSDBG_DEFINE(C_VerifyRecover),
 887#define FUNC_C_DIGESTENCRYPTUPDATE 54
 888    NSSDBG_DEFINE(C_DigestEncryptUpdate),
 889#define FUNC_C_DECRYPTDIGESTUPDATE 55
 890    NSSDBG_DEFINE(C_DecryptDigestUpdate),
 891#define FUNC_C_SIGNENCRYPTUPDATE 56
 892    NSSDBG_DEFINE(C_SignEncryptUpdate),
 893#define FUNC_C_DECRYPTVERIFYUPDATE 57
 894    NSSDBG_DEFINE(C_DecryptVerifyUpdate),
 895#define FUNC_C_GENERATEKEY 58
 896    NSSDBG_DEFINE(C_GenerateKey),
 897#define FUNC_C_GENERATEKEYPAIR 59
 898    NSSDBG_DEFINE(C_GenerateKeyPair),
 899#define FUNC_C_WRAPKEY 60
 900    NSSDBG_DEFINE(C_WrapKey),
 901#define FUNC_C_UNWRAPKEY 61
 902    NSSDBG_DEFINE(C_UnWrapKey),
 903#define FUNC_C_DERIVEKEY 62 
 904    NSSDBG_DEFINE(C_DeriveKey),
 905#define FUNC_C_SEEDRANDOM 63
 906    NSSDBG_DEFINE(C_SeedRandom),
 907#define FUNC_C_GENERATERANDOM 64
 908    NSSDBG_DEFINE(C_GenerateRandom),
 909#define FUNC_C_GETFUNCTIONSTATUS 65
 910    NSSDBG_DEFINE(C_GetFunctionStatus),
 911#define FUNC_C_CANCELFUNCTION 66
 912    NSSDBG_DEFINE(C_CancelFunction),
 913#define FUNC_C_WAITFORSLOTEVENT 67
 914    NSSDBG_DEFINE(C_WaitForSlotEvent)
 915};
 916
 917int nssdbg_prof_size = sizeof(nssdbg_prof_data)/sizeof(nssdbg_prof_data[0]);
 918    
 919
 920static void nssdbg_finish_time(PRInt32 fun_number, PRIntervalTime start)
 921{
 922    PRIntervalTime ival;
 923    PRIntervalTime end = PR_IntervalNow();
 924
 925    ival = end-start;
 926    /* sigh, lie to PRAtomic add and say we are using signed values */
 927    PR_ATOMIC_ADD((PRInt32 *)&nssdbg_prof_data[fun_number].time, (PRInt32)ival);
 928}
 929
 930static void nssdbg_start_time(PRInt32 fun_number, PRIntervalTime *start)
 931{
 932    PR_ATOMIC_INCREMENT((PRInt32 *)&nssdbg_prof_data[fun_number].calls);
 933    *start = PR_IntervalNow();
 934}
 935
 936#define COMMON_DEFINITIONS \
 937    CK_RV rv; \
 938    PRIntervalTime start
 939
 940CK_RV NSSDBGC_Initialize(
 941  CK_VOID_PTR pInitArgs
 942)
 943{
 944    COMMON_DEFINITIONS;
 945
 946    PR_LOG(modlog, 1, ("C_Initialize"));
 947    PR_LOG(modlog, 3, ("  pInitArgs = 0x%p", pInitArgs));
 948    nssdbg_start_time(FUNC_C_INITIALIZE,&start);
 949    rv = module_functions->C_Initialize(pInitArgs);
 950    nssdbg_finish_time(FUNC_C_INITIALIZE,start);
 951    log_rv(rv);
 952    return rv;
 953}
 954
 955CK_RV NSSDBGC_Finalize(
 956  CK_VOID_PTR pReserved
 957)
 958{
 959    COMMON_DEFINITIONS;
 960
 961    PR_LOG(modlog, 1, ("C_Finalize"));
 962    PR_LOG(modlog, 3, ("  pReserved = 0x%p", pReserved));
 963    nssdbg_start_time(FUNC_C_FINALIZE,&start);
 964    rv = module_functions->C_Finalize(pReserved);
 965    nssdbg_finish_time(FUNC_C_FINALIZE,start);
 966    log_rv(rv);
 967    return rv;
 968}
 969
 970CK_RV NSSDBGC_GetInfo(
 971  CK_INFO_PTR pInfo
 972)
 973{
 974    COMMON_DEFINITIONS;
 975
 976    PR_LOG(modlog, 1, ("C_GetInfo"));
 977    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
 978    nssdbg_start_time(FUNC_C_GETINFO,&start);
 979    rv = module_functions->C_GetInfo(pInfo);
 980    nssdbg_finish_time(FUNC_C_GETINFO,start);
 981    if (rv == CKR_OK) {
 982	PR_LOG(modlog, 4, ("  cryptoki version: %d.%d", 
 983			   pInfo->cryptokiVersion.major,
 984			   pInfo->cryptokiVersion.minor));
 985	PR_LOG(modlog, 4, (fmt_manufacturerID, pInfo->manufacturerID));
 986	PR_LOG(modlog, 4, ("  library description = \"%.32s\"", 
 987	                   pInfo->libraryDescription));
 988	PR_LOG(modlog, 4, ("  library version: %d.%d", 
 989			   pInfo->libraryVersion.major,
 990			   pInfo->libraryVersion.minor));
 991    }
 992    log_rv(rv);
 993    return rv;
 994}
 995
 996CK_RV NSSDBGC_GetFunctionList(
 997  CK_FUNCTION_LIST_PTR_PTR ppFunctionList
 998)
 999{
1000    COMMON_DEFINITIONS;
1001
1002    PR_LOG(modlog, 1, ("C_GetFunctionList"));
1003    PR_LOG(modlog, 3, ("  ppFunctionList = 0x%p", ppFunctionList));
1004    nssdbg_start_time(FUNC_C_GETFUNCITONLIST,&start);
1005    rv = module_functions->C_GetFunctionList(ppFunctionList);
1006    nssdbg_finish_time(FUNC_C_GETFUNCITONLIST,start);
1007    log_rv(rv);
1008    return rv;
1009}
1010
1011CK_RV NSSDBGC_GetSlotList(
1012  CK_BBOOL       tokenPresent,
1013  CK_SLOT_ID_PTR pSlotList,
1014  CK_ULONG_PTR   pulCount
1015)
1016{
1017    COMMON_DEFINITIONS;
1018
1019    CK_ULONG i;
1020    PR_LOG(modlog, 1, ("C_GetSlotList"));
1021    PR_LOG(modlog, 3, ("  tokenPresent = 0x%x", tokenPresent));
1022    PR_LOG(modlog, 3, ("  pSlotList = 0x%p", pSlotList));
1023    PR_LOG(modlog, 3, (fmt_pulCount, pulCount));
1024    nssdbg_start_time(FUNC_C_GETSLOTLIST,&start);
1025    rv = module_functions->C_GetSlotList(tokenPresent, pSlotList, pulCount);
1026    nssdbg_finish_time(FUNC_C_GETSLOTLIST,start);
1027    PR_LOG(modlog, 4, (fmt_spulCount, *pulCount));
1028    if (pSlotList) {
1029	for (i=0; i<*pulCount; i++) {
1030	    PR_LOG(modlog, 4, ("  slotID[%d] = %x", i, pSlotList[i]));
1031	}
1032    }
1033    log_rv(rv);
1034    return rv;
1035}
1036
1037CK_RV NSSDBGC_GetSlotInfo(
1038  CK_SLOT_ID       slotID,
1039  CK_SLOT_INFO_PTR pInfo
1040)
1041{
1042    COMMON_DEFINITIONS;
1043
1044    PR_LOG(modlog, 1, ("C_GetSlotInfo"));
1045    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1046    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1047    nssdbg_start_time(FUNC_C_GETSLOTINFO,&start);
1048    rv = module_functions->C_GetSlotInfo(slotID, pInfo);
1049    nssdbg_finish_time(FUNC_C_GETSLOTINFO,start);
1050    if (rv == CKR_OK) {
1051	PR_LOG(modlog, 4, ("  slotDescription = \"%.64s\"", 
1052	                   pInfo->slotDescription));
1053	PR_LOG(modlog, 4, (fmt_manufacturerID, pInfo->manufacturerID));
1054	PR_LOG(modlog, 4, ("  flags = %s %s %s",
1055	    pInfo->flags & CKF_HW_SLOT          ? "CKF_HW_SLOT" : "",
1056	    pInfo->flags & CKF_REMOVABLE_DEVICE ? "CKF_REMOVABLE_DEVICE" : "",
1057	    pInfo->flags & CKF_TOKEN_PRESENT    ? "CKF_TOKEN_PRESENT" : ""));
1058	PR_LOG(modlog, 4, (fmt_hwVersion, 
1059			    pInfo->hardwareVersion.major,
1060			    pInfo->hardwareVersion.minor));
1061	PR_LOG(modlog, 4, (fmt_fwVersion, 
1062			    pInfo->firmwareVersion.major,
1063			    pInfo->firmwareVersion.minor));
1064    }
1065    log_rv(rv);
1066    return rv;
1067}
1068
1069CK_RV NSSDBGC_GetTokenInfo(
1070  CK_SLOT_ID        slotID,
1071  CK_TOKEN_INFO_PTR pInfo
1072)
1073{
1074    COMMON_DEFINITIONS;
1075
1076    PR_LOG(modlog, 1, ("C_GetTokenInfo"));
1077    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1078    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1079    nssdbg_start_time(FUNC_C_GETTOKENINFO,&start);
1080    rv = module_functions->C_GetTokenInfo(slotID, pInfo);
1081    nssdbg_finish_time(FUNC_C_GETTOKENINFO,start);
1082    if (rv == CKR_OK) {
1083    	PR_LOG(modlog, 4, ("  label = \"%.32s\"", pInfo->label));
1084	PR_LOG(modlog, 4, (fmt_manufacturerID, pInfo->manufacturerID));
1085    	PR_LOG(modlog, 4, ("  model = \"%.16s\"", pInfo->model));
1086    	PR_LOG(modlog, 4, ("  serial = \"%.16s\"", pInfo->serialNumber));
1087	PR_LOG(modlog, 4, ("  flags = %s %s %s %s",
1088	    pInfo->flags & CKF_RNG             ? "CKF_RNG" : "",
1089	    pInfo->flags & CKF_WRITE_PROTECTED ? "CKF_WRITE_PROTECTED" : "",
1090	    pInfo->flags & CKF_LOGIN_REQUIRED  ? "CKF_LOGIN_REQUIRED" : "",
1091	    pInfo->flags & CKF_USER_PIN_INITIALIZED ? "CKF_USER_PIN_INIT" : ""));
1092	PR_LOG(modlog, 4, ("  maxSessions = %u, Sessions = %u", 
1093	                   pInfo->ulMaxSessionCount, pInfo->ulSessionCount));
1094	PR_LOG(modlog, 4, ("  maxRwSessions = %u, RwSessions = %u", 
1095	                   pInfo->ulMaxRwSessionCount, 
1096			   pInfo->ulRwSessionCount));
1097	/* ignore Max & Min Pin Len, Public and Private Memory */
1098	PR_LOG(modlog, 4, (fmt_hwVersion, 
1099			    pInfo->hardwareVersion.major,
1100			    pInfo->hardwareVersion.minor));
1101	PR_LOG(modlog, 4, (fmt_fwVersion, 
1102			    pInfo->firmwareVersion.major,
1103			    pInfo->firmwareVersion.minor));
1104    }
1105    log_rv(rv);
1106    return rv;
1107}
1108
1109CK_RV NSSDBGC_GetMechanismList(
1110  CK_SLOT_ID            slotID,
1111  CK_MECHANISM_TYPE_PTR pMechanismList,
1112  CK_ULONG_PTR          pulCount
1113)
1114{
1115    COMMON_DEFINITIONS;
1116
1117    PR_LOG(modlog, 1, ("C_GetMechanismList"));
1118    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1119    PR_LOG(modlog, 3, ("  pMechanismList = 0x%p", pMechanismList));
1120    PR_LOG(modlog, 3, (fmt_pulCount, pulCount));
1121    nssdbg_start_time(FUNC_C_GETMECHANISMLIST,&start);
1122    rv = module_functions->C_GetMechanismList(slotID,
1123                                 pMechanismList,
1124                                 pulCount);
1125    nssdbg_finish_time(FUNC_C_GETMECHANISMLIST,start);
1126    PR_LOG(modlog, 4, (fmt_spulCount, *pulCount));
1127    log_rv(rv);
1128    return rv;
1129}
1130
1131CK_RV NSSDBGC_GetMechanismInfo(
1132  CK_SLOT_ID            slotID,
1133  CK_MECHANISM_TYPE     type,
1134  CK_MECHANISM_INFO_PTR pInfo
1135)
1136{
1137    COMMON_DEFINITIONS;
1138
1139    PR_LOG(modlog, 1, ("C_GetMechanismInfo"));
1140    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1141    PR_LOG(modlog, 3, ("  type = 0x%x", type));
1142    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1143    nssdbg_start_time(FUNC_C_GETMECHANISMINFO,&start);
1144    rv = module_functions->C_GetMechanismInfo(slotID,
1145                                 type,
1146                                 pInfo);
1147    nssdbg_finish_time(FUNC_C_GETMECHANISMINFO,start);
1148    log_rv(rv);
1149    return rv;
1150}
1151
1152CK_RV NSSDBGC_InitToken(
1153  CK_SLOT_ID  slotID,
1154  CK_CHAR_PTR pPin,
1155  CK_ULONG    ulPinLen,
1156  CK_CHAR_PTR pLabel
1157)
1158{
1159    COMMON_DEFINITIONS;
1160
1161    PR_LOG(modlog, 1, ("C_InitToken"));
1162    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1163    PR_LOG(modlog, 3, (fmt_pPin, pPin));
1164    PR_LOG(modlog, 3, (fmt_ulPinLen, ulPinLen));
1165    PR_LOG(modlog, 3, ("  pLabel = 0x%p", pLabel));
1166    nssdbg_start_time(FUNC_C_INITTOKEN,&start);
1167    rv = module_functions->C_InitToken(slotID,
1168                                 pPin,
1169                                 ulPinLen,
1170                                 pLabel);
1171    nssdbg_finish_time(FUNC_C_INITTOKEN,start);
1172    log_rv(rv);
1173    return rv;
1174}
1175
1176CK_RV NSSDBGC_InitPIN(
1177  CK_SESSION_HANDLE hSession,
1178  CK_CHAR_PTR       pPin,
1179  CK_ULONG          ulPinLen
1180)
1181{
1182    COMMON_DEFINITIONS;
1183
1184    PR_LOG(modlog, 1, ("C_InitPIN"));
1185    log_handle(3, fmt_hSession, hSession);
1186    PR_LOG(modlog, 3, (fmt_pPin, pPin));
1187    PR_LOG(modlog, 3, (fmt_ulPinLen, ulPinLen));
1188    nssdbg_start_time(FUNC_C_INITPIN,&start);
1189    rv = module_functions->C_InitPIN(hSession,
1190                                 pPin,
1191                                 ulPinLen);
1192    nssdbg_finish_time(FUNC_C_INITPIN,start);
1193    log_rv(rv);
1194    return rv;
1195}
1196
1197CK_RV NSSDBGC_SetPIN(
1198  CK_SESSION_HANDLE hSession,
1199  CK_CHAR_PTR       pOldPin,
1200  CK_ULONG          ulOldLen,
1201  CK_CHAR_PTR       pNewPin,
1202  CK_ULONG          ulNewLen
1203)
1204{
1205    COMMON_DEFINITIONS;
1206
1207    PR_LOG(modlog, 1, ("C_SetPIN"));
1208    log_handle(3, fmt_hSession, hSession);
1209    PR_LOG(modlog, 3, ("  pOldPin = 0x%p", pOldPin));
1210    PR_LOG(modlog, 3, ("  ulOldLen = %d", ulOldLen));
1211    PR_LOG(modlog, 3, ("  pNewPin = 0x%p", pNewPin));
1212    PR_LOG(modlog, 3, ("  ulNewLen = %d", ulNewLen));
1213    nssdbg_start_time(FUNC_C_SETPIN,&start);
1214    rv = module_functions->C_SetPIN(hSession,
1215                                 pOldPin,
1216                                 ulOldLen,
1217                                 pNewPin,
1218                                 ulNewLen);
1219    nssdbg_finish_time(FUNC_C_SETPIN,start);
1220    log_rv(rv);
1221    return rv;
1222}
1223
1224static PRUint32 numOpenSessions = 0;
1225static PRUint32 maxOpenSessions = 0;
1226
1227CK_RV NSSDBGC_OpenSession(
1228  CK_SLOT_ID            slotID,
1229  CK_FLAGS              flags,
1230  CK_VOID_PTR           pApplication,
1231  CK_NOTIFY             Notify,
1232  CK_SESSION_HANDLE_PTR phSession
1233)
1234{
1235    COMMON_DEFINITIONS;
1236
1237    PR_ATOMIC_INCREMENT((PRInt32 *)&numOpenSessions);
1238    maxOpenSessions = PR_MAX(numOpenSessions, maxOpenSessions);
1239    PR_LOG(modlog, 1, ("C_OpenSession"));
1240    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1241    PR_LOG(modlog, 3, (fmt_flags, flags));
1242    PR_LOG(modlog, 3, ("  pApplication = 0x%p", pApplication));
1243    PR_LOG(modlog, 3, ("  Notify = 0x%x", Notify));
1244    PR_LOG(modlog, 3, ("  phSession = 0x%p", phSession));
1245    nssdbg_start_time(FUNC_C_OPENSESSION,&start);
1246    rv = module_functions->C_OpenSession(slotID,
1247                                 flags,
1248                                 pApplication,
1249                                 Notify,
1250                                 phSession);
1251    nssdbg_finish_time(FUNC_C_OPENSESSION,start);
1252    log_handle(4, "  *phSession = 0x%x", *phSession);
1253    log_rv(rv);
1254    return rv;
1255}
1256
1257CK_RV NSSDBGC_CloseSession(
1258  CK_SESSION_HANDLE hSession
1259)
1260{
1261    COMMON_DEFINITIONS;
1262
1263    PR_ATOMIC_DECREMENT((PRInt32 *)&numOpenSessions);
1264    PR_LOG(modlog, 1, ("C_CloseSession"));
1265    log_handle(3, fmt_hSession, hSession);
1266    nssdbg_start_time(FUNC_C_CLOSESESSION,&start);
1267    rv = module_functions->C_CloseSession(hSession);
1268    nssdbg_finish_time(FUNC_C_CLOSESESSION,start);
1269    log_rv(rv);
1270    return rv;
1271}
1272
1273CK_RV NSSDBGC_CloseAllSessions(
1274  CK_SLOT_ID slotID
1275)
1276{
1277    COMMON_DEFINITIONS;
1278
1279    PR_LOG(modlog, 1, ("C_CloseAllSessions"));
1280    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1281    nssdbg_start_time(FUNC_C_CLOSEALLSESSIONS,&start);
1282    rv = module_functions->C_CloseAllSessions(slotID);
1283    nssdbg_finish_time(FUNC_C_CLOSEALLSESSIONS,start);
1284    log_rv(rv);
1285    return rv;
1286}
1287
1288CK_RV NSSDBGC_GetSessionInfo(
1289  CK_SESSION_HANDLE   hSession,
1290  CK_SESSION_INFO_PTR pInfo
1291)
1292{
1293    COMMON_DEFINITIONS;
1294
1295    PR_LOG(modlog, 1, ("C_GetSessionInfo"));
1296    log_handle(3, fmt_hSession, hSession);
1297    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1298    nssdbg_start_time(FUNC_C_GETSESSIONINFO,&start);
1299    rv = module_functions->C_GetSessionInfo(hSession,
1300                                 pInfo);
1301    nssdbg_finish_time(FUNC_C_GETSESSIONINFO,start);
1302    if (rv == CKR_OK) {
1303	PR_LOG(modlog, 4, (fmt_slotID, pInfo->slotID));
1304	log_state(pInfo->state);
1305	PR_LOG(modlog, 4, ("  flags = %s %s",
1306	    pInfo->flags & CKF_RW_SESSION     ? "CKF_RW_SESSION" : "",
1307	    pInfo->flags & CKF_SERIAL_SESSION ? "CKF_SERIAL_SESSION" : ""));
1308	PR_LOG(modlog, 4, ("  deviceError = 0x%x", pInfo->ulDeviceError));
1309    }
1310    log_rv(rv);
1311    return rv;
1312}
1313
1314CK_RV NSSDBGC_GetOperationState(
1315  CK_SESSION_HANDLE hSession,
1316  CK_BYTE_PTR       pOperationState,
1317  CK_ULONG_PTR      pulOperationStateLen
1318)
1319{
1320    COMMON_DEFINITIONS;
1321
1322    PR_LOG(modlog, 1, ("C_GetOperationState"));
1323    log_handle(3, fmt_hSession, hSession);
1324    PR_LOG(modlog, 3, (fmt_pOperationState, pOperationState));
1325    PR_LOG(modlog, 3, ("  pulOperationStateLen = 0x%p", pulOperationStateLen));
1326    nssdbg_start_time(FUNC_C_GETOPERATIONSTATE,&start);
1327    rv = module_functions->C_GetOperationState(hSession,
1328                                 pOperationState,
1329                                 pulOperationStateLen);
1330    nssdbg_finish_time(FUNC_C_GETOPERATIONSTATE,start);
1331    PR_LOG(modlog, 4, ("  *pulOperationStateLen = 0x%x", *pulOperationStateLen));
1332    log_rv(rv);
1333    return rv;
1334}
1335
1336CK_RV NSSDBGC_SetOperationState(
1337  CK_SESSION_HANDLE hSession,
1338  CK_BYTE_PTR      pOperationState,
1339  CK_ULONG         ulOperationStateLen,
1340  CK_OBJECT_HANDLE hEncryptionKey,
1341  CK_OBJECT_HANDLE hAuthenticationKey
1342)
1343{
1344    COMMON_DEFINITIONS;
1345
1346    PR_LOG(modlog, 1, ("C_SetOperationState"));
1347    log_handle(3, fmt_hSession, hSession);
1348    PR_LOG(modlog, 3, (fmt_pOperationState, pOperationState));
1349    PR_LOG(modlog, 3, ("  ulOperationStateLen = %d", ulOperationStateLen));
1350    log_handle(3, "  hEncryptionKey = 0x%x", hEncryptionKey);
1351    log_handle(3, "  hAuthenticationKey = 0x%x", hAuthenticationKey);
1352    nssdbg_start_time(FUNC_C_SETOPERATIONSTATE,&start);
1353    rv = module_functions->C_SetOperationState(hSession,
1354                                 pOperationState,
1355                                 ulOperationStateLen,
1356                                 hEncryptionKey,
1357                                 hAuthenticationKey);
1358    nssdbg_finish_time(FUNC_C_SETOPERATIONSTATE,start);
1359    log_rv(rv);
1360    return rv;
1361}
1362
1363CK_RV NSSDBGC_Login(
1364  CK_SESSION_HANDLE hSession,
1365  CK_USER_TYPE      userType,
1366  CK_CHAR_PTR       pPin,
1367  CK_ULONG          ulPinLen
1368)
1369{
1370    COMMON_DEFINITIONS;
1371
1372    PR_LOG(modlog, 1, ("C_Login"));
1373    log_handle(3, fmt_hSession, hSession);
1374    PR_LOG(modlog, 3, ("  userType = 0x%x", userType));
1375    PR_LOG(modlog, 3, (fmt_pPin, pPin));
1376    PR_LOG(modlog, 3, (fmt_ulPinLen, ulPinLen));
1377    nssdbg_start_time(FUNC_C_LOGIN,&start);
1378    rv = module_functions->C_Login(hSession,
1379                                 userType,
1380                                 pPin,
1381                                 ulPinLen);
1382    nssdbg_finish_time(FUNC_C_LOGIN,start);
1383    log_rv(rv);
1384    return rv;
1385}
1386
1387CK_RV NSSDBGC_Logout(
1388  CK_SESSION_HANDLE hSession
1389)
1390{
1391    COMMON_DEFINITIONS;
1392
1393    PR_LOG(modlog, 1, ("C_Logout"));
1394    log_handle(3, fmt_hSession, hSession);
1395    nssdbg_start_time(FUNC_C_LOGOUT,&start);
1396    rv = module_functions->C_Logout(hSession);
1397    nssdbg_finish_time(FUNC_C_LOGOUT,start);
1398    log_rv(rv);
1399    return rv;
1400}
1401
1402CK_RV NSSDBGC_CreateObject(
1403  CK_SESSION_HANDLE    hSession,
1404  CK_ATTRIBUTE_PTR     pTemplate,
1405  CK_ULONG             ulCount,
1406  CK_OBJECT_HANDLE_PTR phObject
1407)
1408{
1409    COMMON_DEFINITIONS;
1410
1411    PR_LOG(modlog, 1, ("C_CreateObject"));
1412    log_handle(3, fmt_hSession, hSession);
1413    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1414    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1415    PR_LOG(modlog, 3, (fmt_phObject, phObject));
1416    print_template(pTemplate, ulCount);
1417    nssdbg_start_time(FUNC_C_CREATEOBJECT,&start);
1418    rv = module_functions->C_CreateObject(hSession,
1419                                 pTemplate,
1420                                 ulCount,
1421                                 phObject);
1422    nssdbg_finish_time(FUNC_C_CREATEOBJECT,start);
1423    log_handle(4, "  *phObject = 0x%x", *phObject);
1424    log_rv(rv);
1425    return rv;
1426}
1427
1428CK_RV NSSDBGC_CopyObject(
1429  CK_SESSION_HANDLE    hSession,
1430  CK_OBJECT_HANDLE     hObject,
1431  CK_ATTRIBUTE_PTR     pTemplate,
1432  CK_ULONG             ulCount,
1433  CK_OBJECT_HANDLE_PTR phNewObject
1434)
1435{
1436    COMMON_DEFINITIONS;
1437
1438    PR_LOG(modlog, 1, ("C_CopyObject"));
1439    log_handle(3, fmt_hSession, hSession);
1440    log_handle(3, fmt_hObject, hObject);
1441    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1442    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1443    PR_LOG(modlog, 3, ("  phNewObject = 0x%p", phNewObject));
1444    print_template(pTemplate, ulCount);
1445    nssdbg_start_time(FUNC_C_COPYOBJECT,&start);
1446    rv = module_functions->C_CopyObject(hSession,
1447                                 hObject,
1448                                 pTemplate,
1449                                 ulCount,
1450                                 phNewObject);
1451    nssdbg_finish_time(FUNC_C_COPYOBJECT,start);
1452    log_handle(4, "  *phNewObject = 0x%x", *phNewObject);
1453    log_rv(rv);
1454    return rv;
1455}
1456
1457CK_RV NSSDBGC_DestroyObject(
1458  CK_SESSION_HANDLE hSession,
1459  CK_OBJECT_HANDLE  hObject
1460)
1461{
1462    COMMON_DEFINITIONS;
1463
1464    PR_LOG(modlog, 1, ("C_DestroyObject"));
1465    log_handle(3, fmt_hSession, hSession);
1466    log_handle(3, fmt_hObject, hObject);
1467    nssdbg_start_time(FUNC_C_DESTROYOBJECT,&start);
1468    rv = module_functions->C_DestroyObject(hSession,
1469                                 hObject);
1470    nssdbg_finish_time(FUNC_C_DESTROYOBJECT,start);
1471    log_rv(rv);
1472    return rv;
1473}
1474
1475CK_RV NSSDBGC_GetObjectSize(
1476  CK_SESSION_HANDLE hSession,
1477  CK_OBJECT_HANDLE  hObject,
1478  CK_ULONG_PTR      pulSize
1479)
1480{
1481    COMMON_DEFINITIONS;
1482
1483    PR_LOG(modlog, 1, ("C_GetObjectSize"));
1484    log_handle(3, fmt_hSession, hSession);
1485    log_handle(3, fmt_hObject, hObject);
1486    PR_LOG(modlog, 3, ("  pulSize = 0x%p", pulSize));
1487    nssdbg_start_time(FUNC_C_GETOBJECTSIZE,&start);
1488    rv = module_functions->C_GetObjectSize(hSession,
1489                                 hObject,
1490                                 pulSize);
1491    nssdbg_finish_time(FUNC_C_GETOBJECTSIZE,start);
1492    PR_LOG(modlog, 4, ("  *pulSize = 0x%x", *pulSize));
1493    log_rv(rv);
1494    return rv;
1495}
1496
1497CK_RV NSSDBGC_GetAttributeValue(
1498  CK_SESSION_HANDLE hSession,
1499  CK_OBJECT_HANDLE  hObject,
1500  CK_ATTRIBUTE_PTR  pTemplate,
1501  CK_ULONG          ulCount
1502)
1503{
1504    COMMON_DEFINITIONS;
1505
1506    PR_LOG(modlog, 1, ("C_GetAttributeValue"));
1507    log_handle(3, fmt_hSession, hSession);
1508    log_handle(3, fmt_hObject, hObject);
1509    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1510    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1511    nssdbg_start_time(FUNC_C_GETATTRIBUTEVALUE,&start);
1512    rv = module_functions->C_GetAttributeValue(hSession,
1513                                 hObject,
1514                                 pTemplate,
1515                                 ulCount);
1516    nssdbg_finish_time(FUNC_C_GETATTRIBUTEVALUE,start);
1517    print_template(pTemplate, ulCount);
1518    log_rv(rv);
1519    return rv;
1520}
1521
1522CK_RV NSSDBGC_SetAttributeValue(
1523  CK_SESSION_HANDLE hSession,
1524  CK_OBJECT_HANDLE  hObject,
1525  CK_ATTRIBUTE_PTR  pTemplate,
1526  CK_ULONG          ulCount
1527)
1528{
1529    COMMON_DEFINITIONS;
1530
1531    PR_LOG(modlog, 1, ("C_SetAttributeValue"));
1532    log_handle(3, fmt_hSession, hSession);
1533    log_handle(3, fmt_hObject, hObject);
1534    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1535    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1536    print_template(pTemplate, ulCount);
1537    nssdbg_start_time(FUNC_C_SETATTRIBUTEVALUE,&start);
1538    rv = module_functions->C_SetAttributeValue(hSession,
1539                                 hObject,
1540                                 pTemplate,
1541                                 ulCount);
1542    nssdbg_finish_time(FUNC_C_SETATTRIBUTEVALUE,start);
1543    log_rv(rv);
1544    return rv;
1545}
1546
1547CK_RV NSSDBGC_FindObjectsInit(
1548  CK_SESSION_HANDLE hSession,
1549  CK_ATTRIBUTE_PTR  pTemplate,
1550  CK_ULONG          ulCount
1551)
1552{
1553    COMMON_DEFINITIONS;
1554
1555    PR_LOG(modlog, 1, ("C_FindObjectsInit"));
1556    log_handle(3, fmt_hSession, hSession);
1557    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1558    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1559    print_template(pTemplate, ulCount);
1560    nssdbg_start_time(FUNC_C_FINDOBJECTSINIT,&start);
1561    rv = module_functions->C_FindObjectsInit(hSession,
1562                                 pTemplate,
1563                                 ulCount);
1564    nssdbg_finish_time(FUNC_C_FINDOBJECTSINIT,start);
1565    log_rv(rv);
1566    return rv;
1567}
1568
1569CK_RV NSSDBGC_FindObjects(
1570  CK_SESSION_HANDLE    hSession,
1571  CK_OBJECT_HANDLE_PTR phObject,
1572  CK_ULONG             ulMaxObjectCount,
1573  CK_ULONG_PTR         pulObjectCount
1574)
1575{
1576    COMMON_DEFINITIONS;
1577    CK_ULONG i;
1578
1579    PR_LOG(modlog, 1, ("C_FindObjects"));
1580    log_handle(3, fmt_hSession, hSession);
1581    PR_LOG(modlog, 3, (fmt_phObject, phObject));
1582    PR_LOG(modlog, 3, ("  ulMaxObjectCount = %d", ulMaxObjectCount));
1583    PR_LOG(modlog, 3, ("  pulObjectCount = 0x%p", pulObjectCount));
1584    nssdbg_start_time(FUNC_C_FINDOBJECTS,&start);
1585    rv = module_functions->C_FindObjects(hSession,
1586                                 phObject,
1587                                 ulMaxObjectCount,
1588                                 pulObjectCount);
1589    nssdbg_finish_time(FUNC_C_FINDOBJECTS,start);
1590    PR_LOG(modlog, 4, ("  *pulObjectCount = 0x%x", *pulObjectCount));
1591    for (i=0; i<*pulObjectCount; i++) {
1592	PR_LOG(modlog, 4, ("  phObject[%d] = 0x%x%s", i, phObject[i],
1593	       phObject[i] ? "" : fmt_invalid_handle));
1594    }
1595    log_rv(rv);
1596    return rv;
1597}
1598
1599CK_RV NSSDBGC_FindObjectsFinal(
1600  CK_SESSION_HANDLE hSession
1601)
1602{
1603    COMMON_DEFINITIONS;
1604
1605    PR_LOG(modlog, 1, ("C_FindObjectsFinal"));
1606    log_handle(3, fmt_hSession, hSession);
1607    nssdbg_start_time(FUNC_C_FINDOBJECTSFINAL,&start);
1608    rv = module_functions->C_FindObjectsFinal(hSession);
1609    nssdbg_finish_time(FUNC_C_FINDOBJECTSFINAL,start);
1610    log_rv(rv);
1611    return rv;
1612}
1613
1614CK_RV NSSDBGC_EncryptInit(
1615  CK_SESSION_HANDLE hSession,
1616  CK_MECHANISM_PTR  pMechanism,
1617  CK_OBJECT_HANDLE  h

Large files files are truncated, but you can click here to view the full file