if (crv != CKR_OK) goto loser; keyType = PR_htonl(keyType); keyTypeItem.data = (unsigned char *)&keyType; keyTypeItem.len = sizeof (keyType);
if (crv != CKR_OK) goto loser;  keyTypeStorage = (PRUint32) keyType; keyTypeStorage = PR_htonl(keyTypeStorage); keyTypeItem.data = (unsigned char *)&keyTypeStorage; keyTypeItem.len = sizeof (keyTypeStorage);
pk11_mkSecretKeyRep(PK11Object *object){    NSSLOWKEYPrivateKey *privKey = 0;    PLArenaPool *arena = 0;    CK_KEY_TYPE keyType;    SECItem keyTypeItem;    CK_RV crv;    SECStatus rv;    static unsigned char derZero[1] = { 0 };    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);    if (arena == NULL) { crv = CKR_HOST_MEMORY; goto loser; }    privKey = (NSSLOWKEYPrivateKey *)			PORT_ArenaZAlloc(arena,sizeof(NSSLOWKEYPrivateKey));    if (privKey == NULL) { crv = CKR_HOST_MEMORY; goto loser; }    privKey->arena = arena;    /* Secret keys are represented in the database as "fake" RSA keys.  The RSA key     * is marked as a secret key representation by setting the public exponent field     * to 0, which is an invalid RSA exponent.  The other fields are set as follows:     *   modulus - CKA_ID value for the secret key     *   private exponent - CKA_VALUE (the key itself)     *   coefficient - CKA_KEY_TYPE, which indicates what encryption algorithm     *      is used for the key.     *   all others - set to integer 0     */    privKey->keyType = NSSLOWKEYRSAKey;    /* The modulus is set to the key id of the symmetric key */    crv=pk11_Attribute2SecItem(arena,&privKey->u.rsa.modulus,object,CKA_ID);    if (crv != CKR_OK) goto loser;    /* The public exponent is set to 0 length to indicate a special key */    privKey->u.rsa.publicExponent.len = sizeof derZero;    privKey->u.rsa.publicExponent.data = derZero;    /* The private exponent is the actual key value */    crv=pk11_Attribute2SecItem(arena,&privKey->u.rsa.privateExponent,object,CKA_VALUE);    if (crv != CKR_OK) goto loser;    /* All other fields empty - needs testing */    privKey->u.rsa.prime1.len = sizeof derZero;    privKey->u.rsa.prime1.data = derZero;    privKey->u.rsa.prime2.len = sizeof derZero;    privKey->u.rsa.prime2.data = derZero;    privKey->u.rsa.exponent1.len = sizeof derZero;    privKey->u.rsa.exponent1.data = derZero;    privKey->u.rsa.exponent2.len = sizeof derZero;    privKey->u.rsa.exponent2.data = derZero;    /* Coeficient set to KEY_TYPE */    crv = pk11_GetULongAttribute(object, CKA_KEY_TYPE, &keyType);    if (crv != CKR_OK) goto loser;    keyType = PR_htonl(keyType);    keyTypeItem.data = (unsigned char *)&keyType;    keyTypeItem.len = sizeof (keyType);    rv = SECITEM_CopyItem(arena, &privKey->u.rsa.coefficient, &keyTypeItem);    if (rv != SECSuccess) {	crv = CKR_HOST_MEMORY;	goto loser;    }        /* Private key version field set normally for compatibility */    rv = DER_SetUInteger(privKey->arena, 			&privKey->u.rsa.version, NSSLOWKEY_VERSION);    if (rv != SECSuccess) { crv = CKR_HOST_MEMORY; goto loser; }loser:    if (crv != CKR_OK) {	PORT_FreeArena(arena,PR_FALSE);	privKey = 0;    }    return privKey;}