pkcs11: Code cleanup and added parameter checking at PKCS#11 interface