Print this page
6640 dca gets the instance number a lot, never actually uses it


 397         dca_mech_info_tab1,
 398         0,                              /* pi_logical_provider_count */
 399         NULL                            /* pi_logical_providers */
 400 };
 401 
 402 /* Provider information for the asymmetric cipher provider */
 403 static crypto_provider_info_t dca_prov_info2 = {
 404         CRYPTO_SPI_VERSION_1,
 405         NULL,                           /* pi_provider_description */
 406         CRYPTO_HW_PROVIDER,
 407         NULL,                           /* pi_provider_dev */
 408         NULL,                           /* pi_provider_handle */
 409         &dca_crypto_ops2,
 410         sizeof (dca_mech_info_tab2)/sizeof (crypto_mech_info_t),
 411         dca_mech_info_tab2,
 412         0,                              /* pi_logical_provider_count */
 413         NULL                            /* pi_logical_providers */
 414 };
 415 
 416 /* Convenience macros */
 417 /* Retrieve the softc and instance number from a SPI crypto context */
 418 #define DCA_SOFTC_FROM_CTX(ctx, softc, instance) {              \
 419         (softc) = (dca_t *)(ctx)->cc_provider;                       \
 420         (instance) = ddi_get_instance((softc)->dca_dip);     \
 421 }
 422 
 423 #define DCA_MECH_FROM_CTX(ctx) \
 424         (((dca_request_t *)(ctx)->cc_provider_private)->dr_ctx.ctx_cm_type)
 425 
 426 static int dca_bindchains_one(dca_request_t *reqp, size_t cnt, int dr_offset,
 427     caddr_t kaddr, ddi_dma_handle_t handle, uint_t flags,
 428     dca_chain_t *head, int *n_chain);
 429 static uint64_t dca_ena(uint64_t ena);
 430 static caddr_t dca_bufdaddr_out(crypto_data_t *data);
 431 static char *dca_fma_eclass_string(char *model, dca_fma_eclass_t index);
 432 static int dca_check_acc_handle(dca_t *dca, ddi_acc_handle_t handle,
 433     dca_fma_eclass_t eclass_index);
 434 
 435 static void dca_fma_init(dca_t *dca);
 436 static void dca_fma_fini(dca_t *dca);
 437 static int dca_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err,
 438     const void *impl_data);
 439 
 440 
 441 static dca_device_t dca_devices[] = {
 442         /* Broadcom vanilla variants */


3677 
3678 /* ARGSUSED */
3679 static void
3680 dca_provider_status(crypto_provider_handle_t provider, uint_t *status)
3681 {
3682         *status = CRYPTO_PROVIDER_READY;
3683 }
3684 
3685 /*
3686  * Cipher (encrypt/decrypt) entry points.
3687  */
3688 
3689 /* ARGSUSED */
3690 static int
3691 dca_encrypt_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
3692     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
3693     crypto_req_handle_t req)
3694 {
3695         int error = CRYPTO_FAILED;
3696         dca_t *softc;
3697         /* LINTED E_FUNC_SET_NOT_USED */
3698         int instance;
3699 
3700         /* extract softc and instance number from context */
3701         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
3702         DBG(softc, DENTRY, "dca_encrypt_init: started");
3703 
3704         /* check mechanism */
3705         switch (mechanism->cm_type) {
3706         case DES_CBC_MECH_INFO_TYPE:
3707                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3708                     DR_ENCRYPT);
3709                 break;
3710         case DES3_CBC_MECH_INFO_TYPE:
3711                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3712                     DR_ENCRYPT | DR_TRIPLE);
3713                 break;
3714         case RSA_PKCS_MECH_INFO_TYPE:
3715         case RSA_X_509_MECH_INFO_TYPE:
3716                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
3717                 break;
3718         default:
3719                 cmn_err(CE_WARN, "dca_encrypt_init: unexpected mech type "
3720                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
3721                 error = CRYPTO_MECHANISM_INVALID;
3722         }
3723 
3724         DBG(softc, DENTRY, "dca_encrypt_init: done, err = 0x%x", error);
3725 
3726         if (error == CRYPTO_SUCCESS)
3727                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
3728                     &softc->dca_ctx_list_lock);
3729 
3730         return (error);
3731 }
3732 
3733 /* ARGSUSED */
3734 static int
3735 dca_encrypt(crypto_ctx_t *ctx, crypto_data_t *plaintext,
3736     crypto_data_t *ciphertext, crypto_req_handle_t req)
3737 {
3738         int error = CRYPTO_FAILED;
3739         dca_t *softc;
3740         /* LINTED E_FUNC_SET_NOT_USED */
3741         int instance;
3742 
3743         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3744                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3745 
3746         /* extract softc and instance number from context */
3747         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
3748         DBG(softc, DENTRY, "dca_encrypt: started");
3749 
3750         /* handle inplace ops */
3751         if (!ciphertext) {
3752                 dca_request_t *reqp = ctx->cc_provider_private;
3753                 reqp->dr_flags |= DR_INPLACE;
3754                 ciphertext = plaintext;
3755         }
3756 
3757         /* check mechanism */
3758         switch (DCA_MECH_FROM_CTX(ctx)) {
3759         case DES_CBC_MECH_INFO_TYPE:
3760                 error = dca_3des(ctx, plaintext, ciphertext, req, DR_ENCRYPT);
3761                 break;
3762         case DES3_CBC_MECH_INFO_TYPE:
3763                 error = dca_3des(ctx, plaintext, ciphertext, req,
3764                     DR_ENCRYPT | DR_TRIPLE);
3765                 break;
3766         case RSA_PKCS_MECH_INFO_TYPE:
3767         case RSA_X_509_MECH_INFO_TYPE:


3775                 error = CRYPTO_MECHANISM_INVALID;
3776         }
3777 
3778         if ((error != CRYPTO_QUEUED) && (error != CRYPTO_SUCCESS) &&
3779             (error != CRYPTO_BUFFER_TOO_SMALL)) {
3780                 ciphertext->cd_length = 0;
3781         }
3782 
3783         DBG(softc, DENTRY, "dca_encrypt: done, err = 0x%x", error);
3784 
3785         return (error);
3786 }
3787 
3788 /* ARGSUSED */
3789 static int
3790 dca_encrypt_update(crypto_ctx_t *ctx, crypto_data_t *plaintext,
3791     crypto_data_t *ciphertext, crypto_req_handle_t req)
3792 {
3793         int error = CRYPTO_FAILED;
3794         dca_t *softc;
3795         /* LINTED E_FUNC_SET_NOT_USED */
3796         int instance;
3797 
3798         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3799                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3800 
3801         /* extract softc and instance number from context */
3802         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
3803         DBG(softc, DENTRY, "dca_encrypt_update: started");
3804 
3805         /* handle inplace ops */
3806         if (!ciphertext) {
3807                 dca_request_t *reqp = ctx->cc_provider_private;
3808                 reqp->dr_flags |= DR_INPLACE;
3809                 ciphertext = plaintext;
3810         }
3811 
3812         /* check mechanism */
3813         switch (DCA_MECH_FROM_CTX(ctx)) {
3814         case DES_CBC_MECH_INFO_TYPE:
3815                 error = dca_3desupdate(ctx, plaintext, ciphertext, req,
3816                     DR_ENCRYPT);
3817                 break;
3818         case DES3_CBC_MECH_INFO_TYPE:
3819                 error = dca_3desupdate(ctx, plaintext, ciphertext, req,
3820                     DR_ENCRYPT | DR_TRIPLE);
3821                 break;
3822         default:
3823                 /* Should never reach here */
3824                 cmn_err(CE_WARN, "dca_encrypt_update: unexpected mech type "
3825                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
3826                 error = CRYPTO_MECHANISM_INVALID;
3827         }
3828 
3829         DBG(softc, DENTRY, "dca_encrypt_update: done, err = 0x%x", error);
3830 
3831         return (error);
3832 }
3833 
3834 /* ARGSUSED */
3835 static int
3836 dca_encrypt_final(crypto_ctx_t *ctx, crypto_data_t *ciphertext,
3837     crypto_req_handle_t req)
3838 {
3839         int error = CRYPTO_FAILED;
3840         dca_t *softc;
3841         /* LINTED E_FUNC_SET_NOT_USED */
3842         int instance;
3843 
3844         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3845                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3846 
3847         /* extract softc and instance number from context */
3848         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
3849         DBG(softc, DENTRY, "dca_encrypt_final: started");
3850 
3851         /* check mechanism */
3852         switch (DCA_MECH_FROM_CTX(ctx)) {
3853         case DES_CBC_MECH_INFO_TYPE:
3854                 error = dca_3desfinal(ctx, ciphertext, DR_ENCRYPT);
3855                 break;
3856         case DES3_CBC_MECH_INFO_TYPE:
3857                 error = dca_3desfinal(ctx, ciphertext, DR_ENCRYPT | DR_TRIPLE);
3858                 break;
3859         default:
3860                 /* Should never reach here */
3861                 cmn_err(CE_WARN, "dca_encrypt_final: unexpected mech type "
3862                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
3863                 error = CRYPTO_MECHANISM_INVALID;
3864         }
3865 
3866         DBG(softc, DENTRY, "dca_encrypt_final: done, err = 0x%x", error);
3867 
3868         return (error);


3911                 error = CRYPTO_MECHANISM_INVALID;
3912         }
3913 
3914         if ((error != CRYPTO_QUEUED) && (error != CRYPTO_SUCCESS)) {
3915                 ciphertext->cd_length = 0;
3916         }
3917 
3918         DBG(softc, DENTRY, "dca_encrypt_atomic: done, err = 0x%x", error);
3919 
3920         return (error);
3921 }
3922 
3923 /* ARGSUSED */
3924 static int
3925 dca_decrypt_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
3926     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
3927     crypto_req_handle_t req)
3928 {
3929         int error = CRYPTO_FAILED;
3930         dca_t *softc;
3931         /* LINTED E_FUNC_SET_NOT_USED */
3932         int instance;
3933 
3934         /* extract softc and instance number from context */
3935         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
3936         DBG(softc, DENTRY, "dca_decrypt_init: started");
3937 
3938         /* check mechanism */
3939         switch (mechanism->cm_type) {
3940         case DES_CBC_MECH_INFO_TYPE:
3941                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3942                     DR_DECRYPT);
3943                 break;
3944         case DES3_CBC_MECH_INFO_TYPE:
3945                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3946                     DR_DECRYPT | DR_TRIPLE);
3947                 break;
3948         case RSA_PKCS_MECH_INFO_TYPE:
3949         case RSA_X_509_MECH_INFO_TYPE:
3950                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
3951                 break;
3952         default:
3953                 cmn_err(CE_WARN, "dca_decrypt_init: unexpected mech type "
3954                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
3955                 error = CRYPTO_MECHANISM_INVALID;
3956         }
3957 
3958         DBG(softc, DENTRY, "dca_decrypt_init: done, err = 0x%x", error);
3959 
3960         if (error == CRYPTO_SUCCESS)
3961                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
3962                     &softc->dca_ctx_list_lock);
3963 
3964         return (error);
3965 }
3966 
3967 /* ARGSUSED */
3968 static int
3969 dca_decrypt(crypto_ctx_t *ctx, crypto_data_t *ciphertext,
3970     crypto_data_t *plaintext, crypto_req_handle_t req)
3971 {
3972         int error = CRYPTO_FAILED;
3973         dca_t *softc;
3974         /* LINTED E_FUNC_SET_NOT_USED */
3975         int instance;
3976 
3977         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3978                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3979 
3980         /* extract softc and instance number from context */
3981         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
3982         DBG(softc, DENTRY, "dca_decrypt: started");
3983 
3984         /* handle inplace ops */
3985         if (!plaintext) {
3986                 dca_request_t *reqp = ctx->cc_provider_private;
3987                 reqp->dr_flags |= DR_INPLACE;
3988                 plaintext = ciphertext;
3989         }
3990 
3991         /* check mechanism */
3992         switch (DCA_MECH_FROM_CTX(ctx)) {
3993         case DES_CBC_MECH_INFO_TYPE:
3994                 error = dca_3des(ctx, ciphertext, plaintext, req, DR_DECRYPT);
3995                 break;
3996         case DES3_CBC_MECH_INFO_TYPE:
3997                 error = dca_3des(ctx, ciphertext, plaintext, req,
3998                     DR_DECRYPT | DR_TRIPLE);
3999                 break;
4000         case RSA_PKCS_MECH_INFO_TYPE:
4001         case RSA_X_509_MECH_INFO_TYPE:


4010         }
4011 
4012         if ((error != CRYPTO_QUEUED) && (error != CRYPTO_SUCCESS) &&
4013             (error != CRYPTO_BUFFER_TOO_SMALL)) {
4014                 if (plaintext)
4015                         plaintext->cd_length = 0;
4016         }
4017 
4018         DBG(softc, DENTRY, "dca_decrypt: done, err = 0x%x", error);
4019 
4020         return (error);
4021 }
4022 
4023 /* ARGSUSED */
4024 static int
4025 dca_decrypt_update(crypto_ctx_t *ctx, crypto_data_t *ciphertext,
4026     crypto_data_t *plaintext, crypto_req_handle_t req)
4027 {
4028         int error = CRYPTO_FAILED;
4029         dca_t *softc;
4030         /* LINTED E_FUNC_SET_NOT_USED */
4031         int instance;
4032 
4033         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4034                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4035 
4036         /* extract softc and instance number from context */
4037         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4038         DBG(softc, DENTRY, "dca_decrypt_update: started");
4039 
4040         /* handle inplace ops */
4041         if (!plaintext) {
4042                 dca_request_t *reqp = ctx->cc_provider_private;
4043                 reqp->dr_flags |= DR_INPLACE;
4044                 plaintext = ciphertext;
4045         }
4046 
4047         /* check mechanism */
4048         switch (DCA_MECH_FROM_CTX(ctx)) {
4049         case DES_CBC_MECH_INFO_TYPE:
4050                 error = dca_3desupdate(ctx, ciphertext, plaintext, req,
4051                     DR_DECRYPT);
4052                 break;
4053         case DES3_CBC_MECH_INFO_TYPE:
4054                 error = dca_3desupdate(ctx, ciphertext, plaintext, req,
4055                     DR_DECRYPT | DR_TRIPLE);
4056                 break;
4057         default:
4058                 /* Should never reach here */
4059                 cmn_err(CE_WARN, "dca_decrypt_update: unexpected mech type "
4060                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4061                 error = CRYPTO_MECHANISM_INVALID;
4062         }
4063 
4064         DBG(softc, DENTRY, "dca_decrypt_update: done, err = 0x%x", error);
4065 
4066         return (error);
4067 }
4068 
4069 /* ARGSUSED */
4070 static int
4071 dca_decrypt_final(crypto_ctx_t *ctx, crypto_data_t *plaintext,
4072     crypto_req_handle_t req)
4073 {
4074         int error = CRYPTO_FAILED;
4075         dca_t *softc;
4076         /* LINTED E_FUNC_SET_NOT_USED */
4077         int instance;
4078 
4079         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4080                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4081 
4082         /* extract softc and instance number from context */
4083         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4084         DBG(softc, DENTRY, "dca_decrypt_final: started");
4085 
4086         /* check mechanism */
4087         switch (DCA_MECH_FROM_CTX(ctx)) {
4088         case DES_CBC_MECH_INFO_TYPE:
4089                 error = dca_3desfinal(ctx, plaintext, DR_DECRYPT);
4090                 break;
4091         case DES3_CBC_MECH_INFO_TYPE:
4092                 error = dca_3desfinal(ctx, plaintext, DR_DECRYPT | DR_TRIPLE);
4093                 break;
4094         default:
4095                 /* Should never reach here */
4096                 cmn_err(CE_WARN, "dca_decrypt_final: unexpected mech type "
4097                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4098                 error = CRYPTO_MECHANISM_INVALID;
4099         }
4100 
4101         DBG(softc, DENTRY, "dca_decrypt_final: done, err = 0x%x", error);
4102 
4103         return (error);


4150                 plaintext->cd_length = 0;
4151         }
4152 
4153         DBG(softc, DENTRY, "dca_decrypt_atomic: done, err = 0x%x", error);
4154 
4155         return (error);
4156 }
4157 
4158 /*
4159  * Sign entry points.
4160  */
4161 
4162 /* ARGSUSED */
4163 static int
4164 dca_sign_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4165     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4166     crypto_req_handle_t req)
4167 {
4168         int error = CRYPTO_FAILED;
4169         dca_t *softc;
4170         /* LINTED E_FUNC_SET_NOT_USED */
4171         int instance;
4172 
4173         /* extract softc and instance number from context */
4174         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4175         DBG(softc, DENTRY, "dca_sign_init: started\n");
4176 
4177         if (ctx_template != NULL)
4178                 return (CRYPTO_ARGUMENTS_BAD);
4179 
4180         /* check mechanism */
4181         switch (mechanism->cm_type) {
4182         case RSA_PKCS_MECH_INFO_TYPE:
4183         case RSA_X_509_MECH_INFO_TYPE:
4184                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4185                 break;
4186         case DSA_MECH_INFO_TYPE:
4187                 error = dca_dsainit(ctx, mechanism, key, KM_SLEEP,
4188                     DCA_DSA_SIGN);
4189                 break;
4190         default:
4191                 cmn_err(CE_WARN, "dca_sign_init: unexpected mech type "
4192                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4193                 error = CRYPTO_MECHANISM_INVALID;
4194         }
4195 
4196         DBG(softc, DENTRY, "dca_sign_init: done, err = 0x%x", error);
4197 
4198         if (error == CRYPTO_SUCCESS)
4199                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4200                     &softc->dca_ctx_list_lock);
4201 
4202         return (error);
4203 }
4204 
4205 static int
4206 dca_sign(crypto_ctx_t *ctx, crypto_data_t *data,
4207     crypto_data_t *signature, crypto_req_handle_t req)
4208 {
4209         int error = CRYPTO_FAILED;
4210         dca_t *softc;
4211         /* LINTED E_FUNC_SET_NOT_USED */
4212         int instance;
4213 
4214         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4215                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4216 
4217         /* extract softc and instance number from context */
4218         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4219         DBG(softc, DENTRY, "dca_sign: started\n");
4220 
4221         /* check mechanism */
4222         switch (DCA_MECH_FROM_CTX(ctx)) {
4223         case RSA_PKCS_MECH_INFO_TYPE:
4224         case RSA_X_509_MECH_INFO_TYPE:
4225                 error = dca_rsastart(ctx, data, signature, req, DCA_RSA_SIGN);
4226                 break;
4227         case DSA_MECH_INFO_TYPE:
4228                 error = dca_dsa_sign(ctx, data, signature, req);
4229                 break;
4230         default:
4231                 cmn_err(CE_WARN, "dca_sign: unexpected mech type "
4232                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4233                 error = CRYPTO_MECHANISM_INVALID;
4234         }
4235 
4236         DBG(softc, DENTRY, "dca_sign: done, err = 0x%x", error);
4237 
4238         return (error);
4239 }
4240 
4241 /* ARGSUSED */
4242 static int
4243 dca_sign_update(crypto_ctx_t *ctx, crypto_data_t *data,
4244     crypto_req_handle_t req)
4245 {
4246         int error = CRYPTO_MECHANISM_INVALID;
4247         dca_t *softc;
4248         /* LINTED E_FUNC_SET_NOT_USED */
4249         int instance;
4250 
4251         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4252                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4253 
4254         /* extract softc and instance number from context */
4255         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4256         DBG(softc, DENTRY, "dca_sign_update: started\n");
4257 
4258         cmn_err(CE_WARN, "dca_sign_update: unexpected mech type "
4259             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4260 
4261         DBG(softc, DENTRY, "dca_sign_update: done, err = 0x%x", error);
4262 
4263         return (error);
4264 }
4265 
4266 /* ARGSUSED */
4267 static int
4268 dca_sign_final(crypto_ctx_t *ctx, crypto_data_t *signature,
4269     crypto_req_handle_t req)
4270 {
4271         int error = CRYPTO_MECHANISM_INVALID;
4272         dca_t *softc;
4273         /* LINTED E_FUNC_SET_NOT_USED */
4274         int instance;
4275 
4276         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4277                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4278 
4279         /* extract softc and instance number from context */
4280         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4281         DBG(softc, DENTRY, "dca_sign_final: started\n");
4282 
4283         cmn_err(CE_WARN, "dca_sign_final: unexpected mech type "
4284             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4285 
4286         DBG(softc, DENTRY, "dca_sign_final: done, err = 0x%x", error);
4287 
4288         return (error);
4289 }
4290 
4291 static int
4292 dca_sign_atomic(crypto_provider_handle_t provider,
4293     crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
4294     crypto_key_t *key, crypto_data_t *data, crypto_data_t *signature,
4295     crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
4296 {
4297         int error = CRYPTO_FAILED;
4298         dca_t *softc = (dca_t *)provider;
4299 
4300         DBG(softc, DENTRY, "dca_sign_atomic: started\n");


4315                 break;
4316         default:
4317                 cmn_err(CE_WARN, "dca_sign_atomic: unexpected mech type "
4318                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4319                 error = CRYPTO_MECHANISM_INVALID;
4320         }
4321 
4322         DBG(softc, DENTRY, "dca_sign_atomic: done, err = 0x%x", error);
4323 
4324         return (error);
4325 }
4326 
4327 /* ARGSUSED */
4328 static int
4329 dca_sign_recover_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4330     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4331     crypto_req_handle_t req)
4332 {
4333         int error = CRYPTO_FAILED;
4334         dca_t *softc;
4335         /* LINTED E_FUNC_SET_NOT_USED */
4336         int instance;
4337 
4338         /* extract softc and instance number from context */
4339         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4340         DBG(softc, DENTRY, "dca_sign_recover_init: started\n");
4341 
4342         if (ctx_template != NULL)
4343                 return (CRYPTO_ARGUMENTS_BAD);
4344 
4345         /* check mechanism */
4346         switch (mechanism->cm_type) {
4347         case RSA_PKCS_MECH_INFO_TYPE:
4348         case RSA_X_509_MECH_INFO_TYPE:
4349                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4350                 break;
4351         default:
4352                 cmn_err(CE_WARN, "dca_sign_recover_init: unexpected mech type "
4353                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4354                 error = CRYPTO_MECHANISM_INVALID;
4355         }
4356 
4357         DBG(softc, DENTRY, "dca_sign_recover_init: done, err = 0x%x", error);
4358 
4359         if (error == CRYPTO_SUCCESS)
4360                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4361                     &softc->dca_ctx_list_lock);
4362 
4363         return (error);
4364 }
4365 
4366 static int
4367 dca_sign_recover(crypto_ctx_t *ctx, crypto_data_t *data,
4368     crypto_data_t *signature, crypto_req_handle_t req)
4369 {
4370         int error = CRYPTO_FAILED;
4371         dca_t *softc;
4372         /* LINTED E_FUNC_SET_NOT_USED */
4373         int instance;
4374 
4375         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4376                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4377 
4378         /* extract softc and instance number from context */
4379         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4380         DBG(softc, DENTRY, "dca_sign_recover: started\n");
4381 
4382         /* check mechanism */
4383         switch (DCA_MECH_FROM_CTX(ctx)) {
4384         case RSA_PKCS_MECH_INFO_TYPE:
4385         case RSA_X_509_MECH_INFO_TYPE:
4386                 error = dca_rsastart(ctx, data, signature, req, DCA_RSA_SIGNR);
4387                 break;
4388         default:
4389                 cmn_err(CE_WARN, "dca_sign_recover: unexpected mech type "
4390                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4391                 error = CRYPTO_MECHANISM_INVALID;
4392         }
4393 
4394         DBG(softc, DENTRY, "dca_sign_recover: done, err = 0x%x", error);
4395 
4396         return (error);
4397 }
4398 
4399 static int
4400 dca_sign_recover_atomic(crypto_provider_handle_t provider,
4401     crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
4402     crypto_key_t *key, crypto_data_t *data, crypto_data_t *signature,
4403     crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
4404 {
4405         int error = CRYPTO_FAILED;
4406         dca_t *softc = (dca_t *)provider;
4407         /* LINTED E_FUNC_SET_NOT_USED */
4408         int instance;
4409 
4410         instance = ddi_get_instance(softc->dca_dip);
4411         DBG(softc, DENTRY, "dca_sign_recover_atomic: started\n");
4412 
4413         if (ctx_template != NULL)
4414                 return (CRYPTO_ARGUMENTS_BAD);
4415 
4416         /* check mechanism */
4417         switch (mechanism->cm_type) {
4418         case RSA_PKCS_MECH_INFO_TYPE:
4419         case RSA_X_509_MECH_INFO_TYPE:
4420                 error = dca_rsaatomic(provider, session_id, mechanism, key,
4421                     data, signature, KM_SLEEP, req, DCA_RSA_SIGNR);
4422                 break;
4423         default:
4424                 cmn_err(CE_WARN, "dca_sign_recover_atomic: unexpected mech type"
4425                     " 0x%llx\n", (unsigned long long)mechanism->cm_type);
4426                 error = CRYPTO_MECHANISM_INVALID;
4427         }
4428 
4429         DBG(softc, DENTRY, "dca_sign_recover_atomic: done, err = 0x%x", error);
4430 
4431         return (error);
4432 }
4433 
4434 /*
4435  * Verify entry points.
4436  */
4437 
4438 /* ARGSUSED */
4439 static int
4440 dca_verify_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4441     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4442     crypto_req_handle_t req)
4443 {
4444         int error = CRYPTO_FAILED;
4445         dca_t *softc;
4446         /* LINTED E_FUNC_SET_NOT_USED */
4447         int instance;
4448 
4449         /* extract softc and instance number from context */
4450         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4451         DBG(softc, DENTRY, "dca_verify_init: started\n");
4452 
4453         if (ctx_template != NULL)
4454                 return (CRYPTO_ARGUMENTS_BAD);
4455 
4456         /* check mechanism */
4457         switch (mechanism->cm_type) {
4458         case RSA_PKCS_MECH_INFO_TYPE:
4459         case RSA_X_509_MECH_INFO_TYPE:
4460                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4461                 break;
4462         case DSA_MECH_INFO_TYPE:
4463                 error = dca_dsainit(ctx, mechanism, key, KM_SLEEP,
4464                     DCA_DSA_VRFY);
4465                 break;
4466         default:
4467                 cmn_err(CE_WARN, "dca_verify_init: unexpected mech type "
4468                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4469                 error = CRYPTO_MECHANISM_INVALID;
4470         }
4471 
4472         DBG(softc, DENTRY, "dca_verify_init: done, err = 0x%x", error);
4473 
4474         if (error == CRYPTO_SUCCESS)
4475                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4476                     &softc->dca_ctx_list_lock);
4477 
4478         return (error);
4479 }
4480 
4481 static int
4482 dca_verify(crypto_ctx_t *ctx, crypto_data_t *data, crypto_data_t *signature,
4483     crypto_req_handle_t req)
4484 {
4485         int error = CRYPTO_FAILED;
4486         dca_t *softc;
4487         /* LINTED E_FUNC_SET_NOT_USED */
4488         int instance;
4489 
4490         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4491                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4492 
4493         /* extract softc and instance number from context */
4494         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4495         DBG(softc, DENTRY, "dca_verify: started\n");
4496 
4497         /* check mechanism */
4498         switch (DCA_MECH_FROM_CTX(ctx)) {
4499         case RSA_PKCS_MECH_INFO_TYPE:
4500         case RSA_X_509_MECH_INFO_TYPE:
4501                 error = dca_rsastart(ctx, signature, data, req, DCA_RSA_VRFY);
4502                 break;
4503         case DSA_MECH_INFO_TYPE:
4504                 error = dca_dsa_verify(ctx, data, signature, req);
4505                 break;
4506         default:
4507                 cmn_err(CE_WARN, "dca_verify: unexpected mech type "
4508                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4509                 error = CRYPTO_MECHANISM_INVALID;
4510         }
4511 
4512         DBG(softc, DENTRY, "dca_verify: done, err = 0x%x", error);
4513 
4514         return (error);
4515 }
4516 
4517 /* ARGSUSED */
4518 static int
4519 dca_verify_update(crypto_ctx_t *ctx, crypto_data_t *data,
4520     crypto_req_handle_t req)
4521 {
4522         int error = CRYPTO_MECHANISM_INVALID;
4523         dca_t *softc;
4524         /* LINTED E_FUNC_SET_NOT_USED */
4525         int instance;
4526 
4527         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4528                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4529 
4530         /* extract softc and instance number from context */
4531         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4532         DBG(softc, DENTRY, "dca_verify_update: started\n");
4533 
4534         cmn_err(CE_WARN, "dca_verify_update: unexpected mech type "
4535             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4536 
4537         DBG(softc, DENTRY, "dca_verify_update: done, err = 0x%x", error);
4538 
4539         return (error);
4540 }
4541 
4542 /* ARGSUSED */
4543 static int
4544 dca_verify_final(crypto_ctx_t *ctx, crypto_data_t *signature,
4545     crypto_req_handle_t req)
4546 {
4547         int error = CRYPTO_MECHANISM_INVALID;
4548         dca_t *softc;
4549         /* LINTED E_FUNC_SET_NOT_USED */
4550         int instance;
4551 
4552         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4553                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4554 
4555         /* extract softc and instance number from context */
4556         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4557         DBG(softc, DENTRY, "dca_verify_final: started\n");
4558 
4559         cmn_err(CE_WARN, "dca_verify_final: unexpected mech type "
4560             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4561 
4562         DBG(softc, DENTRY, "dca_verify_final: done, err = 0x%x", error);
4563 
4564         return (error);
4565 }
4566 
4567 static int
4568 dca_verify_atomic(crypto_provider_handle_t provider,
4569     crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
4570     crypto_key_t *key, crypto_data_t *data, crypto_data_t *signature,
4571     crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
4572 {
4573         int error = CRYPTO_FAILED;
4574         dca_t *softc = (dca_t *)provider;
4575 
4576         DBG(softc, DENTRY, "dca_verify_atomic: started\n");


4591                 break;
4592         default:
4593                 cmn_err(CE_WARN, "dca_verify_atomic: unexpected mech type "
4594                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4595                 error = CRYPTO_MECHANISM_INVALID;
4596         }
4597 
4598         DBG(softc, DENTRY, "dca_verify_atomic: done, err = 0x%x", error);
4599 
4600         return (error);
4601 }
4602 
4603 /* ARGSUSED */
4604 static int
4605 dca_verify_recover_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4606     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4607     crypto_req_handle_t req)
4608 {
4609         int error = CRYPTO_MECHANISM_INVALID;
4610         dca_t *softc;
4611         /* LINTED E_FUNC_SET_NOT_USED */
4612         int instance;
4613 
4614         /* extract softc and instance number from context */
4615         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4616         DBG(softc, DENTRY, "dca_verify_recover_init: started\n");
4617 
4618         if (ctx_template != NULL)
4619                 return (CRYPTO_ARGUMENTS_BAD);
4620 
4621         /* check mechanism */
4622         switch (mechanism->cm_type) {
4623         case RSA_PKCS_MECH_INFO_TYPE:
4624         case RSA_X_509_MECH_INFO_TYPE:
4625                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4626                 break;
4627         default:
4628                 cmn_err(CE_WARN, "dca_verify_recover_init: unexpected mech type"
4629                     " 0x%llx\n", (unsigned long long)mechanism->cm_type);
4630         }
4631 
4632         DBG(softc, DENTRY, "dca_verify_recover_init: done, err = 0x%x", error);
4633 
4634         if (error == CRYPTO_SUCCESS)
4635                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4636                     &softc->dca_ctx_list_lock);
4637 
4638         return (error);
4639 }
4640 
4641 static int
4642 dca_verify_recover(crypto_ctx_t *ctx, crypto_data_t *signature,
4643     crypto_data_t *data, crypto_req_handle_t req)
4644 {
4645         int error = CRYPTO_MECHANISM_INVALID;
4646         dca_t *softc;
4647         /* LINTED E_FUNC_SET_NOT_USED */
4648         int instance;
4649 
4650         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4651                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4652 
4653         /* extract softc and instance number from context */
4654         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4655         DBG(softc, DENTRY, "dca_verify_recover: started\n");
4656 
4657         /* check mechanism */
4658         switch (DCA_MECH_FROM_CTX(ctx)) {
4659         case RSA_PKCS_MECH_INFO_TYPE:
4660         case RSA_X_509_MECH_INFO_TYPE:
4661                 error = dca_rsastart(ctx, signature, data, req, DCA_RSA_VRFYR);
4662                 break;
4663         default:
4664                 cmn_err(CE_WARN, "dca_verify_recover: unexpected mech type "
4665                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4666         }
4667 
4668         DBG(softc, DENTRY, "dca_verify_recover: done, err = 0x%x", error);
4669 
4670         return (error);
4671 }
4672 
4673 static int
4674 dca_verify_recover_atomic(crypto_provider_handle_t provider,


4698         }
4699 
4700         DBG(softc, DENTRY,
4701             "dca_verify_recover_atomic: done, err = 0x%x", error);
4702 
4703         return (error);
4704 }
4705 
4706 /*
4707  * Random number entry points.
4708  */
4709 
4710 /* ARGSUSED */
4711 static int
4712 dca_generate_random(crypto_provider_handle_t provider,
4713     crypto_session_id_t session_id,
4714     uchar_t *buf, size_t len, crypto_req_handle_t req)
4715 {
4716         int error = CRYPTO_FAILED;
4717         dca_t *softc = (dca_t *)provider;
4718         /* LINTED E_FUNC_SET_NOT_USED */
4719         int instance;
4720 
4721         instance = ddi_get_instance(softc->dca_dip);
4722         DBG(softc, DENTRY, "dca_generate_random: started");
4723 
4724         error = dca_rng(softc, buf, len, req);
4725 
4726         DBG(softc, DENTRY, "dca_generate_random: done, err = 0x%x", error);
4727 
4728         return (error);
4729 }
4730 
4731 /*
4732  * Context management entry points.
4733  */
4734 
4735 int
4736 dca_free_context(crypto_ctx_t *ctx)
4737 {
4738         int error = CRYPTO_SUCCESS;
4739         dca_t *softc;
4740         /* LINTED E_FUNC_SET_NOT_USED */
4741         int instance;
4742 
4743         /* extract softc and instance number from context */
4744         DCA_SOFTC_FROM_CTX(ctx, softc, instance);
4745         DBG(softc, DENTRY, "dca_free_context: entered");
4746 
4747         if (ctx->cc_provider_private == NULL)
4748                 return (error);
4749 
4750         dca_rmlist2(ctx->cc_provider_private, &softc->dca_ctx_list_lock);
4751 
4752         error = dca_free_context_low(ctx);
4753 
4754         DBG(softc, DENTRY, "dca_free_context: done, err = 0x%x", error);
4755 
4756         return (error);
4757 }
4758 
4759 static int
4760 dca_free_context_low(crypto_ctx_t *ctx)
4761 {
4762         int error = CRYPTO_SUCCESS;
4763 
4764         /* check mechanism */




 397         dca_mech_info_tab1,
 398         0,                              /* pi_logical_provider_count */
 399         NULL                            /* pi_logical_providers */
 400 };
 401 
 402 /* Provider information for the asymmetric cipher provider */
 403 static crypto_provider_info_t dca_prov_info2 = {
 404         CRYPTO_SPI_VERSION_1,
 405         NULL,                           /* pi_provider_description */
 406         CRYPTO_HW_PROVIDER,
 407         NULL,                           /* pi_provider_dev */
 408         NULL,                           /* pi_provider_handle */
 409         &dca_crypto_ops2,
 410         sizeof (dca_mech_info_tab2)/sizeof (crypto_mech_info_t),
 411         dca_mech_info_tab2,
 412         0,                              /* pi_logical_provider_count */
 413         NULL                            /* pi_logical_providers */
 414 };
 415 
 416 /* Convenience macros */
 417 #define DCA_SOFTC_FROM_CTX(ctx) ((dca_t *)(ctx)->cc_provider)





 418 #define DCA_MECH_FROM_CTX(ctx) \
 419         (((dca_request_t *)(ctx)->cc_provider_private)->dr_ctx.ctx_cm_type)
 420 
 421 static int dca_bindchains_one(dca_request_t *reqp, size_t cnt, int dr_offset,
 422     caddr_t kaddr, ddi_dma_handle_t handle, uint_t flags,
 423     dca_chain_t *head, int *n_chain);
 424 static uint64_t dca_ena(uint64_t ena);
 425 static caddr_t dca_bufdaddr_out(crypto_data_t *data);
 426 static char *dca_fma_eclass_string(char *model, dca_fma_eclass_t index);
 427 static int dca_check_acc_handle(dca_t *dca, ddi_acc_handle_t handle,
 428     dca_fma_eclass_t eclass_index);
 429 
 430 static void dca_fma_init(dca_t *dca);
 431 static void dca_fma_fini(dca_t *dca);
 432 static int dca_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err,
 433     const void *impl_data);
 434 
 435 
 436 static dca_device_t dca_devices[] = {
 437         /* Broadcom vanilla variants */


3672 
3673 /* ARGSUSED */
3674 static void
3675 dca_provider_status(crypto_provider_handle_t provider, uint_t *status)
3676 {
3677         *status = CRYPTO_PROVIDER_READY;
3678 }
3679 
3680 /*
3681  * Cipher (encrypt/decrypt) entry points.
3682  */
3683 
3684 /* ARGSUSED */
3685 static int
3686 dca_encrypt_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
3687     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
3688     crypto_req_handle_t req)
3689 {
3690         int error = CRYPTO_FAILED;
3691         dca_t *softc;


3692 
3693         softc = DCA_SOFTC_FROM_CTX(ctx);

3694         DBG(softc, DENTRY, "dca_encrypt_init: started");
3695 
3696         /* check mechanism */
3697         switch (mechanism->cm_type) {
3698         case DES_CBC_MECH_INFO_TYPE:
3699                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3700                     DR_ENCRYPT);
3701                 break;
3702         case DES3_CBC_MECH_INFO_TYPE:
3703                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3704                     DR_ENCRYPT | DR_TRIPLE);
3705                 break;
3706         case RSA_PKCS_MECH_INFO_TYPE:
3707         case RSA_X_509_MECH_INFO_TYPE:
3708                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
3709                 break;
3710         default:
3711                 cmn_err(CE_WARN, "dca_encrypt_init: unexpected mech type "
3712                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
3713                 error = CRYPTO_MECHANISM_INVALID;
3714         }
3715 
3716         DBG(softc, DENTRY, "dca_encrypt_init: done, err = 0x%x", error);
3717 
3718         if (error == CRYPTO_SUCCESS)
3719                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
3720                     &softc->dca_ctx_list_lock);
3721 
3722         return (error);
3723 }
3724 
3725 /* ARGSUSED */
3726 static int
3727 dca_encrypt(crypto_ctx_t *ctx, crypto_data_t *plaintext,
3728     crypto_data_t *ciphertext, crypto_req_handle_t req)
3729 {
3730         int error = CRYPTO_FAILED;
3731         dca_t *softc;


3732 
3733         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3734                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3735 
3736         softc = DCA_SOFTC_FROM_CTX(ctx);

3737         DBG(softc, DENTRY, "dca_encrypt: started");
3738 
3739         /* handle inplace ops */
3740         if (!ciphertext) {
3741                 dca_request_t *reqp = ctx->cc_provider_private;
3742                 reqp->dr_flags |= DR_INPLACE;
3743                 ciphertext = plaintext;
3744         }
3745 
3746         /* check mechanism */
3747         switch (DCA_MECH_FROM_CTX(ctx)) {
3748         case DES_CBC_MECH_INFO_TYPE:
3749                 error = dca_3des(ctx, plaintext, ciphertext, req, DR_ENCRYPT);
3750                 break;
3751         case DES3_CBC_MECH_INFO_TYPE:
3752                 error = dca_3des(ctx, plaintext, ciphertext, req,
3753                     DR_ENCRYPT | DR_TRIPLE);
3754                 break;
3755         case RSA_PKCS_MECH_INFO_TYPE:
3756         case RSA_X_509_MECH_INFO_TYPE:


3764                 error = CRYPTO_MECHANISM_INVALID;
3765         }
3766 
3767         if ((error != CRYPTO_QUEUED) && (error != CRYPTO_SUCCESS) &&
3768             (error != CRYPTO_BUFFER_TOO_SMALL)) {
3769                 ciphertext->cd_length = 0;
3770         }
3771 
3772         DBG(softc, DENTRY, "dca_encrypt: done, err = 0x%x", error);
3773 
3774         return (error);
3775 }
3776 
3777 /* ARGSUSED */
3778 static int
3779 dca_encrypt_update(crypto_ctx_t *ctx, crypto_data_t *plaintext,
3780     crypto_data_t *ciphertext, crypto_req_handle_t req)
3781 {
3782         int error = CRYPTO_FAILED;
3783         dca_t *softc;


3784 
3785         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3786                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3787 
3788         softc = DCA_SOFTC_FROM_CTX(ctx);

3789         DBG(softc, DENTRY, "dca_encrypt_update: started");
3790 
3791         /* handle inplace ops */
3792         if (!ciphertext) {
3793                 dca_request_t *reqp = ctx->cc_provider_private;
3794                 reqp->dr_flags |= DR_INPLACE;
3795                 ciphertext = plaintext;
3796         }
3797 
3798         /* check mechanism */
3799         switch (DCA_MECH_FROM_CTX(ctx)) {
3800         case DES_CBC_MECH_INFO_TYPE:
3801                 error = dca_3desupdate(ctx, plaintext, ciphertext, req,
3802                     DR_ENCRYPT);
3803                 break;
3804         case DES3_CBC_MECH_INFO_TYPE:
3805                 error = dca_3desupdate(ctx, plaintext, ciphertext, req,
3806                     DR_ENCRYPT | DR_TRIPLE);
3807                 break;
3808         default:
3809                 /* Should never reach here */
3810                 cmn_err(CE_WARN, "dca_encrypt_update: unexpected mech type "
3811                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
3812                 error = CRYPTO_MECHANISM_INVALID;
3813         }
3814 
3815         DBG(softc, DENTRY, "dca_encrypt_update: done, err = 0x%x", error);
3816 
3817         return (error);
3818 }
3819 
3820 /* ARGSUSED */
3821 static int
3822 dca_encrypt_final(crypto_ctx_t *ctx, crypto_data_t *ciphertext,
3823     crypto_req_handle_t req)
3824 {
3825         int error = CRYPTO_FAILED;
3826         dca_t *softc;


3827 
3828         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3829                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3830 
3831         softc = DCA_SOFTC_FROM_CTX(ctx);

3832         DBG(softc, DENTRY, "dca_encrypt_final: started");
3833 
3834         /* check mechanism */
3835         switch (DCA_MECH_FROM_CTX(ctx)) {
3836         case DES_CBC_MECH_INFO_TYPE:
3837                 error = dca_3desfinal(ctx, ciphertext, DR_ENCRYPT);
3838                 break;
3839         case DES3_CBC_MECH_INFO_TYPE:
3840                 error = dca_3desfinal(ctx, ciphertext, DR_ENCRYPT | DR_TRIPLE);
3841                 break;
3842         default:
3843                 /* Should never reach here */
3844                 cmn_err(CE_WARN, "dca_encrypt_final: unexpected mech type "
3845                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
3846                 error = CRYPTO_MECHANISM_INVALID;
3847         }
3848 
3849         DBG(softc, DENTRY, "dca_encrypt_final: done, err = 0x%x", error);
3850 
3851         return (error);


3894                 error = CRYPTO_MECHANISM_INVALID;
3895         }
3896 
3897         if ((error != CRYPTO_QUEUED) && (error != CRYPTO_SUCCESS)) {
3898                 ciphertext->cd_length = 0;
3899         }
3900 
3901         DBG(softc, DENTRY, "dca_encrypt_atomic: done, err = 0x%x", error);
3902 
3903         return (error);
3904 }
3905 
3906 /* ARGSUSED */
3907 static int
3908 dca_decrypt_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
3909     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
3910     crypto_req_handle_t req)
3911 {
3912         int error = CRYPTO_FAILED;
3913         dca_t *softc;


3914 
3915         softc = DCA_SOFTC_FROM_CTX(ctx);

3916         DBG(softc, DENTRY, "dca_decrypt_init: started");
3917 
3918         /* check mechanism */
3919         switch (mechanism->cm_type) {
3920         case DES_CBC_MECH_INFO_TYPE:
3921                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3922                     DR_DECRYPT);
3923                 break;
3924         case DES3_CBC_MECH_INFO_TYPE:
3925                 error = dca_3desctxinit(ctx, mechanism, key, KM_SLEEP,
3926                     DR_DECRYPT | DR_TRIPLE);
3927                 break;
3928         case RSA_PKCS_MECH_INFO_TYPE:
3929         case RSA_X_509_MECH_INFO_TYPE:
3930                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
3931                 break;
3932         default:
3933                 cmn_err(CE_WARN, "dca_decrypt_init: unexpected mech type "
3934                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
3935                 error = CRYPTO_MECHANISM_INVALID;
3936         }
3937 
3938         DBG(softc, DENTRY, "dca_decrypt_init: done, err = 0x%x", error);
3939 
3940         if (error == CRYPTO_SUCCESS)
3941                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
3942                     &softc->dca_ctx_list_lock);
3943 
3944         return (error);
3945 }
3946 
3947 /* ARGSUSED */
3948 static int
3949 dca_decrypt(crypto_ctx_t *ctx, crypto_data_t *ciphertext,
3950     crypto_data_t *plaintext, crypto_req_handle_t req)
3951 {
3952         int error = CRYPTO_FAILED;
3953         dca_t *softc;


3954 
3955         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
3956                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
3957 
3958         softc = DCA_SOFTC_FROM_CTX(ctx);

3959         DBG(softc, DENTRY, "dca_decrypt: started");
3960 
3961         /* handle inplace ops */
3962         if (!plaintext) {
3963                 dca_request_t *reqp = ctx->cc_provider_private;
3964                 reqp->dr_flags |= DR_INPLACE;
3965                 plaintext = ciphertext;
3966         }
3967 
3968         /* check mechanism */
3969         switch (DCA_MECH_FROM_CTX(ctx)) {
3970         case DES_CBC_MECH_INFO_TYPE:
3971                 error = dca_3des(ctx, ciphertext, plaintext, req, DR_DECRYPT);
3972                 break;
3973         case DES3_CBC_MECH_INFO_TYPE:
3974                 error = dca_3des(ctx, ciphertext, plaintext, req,
3975                     DR_DECRYPT | DR_TRIPLE);
3976                 break;
3977         case RSA_PKCS_MECH_INFO_TYPE:
3978         case RSA_X_509_MECH_INFO_TYPE:


3987         }
3988 
3989         if ((error != CRYPTO_QUEUED) && (error != CRYPTO_SUCCESS) &&
3990             (error != CRYPTO_BUFFER_TOO_SMALL)) {
3991                 if (plaintext)
3992                         plaintext->cd_length = 0;
3993         }
3994 
3995         DBG(softc, DENTRY, "dca_decrypt: done, err = 0x%x", error);
3996 
3997         return (error);
3998 }
3999 
4000 /* ARGSUSED */
4001 static int
4002 dca_decrypt_update(crypto_ctx_t *ctx, crypto_data_t *ciphertext,
4003     crypto_data_t *plaintext, crypto_req_handle_t req)
4004 {
4005         int error = CRYPTO_FAILED;
4006         dca_t *softc;


4007 
4008         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4009                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4010 
4011         softc = DCA_SOFTC_FROM_CTX(ctx);

4012         DBG(softc, DENTRY, "dca_decrypt_update: started");
4013 
4014         /* handle inplace ops */
4015         if (!plaintext) {
4016                 dca_request_t *reqp = ctx->cc_provider_private;
4017                 reqp->dr_flags |= DR_INPLACE;
4018                 plaintext = ciphertext;
4019         }
4020 
4021         /* check mechanism */
4022         switch (DCA_MECH_FROM_CTX(ctx)) {
4023         case DES_CBC_MECH_INFO_TYPE:
4024                 error = dca_3desupdate(ctx, ciphertext, plaintext, req,
4025                     DR_DECRYPT);
4026                 break;
4027         case DES3_CBC_MECH_INFO_TYPE:
4028                 error = dca_3desupdate(ctx, ciphertext, plaintext, req,
4029                     DR_DECRYPT | DR_TRIPLE);
4030                 break;
4031         default:
4032                 /* Should never reach here */
4033                 cmn_err(CE_WARN, "dca_decrypt_update: unexpected mech type "
4034                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4035                 error = CRYPTO_MECHANISM_INVALID;
4036         }
4037 
4038         DBG(softc, DENTRY, "dca_decrypt_update: done, err = 0x%x", error);
4039 
4040         return (error);
4041 }
4042 
4043 /* ARGSUSED */
4044 static int
4045 dca_decrypt_final(crypto_ctx_t *ctx, crypto_data_t *plaintext,
4046     crypto_req_handle_t req)
4047 {
4048         int error = CRYPTO_FAILED;
4049         dca_t *softc;


4050 
4051         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4052                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4053 
4054         softc = DCA_SOFTC_FROM_CTX(ctx);

4055         DBG(softc, DENTRY, "dca_decrypt_final: started");
4056 
4057         /* check mechanism */
4058         switch (DCA_MECH_FROM_CTX(ctx)) {
4059         case DES_CBC_MECH_INFO_TYPE:
4060                 error = dca_3desfinal(ctx, plaintext, DR_DECRYPT);
4061                 break;
4062         case DES3_CBC_MECH_INFO_TYPE:
4063                 error = dca_3desfinal(ctx, plaintext, DR_DECRYPT | DR_TRIPLE);
4064                 break;
4065         default:
4066                 /* Should never reach here */
4067                 cmn_err(CE_WARN, "dca_decrypt_final: unexpected mech type "
4068                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4069                 error = CRYPTO_MECHANISM_INVALID;
4070         }
4071 
4072         DBG(softc, DENTRY, "dca_decrypt_final: done, err = 0x%x", error);
4073 
4074         return (error);


4121                 plaintext->cd_length = 0;
4122         }
4123 
4124         DBG(softc, DENTRY, "dca_decrypt_atomic: done, err = 0x%x", error);
4125 
4126         return (error);
4127 }
4128 
4129 /*
4130  * Sign entry points.
4131  */
4132 
4133 /* ARGSUSED */
4134 static int
4135 dca_sign_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4136     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4137     crypto_req_handle_t req)
4138 {
4139         int error = CRYPTO_FAILED;
4140         dca_t *softc;


4141 
4142         softc = DCA_SOFTC_FROM_CTX(ctx);

4143         DBG(softc, DENTRY, "dca_sign_init: started\n");
4144 
4145         if (ctx_template != NULL)
4146                 return (CRYPTO_ARGUMENTS_BAD);
4147 
4148         /* check mechanism */
4149         switch (mechanism->cm_type) {
4150         case RSA_PKCS_MECH_INFO_TYPE:
4151         case RSA_X_509_MECH_INFO_TYPE:
4152                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4153                 break;
4154         case DSA_MECH_INFO_TYPE:
4155                 error = dca_dsainit(ctx, mechanism, key, KM_SLEEP,
4156                     DCA_DSA_SIGN);
4157                 break;
4158         default:
4159                 cmn_err(CE_WARN, "dca_sign_init: unexpected mech type "
4160                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4161                 error = CRYPTO_MECHANISM_INVALID;
4162         }
4163 
4164         DBG(softc, DENTRY, "dca_sign_init: done, err = 0x%x", error);
4165 
4166         if (error == CRYPTO_SUCCESS)
4167                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4168                     &softc->dca_ctx_list_lock);
4169 
4170         return (error);
4171 }
4172 
4173 static int
4174 dca_sign(crypto_ctx_t *ctx, crypto_data_t *data,
4175     crypto_data_t *signature, crypto_req_handle_t req)
4176 {
4177         int error = CRYPTO_FAILED;
4178         dca_t *softc;


4179 
4180         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4181                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4182 
4183         softc = DCA_SOFTC_FROM_CTX(ctx);

4184         DBG(softc, DENTRY, "dca_sign: started\n");
4185 
4186         /* check mechanism */
4187         switch (DCA_MECH_FROM_CTX(ctx)) {
4188         case RSA_PKCS_MECH_INFO_TYPE:
4189         case RSA_X_509_MECH_INFO_TYPE:
4190                 error = dca_rsastart(ctx, data, signature, req, DCA_RSA_SIGN);
4191                 break;
4192         case DSA_MECH_INFO_TYPE:
4193                 error = dca_dsa_sign(ctx, data, signature, req);
4194                 break;
4195         default:
4196                 cmn_err(CE_WARN, "dca_sign: unexpected mech type "
4197                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4198                 error = CRYPTO_MECHANISM_INVALID;
4199         }
4200 
4201         DBG(softc, DENTRY, "dca_sign: done, err = 0x%x", error);
4202 
4203         return (error);
4204 }
4205 
4206 /* ARGSUSED */
4207 static int
4208 dca_sign_update(crypto_ctx_t *ctx, crypto_data_t *data,
4209     crypto_req_handle_t req)
4210 {
4211         int error = CRYPTO_MECHANISM_INVALID;
4212         dca_t *softc;


4213 
4214         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4215                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4216 
4217         softc = DCA_SOFTC_FROM_CTX(ctx);

4218         DBG(softc, DENTRY, "dca_sign_update: started\n");
4219 
4220         cmn_err(CE_WARN, "dca_sign_update: unexpected mech type "
4221             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4222 
4223         DBG(softc, DENTRY, "dca_sign_update: done, err = 0x%x", error);
4224 
4225         return (error);
4226 }
4227 
4228 /* ARGSUSED */
4229 static int
4230 dca_sign_final(crypto_ctx_t *ctx, crypto_data_t *signature,
4231     crypto_req_handle_t req)
4232 {
4233         int error = CRYPTO_MECHANISM_INVALID;
4234         dca_t *softc;


4235 
4236         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4237                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4238 
4239         softc = DCA_SOFTC_FROM_CTX(ctx);

4240         DBG(softc, DENTRY, "dca_sign_final: started\n");
4241 
4242         cmn_err(CE_WARN, "dca_sign_final: unexpected mech type "
4243             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4244 
4245         DBG(softc, DENTRY, "dca_sign_final: done, err = 0x%x", error);
4246 
4247         return (error);
4248 }
4249 
4250 static int
4251 dca_sign_atomic(crypto_provider_handle_t provider,
4252     crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
4253     crypto_key_t *key, crypto_data_t *data, crypto_data_t *signature,
4254     crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
4255 {
4256         int error = CRYPTO_FAILED;
4257         dca_t *softc = (dca_t *)provider;
4258 
4259         DBG(softc, DENTRY, "dca_sign_atomic: started\n");


4274                 break;
4275         default:
4276                 cmn_err(CE_WARN, "dca_sign_atomic: unexpected mech type "
4277                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4278                 error = CRYPTO_MECHANISM_INVALID;
4279         }
4280 
4281         DBG(softc, DENTRY, "dca_sign_atomic: done, err = 0x%x", error);
4282 
4283         return (error);
4284 }
4285 
4286 /* ARGSUSED */
4287 static int
4288 dca_sign_recover_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4289     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4290     crypto_req_handle_t req)
4291 {
4292         int error = CRYPTO_FAILED;
4293         dca_t *softc;


4294 
4295         softc = DCA_SOFTC_FROM_CTX(ctx);

4296         DBG(softc, DENTRY, "dca_sign_recover_init: started\n");
4297 
4298         if (ctx_template != NULL)
4299                 return (CRYPTO_ARGUMENTS_BAD);
4300 
4301         /* check mechanism */
4302         switch (mechanism->cm_type) {
4303         case RSA_PKCS_MECH_INFO_TYPE:
4304         case RSA_X_509_MECH_INFO_TYPE:
4305                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4306                 break;
4307         default:
4308                 cmn_err(CE_WARN, "dca_sign_recover_init: unexpected mech type "
4309                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4310                 error = CRYPTO_MECHANISM_INVALID;
4311         }
4312 
4313         DBG(softc, DENTRY, "dca_sign_recover_init: done, err = 0x%x", error);
4314 
4315         if (error == CRYPTO_SUCCESS)
4316                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4317                     &softc->dca_ctx_list_lock);
4318 
4319         return (error);
4320 }
4321 
4322 static int
4323 dca_sign_recover(crypto_ctx_t *ctx, crypto_data_t *data,
4324     crypto_data_t *signature, crypto_req_handle_t req)
4325 {
4326         int error = CRYPTO_FAILED;
4327         dca_t *softc;


4328 
4329         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4330                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4331 
4332         softc = DCA_SOFTC_FROM_CTX(ctx);

4333         DBG(softc, DENTRY, "dca_sign_recover: started\n");
4334 
4335         /* check mechanism */
4336         switch (DCA_MECH_FROM_CTX(ctx)) {
4337         case RSA_PKCS_MECH_INFO_TYPE:
4338         case RSA_X_509_MECH_INFO_TYPE:
4339                 error = dca_rsastart(ctx, data, signature, req, DCA_RSA_SIGNR);
4340                 break;
4341         default:
4342                 cmn_err(CE_WARN, "dca_sign_recover: unexpected mech type "
4343                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4344                 error = CRYPTO_MECHANISM_INVALID;
4345         }
4346 
4347         DBG(softc, DENTRY, "dca_sign_recover: done, err = 0x%x", error);
4348 
4349         return (error);
4350 }
4351 
4352 static int
4353 dca_sign_recover_atomic(crypto_provider_handle_t provider,
4354     crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
4355     crypto_key_t *key, crypto_data_t *data, crypto_data_t *signature,
4356     crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
4357 {
4358         int error = CRYPTO_FAILED;
4359         dca_t *softc = (dca_t *)provider;


4360 

4361         DBG(softc, DENTRY, "dca_sign_recover_atomic: started\n");
4362 
4363         if (ctx_template != NULL)
4364                 return (CRYPTO_ARGUMENTS_BAD);
4365 
4366         /* check mechanism */
4367         switch (mechanism->cm_type) {
4368         case RSA_PKCS_MECH_INFO_TYPE:
4369         case RSA_X_509_MECH_INFO_TYPE:
4370                 error = dca_rsaatomic(provider, session_id, mechanism, key,
4371                     data, signature, KM_SLEEP, req, DCA_RSA_SIGNR);
4372                 break;
4373         default:
4374                 cmn_err(CE_WARN, "dca_sign_recover_atomic: unexpected mech type"
4375                     " 0x%llx\n", (unsigned long long)mechanism->cm_type);
4376                 error = CRYPTO_MECHANISM_INVALID;
4377         }
4378 
4379         DBG(softc, DENTRY, "dca_sign_recover_atomic: done, err = 0x%x", error);
4380 
4381         return (error);
4382 }
4383 
4384 /*
4385  * Verify entry points.
4386  */
4387 
4388 /* ARGSUSED */
4389 static int
4390 dca_verify_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4391     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4392     crypto_req_handle_t req)
4393 {
4394         int error = CRYPTO_FAILED;
4395         dca_t *softc;


4396 
4397         softc = DCA_SOFTC_FROM_CTX(ctx);

4398         DBG(softc, DENTRY, "dca_verify_init: started\n");
4399 
4400         if (ctx_template != NULL)
4401                 return (CRYPTO_ARGUMENTS_BAD);
4402 
4403         /* check mechanism */
4404         switch (mechanism->cm_type) {
4405         case RSA_PKCS_MECH_INFO_TYPE:
4406         case RSA_X_509_MECH_INFO_TYPE:
4407                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4408                 break;
4409         case DSA_MECH_INFO_TYPE:
4410                 error = dca_dsainit(ctx, mechanism, key, KM_SLEEP,
4411                     DCA_DSA_VRFY);
4412                 break;
4413         default:
4414                 cmn_err(CE_WARN, "dca_verify_init: unexpected mech type "
4415                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4416                 error = CRYPTO_MECHANISM_INVALID;
4417         }
4418 
4419         DBG(softc, DENTRY, "dca_verify_init: done, err = 0x%x", error);
4420 
4421         if (error == CRYPTO_SUCCESS)
4422                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4423                     &softc->dca_ctx_list_lock);
4424 
4425         return (error);
4426 }
4427 
4428 static int
4429 dca_verify(crypto_ctx_t *ctx, crypto_data_t *data, crypto_data_t *signature,
4430     crypto_req_handle_t req)
4431 {
4432         int error = CRYPTO_FAILED;
4433         dca_t *softc;


4434 
4435         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4436                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4437 
4438         softc = DCA_SOFTC_FROM_CTX(ctx);

4439         DBG(softc, DENTRY, "dca_verify: started\n");
4440 
4441         /* check mechanism */
4442         switch (DCA_MECH_FROM_CTX(ctx)) {
4443         case RSA_PKCS_MECH_INFO_TYPE:
4444         case RSA_X_509_MECH_INFO_TYPE:
4445                 error = dca_rsastart(ctx, signature, data, req, DCA_RSA_VRFY);
4446                 break;
4447         case DSA_MECH_INFO_TYPE:
4448                 error = dca_dsa_verify(ctx, data, signature, req);
4449                 break;
4450         default:
4451                 cmn_err(CE_WARN, "dca_verify: unexpected mech type "
4452                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4453                 error = CRYPTO_MECHANISM_INVALID;
4454         }
4455 
4456         DBG(softc, DENTRY, "dca_verify: done, err = 0x%x", error);
4457 
4458         return (error);
4459 }
4460 
4461 /* ARGSUSED */
4462 static int
4463 dca_verify_update(crypto_ctx_t *ctx, crypto_data_t *data,
4464     crypto_req_handle_t req)
4465 {
4466         int error = CRYPTO_MECHANISM_INVALID;
4467         dca_t *softc;


4468 
4469         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4470                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4471 
4472         softc = DCA_SOFTC_FROM_CTX(ctx);

4473         DBG(softc, DENTRY, "dca_verify_update: started\n");
4474 
4475         cmn_err(CE_WARN, "dca_verify_update: unexpected mech type "
4476             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4477 
4478         DBG(softc, DENTRY, "dca_verify_update: done, err = 0x%x", error);
4479 
4480         return (error);
4481 }
4482 
4483 /* ARGSUSED */
4484 static int
4485 dca_verify_final(crypto_ctx_t *ctx, crypto_data_t *signature,
4486     crypto_req_handle_t req)
4487 {
4488         int error = CRYPTO_MECHANISM_INVALID;
4489         dca_t *softc;


4490 
4491         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4492                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4493 
4494         softc = DCA_SOFTC_FROM_CTX(ctx);

4495         DBG(softc, DENTRY, "dca_verify_final: started\n");
4496 
4497         cmn_err(CE_WARN, "dca_verify_final: unexpected mech type "
4498             "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4499 
4500         DBG(softc, DENTRY, "dca_verify_final: done, err = 0x%x", error);
4501 
4502         return (error);
4503 }
4504 
4505 static int
4506 dca_verify_atomic(crypto_provider_handle_t provider,
4507     crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
4508     crypto_key_t *key, crypto_data_t *data, crypto_data_t *signature,
4509     crypto_spi_ctx_template_t ctx_template, crypto_req_handle_t req)
4510 {
4511         int error = CRYPTO_FAILED;
4512         dca_t *softc = (dca_t *)provider;
4513 
4514         DBG(softc, DENTRY, "dca_verify_atomic: started\n");


4529                 break;
4530         default:
4531                 cmn_err(CE_WARN, "dca_verify_atomic: unexpected mech type "
4532                     "0x%llx\n", (unsigned long long)mechanism->cm_type);
4533                 error = CRYPTO_MECHANISM_INVALID;
4534         }
4535 
4536         DBG(softc, DENTRY, "dca_verify_atomic: done, err = 0x%x", error);
4537 
4538         return (error);
4539 }
4540 
4541 /* ARGSUSED */
4542 static int
4543 dca_verify_recover_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
4544     crypto_key_t *key, crypto_spi_ctx_template_t ctx_template,
4545     crypto_req_handle_t req)
4546 {
4547         int error = CRYPTO_MECHANISM_INVALID;
4548         dca_t *softc;


4549 
4550         softc = DCA_SOFTC_FROM_CTX(ctx);

4551         DBG(softc, DENTRY, "dca_verify_recover_init: started\n");
4552 
4553         if (ctx_template != NULL)
4554                 return (CRYPTO_ARGUMENTS_BAD);
4555 
4556         /* check mechanism */
4557         switch (mechanism->cm_type) {
4558         case RSA_PKCS_MECH_INFO_TYPE:
4559         case RSA_X_509_MECH_INFO_TYPE:
4560                 error = dca_rsainit(ctx, mechanism, key, KM_SLEEP);
4561                 break;
4562         default:
4563                 cmn_err(CE_WARN, "dca_verify_recover_init: unexpected mech type"
4564                     " 0x%llx\n", (unsigned long long)mechanism->cm_type);
4565         }
4566 
4567         DBG(softc, DENTRY, "dca_verify_recover_init: done, err = 0x%x", error);
4568 
4569         if (error == CRYPTO_SUCCESS)
4570                 dca_enlist2(&softc->dca_ctx_list, ctx->cc_provider_private,
4571                     &softc->dca_ctx_list_lock);
4572 
4573         return (error);
4574 }
4575 
4576 static int
4577 dca_verify_recover(crypto_ctx_t *ctx, crypto_data_t *signature,
4578     crypto_data_t *data, crypto_req_handle_t req)
4579 {
4580         int error = CRYPTO_MECHANISM_INVALID;
4581         dca_t *softc;


4582 
4583         if (!ctx || !ctx->cc_provider || !ctx->cc_provider_private)
4584                 return (CRYPTO_OPERATION_NOT_INITIALIZED);
4585 
4586         softc = DCA_SOFTC_FROM_CTX(ctx);

4587         DBG(softc, DENTRY, "dca_verify_recover: started\n");
4588 
4589         /* check mechanism */
4590         switch (DCA_MECH_FROM_CTX(ctx)) {
4591         case RSA_PKCS_MECH_INFO_TYPE:
4592         case RSA_X_509_MECH_INFO_TYPE:
4593                 error = dca_rsastart(ctx, signature, data, req, DCA_RSA_VRFYR);
4594                 break;
4595         default:
4596                 cmn_err(CE_WARN, "dca_verify_recover: unexpected mech type "
4597                     "0x%llx\n", (unsigned long long)DCA_MECH_FROM_CTX(ctx));
4598         }
4599 
4600         DBG(softc, DENTRY, "dca_verify_recover: done, err = 0x%x", error);
4601 
4602         return (error);
4603 }
4604 
4605 static int
4606 dca_verify_recover_atomic(crypto_provider_handle_t provider,


4630         }
4631 
4632         DBG(softc, DENTRY,
4633             "dca_verify_recover_atomic: done, err = 0x%x", error);
4634 
4635         return (error);
4636 }
4637 
4638 /*
4639  * Random number entry points.
4640  */
4641 
4642 /* ARGSUSED */
4643 static int
4644 dca_generate_random(crypto_provider_handle_t provider,
4645     crypto_session_id_t session_id,
4646     uchar_t *buf, size_t len, crypto_req_handle_t req)
4647 {
4648         int error = CRYPTO_FAILED;
4649         dca_t *softc = (dca_t *)provider;


4650 

4651         DBG(softc, DENTRY, "dca_generate_random: started");
4652 
4653         error = dca_rng(softc, buf, len, req);
4654 
4655         DBG(softc, DENTRY, "dca_generate_random: done, err = 0x%x", error);
4656 
4657         return (error);
4658 }
4659 
4660 /*
4661  * Context management entry points.
4662  */
4663 
4664 int
4665 dca_free_context(crypto_ctx_t *ctx)
4666 {
4667         int error = CRYPTO_SUCCESS;
4668         dca_t *softc;


4669 
4670         softc = DCA_SOFTC_FROM_CTX(ctx);

4671         DBG(softc, DENTRY, "dca_free_context: entered");
4672 
4673         if (ctx->cc_provider_private == NULL)
4674                 return (error);
4675 
4676         dca_rmlist2(ctx->cc_provider_private, &softc->dca_ctx_list_lock);
4677 
4678         error = dca_free_context_low(ctx);
4679 
4680         DBG(softc, DENTRY, "dca_free_context: done, err = 0x%x", error);
4681 
4682         return (error);
4683 }
4684 
4685 static int
4686 dca_free_context_low(crypto_ctx_t *ctx)
4687 {
4688         int error = CRYPTO_SUCCESS;
4689 
4690         /* check mechanism */