switch(mech) { case CKM_DES_KEY_GEN: mech = CKM_DES_ECB; break; case CKM_DES3_KEY_GEN: mech = CKM_DES3_ECB; break; case CKM_RC4_KEY_GEN: mech = CKM_RC4; break; case CKM_AES_KEY_GEN: mech = CKM_AES_CBC; break; default: JSS_throwMsg(env, TOKEN_EXCEPTION, "Unsupported keygen algorithm"); goto finish; }
Java_org_mozilla_jss_pkcs11_PK11KeyGenerator_generateNormal    (JNIEnv *env, jclass clazz, jobject token, jobject alg, jint strength){    PK11SlotInfo *slot=NULL;    PK11SymKey *skey=NULL;    CK_MECHANISM_TYPE mech;    jobject keyObj=NULL;    PR_ASSERT( env!=NULL && clazz!=NULL && token!=NULL && alg!=NULL );    /* Get the slot */    if( JSS_PK11_getTokenSlotPtr(env, token, &slot) != PR_SUCCESS ) {        goto finish;    }    /* Get the algorithm info */    mech = JSS_getPK11MechFromAlg(env, alg);    PR_ASSERT(mech != CKM_INVALID_MECHANISM);    /*     * This translation code can come out once we start using a version     * of NSS that has a fix for bug 162761.     */    switch(mech) {    case CKM_DES_KEY_GEN:        mech = CKM_DES_ECB;        break;    case CKM_DES3_KEY_GEN:        mech = CKM_DES3_ECB;        break;    case CKM_RC4_KEY_GEN:        mech = CKM_RC4;        break;    case CKM_AES_KEY_GEN:        mech = CKM_AES_CBC;        break;    default:        JSS_throwMsg(env, TOKEN_EXCEPTION, "Unsupported keygen algorithm");        goto finish;    }    /* generate the key */    skey = PK11_KeyGen(slot, mech, NULL /*param*/,                    strength/8 /*in bytes*/, NULL /*wincx*/ );    if(skey==NULL) {        JSS_throwMsgPrErr(env, TOKEN_EXCEPTION, "KeyGen failed on token");        goto finish;    }    /* wrap the key. This sets skey to NULL. */    keyObj = JSS_PK11_wrapSymKey(env, &skey);finish:    if(skey!=NULL) {        /* will only be non-NULL if keygen succeeded but wrapSymKey failed */        PK11_FreeSymKey(skey);    }    return keyObj;}