| 182 | } |
| 183 | |
| 184 | int |
| 185 | padlock_cipher_process(struct padlock_session *ses, struct cryptop *crp, |
| 186 | const struct crypto_session_params *csp) |
| 187 | { |
| 188 | union padlock_cw *cw; |
| 189 | struct thread *td; |
| 190 | u_char *buf, *abuf; |
| 191 | uint32_t *key; |
| 192 | uint8_t iv[AES_BLOCK_LEN] __aligned(16); |
| 193 | int allocated; |
| 194 | |
| 195 | buf = padlock_cipher_alloc(crp, &allocated); |
| 196 | if (buf == NULL) |
| 197 | return (ENOMEM); |
| 198 | /* Buffer has to be 16 bytes aligned. */ |
| 199 | abuf = PADLOCK_ALIGN(buf); |
| 200 | |
| 201 | if (crp->crp_cipher_key != NULL) { |
| 202 | padlock_cipher_key_setup(ses, crp->crp_cipher_key, |
| 203 | csp->csp_cipher_klen); |
| 204 | } |
| 205 | |
| 206 | cw = &ses->ses_cw; |
| 207 | cw->cw_filler0 = 0; |
| 208 | cw->cw_filler1 = 0; |
| 209 | cw->cw_filler2 = 0; |
| 210 | cw->cw_filler3 = 0; |
| 211 | |
| 212 | crypto_read_iv(crp, iv); |
| 213 | |
| 214 | if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) { |
| 215 | cw->cw_direction = PADLOCK_DIRECTION_ENCRYPT; |
| 216 | key = ses->ses_ekey; |
| 217 | } else { |
| 218 | cw->cw_direction = PADLOCK_DIRECTION_DECRYPT; |
| 219 | key = ses->ses_dkey; |
| 220 | } |
| 221 | |
| 222 | if (allocated) { |
| 223 | crypto_copydata(crp, crp->crp_payload_start, |
| 224 | crp->crp_payload_length, abuf); |
| 225 | } |
| 226 | |
| 227 | td = curthread; |
| 228 | fpu_kern_enter(td, ses->ses_fpu_ctx, FPU_KERN_NORMAL | FPU_KERN_KTHR); |
| 229 | padlock_cbc(abuf, abuf, crp->crp_payload_length / AES_BLOCK_LEN, key, |
| 230 | cw, iv); |
| 231 | fpu_kern_leave(td, ses->ses_fpu_ctx); |
| 232 | |
| 233 | if (allocated) { |
| 234 | crypto_copyback(crp, crp->crp_payload_start, |
| 235 | crp->crp_payload_length, abuf); |
| 236 | |
| 237 | zfree(buf, M_PADLOCK); |
| 238 | } |
| 239 | return (0); |
| 240 | } |
no test coverage detected